comparison libgui/src/shortcut-manager.cc @ 18976:dcb260e7a648

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Fri, 01 Aug 2014 12:10:05 -0400
parents 479d1d3cb5c3 58f1178f49ef
children
comparison
equal deleted inserted replaced
18972:19cb2530c16b 18976:dcb260e7a648
22 22
23 #ifdef HAVE_CONFIG_H 23 #ifdef HAVE_CONFIG_H
24 #include <config.h> 24 #include <config.h>
25 #endif 25 #endif
26 26
27 #include <QtCore>
27 #include <QMessageBox> 28 #include <QMessageBox>
28 #include <QDebug> 29 #include <QDebug>
29 #include <QGridLayout> 30 #include <QGridLayout>
30 #include <QVBoxLayout> 31 #include <QVBoxLayout>
31 #include <QDialogButtonBox> 32 #include <QDialogButtonBox>
44 shortcut_manager *shortcut_manager::instance = 0; 45 shortcut_manager *shortcut_manager::instance = 0;
45 46
46 shortcut_manager::shortcut_manager () 47 shortcut_manager::shortcut_manager ()
47 { 48 {
48 setObjectName ("Shortcut_Manager"); 49 setObjectName ("Shortcut_Manager");
50
51 // Mac: don't let Qt interpret CMD key ("Meta" in Qt terminology) as Ctrl
52 #if defined (Q_OS_MAC)
53 QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta, true);
54 #endif
49 55
50 _settings = resource_manager::get_settings (); 56 _settings = resource_manager::get_settings ();
51 } 57 }
52 58
53 shortcut_manager::~shortcut_manager () 59 shortcut_manager::~shortcut_manager ()
78 } 84 }
79 85
80 void 86 void
81 shortcut_manager::do_init_data () 87 shortcut_manager::do_init_data ()
82 { 88 {
89 QKeySequence ctrl;
90 int prefix;
91 #if defined (Q_OS_MAC)
92 // Use CMD key as an equivalent of Ctrl key on other platforms
93 ctrl = Qt::MetaModifier;
94 // Some of octave default shortcuts on windows/linux are already defined
95 // as system wide shortcuts on Mac Os X (almost all Function keys).
96 // Prefix those with Option (Alt) modifier to avoid conflicts.
97 prefix = Qt::AltModifier;
98 #else
99 ctrl = Qt::ControlModifier;
100 prefix = Qt::NoModifier;
101 #endif
102
103 QKeySequence ctrl_shift = ctrl + Qt::ShiftModifier;
104 QKeySequence ctrl_alt = ctrl + Qt::AltModifier;
105
83 // actions of the main window 106 // actions of the main window
84 107
85 // file 108 // file
86 init (tr ("New File"), "main_file:new_file", QKeySequence::New); 109 init (tr ("New File"), "main_file:new_file", QKeySequence::New);
87 init (tr ("New Function"), "main_file:new_function", 110 init (tr ("New Function"), "main_file:new_function",
88 QKeySequence ("Ctrl+Shift+N")); 111 QKeySequence (ctrl_shift + Qt::Key_N));
89 init (tr ("New Figure"), "main_file:new_figure", QKeySequence ()); 112 init (tr ("New Figure"), "main_file:new_figure", QKeySequence ());
90 init (tr ("Open File"), "main_file:open_file", QKeySequence::Open); 113 init (tr ("Open File"), "main_file:open_file", QKeySequence::Open);
91 init (tr ("Load Workspace"), "main_file:load_workspace", QKeySequence ()); 114 init (tr ("Load Workspace"), "main_file:load_workspace", QKeySequence ());
92 init (tr ("Save Workspace As"), "main_file:save_workspace", QKeySequence ()); 115 init (tr ("Save Workspace As"), "main_file:save_workspace", QKeySequence ());
93 init (tr ("Preferences"), "main_file:preferences", QKeySequence ()); 116 init (tr ("Preferences"), "main_file:preferences", QKeySequence ());
98 init (tr ("Paste"), "main_edit:paste", QKeySequence::Paste); 121 init (tr ("Paste"), "main_edit:paste", QKeySequence::Paste);
99 init (tr ("Undo"), "main_edit:undo", QKeySequence::Undo); 122 init (tr ("Undo"), "main_edit:undo", QKeySequence::Undo);
100 init (tr ("Select All"), "main_edit:select_all", QKeySequence ()); 123 init (tr ("Select All"), "main_edit:select_all", QKeySequence ());
101 init (tr ("Clear Clipboard"), "main_edit:clear_clipboard", QKeySequence ()); 124 init (tr ("Clear Clipboard"), "main_edit:clear_clipboard", QKeySequence ());
102 init (tr ("Find in Files"), "main_edit:find_in_files", 125 init (tr ("Find in Files"), "main_edit:find_in_files",
103 QKeySequence (Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_F)); 126 QKeySequence (ctrl_shift + Qt::Key_F));
104 init (tr ("Clear Command Window"), "main_edit:clear_command_window", 127 init (tr ("Clear Command Window"), "main_edit:clear_command_window",
105 QKeySequence ()); 128 QKeySequence ());
106 init (tr ("Clear Command History"), "main_edit:clear_history", 129 init (tr ("Clear Command History"), "main_edit:clear_history",
107 QKeySequence ()); 130 QKeySequence ());
108 init (tr ("Clear Workspace"), "main_edit:clear_workspace", QKeySequence ()); 131 init (tr ("Clear Workspace"), "main_edit:clear_workspace", QKeySequence ());
109 132
110 // debug 133 // debug
111 init (tr ("Step Over"), "main_debug:step_over", QKeySequence (Qt::Key_F10)); 134 init (tr ("Step Over"), "main_debug:step_over",
112 init (tr ("Step Into"), "main_debug:step_into", QKeySequence (Qt::Key_F11)); 135 QKeySequence (prefix + Qt::Key_F10));
113 init (tr ("Step Out"), "main_debug:step_out", QKeySequence (Qt::ShiftModifier + Qt::Key_F11)); 136 init (tr ("Step Into"), "main_debug:step_into",
114 init (tr ("Continue"), "main_debug:continue", QKeySequence (Qt::Key_F5)); 137 QKeySequence (prefix + Qt::Key_F11));
115 init (tr ("Quit Debug Mode"), "main_debug:quit", QKeySequence (Qt::ShiftModifier + Qt::Key_F5)); 138 init (tr ("Step Out"), "main_debug:step_out",
139 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F11));
140 init (tr ("Continue"), "main_debug:continue",
141 QKeySequence (prefix + Qt::Key_F5));
142 init (tr ("Quit Debug Mode"), "main_debug:quit",
143 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F5));
116 144
117 // window 145 // window
118 QKeySequence ctrl = Qt::ControlModifier; 146 init (tr ("Show Command Window"), "main_window:show_command",
119 QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; 147 prefix + ctrl_shift + Qt::Key_0);
120 init (tr ("Show Command Window"), "main_window:show_command", ctrl_shift + Qt::Key_0); 148 init (tr ("Show Command History"), "main_window:show_history",
121 init (tr ("Show Command History"), "main_window:show_history", ctrl_shift + Qt::Key_1); 149 prefix + ctrl_shift + Qt::Key_1);
122 init (tr ("Show File Browser"), "main_window:show_file_browser", ctrl_shift + Qt::Key_2); 150 init (tr ("Show File Browser"), "main_window:show_file_browser",
123 init (tr ("Show Workspace"), "main_window:show_workspace", ctrl_shift + Qt::Key_3); 151 prefix + ctrl_shift + Qt::Key_2);
124 init (tr ("Show Editor"), "main_window:show_editor", ctrl_shift + Qt::Key_4); 152 init (tr ("Show Workspace"), "main_window:show_workspace",
125 init (tr ("Show Documentation"), "main_window:show_doc", ctrl_shift + Qt::Key_5); 153 prefix + ctrl_shift + Qt::Key_3);
126 init (tr ("Command Window"), "main_window:command", ctrl + Qt::Key_0); 154 init (tr ("Show Editor"), "main_window:show_editor",
127 init (tr ("Command History"), "main_window:history", ctrl + Qt::Key_1); 155 prefix + ctrl_shift + Qt::Key_4);
128 init (tr ("File Browser"), "main_window:file_browser", ctrl + Qt::Key_2); 156 init (tr ("Show Documentation"), "main_window:show_doc",
129 init (tr ("Workspace"), "main_window:workspace", ctrl + Qt::Key_3); 157 prefix + ctrl_shift + Qt::Key_5);
130 init (tr ("Editor"), "main_window:editor", ctrl + Qt::Key_4); 158 init (tr ("Command Window"), "main_window:command",
131 init (tr ("Documentation"), "main_window:doc", ctrl + Qt::Key_5); 159 prefix + ctrl + Qt::Key_0);
160 init (tr ("Command History"), "main_window:history",
161 prefix + ctrl + Qt::Key_1);
162 init (tr ("File Browser"), "main_window:file_browser",
163 prefix + ctrl + Qt::Key_2);
164 init (tr ("Workspace"), "main_window:workspace",
165 prefix + ctrl + Qt::Key_3);
166 init (tr ("Editor"), "main_window:editor",
167 prefix + ctrl + Qt::Key_4);
168 init (tr ("Documentation"), "main_window:doc",
169 prefix + ctrl + Qt::Key_5);
132 init (tr ("Reset Window Layout"), "main_window:reset", QKeySequence ()); 170 init (tr ("Reset Window Layout"), "main_window:reset", QKeySequence ());
133 171
134 // help 172 // help
135 init (tr ("Show Ondisk Documentation"), "main_help:ondisk_doc", QKeySequence ()); 173 init (tr ("Show Ondisk Documentation"), "main_help:ondisk_doc", QKeySequence ());
136 init (tr ("Show Online Documentation"), "main_help:online_doc", QKeySequence ()); 174 init (tr ("Show Online Documentation"), "main_help:online_doc", QKeySequence ());
147 185
148 // actions of the editor 186 // actions of the editor
149 187
150 // file 188 // file
151 init (tr ("Edit Function"), "editor_file:edit_function", 189 init (tr ("Edit Function"), "editor_file:edit_function",
152 QKeySequence (Qt::ControlModifier + Qt::Key_E)); 190 QKeySequence (ctrl + Qt::Key_E));
153 init (tr ("Save File"), "editor_file:save", QKeySequence::Save); 191 init (tr ("Save File"), "editor_file:save", QKeySequence::Save);
154 init (tr ("Save File As"), "editor_file:save_as", QKeySequence::SaveAs); 192 init (tr ("Save File As"), "editor_file:save_as", QKeySequence::SaveAs);
155 init (tr ("Close"), "editor_file:close", QKeySequence::Close); 193 init (tr ("Close"), "editor_file:close", QKeySequence::Close);
156 init (tr ("Close All"), "editor_file:close_all", QKeySequence ()); 194 init (tr ("Close All"), "editor_file:close_all", QKeySequence ());
157 init (tr ("Close Other"), "editor_file:close_other", QKeySequence ()); 195 init (tr ("Close Other"), "editor_file:close_other", QKeySequence ());
164 init (tr ("Cuy"), "editor_edit:cut", QKeySequence::Cut); 202 init (tr ("Cuy"), "editor_edit:cut", QKeySequence::Cut);
165 init (tr ("Paste"), "editor_edit:paste", QKeySequence::Paste); 203 init (tr ("Paste"), "editor_edit:paste", QKeySequence::Paste);
166 init (tr ("Select All"), "editor_edit:select_all", QKeySequence::SelectAll); 204 init (tr ("Select All"), "editor_edit:select_all", QKeySequence::SelectAll);
167 init (tr ("Find and Replace"), "editor_edit:find_replace", 205 init (tr ("Find and Replace"), "editor_edit:find_replace",
168 QKeySequence::Find); 206 QKeySequence::Find);
169
170 init (tr ("Delete to Start of Word"), "editor_edit:delete_start_word", 207 init (tr ("Delete to Start of Word"), "editor_edit:delete_start_word",
171 QKeySequence::DeleteStartOfWord); 208 QKeySequence::DeleteStartOfWord);
172 init (tr ("Delete to End of Word"), "editor_edit:delete_end_word", 209 init (tr ("Delete to End of Word"), "editor_edit:delete_end_word",
173 QKeySequence::DeleteEndOfWord); 210 QKeySequence::DeleteEndOfWord);
174 init (tr ("Delete to Start of Line"), "editor_edit:delete_start_line", 211 init (tr ("Delete to Start of Line"), "editor_edit:delete_start_line",
175 QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_Backspace)); 212 QKeySequence (ctrl_shift + Qt::Key_Backspace));
176 init (tr ("Delete to End of Line"), "editor_edit:delete_end_line", 213 init (tr ("Delete to End of Line"), "editor_edit:delete_end_line",
177 QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_Delete)); 214 QKeySequence (ctrl_shift + Qt::Key_Delete));
178 init (tr ("Delete Line"), "editor_edit:delete_line", 215 init (tr ("Delete Line"), "editor_edit:delete_line",
179 QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_L)); 216 QKeySequence (ctrl_shift + Qt::Key_L));
180 init (tr ("Copy Line"), "editor_edit:copy_line", 217 init (tr ("Copy Line"), "editor_edit:copy_line",
181 QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_C)); 218 QKeySequence (ctrl_shift + Qt::Key_C));
182 init (tr ("Cut Line"), "editor_edit:cut_line", 219 init (tr ("Cut Line"), "editor_edit:cut_line",
183 QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_X)); 220 QKeySequence (ctrl_shift + Qt::Key_X));
184 init (tr ("Duplicate Selection/Line"), "editor_edit:duplicate_selection", 221 init (tr ("Duplicate Selection/Line"), "editor_edit:duplicate_selection",
185 QKeySequence (Qt::ControlModifier + Qt::Key_D)); 222 QKeySequence (ctrl + Qt::Key_D));
186 init (tr ("Transpose Line"), "editor_edit:transpose_line", 223 init (tr ("Transpose Line"), "editor_edit:transpose_line",
187 QKeySequence (Qt::ControlModifier + Qt::Key_T)); 224 QKeySequence (ctrl + Qt::Key_T));
188 init (tr ("Completion List"), "editor_edit:completion_list", 225 init (tr ("Completion List"), "editor_edit:completion_list",
189 QKeySequence (Qt::ControlModifier + Qt::Key_Space)); 226 QKeySequence (ctrl + Qt::Key_Space));
190 227
191 init (tr ("Comment Selection"), "editor_edit:comment_selection", 228 init (tr ("Comment Selection"), "editor_edit:comment_selection",
192 QKeySequence (Qt::ControlModifier + Qt::Key_R)); 229 QKeySequence (ctrl + Qt::Key_R));
193 init (tr ("Uncomment Selection"), "editor_edit:uncomment_selection", 230 init (tr ("Uncomment Selection"), "editor_edit:uncomment_selection",
194 QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_R)); 231 QKeySequence (ctrl_shift + Qt::Key_R));
195 init (tr ("Uppercase Selection"), "editor_edit:upper_case", 232 init (tr ("Uppercase Selection"), "editor_edit:upper_case",
196 QKeySequence (Qt::ControlModifier + Qt::Key_U)); 233 QKeySequence (ctrl + Qt::Key_U));
197 init (tr ("Lowercase Selection"), "editor_edit:lower_case", 234 init (tr ("Lowercase Selection"), "editor_edit:lower_case",
198 QKeySequence (Qt::ControlModifier + Qt::AltModifier + Qt::Key_U)); 235 QKeySequence (ctrl_alt + Qt::Key_U));
199 init (tr ("Indent Selection"), "editor_edit:indent_selection", 236
200 QKeySequence (Qt::ControlModifier + Qt::Key_Tab)); 237 #if defined (Q_OS_MAC)
201 init (tr ("Unindent Selection"), "editor_edit:unindent_selection", 238 init (tr ("Indent Selection"), "editor_edit:indent_selection",
202 QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_Tab)); 239 QKeySequence (prefix + Qt::Key_Tab));
203 240 init (tr ("Unindent Selection"), "editor_edit:unindent_selection",
204 init (tr ("Goto Line"), "editor_edit:goto_line", 241 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_Tab));
205 QKeySequence (Qt::ControlModifier+ Qt::Key_G)); 242 #else
243 init (tr ("Indent Selection"), "editor_edit:indent_selection",
244 QKeySequence (ctrl + Qt::Key_Tab));
245 init (tr ("Unindent Selection"), "editor_edit:unindent_selection",
246 QKeySequence (ctrl_shift + Qt::Key_Tab));
247 #endif
248
249 init (tr ("Goto Line"), "editor_edit:goto_line",
250 QKeySequence (ctrl + Qt::Key_G));
206 init (tr ("Toggle Bookmark"), "editor_edit:toggle_bookmark", 251 init (tr ("Toggle Bookmark"), "editor_edit:toggle_bookmark",
207 QKeySequence (Qt::Key_F7)); 252 QKeySequence (prefix + Qt::Key_F7));
208 init (tr ("Next Bookmark"), "editor_edit:next_bookmark", 253 init (tr ("Next Bookmark"), "editor_edit:next_bookmark",
209 QKeySequence (Qt::Key_F2)); 254 QKeySequence (prefix + Qt::Key_F2));
210 init (tr ("Previous Bookmark"), "editor_edit:previous_bookmark", 255 init (tr ("Previous Bookmark"), "editor_edit:previous_bookmark",
211 QKeySequence (Qt::SHIFT + Qt::Key_F2)); 256 QKeySequence (prefix + Qt::SHIFT + Qt::Key_F2));
212 init (tr ("Remove All Bookmark"), "editor_edit:remove_bookmark", 257 init (tr ("Remove All Bookmark"), "editor_edit:remove_bookmark",
213 QKeySequence ()); 258 QKeySequence ());
214 259
215 init (tr ("Preferences"), "editor_edit:preferences", QKeySequence ()); 260 init (tr ("Preferences"), "editor_edit:preferences", QKeySequence ());
216 init (tr ("Styles Preferences"), "editor_edit:styles_preferences", 261 init (tr ("Styles Preferences"), "editor_edit:styles_preferences",
217 QKeySequence ()); 262 QKeySequence ());
218 263
219 // view 264 // view
220 init (tr ("Zoom In"), "editor_view:zoom_in", QKeySequence::ZoomIn); 265 init (tr ("Zoom In"), "editor_view:zoom_in", QKeySequence::ZoomIn);
221 init (tr ("Zoom Out"), "editor_view:zoom_out", QKeySequence::ZoomOut); 266 init (tr ("Zoom Out"), "editor_view:zoom_out", QKeySequence::ZoomOut);
222 init (tr ("Zoom Normal"), "editor_view:zoom_normal", QKeySequence (Qt::ControlModifier + Qt::AltModifier + Qt::Key_0)); 267 #if defined (Q_OS_MAC)
268 init (tr ("Zoom Normal"), "editor_view:zoom_normal",
269 QKeySequence (ctrl + Qt::Key_Underscore));
270 #else
271 init (tr ("Zoom Normal"), "editor_view:zoom_normal",
272 QKeySequence (ctrl_alt + Qt::Key_0));
273 #endif
223 274
224 // debug 275 // debug
225 init (tr ("Toggle Breakpoint"), "editor_debug:toggle_breakpoint", 276 init (tr ("Toggle Breakpoint"), "editor_debug:toggle_breakpoint",
226 QKeySequence ()); 277 QKeySequence ());
227 init (tr ("Next Breakpoint"), "editor_debug:next_breakpoint", 278 init (tr ("Next Breakpoint"), "editor_debug:next_breakpoint",
230 QKeySequence ()); 281 QKeySequence ());
231 init (tr ("Remove All Breakpoints"), "editor_debug:remove_breakpoints", 282 init (tr ("Remove All Breakpoints"), "editor_debug:remove_breakpoints",
232 QKeySequence ()); 283 QKeySequence ());
233 284
234 // run 285 // run
235 init (tr ("Run File"), "editor_run:run_file", QKeySequence (Qt::Key_F5)); 286 init (tr ("Run File"), "editor_run:run_file",
236 init (tr ("Run Selection"), "editor_run:run_selection", QKeySequence (Qt::Key_F9)); 287 QKeySequence (prefix + Qt::Key_F5) );
288 init (tr ("Run Selection"), "editor_run:run_selection",
289 QKeySequence (prefix + Qt::Key_F9) );
237 290
238 // help 291 // help
239 init (tr ("Help on Keyword"), "editor_help:help_keyword", QKeySequence::HelpContents); 292 init (tr ("Help on Keyword"), "editor_help:help_keyword", QKeySequence::HelpContents);
240 init (tr ("Document on Keyword"), "editor_help:doc_keyword", QKeySequence (Qt::SHIFT + Qt::Key_F1)); 293 init (tr ("Document on Keyword"), "editor_help:doc_keyword", QKeySequence (Qt::SHIFT + Qt::Key_F1));
241 } 294 }