2010-11-13 00:14:48 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2002 Paul Davis
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WAF_BUILD
|
|
|
|
#include "gtk2ardour-config.h"
|
|
|
|
#endif
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
#include <map>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/profile.h"
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
#include <gtkmm/stock.h>
|
2008-02-16 17:43:18 -05:00
|
|
|
#include <gtkmm/label.h>
|
2007-10-11 21:54:35 -04:00
|
|
|
#include <gtkmm/accelkey.h>
|
|
|
|
#include <gtkmm/accelmap.h>
|
|
|
|
#include <gtkmm/uimanager.h>
|
|
|
|
|
2010-05-25 12:45:21 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/strsplit.h"
|
|
|
|
#include "pbd/replace_all.h"
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/profile.h"
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
#include "actions.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "keyeditor.h"
|
2008-09-10 11:03:30 -04:00
|
|
|
#include "utils.h"
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gdk;
|
2008-01-10 16:20:59 -05:00
|
|
|
using namespace PBD;
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2009-12-04 17:51:32 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
KeyEditor::KeyEditor ()
|
2011-11-18 19:56:35 -05:00
|
|
|
: ArdourWindow (_("Key Bindings"))
|
2008-01-10 17:22:29 -05:00
|
|
|
, unbind_button (_("Remove shortcut"))
|
|
|
|
, unbind_box (BUTTONBOX_END)
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2007-10-12 18:30:25 -04:00
|
|
|
can_bind = false;
|
|
|
|
last_state = 0;
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
model = TreeStore::create(columns);
|
|
|
|
|
|
|
|
view.set_model (model);
|
|
|
|
view.append_column (_("Action"), columns.action);
|
2008-01-10 17:22:29 -05:00
|
|
|
view.append_column (_("Shortcut"), columns.binding);
|
2007-10-11 21:54:35 -04:00
|
|
|
view.set_headers_visible (true);
|
|
|
|
view.get_selection()->set_mode (SELECTION_SINGLE);
|
|
|
|
view.set_reorderable (false);
|
2008-01-10 16:20:59 -05:00
|
|
|
view.set_size_request (500,300);
|
2007-10-11 21:54:35 -04:00
|
|
|
view.set_enable_search (false);
|
|
|
|
view.set_rules_hint (true);
|
|
|
|
view.set_name (X_("KeyEditorTree"));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-11 18:29:48 -05:00
|
|
|
view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &KeyEditor::action_selected));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
scroller.add (view);
|
|
|
|
scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
2007-10-12 18:30:25 -04:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
add (scroller);
|
2008-01-10 17:22:29 -05:00
|
|
|
|
|
|
|
if (!ARDOUR::Profile->get_sae()) {
|
2008-02-16 17:43:18 -05:00
|
|
|
|
|
|
|
Label* hint = manage (new Label (_("Select an action, then press the key(s) to (re)set its shortcut")));
|
|
|
|
hint->show ();
|
|
|
|
unbind_box.set_spacing (6);
|
|
|
|
unbind_box.pack_start (*hint, false, true);
|
|
|
|
unbind_box.pack_start (unbind_button, false, false);
|
2009-12-11 18:29:48 -05:00
|
|
|
unbind_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::unbind));
|
2008-02-16 17:43:18 -05:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
add (unbind_box);
|
2008-01-10 17:22:29 -05:00
|
|
|
unbind_box.show ();
|
|
|
|
unbind_button.show ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
}
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
view.show ();
|
2008-01-10 17:22:29 -05:00
|
|
|
scroller.show ();
|
|
|
|
|
|
|
|
unbind_button.set_sensitive (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::unbind ()
|
|
|
|
{
|
|
|
|
TreeModel::iterator i = view.get_selection()->get_selected();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
unbind_button.set_sensitive (false);
|
|
|
|
|
2009-11-17 08:54:04 -05:00
|
|
|
cerr << "trying to unbind\n";
|
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
if (i != model->children().end()) {
|
|
|
|
string path = (*i)[columns.path];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
if (!(*i)[columns.bindable]) {
|
|
|
|
return;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-01-10 17:22:29 -05:00
|
|
|
|
|
|
|
bool result = AccelMap::change_entry (path,
|
|
|
|
0,
|
|
|
|
(ModifierType) 0,
|
|
|
|
true);
|
|
|
|
if (result) {
|
|
|
|
(*i)[columns.binding] = string ();
|
|
|
|
}
|
|
|
|
}
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::on_show ()
|
|
|
|
{
|
|
|
|
populate ();
|
|
|
|
view.get_selection()->unselect_all ();
|
2011-11-18 19:56:35 -05:00
|
|
|
ArdourWindow::on_show ();
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::on_unmap ()
|
|
|
|
{
|
2011-11-18 19:56:35 -05:00
|
|
|
ArdourWindow::on_unmap ();
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::action_selected ()
|
|
|
|
{
|
2008-01-10 17:22:29 -05:00
|
|
|
if (view.get_selection()->count_selected_rows() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeModel::iterator i = view.get_selection()->get_selected();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
unbind_button.set_sensitive (false);
|
|
|
|
|
|
|
|
if (i != model->children().end()) {
|
|
|
|
|
|
|
|
string path = (*i)[columns.path];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
if (!(*i)[columns.bindable]) {
|
|
|
|
return;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-01-10 17:22:29 -05:00
|
|
|
|
|
|
|
string binding = (*i)[columns.binding];
|
|
|
|
|
|
|
|
if (!binding.empty()) {
|
|
|
|
unbind_button.set_sensitive (true);
|
|
|
|
}
|
|
|
|
}
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
2007-10-12 18:30:25 -04:00
|
|
|
bool
|
|
|
|
KeyEditor::on_key_press_event (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
can_bind = true;
|
|
|
|
last_state = ev->state;
|
2007-10-12 19:25:48 -04:00
|
|
|
return false;
|
2007-10-12 18:30:25 -04:00
|
|
|
}
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
bool
|
|
|
|
KeyEditor::on_key_release_event (GdkEventKey* ev)
|
|
|
|
{
|
2008-01-10 16:20:59 -05:00
|
|
|
if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
|
2007-10-12 18:30:25 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
TreeModel::iterator i = view.get_selection()->get_selected();
|
|
|
|
|
|
|
|
if (i != model->children().end()) {
|
|
|
|
string path = (*i)[columns.path];
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-12 18:30:25 -04:00
|
|
|
if (!(*i)[columns.bindable]) {
|
|
|
|
goto out;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2007-10-12 18:30:25 -04:00
|
|
|
|
2009-11-17 08:54:04 -05:00
|
|
|
cerr << "real lkeyval: " << ev->keyval << endl;
|
2010-05-25 12:45:21 -04:00
|
|
|
Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
|
2009-11-17 08:54:04 -05:00
|
|
|
cerr << "using keyval = " << ev->keyval << endl;
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
bool result = AccelMap::change_entry (path,
|
|
|
|
ev->keyval,
|
2009-07-20 23:23:57 -04:00
|
|
|
ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
|
2007-10-11 21:54:35 -04:00
|
|
|
true);
|
|
|
|
|
2009-11-17 08:54:04 -05:00
|
|
|
cerr << "New binding to " << ev->keyval << " worked: " << result << endl;
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
if (result) {
|
|
|
|
AccelKey key;
|
2009-11-17 08:54:04 -05:00
|
|
|
(*i)[columns.binding] = ActionManager::get_key_representation (path, key);
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 18:30:25 -04:00
|
|
|
out:
|
|
|
|
can_bind = false;
|
2007-10-11 21:54:35 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::populate ()
|
|
|
|
{
|
|
|
|
vector<string> paths;
|
|
|
|
vector<string> labels;
|
2011-02-20 12:29:52 -05:00
|
|
|
vector<string> tooltips;
|
2007-10-11 21:54:35 -04:00
|
|
|
vector<string> keys;
|
|
|
|
vector<AccelKey> bindings;
|
|
|
|
typedef std::map<string,TreeIter> NodeMap;
|
|
|
|
NodeMap nodes;
|
|
|
|
NodeMap::iterator r;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-02-20 12:29:52 -05:00
|
|
|
ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
vector<string>::iterator k;
|
|
|
|
vector<string>::iterator p;
|
2011-02-20 12:29:52 -05:00
|
|
|
vector<string>::iterator t;
|
2007-10-11 21:54:35 -04:00
|
|
|
vector<string>::iterator l;
|
|
|
|
|
|
|
|
model->clear ();
|
|
|
|
|
2011-02-20 12:29:52 -05:00
|
|
|
for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
TreeModel::Row row;
|
|
|
|
vector<string> parts;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
parts.clear ();
|
|
|
|
|
|
|
|
split (*p, parts, '/');
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
if (parts.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-12 15:24:16 -04:00
|
|
|
//kinda kludgy way to avoid displaying menu items as mappable
|
|
|
|
if ( parts[1] == _("Main_menu") )
|
|
|
|
continue;
|
|
|
|
if ( parts[1] == _("JACK") )
|
|
|
|
continue;
|
|
|
|
if ( parts[1] == _("redirectmenu") )
|
|
|
|
continue;
|
|
|
|
if ( parts[1] == _("Editor_menus") )
|
|
|
|
continue;
|
|
|
|
if ( parts[1] == _("RegionList") )
|
|
|
|
continue;
|
|
|
|
if ( parts[1] == _("ProcessorMenu") )
|
|
|
|
continue;
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
if ((r = nodes.find (parts[1])) == nodes.end()) {
|
|
|
|
|
|
|
|
/* top level is missing */
|
|
|
|
|
|
|
|
TreeIter rowp;
|
|
|
|
TreeModel::Row parent;
|
|
|
|
rowp = model->append();
|
|
|
|
nodes[parts[1]] = rowp;
|
|
|
|
parent = *(rowp);
|
|
|
|
parent[columns.action] = parts[1];
|
2007-10-12 18:30:25 -04:00
|
|
|
parent[columns.bindable] = false;
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
row = *(model->append (parent.children()));
|
|
|
|
|
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
row = *(model->append ((*r->second)->children()));
|
|
|
|
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
/* add this action */
|
|
|
|
|
2011-02-20 12:29:52 -05:00
|
|
|
if (l->empty ()) {
|
|
|
|
row[columns.action] = *t;
|
|
|
|
} else {
|
|
|
|
row[columns.action] = *l;
|
|
|
|
}
|
2007-10-11 21:54:35 -04:00
|
|
|
row[columns.path] = (*p);
|
2007-10-12 18:30:25 -04:00
|
|
|
row[columns.bindable] = true;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
if (*k == ActionManager::unbound_string) {
|
|
|
|
row[columns.binding] = string();
|
|
|
|
} else {
|
|
|
|
row[columns.binding] = (*k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|