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"
|
|
|
|
|
2005-10-17 11:12:50 -04:00
|
|
|
#include "actions.h"
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/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
|
|
|
|
2015-08-01 23:40:55 -04:00
|
|
|
typedef std::vector<RefPtr<Gtk::Action> > RelatedActions;
|
|
|
|
|
|
|
|
RelatedActions ActionManager::session_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::write_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::region_list_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::plugin_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::track_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::point_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::time_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::line_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::playlist_selection_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::mouse_edit_point_requires_canvas_actions;
|
|
|
|
RelatedActions ActionManager::range_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::engine_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::engine_opposite_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::transport_sensitive_actions;
|
|
|
|
RelatedActions ActionManager::edit_point_in_region_sensitive_actions;
|
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) {
|
2015-01-02 09:44:54 -05:00
|
|
|
bool x = (UIConfiguration::instance().*get)();
|
2014-12-22 13:39:41 -05:00
|
|
|
|
|
|
|
if (x != tact->get_active()) {
|
2015-01-02 09:44:54 -05:00
|
|
|
(UIConfiguration::instance().*set) (!x);
|
2014-12-22 13:39:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
bool x = (UIConfiguration::instance().*get)();
|
2014-12-22 13:39:41 -05:00
|
|
|
|
|
|
|
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
|
|
|
|