28 #include <QMessageBox>
30 #include <QGridLayout>
31 #include <QVBoxLayout>
32 #include <QDialogButtonBox>
33 #include <QPushButton>
36 #include <QHeaderView>
38 #include <QFileDialog>
49 setObjectName (
"Shortcut_Manager");
52 #if defined (Q_OS_MAC)
53 QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta,
true);
78 ::error (
"unable to create shortcut_manager object!");
91 #if defined (Q_OS_MAC)
93 ctrl = Qt::MetaModifier;
97 prefix = Qt::AltModifier;
99 ctrl = Qt::ControlModifier;
100 prefix = Qt::NoModifier;
103 QKeySequence ctrl_shift = ctrl + Qt::ShiftModifier;
104 QKeySequence ctrl_alt = ctrl + Qt::AltModifier;
109 init (tr (
"New File"),
"main_file:new_file", QKeySequence::New);
110 init (tr (
"New Function"),
"main_file:new_function",
111 QKeySequence (ctrl_shift + Qt::Key_N));
112 init (tr (
"New Figure"),
"main_file:new_figure", QKeySequence ());
113 init (tr (
"Open File"),
"main_file:open_file", QKeySequence::Open);
114 init (tr (
"Load Workspace"),
"main_file:load_workspace", QKeySequence ());
115 init (tr (
"Save Workspace As"),
"main_file:save_workspace", QKeySequence ());
116 init (tr (
"Exit Octave"),
"main_file:exit", QKeySequence::Quit);
119 init (tr (
"Copy"),
"main_edit:copy", QKeySequence::Copy);
120 init (tr (
"Paste"),
"main_edit:paste", QKeySequence::Paste);
121 init (tr (
"Undo"),
"main_edit:undo", QKeySequence::Undo);
122 init (tr (
"Select All"),
"main_edit:select_all", QKeySequence ());
123 init (tr (
"Clear Clipboard"),
"main_edit:clear_clipboard", QKeySequence ());
124 init (tr (
"Find in Files"),
"main_edit:find_in_files",
125 QKeySequence (ctrl_shift + Qt::Key_F));
126 init (tr (
"Clear Command Window"),
"main_edit:clear_command_window",
128 init (tr (
"Clear Command History"),
"main_edit:clear_history",
130 init (tr (
"Clear Workspace"),
"main_edit:clear_workspace", QKeySequence ());
131 init (tr (
"Preferences"),
"main_edit:preferences", QKeySequence ());
134 init (tr (
"Step"),
"main_debug:step_over",
135 QKeySequence (prefix + Qt::Key_F10));
136 init (tr (
"Step Into"),
"main_debug:step_into",
137 QKeySequence (prefix + Qt::Key_F11));
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));
146 init (tr (
"Show Command Window"),
"main_window:show_command",
147 prefix + ctrl_shift + Qt::Key_0);
148 init (tr (
"Show Command History"),
"main_window:show_history",
149 prefix + ctrl_shift + Qt::Key_1);
150 init (tr (
"Show File Browser"),
"main_window:show_file_browser",
151 prefix + ctrl_shift + Qt::Key_2);
152 init (tr (
"Show Workspace"),
"main_window:show_workspace",
153 prefix + ctrl_shift + Qt::Key_3);
154 init (tr (
"Show Editor"),
"main_window:show_editor",
155 prefix + ctrl_shift + Qt::Key_4);
156 init (tr (
"Show Documentation"),
"main_window:show_doc",
157 prefix + ctrl_shift + Qt::Key_5);
158 init (tr (
"Command Window"),
"main_window:command",
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);
170 init (tr (
"Reset Default Window Layout"),
"main_window:reset", QKeySequence ());
173 init (tr (
"Show Ondisk Documentation"),
"main_help:ondisk_doc",
175 init (tr (
"Show Online Documentation"),
"main_help:online_doc",
177 init (tr (
"Report Bug"),
"main_help:report_bug", QKeySequence ());
178 init (tr (
"Octave Packages"),
"main_help:packages", QKeySequence ());
179 init (tr (
"Share Code"),
"main_help:agora", QKeySequence ());
180 init (tr (
"Contribute to Octave"),
"main_help:contribute", QKeySequence ());
181 init (tr (
"Octave Developer Resources"),
"main_help:developer",
183 init (tr (
"About Octave"),
"main_help:about", QKeySequence ());
186 init (tr (
"Release Notes"),
"main_news:release_notes", QKeySequence ());
187 init (tr (
"Community News"),
"main_news:community_news", QKeySequence ());
192 init (tr (
"Edit Function"),
"editor_file:edit_function",
193 QKeySequence (ctrl + Qt::Key_E));
194 init (tr (
"Save File"),
"editor_file:save", QKeySequence::Save);
195 init (tr (
"Save File As"),
"editor_file:save_as", QKeySequence::SaveAs);
196 init (tr (
"Close"),
"editor_file:close", QKeySequence::Close);
197 init (tr (
"Close All"),
"editor_file:close_all", QKeySequence ());
198 init (tr (
"Close Other Files"),
"editor_file:close_other", QKeySequence ());
199 init (tr (
"Print"),
"editor_file:print", QKeySequence::Print);
202 init (tr (
"Undo"),
"editor_edit:undo", QKeySequence::Undo);
203 init (tr (
"Redo"),
"editor_edit:redo", QKeySequence::Redo);
204 init (tr (
"Copy"),
"editor_edit:copy", QKeySequence::Copy);
205 init (tr (
"Cut"),
"editor_edit:cut", QKeySequence::Cut);
206 init (tr (
"Paste"),
"editor_edit:paste", QKeySequence::Paste);
207 init (tr (
"Select All"),
"editor_edit:select_all", QKeySequence::SelectAll);
208 init (tr (
"Find and Replace"),
"editor_edit:find_replace",
210 init (tr (
"Delete to Start of Word"),
"editor_edit:delete_start_word",
211 QKeySequence::DeleteStartOfWord);
212 init (tr (
"Delete to End of Word"),
"editor_edit:delete_end_word",
213 QKeySequence::DeleteEndOfWord);
214 init (tr (
"Delete to Start of Line"),
"editor_edit:delete_start_line",
215 QKeySequence (ctrl_shift + Qt::Key_Backspace));
216 init (tr (
"Delete to End of Line"),
"editor_edit:delete_end_line",
217 QKeySequence (ctrl_shift + Qt::Key_Delete));
218 init (tr (
"Delete Line"),
"editor_edit:delete_line",
219 QKeySequence (ctrl_shift + Qt::Key_L));
220 init (tr (
"Copy Line"),
"editor_edit:copy_line",
221 QKeySequence (ctrl_shift + Qt::Key_C));
222 init (tr (
"Cut Line"),
"editor_edit:cut_line",
223 QKeySequence (ctrl_shift + Qt::Key_X));
224 init (tr (
"Duplicate Selection/Line"),
"editor_edit:duplicate_selection",
225 QKeySequence (ctrl + Qt::Key_D));
226 init (tr (
"Transpose Line"),
"editor_edit:transpose_line",
227 QKeySequence (ctrl + Qt::Key_T));
228 init (tr (
"Show Completion List"),
"editor_edit:completion_list",
229 QKeySequence (ctrl + Qt::Key_Space));
231 init (tr (
"Comment Selection"),
"editor_edit:comment_selection",
232 QKeySequence (ctrl + Qt::Key_R));
233 init (tr (
"Uncomment Selection"),
"editor_edit:uncomment_selection",
234 QKeySequence (ctrl_shift + Qt::Key_R));
235 init (tr (
"Uppercase Selection"),
"editor_edit:upper_case",
236 QKeySequence (ctrl + Qt::Key_U));
237 init (tr (
"Lowercase Selection"),
"editor_edit:lower_case",
238 QKeySequence (ctrl_alt + Qt::Key_U));
240 #if defined (Q_OS_MAC)
241 init (tr (
"Indent Selection"),
"editor_edit:indent_selection",
242 QKeySequence (prefix + Qt::Key_Tab));
243 init (tr (
"Unindent Selection"),
"editor_edit:unindent_selection",
244 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_Tab));
246 init (tr (
"Indent Selection"),
"editor_edit:indent_selection",
247 QKeySequence (ctrl + Qt::Key_Tab));
248 init (tr (
"Unindent Selection"),
"editor_edit:unindent_selection",
249 QKeySequence (ctrl_shift + Qt::Key_Tab));
252 init (tr (
"Convert Line Endings to Windows"),
"editor_edit:conv_eol_winows",
254 init (tr (
"Convert Line Endings to Unix"),
"editor_edit:conv_eol_unix",
256 init (tr (
"Convert Line Endings to Mac"),
"editor_edit:conv_eol_mac",
259 init (tr (
"Goto Line"),
"editor_edit:goto_line",
260 QKeySequence (ctrl + Qt::Key_G));
261 init (tr (
"Move to Matching Brace"),
"editor_edit:move_to_brace",
262 QKeySequence (ctrl + Qt::Key_M));
263 init (tr (
"Select to Matching Brace"),
"editor_edit:select_to_brace",
264 QKeySequence (ctrl_shift + Qt::Key_M));
265 init (tr (
"Toggle Bookmark"),
"editor_edit:toggle_bookmark",
266 QKeySequence (prefix + Qt::Key_F7));
267 init (tr (
"Next Bookmark"),
"editor_edit:next_bookmark",
268 QKeySequence (prefix + Qt::Key_F2));
269 init (tr (
"Previous Bookmark"),
"editor_edit:previous_bookmark",
270 QKeySequence (prefix + Qt::SHIFT + Qt::Key_F2));
271 init (tr (
"Remove All Bookmark"),
"editor_edit:remove_bookmark",
274 init (tr (
"Preferences"),
"editor_edit:preferences", QKeySequence ());
275 init (tr (
"Styles Preferences"),
"editor_edit:styles_preferences",
279 init (tr (
"Show Line Numbers"),
"editor_view:show_line_numbers",
281 init (tr (
"Show Whitespace Characters"),
"editor_view:show_white_spaces",
283 init (tr (
"Show Line Endings"),
"editor_view:show_eol_chars", QKeySequence ());
284 init (tr (
"Show Indentation Guides"),
"editor_view:show_ind_guides",
286 init (tr (
"Show Long Line Marker"),
"editor_view:show_long_line",
288 init (tr (
"Zoom In"),
"editor_view:zoom_in", QKeySequence::ZoomIn);
289 init (tr (
"Zoom Out"),
"editor_view:zoom_out", QKeySequence::ZoomOut);
290 #if defined (Q_OS_MAC)
291 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
292 QKeySequence (ctrl + Qt::Key_Underscore));
294 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
295 QKeySequence (ctrl + Qt::Key_Period));
299 init (tr (
"Toggle Breakpoint"),
"editor_debug:toggle_breakpoint",
301 init (tr (
"Next Breakpoint"),
"editor_debug:next_breakpoint",
303 init (tr (
"Previous Breakpoint"),
"editor_debug:previous_breakpoint",
305 init (tr (
"Remove All Breakpoints"),
"editor_debug:remove_breakpoints",
309 init (tr (
"Run File"),
"editor_run:run_file",
310 QKeySequence (prefix + Qt::Key_F5) );
311 init (tr (
"Run Selection"),
"editor_run:run_selection",
312 QKeySequence (prefix + Qt::Key_F9) );
315 init (tr (
"Help on Keyword"),
"editor_help:help_keyword",
316 QKeySequence::HelpContents);
317 init (tr (
"Document on Keyword"),
"editor_help:doc_keyword",
318 QKeySequence (Qt::SHIFT + Qt::Key_F1));
324 QKeySequence actual_0
325 = QKeySequence (
_settings->value (
"shortcuts/"+key, def_sc).toString ());
326 QKeySequence actual_1
327 = QKeySequence (
_settings->value (
"shortcuts/"+key+
"_1", def_sc).toString ());
332 shortcut_info.settings_key = key;
333 shortcut_info.actual_sc [0] = actual_0;
334 shortcut_info.actual_sc [1] = actual_1;
335 shortcut_info.default_sc [0] = def_sc;
336 shortcut_info.default_sc [1] = def_sc;
337 _sc << shortcut_info;
340 QString widget = key.section (
'_',0,0);
341 if (! actual_0.isEmpty ())
344 if (! actual_1.isEmpty ())
356 tree_view->header ()->setResizeMode (QHeaderView::ResizeToContents);
358 QTreeWidgetItem *
main =
new QTreeWidgetItem (tree_view);
359 main->setText (0, tr (
"Main"));
360 main->setExpanded (
true);
361 QTreeWidgetItem *main_file =
new QTreeWidgetItem (main);
362 main_file->setText (0, tr (
"File"));
363 QTreeWidgetItem *main_edit =
new QTreeWidgetItem (main);
364 main_edit->setText (0, tr (
"Edit"));
365 QTreeWidgetItem *main_debug =
new QTreeWidgetItem (main);
366 main_debug->setText (0, tr (
"Debug"));
367 QTreeWidgetItem *
main_window =
new QTreeWidgetItem (main);
368 main_window->setText (0, tr (
"Window"));
369 QTreeWidgetItem *main_help =
new QTreeWidgetItem (main);
370 main_help->setText (0, tr (
"Help"));
371 QTreeWidgetItem *main_news =
new QTreeWidgetItem (main);
372 main_news->setText (0, tr (
"News"));
381 QTreeWidgetItem *editor =
new QTreeWidgetItem (tree_view);
382 editor->setText (0, tr (
"Editor"));
383 editor->setExpanded (
true);
384 QTreeWidgetItem *editor_file =
new QTreeWidgetItem (editor);
385 editor_file->setText (0, tr (
"File"));
386 QTreeWidgetItem *editor_edit =
new QTreeWidgetItem (editor);
387 editor_edit->setText (0, tr (
"Edit"));
388 QTreeWidgetItem *editor_view =
new QTreeWidgetItem (editor);
389 editor_view->setText (0, tr (
"View"));
390 QTreeWidgetItem *editor_debug =
new QTreeWidgetItem (editor);
391 editor_debug->setText (0, tr (
"Debug"));
392 QTreeWidgetItem *editor_run =
new QTreeWidgetItem (editor);
393 editor_run->setText (0, tr (
"Run"));
394 QTreeWidgetItem *editor_help =
new QTreeWidgetItem (editor);
395 editor_help->setText (0, tr (
"Help"));
404 connect (tree_view, SIGNAL (itemDoubleClicked (QTreeWidgetItem*,
int)),
407 for (
int i = 0; i <
_sc.count (); i++)
412 QTreeWidgetItem* tree_item =
new QTreeWidgetItem (section);
415 QColor fg = QColor (tree_item->foreground (1).color ());
417 tree_item->setForeground (1, QBrush (fg));
418 tree_item->setForeground (3, QBrush (fg));
423 tree_item->setText (2, sc.
actual_sc [0]);
425 tree_item->setText (4, sc.
actual_sc [1]);
442 for (
int i = 0; i <
_sc.count (); i++)
444 settings->setValue(
"shortcuts/"+
_sc.at (i).settings_key,
445 _sc.at (i).actual_sc[set-1].toString ());
452 for (
int i = 0; i <
_sc.count (); i++)
454 settings->setValue(
"shortcuts/"+
_sc.at (i).settings_key,
455 _sc.at (i).actual_sc[0].toString ());
456 settings->setValue(
"shortcuts/"+
_sc.at (i).settings_key+
"_1",
457 _sc.at (i).actual_sc[1].toString ());
473 int set =
_settings->value (
"shortcuts/set",0).toInt ();
478 QString key_set = key;
482 if (index > -1 && index <
_sc.count ())
483 action->setShortcut (QKeySequence (
484 _settings->value (
"shortcuts/" + key_set,
_sc.at (index).default_sc[set]).toString ()));
486 qDebug () <<
"Key: " << key_set <<
" not found in _action_hash";
517 _dialog->setWindowTitle (tr (
"Enter new Shortcut for Set %1")
522 QLabel *help =
new QLabel (tr (
"Apply the desired shortcut or click "
523 "on the right button to reset the "
524 "shortcut to its default."));
525 help->setWordWrap (
true);
526 box->addWidget (help);
528 QCheckBox *direct =
new QCheckBox (
529 tr (
"Enter shortcut directly by performing it"));
530 direct->setCheckState (Qt::Checked);
531 box->addWidget (direct);
533 QGridLayout *grid =
new QGridLayout();
535 QLabel *actual =
new QLabel (tr (
"Actual shortcut"));
538 grid->addWidget (actual, 0, 0);
541 QLabel *def =
new QLabel (tr (
"Default shortcut"));
544 grid->addWidget (def, 1, 0);
548 grid->addWidget (set_default, 0, 2);
549 connect (set_default, SIGNAL (clicked ()),
552 box->addLayout (grid);
554 QDialogButtonBox *button_box =
new QDialogButtonBox (QDialogButtonBox::Ok
555 | QDialogButtonBox::Cancel);
557 for (
int i = 0; i < buttons.count (); i++)
558 buttons.at (i)->setShortcut (QKeySequence ());
559 connect(button_box, SIGNAL (accepted ()),
_dialog, SLOT (accept ()));
560 connect(button_box, SIGNAL (rejected ()),
_dialog, SLOT (reject ()));
561 box->addWidget (button_box);
565 connect (direct, SIGNAL (stateChanged (
int)),
567 connect (
_dialog, SIGNAL (finished (
int)),
584 if (result == QDialog::Rejected)
601 tr (
"The chosen shortcut\n \"%1\"\n"
602 "is already used for the action\n \"%2\".\n"
603 "Do you want to use the shortcut anyhow removing it "
604 "from the previous action?")
606 .
arg (
_sc.at (double_index).description),
607 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
609 if (ret == QMessageBox::Yes)
613 _sc.replace (double_index, double_shortcut);
645 for (
int i = 0; i <
_sc.count (); i++)
656 tree_item->setText (2*set, sc.
actual_sc [set-1]);
671 file = QFileDialog::getOpenFileName (
this,
672 tr (
"Import shortcut set %1 from file ...").
arg (set), QString (),
673 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"));
677 file = QFileDialog::getSaveFileName (
this,
678 tr (
"Export shortcut set %1 into file ...").
arg (set), QString (),
679 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"));
683 QSettings *osc_settings =
new QSettings (file, QSettings::IniFormat);
693 qWarning () << tr (
"Failed to open %1 as octave shortcut file").
arg (file);
725 QLineEdit::keyPressEvent (e);
729 if (e->type () == QEvent::KeyPress)
733 if (key == Qt::Key_unknown || key == 0)
736 Qt::KeyboardModifiers modifiers = e->modifiers ();
738 if (modifiers & Qt::ShiftModifier)
740 if (modifiers & Qt::ControlModifier)
742 if (modifiers & Qt::AltModifier)
744 if (modifiers & Qt::MetaModifier)
747 setText (QKeySequence(key));
QKeySequence * default_sc
QHash< int, QTreeWidgetItem * > _index_item_hash
int main(int argc, char **argv)
QHash< QTreeWidgetItem *, int > _item_index_hash
static uint32_t state[624]
void do_import_export(bool import, int set)
void init(QString, QString, QKeySequence)
enter_shortcut * _edit_actual
OCTINTERP_API octave_value box(JNIEnv *jni_env, jobject jobj, jclass jcls=0)
void shortcut_dialog_set_default()
void error(const char *fmt,...)
static shortcut_manager * instance
void handle_double_clicked(QTreeWidgetItem *, int)
QHash< QString, int > _action_hash
void do_write_shortcuts(int set, QSettings *settings, bool closing)
void handle_direct_shortcut(int)
static void cleanup_instance(void)
enter_shortcut(QWidget *p=0)
virtual void keyPressEvent(QKeyEvent *e)
static QSettings * get_settings(void)
void warning(const char *fmt,...)
QHash< QString, QTreeWidgetItem * > _level_hash
void shortcut_dialog(int)
void do_fill_treewidget(QTreeWidget *tree_view)
QHash< QString, int > _shortcut_hash
static bool instance_ok(void)
void do_set_shortcut(QAction *action, const QString &key)
void import_shortcuts(int set, QSettings *settings)
void shortcut_dialog_finished(int)