2 Copyright (C) 2001 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/error.h"
21 #include "pbd/file_utils.h"
23 #include "ardour/filesystem_paths.h"
25 #include "ardour_ui.h"
26 #include "public_editor.h"
35 using namespace ARDOUR;
36 using Gtkmm2ext::Keyboard;
39 accel_map_changed (GtkAccelMap* /*map*/,
42 GdkModifierType /*mod*/,
45 ArdourKeyboard* me = (ArdourKeyboard*)keyboard;
46 Keyboard::keybindings_changed ();
47 me->ui.setup_tooltips ();
51 ArdourKeyboard::setup_keybindings ()
53 using namespace ARDOUR_COMMAND_LINE;
54 string default_bindings = "mnemonic-us.bindings";
57 binding_files.clear ();
59 ARDOUR::find_bindings_files (binding_files);
61 /* set up the per-user bindings path */
63 user_keybindings_path = Glib::build_filename (user_config_directory(), "ardour.bindings");
65 if (Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) {
66 std::pair<string,string> newpair;
67 newpair.first = _("your own");
68 newpair.second = user_keybindings_path;
69 binding_files.insert (newpair);
72 /* check to see if they gave a style name ("SAE", "ergonomic") or
73 an actual filename (*.bindings)
76 if (!keybindings_path.empty() && keybindings_path.find (".bindings") == string::npos) {
78 // just a style name - allow user to
79 // specify the layout type.
83 if ((layout = getenv ("ARDOUR_KEYBOARD_LAYOUT")) != 0 && layout[0] != '\0') {
85 /* user-specified keyboard layout */
87 keybindings_path += '-';
88 keybindings_path += layout;
92 /* default to US/ANSI - we have to pick something */
94 keybindings_path += "-us";
97 keybindings_path += ".bindings";
100 if (keybindings_path.empty()) {
102 /* no path or binding name given: check the user one first */
104 if (!Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) {
106 keybindings_path = "";
110 keybindings_path = user_keybindings_path;
114 /* if we still don't have a path at this point, use the default */
116 if (keybindings_path.empty()) {
117 keybindings_path = default_bindings;
122 if (!Glib::path_is_absolute (keybindings_path)) {
124 /* not absolute - look in the usual places */
125 std::string keybindings_file;
127 if ( ! find_file (ardour_config_search_path(), keybindings_path, keybindings_file)) {
129 if (keybindings_path == default_bindings) {
130 error << string_compose (_("Default keybindings not found - %1 will be hard to use!"), PROGRAM_NAME) << endmsg;
133 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
136 keybindings_path = default_bindings;
143 keybindings_path = keybindings_file;
150 /* path is absolute already */
152 if (!Glib::file_test (keybindings_path, Glib::FILE_TEST_EXISTS)) {
153 if (keybindings_path == default_bindings) {
154 error << string_compose (_("Default keybindings not found - %1 will be hard to use!"), PROGRAM_NAME) << endmsg;
157 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
160 keybindings_path = default_bindings;
169 load_keybindings (keybindings_path);
173 GtkAccelMap* accelmap = gtk_accel_map_get();
174 g_signal_connect (accelmap, "changed", (GCallback) accel_map_changed, this);
178 ArdourKeyboard::selection_type (guint state)
180 /* note that there is no modifier for "Add" */
182 if (modifier_state_equals (state, RangeSelectModifier)) {
183 return Selection::Extend;
184 } else if (modifier_state_equals (state, PrimaryModifier)) {
185 return Selection::Toggle;
187 return Selection::Set;