2013-09-19 15:02:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-04-30 08:46:01 +00:00
|
|
|
* Copyright (C) 2013-2015 CERN
|
2013-09-19 15:02:57 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-27 16:51:21 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2013-09-19 15:02:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-09-18 17:56:37 +00:00
|
|
|
#ifndef __TOOL_ACTION_H
|
|
|
|
#define __TOOL_ACTION_H
|
|
|
|
|
|
|
|
#include <string>
|
2013-09-26 12:09:18 +00:00
|
|
|
#include <cassert>
|
2013-09-18 17:56:37 +00:00
|
|
|
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_event.h>
|
2013-09-18 17:56:37 +00:00
|
|
|
|
2015-04-02 14:09:48 +00:00
|
|
|
struct BITMAP_OPAQUE;
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
/**
|
|
|
|
* Class TOOL_ACTION
|
|
|
|
*
|
|
|
|
* Represents a single user action. For instance:
|
|
|
|
* - changing layer to top by pressing PgUp
|
|
|
|
* - running the DRC from the menu
|
|
|
|
* and so on, and so forth....
|
|
|
|
* Action class groups all necessary properties of an action, including explanation,
|
2015-04-30 08:46:01 +00:00
|
|
|
* icons, hotkeys, menu items, etc.
|
2013-09-27 16:51:21 +00:00
|
|
|
*/
|
2013-09-19 15:02:57 +00:00
|
|
|
class TOOL_ACTION
|
2013-09-18 17:56:37 +00:00
|
|
|
{
|
2013-09-19 15:02:57 +00:00
|
|
|
public:
|
2013-10-14 18:40:36 +00:00
|
|
|
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
|
2019-06-09 21:57:23 +00:00
|
|
|
int aDefaultHotKey = 0, const std::string& aLegacyHotKeyName = "",
|
|
|
|
const wxString& aMenuText = wxEmptyString, const wxString& aTooltip = wxEmptyString,
|
|
|
|
const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE,
|
|
|
|
void* aParam = nullptr );
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2015-05-05 18:39:41 +00:00
|
|
|
~TOOL_ACTION();
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
bool operator==( const TOOL_ACTION& aRhs ) const
|
|
|
|
{
|
|
|
|
return m_id == aRhs.m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=( const TOOL_ACTION& aRhs ) const
|
|
|
|
{
|
|
|
|
return m_id != aRhs.m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetName()
|
|
|
|
* Returns name of the action. It is the same one that is contained in TOOL_EVENT that is
|
2019-06-09 21:57:23 +00:00
|
|
|
* sent by activating the TOOL_ACTION. Convention is "app.tool.actionName".
|
2013-09-19 15:02:57 +00:00
|
|
|
*
|
|
|
|
* @return Name of the action.
|
|
|
|
*/
|
2019-06-09 21:57:23 +00:00
|
|
|
const std::string& GetName() const { return m_name; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetDefaultHotKey()
|
|
|
|
* Returns the default hotkey (if any) for the action.
|
|
|
|
*/
|
|
|
|
int GetDefaultHotKey() const { return m_defaultHotKey; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetHotKey()
|
|
|
|
* Returns the hotkey keycode which initiates the action.
|
|
|
|
*/
|
|
|
|
int GetHotKey() const { return m_hotKey; }
|
2019-06-10 14:23:37 +00:00
|
|
|
void SetHotKey( int aKeycode );
|
2019-06-09 21:57:23 +00:00
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
/**
|
|
|
|
* Function GetId()
|
|
|
|
* Returns the unique id of the TOOL_ACTION object. It is valid only after registering the
|
|
|
|
* TOOL_ACTION by ACTION_MANAGER.
|
|
|
|
*
|
|
|
|
* @return The unique identification number. If the number is negative, then it is not valid.
|
|
|
|
*/
|
2019-06-09 21:57:23 +00:00
|
|
|
int GetId() const { return m_id; }
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-27 16:51:21 +00:00
|
|
|
* Function MakeEvent()
|
2014-07-09 11:50:27 +00:00
|
|
|
* Returns the event associated with the action (i.e. the event that will be sent after
|
2013-09-19 15:02:57 +00:00
|
|
|
* activating the action).
|
|
|
|
*/
|
2013-09-27 16:51:21 +00:00
|
|
|
TOOL_EVENT MakeEvent() const
|
2013-09-19 15:02:57 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
if( IsActivation() )
|
2015-04-30 08:46:01 +00:00
|
|
|
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
|
2014-07-09 13:10:32 +00:00
|
|
|
else if( IsNotification() )
|
2015-04-30 08:46:01 +00:00
|
|
|
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
|
2014-07-09 11:50:27 +00:00
|
|
|
else
|
2015-04-30 08:46:01 +00:00
|
|
|
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 14:23:37 +00:00
|
|
|
const wxString& GetLabel() const { return m_label; }
|
|
|
|
|
|
|
|
const wxString& GetMenuItem() const { return m_menuItem; }
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
const wxString& GetDescription() const { return m_tooltip; }
|
|
|
|
void SetDescription( const wxString& aDescription ) { m_tooltip = aDescription; }
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
TOOL_ACTION_SCOPE GetScope() const { return m_scope; }
|
2014-04-09 15:05:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns name of the tool associated with the action. It is basically the action name
|
|
|
|
* stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is
|
|
|
|
* "pcbnew.InteractiveDrawing").
|
|
|
|
*/
|
2014-07-09 11:50:27 +00:00
|
|
|
std::string GetToolName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the action is intended to activate a tool.
|
|
|
|
*/
|
|
|
|
bool IsActivation() const
|
2014-04-09 15:05:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
return m_flags & AF_ACTIVATE;
|
2014-04-09 15:05:05 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the action is a notification.
|
|
|
|
*/
|
|
|
|
bool IsNotification() const
|
|
|
|
{
|
|
|
|
return m_flags & AF_NOTIFY;
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:48 +00:00
|
|
|
/**
|
|
|
|
* Returns an icon associated with the action. It is used in context menu.
|
|
|
|
*/
|
|
|
|
const BITMAP_OPAQUE* GetIcon() const
|
|
|
|
{
|
|
|
|
return m_icon;
|
|
|
|
}
|
|
|
|
|
2019-06-12 14:39:47 +00:00
|
|
|
protected:
|
|
|
|
TOOL_ACTION();
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
friend class ACTION_MANAGER;
|
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
/// Name of the action (convention is "app.tool.actionName")
|
|
|
|
std::string m_name;
|
|
|
|
TOOL_ACTION_SCOPE m_scope;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
const int m_defaultHotKey; // Default hot key
|
|
|
|
int m_hotKey; // The curret hotkey (post-user-settings-application)
|
|
|
|
const std::string m_legacyName; // Name for reading legacy hotkey settings
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2019-06-12 14:39:47 +00:00
|
|
|
wxString m_label;
|
2019-06-10 14:23:37 +00:00
|
|
|
wxString m_menuItem; // Label + hotkey text for menus
|
2019-06-09 21:57:23 +00:00
|
|
|
wxString m_tooltip;
|
|
|
|
const BITMAP_OPAQUE* m_icon; // Icon for the menu entry
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
int m_id; // Unique ID for maps. Assigned by ACTION_MANAGER.
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
TOOL_ACTION_FLAGS m_flags;
|
|
|
|
void* m_param; // Generic parameter
|
2015-05-05 18:39:42 +00:00
|
|
|
|
2013-09-18 17:56:37 +00:00
|
|
|
};
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2013-09-18 17:56:37 +00:00
|
|
|
#endif
|