mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-21 06:06:25 +01:00
add new action management functions to save and restore sensitity of all actions
This commit is contained in:
parent
a77b1f6c8e
commit
19ac902df0
2 changed files with 83 additions and 0 deletions
|
|
@ -21,8 +21,11 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <gtk/gtkaccelmap.h>
|
||||
#include <gtk/gtkuimanager.h>
|
||||
#include <gtk/gtkactiongroup.h>
|
||||
|
|
@ -232,6 +235,81 @@ ActionManager::get_all_actions (vector<string>& names, vector<string>& paths, ve
|
|||
}
|
||||
}
|
||||
|
||||
struct ActionState {
|
||||
GtkAction* action;
|
||||
bool sensitive;
|
||||
ActionState (GtkAction* a, bool s) : action (a), sensitive (s) {}
|
||||
};
|
||||
|
||||
typedef std::vector<ActionState> ActionStates;
|
||||
|
||||
static std::stack<boost::shared_ptr<ActionStates> > state_stack;
|
||||
|
||||
static boost::shared_ptr<ActionStates>
|
||||
get_action_state ()
|
||||
{
|
||||
boost::shared_ptr<ActionStates> state = boost::shared_ptr<ActionStates>(new ActionStates);
|
||||
|
||||
/* the C++ API for functions used here appears to be broken in
|
||||
gtkmm2.6, so we fall back to the C level.
|
||||
*/
|
||||
|
||||
GList* list = gtk_ui_manager_get_action_groups (ActionManager::ui_manager->gobj());
|
||||
GList* node;
|
||||
GList* acts;
|
||||
|
||||
for (node = list; node; node = g_list_next (node)) {
|
||||
|
||||
GtkActionGroup* group = (GtkActionGroup*) node->data;
|
||||
|
||||
/* first pass: collect them all */
|
||||
|
||||
typedef std::list<Glib::RefPtr<Gtk::Action> > action_list;
|
||||
action_list the_acts;
|
||||
|
||||
for (acts = gtk_action_group_list_actions (group); acts; acts = g_list_next (acts)) {
|
||||
GtkAction* action = (GtkAction*) acts->data;
|
||||
|
||||
state->push_back (ActionState (action, gtk_action_get_sensitive (action)));
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void
|
||||
ActionManager::push_action_state ()
|
||||
{
|
||||
state_stack.push (get_action_state());
|
||||
}
|
||||
|
||||
void
|
||||
ActionManager::pop_action_state ()
|
||||
{
|
||||
if (state_stack.empty()) {
|
||||
warning << string_compose (_("programming error: %1"), X_("ActionManager::pop_action_state called with empty stack")) << endmsg;
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ActionStates> as = state_stack.top ();
|
||||
state_stack.pop ();
|
||||
|
||||
for (ActionStates::iterator i = as->begin(); i != as->end(); ++i) {
|
||||
gtk_action_set_sensitive ((*i).action, (*i).sensitive);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ActionManager::disable_all_actions ()
|
||||
{
|
||||
push_action_state ();
|
||||
boost::shared_ptr<ActionStates> as = state_stack.top ();
|
||||
|
||||
for (ActionStates::iterator i = as->begin(); i != as->end(); ++i) {
|
||||
gtk_action_set_sensitive ((*i).action, false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ActionManager::add_action_group (RefPtr<ActionGroup> grp)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,6 +91,11 @@ namespace ActionManager {
|
|||
LIBGTKMM2EXT_API extern void check_toggleaction (std::string);
|
||||
LIBGTKMM2EXT_API extern void uncheck_toggleaction (std::string);
|
||||
LIBGTKMM2EXT_API extern void set_toggleaction_state (std::string, bool);
|
||||
|
||||
|
||||
LIBGTKMM2EXT_API extern void push_action_state ();
|
||||
LIBGTKMM2EXT_API extern void pop_action_state ();
|
||||
LIBGTKMM2EXT_API extern void disable_all_actions ();
|
||||
};
|
||||
|
||||
#endif /* __libgtkmm2ext_actions_h__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue