2005-11-14 11:28:45 -05:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2005 Paul Davis
|
2005-11-14 11:28:45 -05: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, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-05-02 14:35:05 -04:00
|
|
|
#include <cstring>
|
2006-07-18 23:49:52 -04:00
|
|
|
#include <string>
|
2008-01-10 16:20:59 -05:00
|
|
|
#include <list>
|
2005-12-07 17:57:47 -05:00
|
|
|
|
2005-10-17 11:12:50 -04:00
|
|
|
#include <gtk/gtkaccelmap.h>
|
2005-12-04 23:11:08 -05:00
|
|
|
#include <gtk/gtkuimanager.h>
|
|
|
|
#include <gtk/gtkactiongroup.h>
|
2005-12-07 17:57:47 -05:00
|
|
|
|
2005-10-17 11:12:50 -04:00
|
|
|
#include <gtkmm/accelmap.h>
|
|
|
|
#include <gtkmm/uimanager.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/file_utils.h"
|
2005-11-25 19:06:46 -05:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/filesystem_paths.h"
|
2009-05-13 20:13:27 -04:00
|
|
|
#include "ardour/rc_configuration.h"
|
2005-11-26 07:08:33 -05:00
|
|
|
|
2009-12-04 15:52:04 -05:00
|
|
|
#include "gtkmm2ext/actions.h"
|
|
|
|
|
2014-12-22 13:39:41 -05:00
|
|
|
#include "ardour_ui.h"
|
2005-10-17 11:12:50 -04:00
|
|
|
#include "actions.h"
|
2005-12-29 19:34:21 -05:00
|
|
|
#include "i18n.h"
|
2005-10-17 11:12:50 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2006-09-29 17:39:39 -04:00
|
|
|
using namespace ARDOUR;
|
2005-10-17 11:12:50 -04:00
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::session_sensitive_actions;
|
2009-10-13 16:43:28 -04:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::write_sensitive_actions;
|
2005-11-17 16:31:37 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::region_list_selection_sensitive_actions;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::track_selection_sensitive_actions;
|
2006-03-05 14:39:16 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::point_selection_sensitive_actions;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::time_selection_sensitive_actions;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::line_selection_sensitive_actions;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::playlist_selection_sensitive_actions;
|
2008-04-11 10:06:50 -04:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::mouse_edit_point_requires_canvas_actions;
|
2006-03-05 14:39:16 -05:00
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::range_sensitive_actions;
|
2013-09-04 12:49:52 -04:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::engine_sensitive_actions;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::engine_opposite_sensitive_actions;
|
2005-12-21 16:37:18 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::transport_sensitive_actions;
|
2007-11-12 17:23:01 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::edit_point_in_region_sensitive_actions;
|
2005-12-24 13:25:26 -05:00
|
|
|
|
2013-05-08 11:43:33 -04:00
|
|
|
static Glib::RefPtr<UIManager> ui_manager;
|
2005-10-17 11:12:50 -04:00
|
|
|
|
2005-11-25 19:06:46 -05:00
|
|
|
void
|
|
|
|
ActionManager::init ()
|
|
|
|
{
|
2011-11-14 12:41:29 -05:00
|
|
|
ui_manager = UIManager::create ();
|
2013-05-08 11:43:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-10 04:10:50 -04:00
|
|
|
ActionManager::load_menus (const string& menus_file)
|
2013-05-08 11:43:33 -04:00
|
|
|
{
|
|
|
|
std::string ui_file;
|
2011-11-14 12:41:29 -05:00
|
|
|
|
2014-06-19 07:23:12 -04:00
|
|
|
find_file (ardour_config_search_path(), menus_file, ui_file);
|
2005-11-25 19:06:46 -05:00
|
|
|
|
2006-01-28 18:45:06 -05:00
|
|
|
bool loaded = false;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-11-25 19:06:46 -05:00
|
|
|
try {
|
2012-06-23 01:06:54 -04:00
|
|
|
ui_manager->add_ui_from_file (ui_file);
|
|
|
|
info << string_compose (_("Loading menus from %1"), ui_file) << endmsg;
|
2006-01-28 18:45:06 -05:00
|
|
|
loaded = true;
|
2005-11-25 19:06:46 -05:00
|
|
|
} catch (Glib::MarkupError& err) {
|
2014-04-10 07:31:06 -04:00
|
|
|
error << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endmsg;
|
|
|
|
cerr << string_compose (_("badly formatted menu definition file: %1"), err.what()) << endl;
|
2005-11-26 07:08:33 -05:00
|
|
|
} catch (...) {
|
2010-03-14 22:31:27 -04:00
|
|
|
error << string_compose (_("%1 menu definition file not found"), PROGRAM_NAME) << endmsg;
|
2005-11-25 19:06:46 -05:00
|
|
|
}
|
2006-01-28 18:45:06 -05:00
|
|
|
|
|
|
|
if (!loaded) {
|
2014-04-10 07:31:06 -04:00
|
|
|
cerr << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endl;
|
|
|
|
error << string_compose (_("%1 will not work without a valid menu definition file"), PROGRAM_NAME) << endmsg;
|
2006-01-28 18:45:06 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-11-25 19:06:46 -05:00
|
|
|
}
|
2005-10-17 11:12:50 -04:00
|
|
|
|
2007-04-26 16:54:31 -04:00
|
|
|
/** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
|
|
|
|
* setting if its state doesn't match the toggle action.
|
|
|
|
* @param group Action group.
|
|
|
|
* @param action Action name.
|
|
|
|
* @param Method to set the state of the Configuration setting.
|
|
|
|
* @param Method to get the state of the Configuration setting.
|
|
|
|
*/
|
2006-09-29 17:39:39 -04:00
|
|
|
void
|
2009-05-13 20:13:27 -04:00
|
|
|
ActionManager::toggle_config_state (const char* group, const char* action, bool (RCConfiguration::*set)(bool), bool (RCConfiguration::*get)(void) const)
|
2006-09-29 17:39:39 -04:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
2009-06-29 10:29:53 -04:00
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
if (tact) {
|
|
|
|
bool x = (Config->*get)();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
if (x != tact->get_active()) {
|
|
|
|
(Config->*set) (!x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 13:39:41 -05:00
|
|
|
/** Examine the state of a Configuration setting and a toggle action, and toggle the Configuration
|
|
|
|
* setting if its state doesn't match the toggle action.
|
|
|
|
* @param group Action group.
|
|
|
|
* @param action Action name.
|
|
|
|
* @param Method to set the state of the Configuration setting.
|
|
|
|
* @param Method to get the state of the Configuration setting.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ActionManager::toggle_config_state (const char* group, const char* action, bool (UIConfiguration::*set)(bool), bool (UIConfiguration::*get)(void) const)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
|
|
|
|
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
|
|
|
|
|
|
|
if (tact) {
|
|
|
|
bool x = (ARDOUR_UI::config()->*get)();
|
|
|
|
|
|
|
|
if (x != tact->get_active()) {
|
|
|
|
(ARDOUR_UI::config()->*set) (!x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
void
|
2009-05-13 20:13:27 -04:00
|
|
|
ActionManager::toggle_config_state_foo (const char* group, const char* action, sigc::slot<bool, bool> set, sigc::slot<bool> get)
|
2006-09-29 17:39:39 -04:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
2009-06-29 10:29:53 -04:00
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
2009-06-29 10:29:53 -04:00
|
|
|
|
|
|
|
if (tact) {
|
2009-05-13 20:13:27 -04:00
|
|
|
bool const x = get ();
|
2009-06-29 10:29:53 -04:00
|
|
|
|
2009-05-13 20:13:27 -04:00
|
|
|
if (x != tact->get_active ()) {
|
2009-06-29 10:29:53 -04:00
|
|
|
set (!x);
|
2009-05-13 20:13:27 -04:00
|
|
|
}
|
2006-09-29 17:39:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 16:54:31 -04:00
|
|
|
|
|
|
|
/** Set the state of a ToggleAction using a particular Configuration get() method
|
|
|
|
* @param group Action group.
|
|
|
|
* @param action Action name.
|
|
|
|
* @param get Method to obtain the state that the ToggleAction should have.
|
|
|
|
*/
|
2006-09-29 17:39:39 -04:00
|
|
|
void
|
2009-05-13 20:13:27 -04:00
|
|
|
ActionManager::map_some_state (const char* group, const char* action, bool (RCConfiguration::*get)() const)
|
2006-09-29 17:39:39 -04:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
|
|
|
|
|
|
|
if (tact) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2006-09-29 17:39:39 -04:00
|
|
|
bool x = (Config->*get)();
|
|
|
|
|
|
|
|
if (tact->get_active() != x) {
|
|
|
|
tact->set_active (x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-13 20:13:27 -04:00
|
|
|
|
2014-12-22 13:39:41 -05:00
|
|
|
/** Set the state of a ToggleAction using a particular Configuration get() method
|
|
|
|
* @param group Action group.
|
|
|
|
* @param action Action name.
|
|
|
|
* @param get Method to obtain the state that the ToggleAction should have.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ActionManager::map_some_state (const char* group, const char* action, bool (UIConfiguration::*get)() const)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
|
|
|
|
|
|
|
if (tact) {
|
|
|
|
|
|
|
|
bool x = (ARDOUR_UI::config()->*get)();
|
|
|
|
|
|
|
|
if (tact->get_active() != x) {
|
|
|
|
tact->set_active (x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-13 20:13:27 -04:00
|
|
|
void
|
|
|
|
ActionManager::map_some_state (const char* group, const char* action, sigc::slot<bool> get)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act = ActionManager::get_action (group, action);
|
|
|
|
if (act) {
|
|
|
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
|
|
|
|
|
|
|
|
if (tact) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-05-13 20:13:27 -04:00
|
|
|
bool const x = get ();
|
|
|
|
|
|
|
|
if (tact->get_active() != x) {
|
|
|
|
tact->set_active (x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-17 08:54:04 -05:00
|
|
|
|