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>
|
2016-05-21 09:30:24 -04:00
|
|
|
#include <fstream>
|
2016-06-15 19:45:59 -04:00
|
|
|
#include <sstream>
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2016-06-15 19:45:59 -04:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
#include <gtkmm/accelkey.h>
|
|
|
|
#include <gtkmm/accelmap.h>
|
2017-07-16 21:48:18 -04:00
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <gtkmm/separator.h>
|
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
#include <gtkmm/treemodelsort.h>
|
2007-10-11 21:54:35 -04:00
|
|
|
#include <gtkmm/uimanager.h>
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
#include "gtkmm2ext/bindings.h"
|
2010-05-25 12:45:21 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2016-06-15 19:45:59 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/openuri.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/strsplit.h"
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2014-07-10 11:04:24 -04:00
|
|
|
#include "ardour/filesystem_paths.h"
|
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"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
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;
|
2015-08-04 13:59:32 -04:00
|
|
|
using Gtkmm2ext::Bindings;
|
2009-12-04 17:51:32 -05:00
|
|
|
|
2016-04-24 16:20:44 -04:00
|
|
|
sigc::signal<void> KeyEditor::UpdateBindings;
|
|
|
|
|
2017-01-12 14:51:29 -05:00
|
|
|
static void bindings_collision_dialog (Gtk::Window& parent, const std::string& bound_name)
|
2016-02-28 15:54:08 -05:00
|
|
|
{
|
|
|
|
ArdourDialog dialog (parent, _("Colliding keybindings"), true);
|
2017-01-12 14:51:29 -05:00
|
|
|
Label label (string_compose(
|
|
|
|
_("The key sequence is already bound to '%1'. Please remove the other binding first."), bound_name));
|
2016-02-28 15:54:08 -05:00
|
|
|
|
|
|
|
dialog.get_vbox()->pack_start (label, true, true);
|
|
|
|
dialog.add_button (_("Ok"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
dialog.show_all ();
|
|
|
|
dialog.run();
|
|
|
|
}
|
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
KeyEditor::KeyEditor ()
|
2017-01-12 11:08:50 -05:00
|
|
|
: ArdourWindow (_("Keyboard Shortcuts"))
|
2008-01-10 17:22:29 -05:00
|
|
|
, unbind_button (_("Remove shortcut"))
|
|
|
|
, unbind_box (BUTTONBOX_END)
|
2016-03-08 03:14:50 -05:00
|
|
|
, filter_entry (_("Search..."), true)
|
2016-03-07 17:56:03 -05:00
|
|
|
, filter_string("")
|
2016-02-27 18:53:39 -05:00
|
|
|
, sort_column(0)
|
|
|
|
, sort_type(Gtk::SORT_ASCENDING)
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2007-10-12 18:30:25 -04:00
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
notebook.signal_switch_page ().connect (sigc::mem_fun (*this, &KeyEditor::page_change));
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
vpacker.pack_start (notebook, true, true);
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> icon = ARDOUR_UI_UTILS::get_icon ("search");
|
|
|
|
filter_entry.set_icon_from_pixbuf (icon);
|
2016-03-08 03:14:50 -05:00
|
|
|
filter_entry.set_icon_tooltip_text (_("Click to reset search string"));
|
2016-03-07 17:56:03 -05:00
|
|
|
filter_entry.signal_search_string_updated ().connect (sigc::mem_fun (*this, &KeyEditor::search_string_updated));
|
|
|
|
vpacker.pack_start (filter_entry, false, false);
|
|
|
|
|
2017-01-05 15:31:27 -05:00
|
|
|
Label* hint = manage (new Label (_("To remove a shortcut, select an action then press this: ")));
|
2015-10-26 15:17:42 -04:00
|
|
|
hint->show ();
|
|
|
|
unbind_box.pack_start (*hint, false, true);
|
|
|
|
unbind_box.pack_start (unbind_button, false, false);
|
|
|
|
unbind_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::unbind));
|
2008-02-16 17:43:18 -05:00
|
|
|
|
2017-01-05 15:31:27 -05:00
|
|
|
vpacker.set_spacing (4);
|
2015-10-26 15:17:42 -04:00
|
|
|
vpacker.pack_start (unbind_box, false, false);
|
|
|
|
unbind_box.show ();
|
|
|
|
unbind_button.show ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-07-10 11:04:24 -04:00
|
|
|
reset_button.add (reset_label);
|
2017-01-05 15:31:27 -05:00
|
|
|
reset_label.set_markup (string_compose (" <span size=\"large\" weight=\"bold\">%1</span> ", _("Reset Bindings to Defaults")));
|
|
|
|
|
|
|
|
print_button.add (print_label);
|
|
|
|
print_label.set_markup (string_compose (" <span size=\"large\" weight=\"bold\">%1</span> ", _("Print Bindings (to your web browser)")));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-05-21 09:30:24 -04:00
|
|
|
print_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::print));
|
|
|
|
|
2014-07-10 11:04:24 -04:00
|
|
|
reset_box.pack_start (reset_button, true, false);
|
2016-05-21 09:30:24 -04:00
|
|
|
reset_box.pack_start (print_button, true, false);
|
2014-07-10 11:04:24 -04:00
|
|
|
reset_box.show ();
|
|
|
|
reset_button.show ();
|
|
|
|
reset_label.show ();
|
2016-05-21 09:30:24 -04:00
|
|
|
print_button.show ();
|
2014-07-10 11:04:24 -04:00
|
|
|
reset_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::reset));
|
2017-01-12 14:52:21 -05:00
|
|
|
vpacker.pack_start (*(manage (new HSeparator())), false, false, 5);
|
2014-07-10 11:53:39 -04:00
|
|
|
vpacker.pack_start (reset_box, false, false);
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2014-07-10 11:04:24 -04:00
|
|
|
add (vpacker);
|
2012-07-24 20:32:59 -04:00
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
unbind_button.set_sensitive (false);
|
2016-08-21 16:08:54 -04:00
|
|
|
_refresh_connection = UpdateBindings.connect (sigc::mem_fun (*this, &KeyEditor::refresh));
|
2008-01-10 17:22:29 -05:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
void
|
|
|
|
KeyEditor::add_tab (string const & name, Bindings& bindings)
|
|
|
|
{
|
|
|
|
Tab* t = new Tab (*this, name, &bindings);
|
2016-03-15 19:46:28 -04:00
|
|
|
|
|
|
|
if (t->populate () == 0) {
|
|
|
|
/* no bindings */
|
|
|
|
delete t;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-24 16:20:44 -04:00
|
|
|
tabs.push_back (t);
|
2015-08-04 13:59:32 -04:00
|
|
|
t->show_all ();
|
|
|
|
notebook.append_page (*t, name);
|
|
|
|
}
|
|
|
|
|
2016-03-15 16:42:45 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::remove_tab (string const &name)
|
|
|
|
{
|
|
|
|
guint npages = notebook.get_n_pages ();
|
|
|
|
|
|
|
|
for (guint n = 0; n < npages; ++n) {
|
|
|
|
Widget* w = notebook.get_nth_page (n);
|
|
|
|
Tab* tab = dynamic_cast<Tab*> (w);
|
|
|
|
if (tab) {
|
|
|
|
if (tab->name == name) {
|
|
|
|
notebook.remove_page (*w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-15 19:46:28 -04:00
|
|
|
cerr << "Removed " << name << endl;
|
2016-03-15 16:42:45 -04:00
|
|
|
}
|
|
|
|
|
2008-01-10 17:22:29 -05:00
|
|
|
void
|
|
|
|
KeyEditor::unbind ()
|
|
|
|
{
|
2015-08-04 13:59:32 -04:00
|
|
|
current_tab()->unbind ();
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
void
|
|
|
|
KeyEditor::page_change (GtkNotebookPage*, guint)
|
|
|
|
{
|
|
|
|
current_tab()->view.get_selection()->unselect_all ();
|
2008-01-10 17:22:29 -05:00
|
|
|
unbind_button.set_sensitive (false);
|
2015-08-04 13:59:32 -04:00
|
|
|
}
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
bool
|
2016-03-15 18:15:26 -04:00
|
|
|
KeyEditor::Tab::key_press_event (GdkEventKey* ev)
|
2015-08-04 13:59:32 -04:00
|
|
|
{
|
2016-03-15 18:15:26 -04:00
|
|
|
if (view.get_selection()->count_selected_rows() != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
if (!ev->is_modifier) {
|
|
|
|
last_keyval = ev->keyval;
|
2008-01-10 17:22:29 -05:00
|
|
|
}
|
2015-08-05 10:57:00 -04:00
|
|
|
|
|
|
|
/* Don't let anything else handle the key press, because navigation
|
|
|
|
* keys will be used by GTK to change the selection/treeview cursor
|
|
|
|
* position
|
|
|
|
*/
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
return true;
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
bool
|
2016-03-15 18:15:26 -04:00
|
|
|
KeyEditor::Tab::key_release_event (GdkEventKey* ev)
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2016-03-15 18:15:26 -04:00
|
|
|
if (view.get_selection()->count_selected_rows() != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-26 15:17:42 -04:00
|
|
|
if (last_keyval == 0) {
|
2015-08-04 13:59:32 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
owner.current_tab()->bind (ev, last_keyval);
|
2015-08-04 13:59:32 -04:00
|
|
|
|
|
|
|
last_keyval = 0;
|
|
|
|
return true;
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
KeyEditor::Tab::Tab (KeyEditor& ke, string const & str, Bindings* b)
|
|
|
|
: owner (ke)
|
|
|
|
, name (str)
|
|
|
|
, bindings (b)
|
2016-03-07 17:56:03 -05:00
|
|
|
, last_keyval (0)
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2016-03-07 17:56:03 -05:00
|
|
|
data_model = TreeStore::create(columns);
|
|
|
|
populate ();
|
2016-03-15 18:15:26 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
filter = TreeModelFilter::create(data_model);
|
|
|
|
filter->set_visible_func (sigc::mem_fun (*this, &Tab::visible_func));
|
|
|
|
|
|
|
|
sorted_filter = TreeModelSort::create(filter);
|
2015-08-04 13:59:32 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
view.set_model (sorted_filter);
|
2015-08-05 10:57:00 -04:00
|
|
|
view.append_column (_("Action"), columns.name);
|
2015-08-04 13:59:32 -04:00
|
|
|
view.append_column (_("Shortcut"), columns.binding);
|
|
|
|
view.set_headers_visible (true);
|
2016-02-27 18:53:39 -05:00
|
|
|
view.set_headers_clickable (true);
|
2015-08-04 13:59:32 -04:00
|
|
|
view.get_selection()->set_mode (SELECTION_SINGLE);
|
|
|
|
view.set_reorderable (false);
|
|
|
|
view.set_size_request (500,300);
|
|
|
|
view.set_enable_search (false);
|
|
|
|
view.set_rules_hint (true);
|
|
|
|
view.set_name (X_("KeyEditorTree"));
|
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
view.signal_cursor_changed().connect (sigc::mem_fun (*this, &Tab::action_selected));
|
2016-03-15 18:15:26 -04:00
|
|
|
view.signal_key_press_event().connect (sigc::mem_fun (*this, &Tab::key_press_event), false);
|
|
|
|
view.signal_key_release_event().connect (sigc::mem_fun (*this, &Tab::key_release_event), false);
|
2015-08-04 13:59:32 -04:00
|
|
|
|
2016-02-27 18:53:39 -05:00
|
|
|
view.get_column(0)->set_sort_column (columns.name);
|
|
|
|
view.get_column(1)->set_sort_column (columns.binding);
|
2016-03-07 17:56:03 -05:00
|
|
|
data_model->set_sort_column (owner.sort_column, owner.sort_type);
|
|
|
|
data_model->signal_sort_column_changed().connect (sigc::mem_fun (*this, &Tab::sort_column_changed));
|
2016-02-27 18:53:39 -05:00
|
|
|
|
|
|
|
signal_map().connect (sigc::mem_fun (*this, &Tab::tab_mapped));
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
scroller.add (view);
|
|
|
|
scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
|
|
|
|
|
|
|
set_spacing (6);
|
|
|
|
set_border_width (12);
|
|
|
|
pack_start (scroller);
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-04 13:59:32 -04:00
|
|
|
KeyEditor::Tab::action_selected ()
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2008-01-10 17:22:29 -05:00
|
|
|
if (view.get_selection()->count_selected_rows() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
TreeModel::const_iterator it = view.get_selection()->get_selected();
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
if (!it) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
if (!(*it)[columns.bindable]) {
|
|
|
|
owner.unbind_button.set_sensitive (false);
|
|
|
|
return;
|
|
|
|
}
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
const string& binding = (*it)[columns.binding];
|
2008-01-10 17:22:29 -05:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
if (!binding.empty()) {
|
|
|
|
owner.unbind_button.set_sensitive (true);
|
2008-01-10 17:22:29 -05:00
|
|
|
}
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
void
|
|
|
|
KeyEditor::Tab::unbind ()
|
2007-10-12 18:30:25 -04:00
|
|
|
{
|
2016-03-07 17:56:03 -05:00
|
|
|
const std::string& action_path = (*view.get_selection()->get_selected())[columns.path];
|
2015-08-04 13:59:32 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
TreeModel::iterator it = find_action_path (data_model->children().begin(), data_model->children().end(), action_path);
|
2015-08-04 13:59:32 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
if (!it || !(*it)[columns.bindable]) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
bindings->remove (Gtkmm2ext::Bindings::Press, action_path , true);
|
|
|
|
(*it)[columns.binding] = string ();
|
2016-02-28 15:54:08 -05:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
owner.unbind_button.set_sensitive (false);
|
2007-10-12 18:30:25 -04:00
|
|
|
}
|
|
|
|
|
2015-08-04 13:59:32 -04:00
|
|
|
void
|
|
|
|
KeyEditor::Tab::bind (GdkEventKey* release_event, guint pressed_key)
|
2007-10-11 21:54:35 -04:00
|
|
|
{
|
2016-03-07 17:56:03 -05:00
|
|
|
const std::string& action_path = (*view.get_selection()->get_selected())[columns.path];
|
|
|
|
TreeModel::iterator it = find_action_path (data_model->children().begin(), data_model->children().end(), action_path);
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2016-03-05 11:53:42 -05:00
|
|
|
/* pressed key could be upper case if Shift was used. We want all
|
|
|
|
single keys stored as their lower-case version, so ensure this
|
|
|
|
*/
|
|
|
|
|
|
|
|
pressed_key = gdk_keyval_to_lower (pressed_key);
|
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
if (!it || !(*it)[columns.bindable]) {
|
2016-02-28 15:54:08 -05:00
|
|
|
return;
|
|
|
|
}
|
2007-10-12 18:30:25 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & release_event->state);
|
|
|
|
Gtkmm2ext::KeyboardKey new_binding (mod, pressed_key);
|
2015-01-14 20:31:38 -05:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
if (bindings->is_bound (new_binding, Gtkmm2ext::Bindings::Press)) {
|
2017-01-12 14:51:29 -05:00
|
|
|
bindings_collision_dialog (owner, bindings->bound_name (new_binding, Gtkmm2ext::Bindings::Press));
|
2016-02-28 15:54:08 -05:00
|
|
|
return;
|
|
|
|
}
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2016-02-28 15:54:08 -05:00
|
|
|
bool result = bindings->replace (new_binding, Gtkmm2ext::Bindings::Press, action_path);
|
|
|
|
|
|
|
|
if (result) {
|
2016-03-07 17:56:03 -05:00
|
|
|
(*it)[columns.binding] = gtk_accelerator_get_label (new_binding.key(), (GdkModifierType) new_binding.state());
|
2016-02-28 15:54:08 -05:00
|
|
|
owner.unbind_button.set_sensitive (true);
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-15 19:46:28 -04:00
|
|
|
uint32_t
|
2015-08-04 13:59:32 -04:00
|
|
|
KeyEditor::Tab::populate ()
|
2015-10-26 14:35:06 -04:00
|
|
|
{
|
2007-10-11 21:54:35 -04:00
|
|
|
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;
|
2015-08-05 10:57:00 -04:00
|
|
|
vector<Glib::RefPtr<Action> > actions;
|
2007-10-11 21:54:35 -04:00
|
|
|
typedef std::map<string,TreeIter> NodeMap;
|
|
|
|
NodeMap nodes;
|
|
|
|
NodeMap::iterator r;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
bindings->get_all_actions (paths, labels, tooltips, keys, actions);
|
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;
|
2015-08-05 10:57:00 -04:00
|
|
|
vector<Glib::RefPtr<Action> >::iterator a;
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
data_model->clear ();
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
for (a = actions.begin(), l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l, ++a) {
|
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
|
|
|
split (*p, parts, '/');
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
string category = parts[1];
|
|
|
|
string action_name = parts[2];
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
if (action_name.empty()) {
|
2007-10-11 21:54:35 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-12 15:24:16 -04:00
|
|
|
//kinda kludgy way to avoid displaying menu items as mappable
|
2019-02-16 15:06:08 -05:00
|
|
|
if ((action_name.find (X_("Menu")) == action_name.length() - 4) ||
|
|
|
|
(action_name.find (X_("menu")) == action_name.length() - 4) ||
|
|
|
|
(category.find (X_("Menu")) == category.length() - 4) ||
|
|
|
|
(category.find (X_("menu")) == category.length() - 4) ||
|
2015-08-05 10:57:00 -04:00
|
|
|
(action_name == _("RegionList"))) {
|
2012-03-12 15:24:16 -04:00
|
|
|
continue;
|
2015-08-04 13:59:32 -04:00
|
|
|
}
|
2012-03-12 15:24:16 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
if ((r = nodes.find (category)) == nodes.end()) {
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
/* category/group is missing, so add it first */
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
TreeIter rowp;
|
|
|
|
TreeModel::Row parent;
|
2016-03-07 17:56:03 -05:00
|
|
|
rowp = data_model->append();
|
2015-08-05 10:57:00 -04:00
|
|
|
nodes[category] = rowp;
|
2007-10-11 21:54:35 -04:00
|
|
|
parent = *(rowp);
|
2015-08-05 10:57:00 -04:00
|
|
|
parent[columns.name] = category;
|
2007-10-12 18:30:25 -04:00
|
|
|
parent[columns.bindable] = false;
|
2015-08-05 10:57:00 -04:00
|
|
|
parent[columns.action] = *a;
|
2007-10-11 21:54:35 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
/* now set up the child row that we're about to fill
|
|
|
|
* out with information
|
|
|
|
*/
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
row = *(data_model->append (parent.children()));
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
} else {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
/* category/group is present, so just add the child row */
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2016-03-07 17:56:03 -05:00
|
|
|
row = *(data_model->append ((*r->second)->children()));
|
2007-10-11 21:54:35 -04:00
|
|
|
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2007-10-11 21:54:35 -04:00
|
|
|
/* add this action */
|
|
|
|
|
2015-08-05 10:57:00 -04:00
|
|
|
/* use the "visible label" as the action name */
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2011-02-20 12:29:52 -05:00
|
|
|
if (l->empty ()) {
|
2015-08-05 10:57:00 -04:00
|
|
|
/* no label, try using the tooltip instead */
|
|
|
|
row[columns.name] = *t;
|
2011-02-20 12:29:52 -05:00
|
|
|
} else {
|
2015-08-05 10:57:00 -04:00
|
|
|
row[columns.name] = *l;
|
2011-02-20 12:29:52 -05:00
|
|
|
}
|
2015-08-05 10:57:00 -04:00
|
|
|
row[columns.path] = string_compose ("%1/%2", category, action_name);
|
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 {
|
2015-08-05 10:57:00 -04:00
|
|
|
row[columns.binding] = *k;
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
2015-08-05 10:57:00 -04:00
|
|
|
row[columns.action] = *a;
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
2016-03-15 19:46:28 -04:00
|
|
|
|
|
|
|
return data_model->children().size();
|
2007-10-11 21:54:35 -04:00
|
|
|
}
|
2014-07-10 11:04:24 -04:00
|
|
|
|
2016-02-27 18:53:39 -05:00
|
|
|
void
|
|
|
|
KeyEditor::Tab::sort_column_changed ()
|
|
|
|
{
|
|
|
|
int column;
|
|
|
|
SortType type;
|
2016-03-07 17:56:03 -05:00
|
|
|
if (data_model->get_sort_column_id (column, type)) {
|
2016-02-27 18:53:39 -05:00
|
|
|
owner.sort_column = column;
|
|
|
|
owner.sort_type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::Tab::tab_mapped ()
|
|
|
|
{
|
2016-03-07 17:56:03 -05:00
|
|
|
data_model->set_sort_column (owner.sort_column, owner.sort_type);
|
|
|
|
filter->refilter ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
KeyEditor::Tab::visible_func(const Gtk::TreeModel::const_iterator& iter) const
|
|
|
|
{
|
|
|
|
if (!iter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// never filter when search string is empty or item is a category
|
|
|
|
if (owner.filter_string.empty () || !(*iter)[columns.bindable]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search name
|
|
|
|
std::string name = (*iter)[columns.name];
|
|
|
|
boost::to_lower (name);
|
|
|
|
if (name.find (owner.filter_string) != std::string::npos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search binding
|
|
|
|
std::string binding = (*iter)[columns.binding];
|
|
|
|
boost::to_lower (binding);
|
|
|
|
if (binding.find (owner.filter_string) != std::string::npos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeModel::iterator
|
|
|
|
KeyEditor::Tab::find_action_path (TreeModel::const_iterator begin, TreeModel::const_iterator end, const std::string& action_path) const
|
|
|
|
{
|
|
|
|
if (!begin) {
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (TreeModel::iterator it = begin; it != end; ++it) {
|
|
|
|
if (it->children()) {
|
|
|
|
TreeModel::iterator jt = find_action_path (it->children().begin(), it->children().end(), action_path);
|
|
|
|
if (jt != it->children().end()) {
|
|
|
|
return jt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const std::string& path = (*it)[columns.path];
|
|
|
|
if (action_path.compare(path) == 0) {
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return end;
|
2016-02-27 18:53:39 -05:00
|
|
|
}
|
|
|
|
|
2014-07-10 11:04:24 -04:00
|
|
|
void
|
|
|
|
KeyEditor::reset ()
|
|
|
|
{
|
|
|
|
Keyboard::the_keyboard().reset_bindings ();
|
2016-04-24 16:20:44 -04:00
|
|
|
refresh ();
|
|
|
|
}
|
2015-08-04 13:59:32 -04:00
|
|
|
|
2016-04-24 16:20:44 -04:00
|
|
|
void
|
|
|
|
KeyEditor::refresh ()
|
|
|
|
{
|
2015-08-04 13:59:32 -04:00
|
|
|
for (Tabs::iterator t = tabs.begin(); t != tabs.end(); ++t) {
|
|
|
|
(*t)->view.get_selection()->unselect_all ();
|
|
|
|
(*t)->populate ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyEditor::Tab*
|
|
|
|
KeyEditor::current_tab ()
|
|
|
|
{
|
|
|
|
return dynamic_cast<Tab*> (notebook.get_nth_page (notebook.get_current_page()));
|
2014-07-10 11:04:24 -04:00
|
|
|
}
|
2016-03-07 17:56:03 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::search_string_updated (const std::string& filter)
|
|
|
|
{
|
|
|
|
filter_string = boost::to_lower_copy(filter);
|
2016-03-28 14:08:35 -04:00
|
|
|
KeyEditor::Tab* tab = current_tab ();
|
|
|
|
if (tab) {
|
|
|
|
tab->filter->refilter ();
|
|
|
|
}
|
2016-03-07 17:56:03 -05:00
|
|
|
}
|
2016-05-21 09:30:24 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
KeyEditor::print () const
|
|
|
|
{
|
2016-06-15 19:45:59 -04:00
|
|
|
stringstream sstr;
|
|
|
|
Bindings::save_all_bindings_as_html (sstr);
|
|
|
|
|
|
|
|
if (sstr.str().empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gchar* file_name;
|
|
|
|
GError *err = NULL;
|
|
|
|
gint fd;
|
|
|
|
|
|
|
|
if ((fd = g_file_open_tmp ("akprintXXXXXX.html", &file_name, &err)) < 0) {
|
|
|
|
if (err) {
|
|
|
|
error << string_compose (_("Could not open temporary file to print bindings (%1)"), err->message) << endmsg;
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-24 16:45:03 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
::close (fd);
|
|
|
|
#endif
|
|
|
|
|
2016-06-15 19:45:59 -04:00
|
|
|
err = NULL;
|
|
|
|
|
|
|
|
if (!g_file_set_contents (file_name, sstr.str().c_str(), sstr.str().size(), &err)) {
|
2016-06-24 16:45:03 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2016-06-15 19:45:59 -04:00
|
|
|
::close (fd);
|
2016-06-24 16:45:03 -04:00
|
|
|
#endif
|
2016-06-15 19:45:59 -04:00
|
|
|
g_unlink (file_name);
|
|
|
|
if (err) {
|
|
|
|
error << string_compose (_("Could not save bindings to file (%1)"), err->message) << endmsg;
|
|
|
|
g_error_free (err);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-24 16:45:03 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2016-06-15 19:45:59 -04:00
|
|
|
::close (fd);
|
2016-06-24 16:45:03 -04:00
|
|
|
#endif
|
2016-06-15 19:45:59 -04:00
|
|
|
|
|
|
|
PBD::open_uri (string_compose ("file:///%1", file_name));
|
2016-05-21 09:30:24 -04:00
|
|
|
}
|