mousetrap v0.2.0
Loading...
Searching...
No Matches
mousetrap::Action Class Reference

Command with a name, registered to an application. See the manual section on actions for more information. More...

#include <action.hpp>

Inheritance diagram for mousetrap::Action:
mousetrap::SignalEmitter mousetrap::has_signal_activated< Action >

Public Member Functions

 Action (const std::string &id, Application &application)
 construct an action with immutable id
 
 Action (detail::ActionInternal *internal)
 create from internal
 
 ~Action ()
 dtor
 
ActionID get_id () const
 get action id
 
 Action (const Action &)
 copy ctor delete
 
 Action (Action &&) noexcept
 move ctor
 
Actionoperator= (const Action &)=delete
 copy assignment deleted, actions should not be duplicated
 
Actionoperator= (Action &&) noexcept=delete
 move assignment deleted, actions should not be moved
 
 operator NativeObject () const override
 expose as GObject
 
NativeObject get_internal () const override
 get internal
 
template<typename Function_t >
void set_function (Function_t f)
 create action as stateless, given function is executed when action is triggered
 
template<typename Function_t , typename Data_t >
void set_function (Function_t f, Data_t data)
 create action as stateless, given function is executed when action is triggered
 
template<typename Function_t >
void set_stateful_function (Function_t f, bool initial_state=false)
 create action as stateful, given function is executed when action is triggered
 
template<typename Function_t , typename Data_t >
void set_stateful_function (Function_t f, Data_t data, bool initial_state=false)
 create action as stateful, given function is executed when action is triggered
 
void set_state (bool new_state)
 set the state of a stateful action, if the action is not stateful, does nothing
 
bool get_state () const
 get state of a stateful action, if the action is not stateful, returns false
 
void activate ()
 trigger the action
 
void add_shortcut (const ShortcutTriggerID &trigger)
 add a shortcut trigger for action, warns but does not throw if trigger is malformed
 
const std::vector< ShortcutTriggerID > & get_shortcuts () const
 get shortcuts for action
 
void clear_shortcuts ()
 reset all shortcuts
 
void set_enabled (bool is_enabled)
 set whether triggering the action will execute the registered function
 
bool get_enabled () const
 get whether the action is currently enabled
 
bool get_is_stateful () const
 get whether the action is stateful
 
- Public Member Functions inherited from mousetrap::SignalEmitter
void set_signal_blocked (const std::string &signal_id, bool b)
 block a signal by id \for_internal_use_only
 
bool get_signal_blocked (const std::string &signal_id) const
 get whether a signal is currently blocked
 
std::vector< std::string > get_all_signal_names ()
 get list of possible signal ids \for_internal_use_only
 
template<typename Function_t >
void connect_signal (const std::string &signal_id, Function_t *function, void *data=nullptr)
 connect static function to signal, does not work with lambdas \for_internal_use_only
 
void disconnect_signal (const std::string &signal_id)
 disconnect signal, it may not be invoked until reconnected, if signal is not registered, does nothing. For internal use only
 
virtual operator NativeObject () const =0
 expose as NativeObject, this is the GLib instance that signals are emitted on \for_internal_use_only
 
virtual NativeObject get_internal () const
 expose internally managed object, \for_internal_use_only
 
- Public Member Functions inherited from mousetrap::has_signal_activated< Action >
void connect_signal_activated (Function_t f, Data_t data)
 connect handler, will be invoked when signal is emitted. Data is passed to the signal handler function
 
void connect_signal_activated (Function_t f)
 connect handler, will be invoked when signal is emitted
 
void set_signal_activated_blocked (bool b)
 
bool get_signal_activated_blocked () const
 
void emit_signal_activated (UnusedArgument_t _)
 invoke signal handler manually
 
void disconnect_signal_activated ()
 

Friends

class Application
 

Additional Inherited Members

- Static Public Attributes inherited from mousetrap::has_signal_activated< Action >
static const char * signal_id
 glib ID
 
- Protected Member Functions inherited from mousetrap::SignalEmitter
 SignalEmitter ()
 ctor
 
 ~SignalEmitter ()
 destructor
 
- Protected Member Functions inherited from mousetrap::has_signal_activated< Action >
 has_signal_activated (Action *instance)
 

Detailed Description

Command with a name, registered to an application. See the manual section on actions for more information.

signal id signature emitted when...
activated (Action&, void* _, (Data_t)) -> void Action is triggered

Constructor & Destructor Documentation

◆ Action() [1/2]

mousetrap::Action::Action ( const std::string &  id,
Application application 
)

construct an action with immutable id

Parameters
idstring, usually of the form scope.action_name
application

◆ Action() [2/2]

mousetrap::Action::Action ( detail::ActionInternal *  internal)

create from internal

Parameters
internal

Member Function Documentation

◆ add_shortcut()

void mousetrap::Action::add_shortcut ( const ShortcutTriggerID &  trigger)

add a shortcut trigger for action, warns but does not throw if trigger is malformed

Parameters
trigger
Note
shortcuts can be changed only before the action is registered with an application. If already registered, unregister the action and reregister a new action with the same behavior but different shortcuts

References mousetrap::log::critical().

◆ clear_shortcuts()

void mousetrap::Action::clear_shortcuts ( )

reset all shortcuts

Parameters
action

◆ get_enabled()

bool mousetrap::Action::get_enabled ( ) const

get whether the action is currently enabled

Returns
true if enabled, false otherwise

◆ get_id()

◆ get_internal()

NativeObject mousetrap::Action::get_internal ( ) const
overridevirtual

get internal

Reimplemented from mousetrap::SignalEmitter.

◆ get_is_stateful()

bool mousetrap::Action::get_is_stateful ( ) const

get whether the action is stateful

Returns
true if action was set as stateful, false otherwise

Referenced by mousetrap::MenuModel::add_action(), get_state(), and set_state().

◆ get_shortcuts()

const std::vector< ShortcutTriggerID > & mousetrap::Action::get_shortcuts ( ) const

◆ get_state()

bool mousetrap::Action::get_state ( ) const

get state of a stateful action, if the action is not stateful, returns false

Returns
false if state is set to false or the action is not stateful, true otherwise

References get_id(), get_is_stateful(), and mousetrap::log::warning().

Referenced by mousetrap::MenuModel::add_action().

◆ operator NativeObject()

mousetrap::Action::operator NativeObject ( ) const
overridevirtual

expose as GObject

Implements mousetrap::SignalEmitter.

◆ set_enabled()

void mousetrap::Action::set_enabled ( bool  is_enabled)

set whether triggering the action will execute the registered function

Parameters
is_enabled

Referenced by set_function(), and set_stateful_function().

◆ set_function() [1/2]

template<typename Function_t >
void mousetrap::Action::set_function ( Function_t  f)

create action as stateless, given function is executed when action is triggered

Template Parameters
Function_tlambda or static function with signature (Action&) -> void
Parameters
ffunction

References set_enabled().

◆ set_function() [2/2]

template<typename Function_t , typename Data_t >
void mousetrap::Action::set_function ( Function_t  f,
Data_t  data 
)

create action as stateless, given function is executed when action is triggered

Template Parameters
Function_tlambda or static function with signature (Action&, Data_t) -> void
Data_tarbitrary data type
Parameters
ffunction
datadata

References set_enabled().

◆ set_state()

void mousetrap::Action::set_state ( bool  new_state)

set the state of a stateful action, if the action is not stateful, does nothing

Parameters
new_state

References get_id(), get_is_stateful(), and mousetrap::log::warning().

◆ set_stateful_function() [1/2]

template<typename Function_t >
void mousetrap::Action::set_stateful_function ( Function_t  f,
bool  initial_state = false 
)

create action as stateful, given function is executed when action is triggered

Template Parameters
Function_tlambda or static function with signature (Action&, bool) -> bool
Parameters
ffunction
initial_statestate of the action on initialization

References set_enabled().

◆ set_stateful_function() [2/2]

template<typename Function_t , typename Data_t >
void mousetrap::Action::set_stateful_function ( Function_t  f,
Data_t  data,
bool  initial_state = false 
)

create action as stateful, given function is executed when action is triggered

Template Parameters
Function_tlambda or static function with signature (Action&, bool, Data_t) -> bool
Parameters
ffunction
datadata
initial_statestate of the action on initialization

References set_enabled().


The documentation for this class was generated from the following files: