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"
34 using namespace ARDOUR;
35 using Gtkmm2ext::Keyboard;
38 accel_map_changed (GtkAccelMap* /*map*/,
41 GdkModifierType /*mod*/,
44 ArdourKeyboard* me = (ArdourKeyboard*)keyboard;
45 Keyboard::keybindings_changed ();
46 me->ui.setup_tooltips ();
50 ArdourKeyboard::setup_keybindings ()
52 using namespace ARDOUR_COMMAND_LINE;
53 string default_bindings = "mnemonic-us.bindings";
56 binding_files.clear ();
58 ARDOUR::find_bindings_files (binding_files);
60 /* set up the per-user bindings path */
62 user_keybindings_path = Glib::build_filename (user_config_directory(), "ardour.bindings");
64 if (Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) {
65 std::pair<string,string> newpair;
66 newpair.first = _("your own");
67 newpair.second = user_keybindings_path;
68 binding_files.insert (newpair);
71 /* check to see if they gave a style name ("SAE", "ergonomic") or
72 an actual filename (*.bindings)
75 if (!keybindings_path.empty() && keybindings_path.find (".bindings") == string::npos) {
77 // just a style name - allow user to
78 // specify the layout type.
82 if ((layout = getenv ("ARDOUR_KEYBOARD_LAYOUT")) != 0 && layout[0] != '\0') {
84 /* user-specified keyboard layout */
86 keybindings_path += '-';
87 keybindings_path += layout;
91 /* default to US/ANSI - we have to pick something */
93 keybindings_path += "-us";
96 keybindings_path += ".bindings";
99 if (keybindings_path.empty()) {
101 /* no path or binding name given: check the user one first */
103 if (!Glib::file_test (user_keybindings_path, Glib::FILE_TEST_EXISTS)) {
105 keybindings_path = "";
109 keybindings_path = user_keybindings_path;
113 /* if we still don't have a path at this point, use the default */
115 if (keybindings_path.empty()) {
116 keybindings_path = default_bindings;
121 if (!Glib::path_is_absolute (keybindings_path)) {
123 /* not absolute - look in the usual places */
124 std::string keybindings_file;
126 if ( ! find_file_in_search_path (ardour_config_search_path(), keybindings_path, keybindings_file)) {
128 if (keybindings_path == default_bindings) {
129 error << string_compose (_("Default keybindings not found - %1 will be hard to use!"), PROGRAM_NAME) << endmsg;
132 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
135 keybindings_path = default_bindings;
142 keybindings_path = keybindings_file;
149 /* path is absolute already */
151 if (!Glib::file_test (keybindings_path, Glib::FILE_TEST_EXISTS)) {
152 if (keybindings_path == default_bindings) {
153 error << string_compose (_("Default keybindings not found - %1 will be hard to use!"), PROGRAM_NAME) << endmsg;
156 warning << string_compose (_("Key bindings file \"%1\" not found. Default bindings used instead"),
159 keybindings_path = default_bindings;
168 load_keybindings (keybindings_path);
172 GtkAccelMap* accelmap = gtk_accel_map_get();
173 g_signal_connect (accelmap, "changed", (GCallback) accel_map_changed, this);
177 ArdourKeyboard::selection_type (guint state)
179 /* note that there is no modifier for "Add" */
181 if (modifier_state_equals (state, RangeSelectModifier)) {
182 return Selection::Extend;
183 } else if (modifier_state_equals (state, PrimaryModifier)) {
184 return Selection::Toggle;
186 return Selection::Set;