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/ardour.h"
|
|
|
|
#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"
|
|
|
|
|
2009-11-17 08:54:04 -05:00
|
|
|
#include "utils.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;
|
2006-03-05 14:39:16 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::plugin_selection_sensitive_actions;
|
2005-11-17 16:31:37 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::region_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;
|
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::jack_sensitive_actions;
|
2005-11-28 10:29:49 -05:00
|
|
|
vector<RefPtr<Gtk::Action> > ActionManager::jack_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
|
|
|
|
2005-10-17 11:12:50 -04:00
|
|
|
|
2005-11-25 19:06:46 -05:00
|
|
|
void
|
|
|
|
ActionManager::init ()
|
|
|
|
{
|
|
|
|
ui_manager = UIManager::create ();
|
2007-06-27 08:12:29 -04:00
|
|
|
|
|
|
|
sys::path ui_file;
|
|
|
|
|
|
|
|
SearchPath spath = ardour_search_path() + user_config_directory() + system_config_search_path();
|
|
|
|
|
|
|
|
find_file_in_search_path (spath, "ardour.menus", 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 {
|
2007-06-27 08:12:29 -04:00
|
|
|
ui_manager->add_ui_from_file (ui_file.to_string());
|
2009-11-18 23:25:46 -05:00
|
|
|
info << string_compose (_("Loading menus from %1"), ui_file.to_string()) << endmsg;
|
2006-01-28 18:45:06 -05:00
|
|
|
loaded = true;
|
2005-11-25 19:06:46 -05:00
|
|
|
} catch (Glib::MarkupError& err) {
|
2008-02-19 17:10:27 -05:00
|
|
|
error << string_compose (_("badly formatted UI definition file: %1"), err.what()) << endmsg;
|
|
|
|
cerr << string_compose (_("badly formatted UI 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) {
|
2010-03-14 22:31:27 -04:00
|
|
|
cerr << string_compose (_("%1 will not work without a valid ardour.menus file"), PROGRAM_NAME) << endl;
|
|
|
|
error << string_compose (_("%1 will not work without a valid ardour.menus 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} else {
|
2006-10-02 14:09:34 -04:00
|
|
|
cerr << group << ':' << action << " is not a toggle\n";
|
2006-09-29 17:39:39 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cerr << group << ':' << action << " not an action\n";
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
string
|
|
|
|
ActionManager::get_key_representation (const string& accel_path, AccelKey& key)
|
|
|
|
{
|
|
|
|
bool known = lookup_entry (accel_path, key);
|
|
|
|
|
|
|
|
if (known) {
|
|
|
|
uint32_t k = possibly_translate_legal_accelerator_to_real_key (key.get_key());
|
|
|
|
key = AccelKey (k, Gdk::ModifierType (key.get_mod()));
|
|
|
|
return ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return unbound_string;
|
|
|
|
}
|