23 #if defined (HAVE_CONFIG_H) 28 #include <QMessageBox> 30 #include <QGridLayout> 31 #include <QVBoxLayout> 32 #include <QDialogButtonBox> 33 #include <QKeySequence> 34 #include <QPushButton> 37 #include <QHeaderView> 39 #include <QFileDialog> 60 QLineEdit::keyPressEvent (
e);
64 if (
e->type () == QEvent::KeyPress)
68 if (key == Qt::Key_unknown || key == 0)
71 Qt::KeyboardModifiers modifiers =
e->modifiers ();
73 if (modifiers & Qt::ShiftModifier)
75 if (modifiers & Qt::ControlModifier)
77 if (modifiers & Qt::AltModifier)
79 if (modifiers & Qt::MetaModifier)
82 setText (QKeySequence (key).toString ());
99 setObjectName (
"Shortcut_Manager");
102 #if defined (Q_OS_MAC) 103 QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta,
true);
123 if (
result == QDialog::Rejected)
132 tr (
"The chosen shortcut\n \"%1\"\n" 133 "is already used for the action\n \"%2\".\n" 134 "Do you want to use the shortcut anyhow removing it " 135 "from the previous action?")
137 .
arg (
m_sc.at (double_index).m_description),
140 if (ret == QMessageBox::Yes)
144 m_sc.replace (double_index, double_shortcut);
177 error (
"unable to create shortcut_manager object!");
186 const QKeySequence& def_sc)
189 = QKeySequence (
m_settings->value (
"shortcuts/" + key, def_sc).toString ());
194 shortcut_info.m_settings_key = key;
195 shortcut_info.m_actual_sc = actual;
196 shortcut_info.m_default_sc = def_sc;
197 m_sc << shortcut_info;
200 if (! actual.isEmpty ())
205 if (key.startsWith (
"main_")
206 && actual == QKeySequence (Qt::ControlModifier+Qt::Key_D))
207 m_settings->setValue (
"shortcuts/main_ctrld",
true);
212 Qt::KeyboardModifier ctrl;
214 #if defined (Q_OS_MAC) 216 ctrl = Qt::MetaModifier;
220 prefix = Qt::AltModifier;
222 ctrl = Qt::ControlModifier;
223 prefix = Qt::NoModifier;
226 Qt::KeyboardModifiers ctrl_shift = ctrl | Qt::ShiftModifier;
227 Qt::KeyboardModifiers ctrl_alt = ctrl | Qt::AltModifier;
231 m_settings->setValue (
"shortcuts/main_ctrld",
false);
234 init (tr (
"New File"),
"main_file:new_file", QKeySequence::New);
235 init (tr (
"New Function"),
"main_file:new_function",
236 QKeySequence (ctrl_shift + Qt::Key_N));
237 init (tr (
"New Figure"),
"main_file:new_figure", QKeySequence ());
238 init (tr (
"Open File"),
"main_file:open_file", QKeySequence::Open);
239 init (tr (
"Load Workspace"),
"main_file:load_workspace", QKeySequence ());
240 init (tr (
"Save Workspace As"),
"main_file:save_workspace", QKeySequence ());
241 init (tr (
"Exit Octave"),
"main_file:exit", QKeySequence::Quit);
244 init (tr (
"Copy"),
"main_edit:copy", QKeySequence::Copy);
245 init (tr (
"Paste"),
"main_edit:paste", QKeySequence::Paste);
246 init (tr (
"Undo"),
"main_edit:undo", QKeySequence::Undo);
247 init (tr (
"Select All"),
"main_edit:select_all", QKeySequence::SelectAll);
248 init (tr (
"Clear Clipboard"),
"main_edit:clear_clipboard", QKeySequence ());
249 init (tr (
"Find in Files"),
"main_edit:find_in_files",
250 QKeySequence (ctrl_shift + Qt::Key_F));
251 init (tr (
"Clear Command Window"),
"main_edit:clear_command_window",
253 init (tr (
"Clear Command History"),
"main_edit:clear_history",
255 init (tr (
"Clear Workspace"),
"main_edit:clear_workspace", QKeySequence ());
256 init (tr (
"Preferences"),
"main_edit:preferences", QKeySequence ());
259 init (tr (
"Step"),
"main_debug:step_over",
260 QKeySequence (prefix + Qt::Key_F10));
261 init (tr (
"Step Into"),
"main_debug:step_into",
262 QKeySequence (prefix + Qt::Key_F11));
263 init (tr (
"Step Out"),
"main_debug:step_out",
264 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F11));
265 init (tr (
"Continue"),
"main_debug:continue",
266 QKeySequence (prefix + Qt::Key_F5));
267 init (tr (
"Quit Debug Mode"),
"main_debug:quit",
268 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F5));
271 init (tr (
"Show Command Window"),
"main_window:show_command",
272 prefix + ctrl_shift + Qt::Key_0);
273 init (tr (
"Show Command History"),
"main_window:show_history",
274 prefix + ctrl_shift + Qt::Key_1);
275 init (tr (
"Show File Browser"),
"main_window:show_file_browser",
276 prefix + ctrl_shift + Qt::Key_2);
277 init (tr (
"Show Workspace"),
"main_window:show_workspace",
278 prefix + ctrl_shift + Qt::Key_3);
279 init (tr (
"Show Editor"),
"main_window:show_editor",
280 prefix + ctrl_shift + Qt::Key_4);
281 init (tr (
"Show Documentation"),
"main_window:show_doc",
282 prefix + ctrl_shift + Qt::Key_5);
283 init (tr (
"Show Variable Editor"),
"main_window:show_variable_editor",
284 prefix + ctrl_shift + Qt::Key_6);
285 init (tr (
"Command Window"),
"main_window:command",
286 prefix + ctrl + Qt::Key_0);
287 init (tr (
"Command History"),
"main_window:history",
288 prefix + ctrl + Qt::Key_1);
289 init (tr (
"File Browser"),
"main_window:file_browser",
290 prefix + ctrl + Qt::Key_2);
291 init (tr (
"Workspace"),
"main_window:workspace",
292 prefix + ctrl + Qt::Key_3);
293 init (tr (
"Editor"),
"main_window:editor",
294 prefix + ctrl + Qt::Key_4);
295 init (tr (
"Documentation"),
"main_window:doc",
296 prefix + ctrl + Qt::Key_5);
297 init (tr (
"Variable Editor"),
"main_window:variable_editor",
298 prefix + ctrl + Qt::Key_6);
299 init (tr (
"Reset Default Window Layout"),
"main_window:reset", QKeySequence ());
302 init (tr (
"Show Ondisk Documentation"),
"main_help:ondisk_doc",
304 init (tr (
"Show Online Documentation"),
"main_help:online_doc",
306 init (tr (
"Report Bug"),
"main_help:report_bug", QKeySequence ());
307 init (tr (
"Octave Packages"),
"main_help:packages", QKeySequence ());
308 init (tr (
"Contribute to Octave"),
"main_help:contribute", QKeySequence ());
309 init (tr (
"Octave Developer Resources"),
"main_help:developer",
311 init (tr (
"About Octave"),
"main_help:about", QKeySequence ());
314 init (tr (
"Release Notes"),
"main_news:release_notes", QKeySequence ());
315 init (tr (
"Community News"),
"main_news:community_news", QKeySequence ());
320 init (tr (
"Close Tab"),
"editor_file:close", QKeySequence::Close);
321 init (tr (
"Close All Tabs"),
"editor_file:close_all", QKeySequence ());
322 init (tr (
"Close Other Tabs"),
"editor_file:close_other", QKeySequence ());
323 init (tr (
"Switch to Left Tab"),
"editor_tabs:switch_left_tab",
324 QKeySequence (ctrl + Qt::Key_PageUp));
325 init (tr (
"Switch to Right Tab"),
"editor_tabs:switch_right_tab",
326 QKeySequence (ctrl + Qt::Key_PageDown));
327 init (tr (
"Move Tab Left"),
"editor_tabs:move_tab_left",
328 QKeySequence (Qt::AltModifier + Qt::Key_PageUp));
329 init (tr (
"Move Tab Right"),
"editor_tabs:move_tab_right",
330 QKeySequence (Qt::AltModifier + Qt::Key_PageDown));
335 init (tr (
"Edit Function"),
"editor_file:edit_function",
336 QKeySequence (ctrl + Qt::Key_E));
337 init (tr (
"Save File"),
"editor_file:save", QKeySequence::Save);
338 init (tr (
"Save File As"),
"editor_file:save_as", QKeySequence::SaveAs);
339 init (tr (
"Print"),
"editor_file:print", QKeySequence::Print);
342 init (tr (
"Redo"),
"editor_edit:redo", QKeySequence::Redo);
343 init (tr (
"Cut"),
"editor_edit:cut", QKeySequence::Cut);
344 init (tr (
"Find and Replace"),
"editor_edit:find_replace",
346 init (tr (
"Find Next"),
"editor_edit:find_next",
347 QKeySequence::FindNext);
348 init (tr (
"Find Previous"),
"editor_edit:find_previous",
349 QKeySequence::FindPrevious);
350 init (tr (
"Delete to Start of Word"),
"editor_edit:delete_start_word",
351 QKeySequence::DeleteStartOfWord);
352 init (tr (
"Delete to End of Word"),
"editor_edit:delete_end_word",
353 QKeySequence::DeleteEndOfWord);
354 init (tr (
"Delete to Start of Line"),
"editor_edit:delete_start_line",
355 QKeySequence (ctrl_shift + Qt::Key_Backspace));
356 init (tr (
"Delete to End of Line"),
"editor_edit:delete_end_line",
357 QKeySequence (ctrl_shift + Qt::Key_Delete));
358 init (tr (
"Delete Line"),
"editor_edit:delete_line",
359 QKeySequence (ctrl_shift + Qt::Key_L));
360 init (tr (
"Copy Line"),
"editor_edit:copy_line",
361 QKeySequence (ctrl_shift + Qt::Key_C));
362 init (tr (
"Cut Line"),
"editor_edit:cut_line",
363 QKeySequence (ctrl_shift + Qt::Key_X));
364 init (tr (
"Duplicate Selection/Line"),
"editor_edit:duplicate_selection",
365 QKeySequence (ctrl + Qt::Key_D));
366 init (tr (
"Transpose Line"),
"editor_edit:transpose_line",
367 QKeySequence (ctrl + Qt::Key_T));
368 init (tr (
"Show Completion List"),
"editor_edit:completion_list",
369 QKeySequence (ctrl + Qt::Key_Space));
371 init (tr (
"Comment Selection"),
"editor_edit:comment_selection",
372 QKeySequence (ctrl + Qt::Key_R));
373 init (tr (
"Uncomment Selection"),
"editor_edit:uncomment_selection",
374 QKeySequence (ctrl_shift + Qt::Key_R));
375 init (tr (
"Comment Selection (Choosing String)"),
"editor_edit:comment_var_selection",
376 QKeySequence (ctrl_alt + Qt::Key_R));
377 init (tr (
"Uppercase Selection"),
"editor_edit:upper_case",
378 QKeySequence (ctrl + Qt::Key_U));
379 init (tr (
"Lowercase Selection"),
"editor_edit:lower_case",
380 QKeySequence (ctrl_alt + Qt::Key_U));
382 #if defined (Q_OS_MAC) 383 init (tr (
"Indent Selection Rigidly"),
"editor_edit:indent_selection",
384 QKeySequence (prefix + Qt::Key_Tab));
385 init (tr (
"Unindent Selection Rigidly"),
"editor_edit:unindent_selection",
386 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_Tab));
388 init (tr (
"Indent Selection Rigidly"),
"editor_edit:indent_selection",
389 QKeySequence (ctrl + Qt::Key_Tab));
390 init (tr (
"Unindent Selection Rigidly"),
"editor_edit:unindent_selection",
391 QKeySequence (ctrl_shift + Qt::Key_Tab));
393 init (tr (
"Indent Code"),
"editor_edit:smart_indent_line_or_selection",
396 init (tr (
"Convert Line Endings to Windows"),
"editor_edit:conv_eol_winows",
398 init (tr (
"Convert Line Endings to Unix"),
"editor_edit:conv_eol_unix",
400 init (tr (
"Convert Line Endings to Mac"),
"editor_edit:conv_eol_mac",
403 init (tr (
"Goto Line"),
"editor_edit:goto_line",
404 QKeySequence (ctrl + Qt::Key_L));
405 init (tr (
"Move to Matching Brace"),
"editor_edit:move_to_brace",
406 QKeySequence (ctrl + Qt::Key_M));
407 init (tr (
"Select to Matching Brace"),
"editor_edit:select_to_brace",
408 QKeySequence (ctrl_shift + Qt::Key_M));
409 init (tr (
"Toggle Bookmark"),
"editor_edit:toggle_bookmark",
410 QKeySequence (prefix + Qt::Key_F7));
411 init (tr (
"Next Bookmark"),
"editor_edit:next_bookmark",
412 QKeySequence (prefix + Qt::Key_F2));
413 init (tr (
"Previous Bookmark"),
"editor_edit:previous_bookmark",
414 QKeySequence (prefix + Qt::SHIFT + Qt::Key_F2));
415 init (tr (
"Remove All Bookmark"),
"editor_edit:remove_bookmark",
418 init (tr (
"Preferences"),
"editor_edit:preferences", QKeySequence ());
419 init (tr (
"Styles Preferences"),
"editor_edit:styles_preferences",
423 init (tr (
"Show Line Numbers"),
"editor_view:show_line_numbers",
425 init (tr (
"Show Whitespace Characters"),
"editor_view:show_white_spaces",
427 init (tr (
"Show Line Endings"),
"editor_view:show_eol_chars", QKeySequence ());
428 init (tr (
"Show Indentation Guides"),
"editor_view:show_ind_guides",
430 init (tr (
"Show Long Line Marker"),
"editor_view:show_long_line",
432 init (tr (
"Show Toolbar"),
"editor_view:show_toolbar",
434 init (tr (
"Show Statusbar"),
"editor_view:show_statusbar",
436 init (tr (
"Show Horizontal Scrollbar"),
"editor_view:show_hscrollbar",
438 init (tr (
"Zoom In"),
"editor_view:zoom_in", QKeySequence::ZoomIn);
439 init (tr (
"Zoom Out"),
"editor_view:zoom_out", QKeySequence::ZoomOut);
440 #if defined (Q_OS_MAC) 441 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
442 QKeySequence (ctrl + Qt::Key_Underscore));
444 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
445 QKeySequence (ctrl + Qt::Key_Period));
449 init (tr (
"Toggle Breakpoint"),
"editor_debug:toggle_breakpoint",
451 init (tr (
"Next Breakpoint"),
"editor_debug:next_breakpoint",
453 init (tr (
"Previous Breakpoint"),
"editor_debug:previous_breakpoint",
455 init (tr (
"Remove All Breakpoints"),
"editor_debug:remove_breakpoints",
459 init (tr (
"Run File"),
"editor_run:run_file",
460 QKeySequence (prefix + Qt::Key_F5));
461 init (tr (
"Run Selection"),
"editor_run:run_selection",
462 QKeySequence (prefix + Qt::Key_F9));
465 init (tr (
"Help on Keyword"),
"editor_help:help_keyword",
466 QKeySequence::HelpContents);
467 init (tr (
"Document on Keyword"),
"editor_help:doc_keyword",
468 QKeySequence (Qt::SHIFT + Qt::Key_F1));
476 bool sc_ctrld =
false;
478 for (
int i = 0;
i <
m_sc.count ();
i++)
480 settings->setValue (
"shortcuts/" +
m_sc.at (
i).m_settings_key,
481 m_sc.at (
i).m_actual_sc.toString ());
483 if (
m_sc.at (
i).m_settings_key.startsWith (
"main_")
484 &&
m_sc.at (
i).m_actual_sc == QKeySequence (Qt::ControlModifier+Qt::Key_D))
488 settings->setValue (
"shortcuts/main_ctrld",sc_ctrld);
505 if (index > -1 && index <
m_sc.count ())
506 action->setShortcut (QKeySequence (
507 m_settings->value (
"shortcuts/" + key,
m_sc.at (index).m_default_sc).toString ()));
509 qDebug () <<
"Key: " << key <<
" not found in m_action_hash";
517 #if defined (HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE) 518 tree_view->header ()->setSectionResizeMode (QHeaderView::ResizeToContents);
520 tree_view->header ()->setResizeMode (QHeaderView::ResizeToContents);
523 QTreeWidgetItem *
main =
new QTreeWidgetItem (tree_view);
524 main->setText (0, tr (
"Global"));
525 main->setExpanded (
true);
526 QTreeWidgetItem *main_file =
new QTreeWidgetItem (
main);
527 main_file->setText (0, tr (
"File Menu"));
528 QTreeWidgetItem *main_edit =
new QTreeWidgetItem (
main);
529 main_edit->setText (0, tr (
"Edit Menu"));
530 QTreeWidgetItem *main_debug =
new QTreeWidgetItem (
main);
531 main_debug->setText (0, tr (
"Debug Menu"));
534 QTreeWidgetItem *main_help =
new QTreeWidgetItem (
main);
535 main_help->setText (0, tr (
"Help Menu"));
536 QTreeWidgetItem *main_news =
new QTreeWidgetItem (
main);
537 main_news->setText (0, tr (
"News Menu"));
538 QTreeWidgetItem *main_tabs =
new QTreeWidgetItem (
main);
539 main_tabs->setText (0, tr (
"Tab Handling in Dock Widgets"));
550 QTreeWidgetItem *editor =
new QTreeWidgetItem (tree_view);
551 editor->setText (0, tr (
"Editor"));
552 editor->setExpanded (
true);
553 QTreeWidgetItem *editor_file =
new QTreeWidgetItem (editor);
554 editor_file->setText (0, tr (
"File Menu"));
555 QTreeWidgetItem *editor_edit =
new QTreeWidgetItem (editor);
556 editor_edit->setText (0, tr (
"Edit Menu"));
557 QTreeWidgetItem *editor_view =
new QTreeWidgetItem (editor);
558 editor_view->setText (0, tr (
"View Menu"));
559 QTreeWidgetItem *editor_debug =
new QTreeWidgetItem (editor);
560 editor_debug->setText (0, tr (
"Debug Menu"));
561 QTreeWidgetItem *editor_run =
new QTreeWidgetItem (editor);
562 editor_run->setText (0, tr (
"Run Menu"));
563 QTreeWidgetItem *editor_help =
new QTreeWidgetItem (editor);
564 editor_help->setText (0, tr (
"Help Menu"));
573 connect (tree_view, SIGNAL (itemDoubleClicked (QTreeWidgetItem*,
int)),
576 for (
int i = 0;
i <
m_sc.count ();
i++)
580 QTreeWidgetItem *section =
m_level_hash[
sc.m_settings_key.section (
':',0,0)];
584 if (section == editor_file)
587 if (
sc.m_settings_key.contains (
"editor_file:close"))
591 QTreeWidgetItem *tree_item =
new QTreeWidgetItem (section);
594 QColor fg = QColor (tree_item->foreground (1).color ());
596 tree_item->setForeground (1, QBrush (fg));
599 tree_item->setText (0,
sc.m_description);
600 tree_item->setText (1,
sc.m_default_sc.toString ());
601 tree_item->setText (2,
sc.m_actual_sc.toString ());
629 file = QFileDialog::getOpenFileName (
this,
630 tr (
"Import shortcuts from file ..."), QString (),
631 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"),
632 nullptr, QFileDialog::DontUseNativeDialog);
634 file = QFileDialog::getSaveFileName (
this,
635 tr (
"Export shortcuts into file ..."), QString (),
636 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"),
637 nullptr, QFileDialog::DontUseNativeDialog);
642 QSettings *osc_settings =
new QSettings (
file, QSettings::IniFormat);
646 qWarning () << tr (
"Failed to open %1 as octave shortcut file")
672 m_dialog->setWindowTitle (tr (
"Enter new Shortcut"));
676 QLabel *help =
new QLabel (tr (
"Apply the desired shortcut or click " 677 "on the right button to reset the " 678 "shortcut to its default."));
679 help->setWordWrap (
true);
680 box->addWidget (help);
682 QCheckBox *direct =
new QCheckBox (
683 tr (
"Enter shortcut directly by performing it"));
684 direct->setCheckState (Qt::Checked);
685 box->addWidget (direct);
687 QGridLayout *grid =
new QGridLayout ();
689 QLabel *actual =
new QLabel (tr (
"Actual shortcut"));
692 grid->addWidget (actual, 0, 0);
695 QLabel *def =
new QLabel (tr (
"Default shortcut"));
698 grid->addWidget (def, 1, 0);
702 grid->addWidget (set_default, 0, 2);
703 connect (set_default, SIGNAL (clicked ()),
706 box->addLayout (grid);
708 QDialogButtonBox *button_box =
new QDialogButtonBox (QDialogButtonBox::Ok
709 | QDialogButtonBox::Cancel);
711 for (
int i = 0;
i < buttons.count ();
i++)
712 buttons.at (
i)->setShortcut (QKeySequence ());
713 connect (button_box, SIGNAL (accepted ()),
m_dialog, SLOT (accept ()));
714 connect (button_box, SIGNAL (rejected ()),
m_dialog, SLOT (reject ()));
715 box->addWidget (button_box);
719 connect (direct, SIGNAL (stateChanged (
int)),
721 connect (
m_dialog, SIGNAL (finished (
int)),
739 for (
int i = 0;
i <
m_sc.count ();
i++)
745 sc.m_actual_sc = QKeySequence (
746 settings->value (
"shortcuts/" +
sc.m_settings_key,
sc.m_actual_sc).
749 sc.m_actual_sc = QKeySequence (
sc.m_default_sc);
755 tree_item->setText (2,
sc.m_actual_sc.toString ());
764 msg_box.setWindowTitle (tr (
"Overwriting Shortcuts"));
765 msg_box.setIcon (QMessageBox::Warning);
766 msg_box.setText (tr (
"You are about to overwrite all shortcuts.\n" 767 "Would you like to save the current shortcut set or cancel the action?"));
768 msg_box.setStandardButtons (QMessageBox::Save | QMessageBox::Cancel);
769 QPushButton *discard = msg_box.addButton (tr (
"Don't save"),
770 QMessageBox::DestructiveRole);
771 msg_box.setDefaultButton (QMessageBox::Save);
773 int ret = msg_box.exec ();
775 if (msg_box.clickedButton () == discard)
778 if (ret == QMessageBox::Save)
For example cd octave end example noindent changes the current working directory to an error message is printed and the working directory is not changed sc
For example cd octave end example noindent changes the current working directory to file
int main(int argc, char **argv)
void do_fill_treewidget(QTreeWidget *tree_view)
void shortcut_dialog_set_default()
void do_set_shortcut(QAction *action, const QString &key)
QHash< int, QTreeWidgetItem * > m_index_item_hash
void error(const char *fmt,...)
QHash< QString, int > m_action_hash
bool do_import_export(int action)
virtual void keyPressEvent(QKeyEvent *e)
QHash< QString, int > m_shortcut_hash
enter_shortcut * m_edit_actual
static shortcut_manager * instance
void do_write_shortcuts(QSettings *settings, bool closing)
void handle_direct_shortcut(int)
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=nullptr)
void init(const QString &, const QString &, const QKeySequence &)
void import_shortcuts(QSettings *settings)
QHash< QTreeWidgetItem *, int > m_item_index_hash
static bool instance_ok(void)
QHash< QString, QTreeWidgetItem * > m_level_hash
void shortcut_dialog(int)
void shortcut_dialog_finished(int)
enter_shortcut(QWidget *p=nullptr)
Represents the main window.
With real return the complex result
static uint32_t state[624]
void warning(const char *fmt,...)
void handle_double_clicked(QTreeWidgetItem *, int)
static QSettings * get_settings(void)
nd example The result of the integration is returned in the value of it is recommended to verify this value for difficult integrands and then a warning is issued and as may be less efficient for a smooth or otherwise well behaved integrand than other methods such as Article No
bool overwrite_all_shortcuts(void)