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>
49 setObjectName (
"Shortcut_Manager");
52 #if defined (Q_OS_MAC)
53 QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta,
true);
72 error (
"unable to create shortcut_manager object!");
83 Qt::KeyboardModifier ctrl;
85 #if defined (Q_OS_MAC)
87 ctrl = Qt::MetaModifier;
91 prefix = Qt::AltModifier;
93 ctrl = Qt::ControlModifier;
94 prefix = Qt::NoModifier;
97 Qt::KeyboardModifiers ctrl_shift = ctrl | Qt::ShiftModifier;
98 Qt::KeyboardModifiers ctrl_alt = ctrl | Qt::AltModifier;
102 _settings->setValue (
"shortcuts/main_ctrld",
false);
105 init (tr (
"New File"),
"main_file:new_file", QKeySequence::New);
106 init (tr (
"New Function"),
"main_file:new_function",
107 QKeySequence (ctrl_shift + Qt::Key_N));
108 init (tr (
"New Figure"),
"main_file:new_figure", QKeySequence ());
109 init (tr (
"Open File"),
"main_file:open_file", QKeySequence::Open);
110 init (tr (
"Load Workspace"),
"main_file:load_workspace", QKeySequence ());
111 init (tr (
"Save Workspace As"),
"main_file:save_workspace", QKeySequence ());
112 init (tr (
"Exit Octave"),
"main_file:exit", QKeySequence::Quit);
115 init (tr (
"Copy"),
"main_edit:copy", QKeySequence::Copy);
116 init (tr (
"Paste"),
"main_edit:paste", QKeySequence::Paste);
117 init (tr (
"Undo"),
"main_edit:undo", QKeySequence::Undo);
118 init (tr (
"Select All"),
"main_edit:select_all", QKeySequence ());
119 init (tr (
"Clear Clipboard"),
"main_edit:clear_clipboard", QKeySequence ());
120 init (tr (
"Find in Files"),
"main_edit:find_in_files",
121 QKeySequence (ctrl_shift + Qt::Key_F));
122 init (tr (
"Clear Command Window"),
"main_edit:clear_command_window",
124 init (tr (
"Clear Command History"),
"main_edit:clear_history",
126 init (tr (
"Clear Workspace"),
"main_edit:clear_workspace", QKeySequence ());
127 init (tr (
"Preferences"),
"main_edit:preferences", QKeySequence ());
130 init (tr (
"Step"),
"main_debug:step_over",
131 QKeySequence (prefix + Qt::Key_F10));
132 init (tr (
"Step Into"),
"main_debug:step_into",
133 QKeySequence (prefix + Qt::Key_F11));
134 init (tr (
"Step Out"),
"main_debug:step_out",
135 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F11));
136 init (tr (
"Continue"),
"main_debug:continue",
137 QKeySequence (prefix + Qt::Key_F5));
138 init (tr (
"Quit Debug Mode"),
"main_debug:quit",
139 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_F5));
142 init (tr (
"Show Command Window"),
"main_window:show_command",
143 prefix + ctrl_shift + Qt::Key_0);
144 init (tr (
"Show Command History"),
"main_window:show_history",
145 prefix + ctrl_shift + Qt::Key_1);
146 init (tr (
"Show File Browser"),
"main_window:show_file_browser",
147 prefix + ctrl_shift + Qt::Key_2);
148 init (tr (
"Show Workspace"),
"main_window:show_workspace",
149 prefix + ctrl_shift + Qt::Key_3);
150 init (tr (
"Show Editor"),
"main_window:show_editor",
151 prefix + ctrl_shift + Qt::Key_4);
152 init (tr (
"Show Documentation"),
"main_window:show_doc",
153 prefix + ctrl_shift + Qt::Key_5);
154 init (tr (
"Command Window"),
"main_window:command",
155 prefix + ctrl + Qt::Key_0);
156 init (tr (
"Command History"),
"main_window:history",
157 prefix + ctrl + Qt::Key_1);
158 init (tr (
"File Browser"),
"main_window:file_browser",
159 prefix + ctrl + Qt::Key_2);
160 init (tr (
"Workspace"),
"main_window:workspace",
161 prefix + ctrl + Qt::Key_3);
162 init (tr (
"Editor"),
"main_window:editor",
163 prefix + ctrl + Qt::Key_4);
164 init (tr (
"Documentation"),
"main_window:doc",
165 prefix + ctrl + Qt::Key_5);
166 init (tr (
"Reset Default Window Layout"),
"main_window:reset", QKeySequence ());
169 init (tr (
"Show Ondisk Documentation"),
"main_help:ondisk_doc",
171 init (tr (
"Show Online Documentation"),
"main_help:online_doc",
173 init (tr (
"Report Bug"),
"main_help:report_bug", QKeySequence ());
174 init (tr (
"Octave Packages"),
"main_help:packages", QKeySequence ());
175 init (tr (
"Contribute to Octave"),
"main_help:contribute", QKeySequence ());
176 init (tr (
"Octave Developer Resources"),
"main_help:developer",
178 init (tr (
"About Octave"),
"main_help:about", QKeySequence ());
181 init (tr (
"Release Notes"),
"main_news:release_notes", QKeySequence ());
182 init (tr (
"Community News"),
"main_news:community_news", QKeySequence ());
187 init (tr (
"Edit Function"),
"editor_file:edit_function",
188 QKeySequence (ctrl + Qt::Key_E));
189 init (tr (
"Save File"),
"editor_file:save", QKeySequence::Save);
190 init (tr (
"Save File As"),
"editor_file:save_as", QKeySequence::SaveAs);
191 init (tr (
"Close"),
"editor_file:close", QKeySequence::Close);
192 init (tr (
"Close All"),
"editor_file:close_all", QKeySequence ());
193 init (tr (
"Close Other Files"),
"editor_file:close_other", QKeySequence ());
194 init (tr (
"Print"),
"editor_file:print", QKeySequence::Print);
197 init (tr (
"Redo"),
"editor_edit:redo", QKeySequence::Redo);
198 init (tr (
"Cut"),
"editor_edit:cut", QKeySequence::Cut);
199 init (tr (
"Find and Replace"),
"editor_edit:find_replace",
201 init (tr (
"Find Next"),
"editor_edit:find_next",
202 QKeySequence::FindNext);
203 init (tr (
"Find Previous"),
"editor_edit:find_previous",
204 QKeySequence::FindPrevious);
205 init (tr (
"Delete to Start of Word"),
"editor_edit:delete_start_word",
206 QKeySequence::DeleteStartOfWord);
207 init (tr (
"Delete to End of Word"),
"editor_edit:delete_end_word",
208 QKeySequence::DeleteEndOfWord);
209 init (tr (
"Delete to Start of Line"),
"editor_edit:delete_start_line",
210 QKeySequence (ctrl_shift + Qt::Key_Backspace));
211 init (tr (
"Delete to End of Line"),
"editor_edit:delete_end_line",
212 QKeySequence (ctrl_shift + Qt::Key_Delete));
213 init (tr (
"Delete Line"),
"editor_edit:delete_line",
214 QKeySequence (ctrl_shift + Qt::Key_L));
215 init (tr (
"Copy Line"),
"editor_edit:copy_line",
216 QKeySequence (ctrl_shift + Qt::Key_C));
217 init (tr (
"Cut Line"),
"editor_edit:cut_line",
218 QKeySequence (ctrl_shift + Qt::Key_X));
219 init (tr (
"Duplicate Selection/Line"),
"editor_edit:duplicate_selection",
220 QKeySequence (ctrl + Qt::Key_D));
221 init (tr (
"Transpose Line"),
"editor_edit:transpose_line",
222 QKeySequence (ctrl + Qt::Key_T));
223 init (tr (
"Show Completion List"),
"editor_edit:completion_list",
224 QKeySequence (ctrl + Qt::Key_Space));
226 init (tr (
"Comment Selection"),
"editor_edit:comment_selection",
227 QKeySequence (ctrl + Qt::Key_R));
228 init (tr (
"Uncomment Selection"),
"editor_edit:uncomment_selection",
229 QKeySequence (ctrl_shift + Qt::Key_R));
230 init (tr (
"Uppercase Selection"),
"editor_edit:upper_case",
231 QKeySequence (ctrl + Qt::Key_U));
232 init (tr (
"Lowercase Selection"),
"editor_edit:lower_case",
233 QKeySequence (ctrl_alt + Qt::Key_U));
235 #if defined (Q_OS_MAC)
236 init (tr (
"Indent Selection"),
"editor_edit:indent_selection",
237 QKeySequence (prefix + Qt::Key_Tab));
238 init (tr (
"Unindent Selection"),
"editor_edit:unindent_selection",
239 QKeySequence (prefix + Qt::ShiftModifier + Qt::Key_Tab));
241 init (tr (
"Indent Selection"),
"editor_edit:indent_selection",
242 QKeySequence (ctrl + Qt::Key_Tab));
243 init (tr (
"Unindent Selection"),
"editor_edit:unindent_selection",
244 QKeySequence (ctrl_shift + Qt::Key_Tab));
247 init (tr (
"Convert Line Endings to Windows"),
"editor_edit:conv_eol_winows",
249 init (tr (
"Convert Line Endings to Unix"),
"editor_edit:conv_eol_unix",
251 init (tr (
"Convert Line Endings to Mac"),
"editor_edit:conv_eol_mac",
254 init (tr (
"Goto Line"),
"editor_edit:goto_line",
255 QKeySequence (ctrl + Qt::Key_L));
256 init (tr (
"Move to Matching Brace"),
"editor_edit:move_to_brace",
257 QKeySequence (ctrl + Qt::Key_M));
258 init (tr (
"Select to Matching Brace"),
"editor_edit:select_to_brace",
259 QKeySequence (ctrl_shift + Qt::Key_M));
260 init (tr (
"Toggle Bookmark"),
"editor_edit:toggle_bookmark",
261 QKeySequence (prefix + Qt::Key_F7));
262 init (tr (
"Next Bookmark"),
"editor_edit:next_bookmark",
263 QKeySequence (prefix + Qt::Key_F2));
264 init (tr (
"Previous Bookmark"),
"editor_edit:previous_bookmark",
265 QKeySequence (prefix + Qt::SHIFT + Qt::Key_F2));
266 init (tr (
"Remove All Bookmark"),
"editor_edit:remove_bookmark",
269 init (tr (
"Preferences"),
"editor_edit:preferences", QKeySequence ());
270 init (tr (
"Styles Preferences"),
"editor_edit:styles_preferences",
274 init (tr (
"Show Line Numbers"),
"editor_view:show_line_numbers",
276 init (tr (
"Show Whitespace Characters"),
"editor_view:show_white_spaces",
278 init (tr (
"Show Line Endings"),
"editor_view:show_eol_chars", QKeySequence ());
279 init (tr (
"Show Indentation Guides"),
"editor_view:show_ind_guides",
281 init (tr (
"Show Long Line Marker"),
"editor_view:show_long_line",
283 init (tr (
"Show Toolbar"),
"editor_view:show_toolbar",
285 init (tr (
"Show Statusbar"),
"editor_view:show_statusbar",
287 init (tr (
"Show Horizontal Scrollbar"),
"editor_view:show_hscrollbar",
289 init (tr (
"Zoom In"),
"editor_view:zoom_in", QKeySequence::ZoomIn);
290 init (tr (
"Zoom Out"),
"editor_view:zoom_out", QKeySequence::ZoomOut);
291 #if defined (Q_OS_MAC)
292 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
293 QKeySequence (ctrl + Qt::Key_Underscore));
295 init (tr (
"Zoom Normal"),
"editor_view:zoom_normal",
296 QKeySequence (ctrl + Qt::Key_Period));
300 init (tr (
"Toggle Breakpoint"),
"editor_debug:toggle_breakpoint",
302 init (tr (
"Next Breakpoint"),
"editor_debug:next_breakpoint",
304 init (tr (
"Previous Breakpoint"),
"editor_debug:previous_breakpoint",
306 init (tr (
"Remove All Breakpoints"),
"editor_debug:remove_breakpoints",
310 init (tr (
"Run File"),
"editor_run:run_file",
311 QKeySequence (prefix + Qt::Key_F5));
312 init (tr (
"Run Selection"),
"editor_run:run_selection",
313 QKeySequence (prefix + Qt::Key_F9));
316 init (tr (
"Help on Keyword"),
"editor_help:help_keyword",
317 QKeySequence::HelpContents);
318 init (tr (
"Document on Keyword"),
"editor_help:doc_keyword",
319 QKeySequence (Qt::SHIFT + Qt::Key_F1));
322 init (tr (
"Switch to Left Tab"),
"editor_tabs:switch_left_tab",
323 QKeySequence (ctrl + Qt::Key_PageUp));
324 init (tr (
"Switch to Right Tab"),
"editor_tabs:switch_right_tab",
325 QKeySequence (ctrl + Qt::Key_PageDown));
326 init (tr (
"Move Tab Left"),
"editor_tabs:move_tab_left",
327 QKeySequence (Qt::AltModifier + Qt::Key_PageUp));
328 init (tr (
"Move Tab Right"),
"editor_tabs:move_tab_right",
329 QKeySequence (Qt::AltModifier + Qt::Key_PageDown));
335 const QKeySequence& def_sc)
338 = QKeySequence (
_settings->value (
"shortcuts/"+key, def_sc).toString ());
343 shortcut_info.settings_key = key;
344 shortcut_info.actual_sc = actual;
345 shortcut_info.default_sc = def_sc;
346 _sc << shortcut_info;
349 if (! actual.isEmpty ())
354 if (key.startsWith (
"main_")
355 && actual == QKeySequence (Qt::ControlModifier+Qt::Key_D))
356 _settings->setValue (
"shortcuts/main_ctrld",
true);
365 #if defined (HAVE_QT4)
366 tree_view->header ()->setResizeMode (QHeaderView::ResizeToContents);
368 tree_view->header ()->setSectionResizeMode (QHeaderView::ResizeToContents);
371 QTreeWidgetItem *
main =
new QTreeWidgetItem (tree_view);
372 main->setText (0, tr (
"Global"));
373 main->setExpanded (
true);
374 QTreeWidgetItem *main_file =
new QTreeWidgetItem (main);
375 main_file->setText (0, tr (
"File"));
376 QTreeWidgetItem *main_edit =
new QTreeWidgetItem (main);
377 main_edit->setText (0, tr (
"Edit"));
378 QTreeWidgetItem *main_debug =
new QTreeWidgetItem (main);
379 main_debug->setText (0, tr (
"Debug"));
380 QTreeWidgetItem *
main_window =
new QTreeWidgetItem (main);
381 main_window->setText (0, tr (
"Window"));
382 QTreeWidgetItem *main_help =
new QTreeWidgetItem (main);
383 main_help->setText (0, tr (
"Help"));
384 QTreeWidgetItem *main_news =
new QTreeWidgetItem (main);
385 main_news->setText (0, tr (
"News"));
394 QTreeWidgetItem *editor =
new QTreeWidgetItem (tree_view);
395 editor->setText (0, tr (
"Editor"));
396 editor->setExpanded (
true);
397 QTreeWidgetItem *editor_file =
new QTreeWidgetItem (editor);
398 editor_file->setText (0, tr (
"File"));
399 QTreeWidgetItem *editor_edit =
new QTreeWidgetItem (editor);
400 editor_edit->setText (0, tr (
"Edit"));
401 QTreeWidgetItem *editor_view =
new QTreeWidgetItem (editor);
402 editor_view->setText (0, tr (
"View"));
403 QTreeWidgetItem *editor_debug =
new QTreeWidgetItem (editor);
404 editor_debug->setText (0, tr (
"Debug"));
405 QTreeWidgetItem *editor_run =
new QTreeWidgetItem (editor);
406 editor_run->setText (0, tr (
"Run"));
407 QTreeWidgetItem *editor_help =
new QTreeWidgetItem (editor);
408 editor_help->setText (0, tr (
"Help"));
409 QTreeWidgetItem *editor_tabs =
new QTreeWidgetItem (editor);
410 editor_tabs->setText (0, tr (
"Tabs"));
420 connect (tree_view, SIGNAL (itemDoubleClicked (QTreeWidgetItem*,
int)),
423 for (
int i = 0;
i <
_sc.count ();
i++)
428 QTreeWidgetItem* tree_item =
new QTreeWidgetItem (section);
431 QColor fg = QColor (tree_item->foreground (1).color ());
433 tree_item->setForeground (1, QBrush (fg));
437 tree_item->setText (1, sc.
default_sc.toString ());
438 tree_item->setText (2, sc.
actual_sc.toString ());
451 bool sc_ctrld =
false;
453 for (
int i = 0;
i <
_sc.count ();
i++)
455 settings->setValue (
"shortcuts/"+
_sc.at (
i).settings_key,
456 _sc.at (
i).actual_sc.toString ());
458 if (
_sc.at (
i).settings_key.startsWith (
"main_")
459 &&
_sc.at (
i).actual_sc == QKeySequence (Qt::ControlModifier+Qt::Key_D))
463 settings->setValue (
"shortcuts/main_ctrld",sc_ctrld);
481 if (index > -1 && index <
_sc.count ())
482 action->setShortcut (QKeySequence (
483 _settings->value (
"shortcuts/" + key,
_sc.at (index).default_sc).toString ()));
485 qDebug () <<
"Key: " << key <<
" not found in _action_hash";
508 _dialog->setWindowTitle (tr (
"Enter new Shortcut"));
512 QLabel *help =
new QLabel (tr (
"Apply the desired shortcut or click "
513 "on the right button to reset the "
514 "shortcut to its default."));
515 help->setWordWrap (
true);
516 box->addWidget (help);
518 QCheckBox *direct =
new QCheckBox (
519 tr (
"Enter shortcut directly by performing it"));
520 direct->setCheckState (Qt::Checked);
521 box->addWidget (direct);
523 QGridLayout *grid =
new QGridLayout();
525 QLabel *actual =
new QLabel (tr (
"Actual shortcut"));
528 grid->addWidget (actual, 0, 0);
531 QLabel *def =
new QLabel (tr (
"Default shortcut"));
534 grid->addWidget (def, 1, 0);
538 grid->addWidget (set_default, 0, 2);
539 connect (set_default, SIGNAL (clicked ()),
542 box->addLayout (grid);
544 QDialogButtonBox *button_box =
new QDialogButtonBox (QDialogButtonBox::Ok
545 | QDialogButtonBox::Cancel);
547 for (
int i = 0;
i < buttons.count ();
i++)
548 buttons.at (
i)->setShortcut (QKeySequence ());
549 connect(button_box, SIGNAL (accepted ()),
_dialog, SLOT (accept ()));
550 connect(button_box, SIGNAL (rejected ()),
_dialog, SLOT (reject ()));
551 box->addWidget (button_box);
555 connect (direct, SIGNAL (stateChanged (
int)),
557 connect (
_dialog, SIGNAL (finished (
int)),
574 if (result == QDialog::Rejected)
583 tr (
"The chosen shortcut\n \"%1\"\n"
584 "is already used for the action\n \"%2\".\n"
585 "Do you want to use the shortcut anyhow removing it "
586 "from the previous action?")
588 .
arg (
_sc.at (double_index).description),
591 if (ret == QMessageBox::Yes)
594 double_shortcut.
actual_sc = QKeySequence ();
595 _sc.replace (double_index, double_shortcut);
625 for (
int i = 0;
i <
_sc.count ();
i++)
641 tree_item->setText (2, sc.
actual_sc.toString ());
651 msg_box.setWindowTitle(tr (
"Overwriting Shortcuts"));
652 msg_box.setIcon (QMessageBox::Warning);
653 msg_box.setText(tr (
"You are about to overwrite all shortcuts.\n"
654 "Would you like to save the current shortcut set or cancel the action?"));
655 msg_box.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
656 QPushButton *discard = msg_box.addButton (tr (
"Don't save"),
657 QMessageBox::DestructiveRole);
658 msg_box.setDefaultButton(QMessageBox::Save);
660 int ret = msg_box.exec ();
662 if (msg_box.clickedButton () == discard)
665 if (ret == QMessageBox::Save)
694 file = QFileDialog::getOpenFileName (
this,
695 tr (
"Import shortcuts from file ..."), QString (),
696 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"),
697 0, QFileDialog::DontUseNativeDialog);
699 file = QFileDialog::getSaveFileName (
this,
700 tr (
"Export shortcuts into file ..."), QString (),
701 tr (
"Octave Shortcut Files (*.osc);;All Files (*)"),
702 0, QFileDialog::DontUseNativeDialog);
707 QSettings *osc_settings =
new QSettings (file, QSettings::IniFormat);
711 qWarning () << tr (
"Failed to open %1 as octave shortcut file")
757 QLineEdit::keyPressEvent (e);
761 if (e->type () == QEvent::KeyPress)
765 if (key == Qt::Key_unknown || key == 0)
768 Qt::KeyboardModifiers modifiers = e->modifiers ();
770 if (modifiers & Qt::ShiftModifier)
772 if (modifiers & Qt::ControlModifier)
774 if (modifiers & Qt::AltModifier)
776 if (modifiers & Qt::MetaModifier)
779 setText (QKeySequence(key).toString ());
QHash< int, QTreeWidgetItem * > _index_item_hash
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
void init(const QString &, const QString &, const QKeySequence &)
int main(int argc, char **argv)
QHash< QTreeWidgetItem *, int > _item_index_hash
bool do_import_export(int action)
enter_shortcut * _edit_actual
void shortcut_dialog_set_default()
void error(const char *fmt,...)
bool overwrite_all_shortcuts(void)
void import_shortcuts(QSettings *settings)
void do_write_shortcuts(QSettings *settings, bool closing)
static shortcut_manager * instance
void handle_double_clicked(QTreeWidgetItem *, int)
QHash< QString, int > _action_hash
void handle_direct_shortcut(int)
enter_shortcut(QWidget *p=0)
virtual void keyPressEvent(QKeyEvent *e)
static QSettings * get_settings(void)
With real return the complex result
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 ACM Transactions on Mathematical Article No
static uint32_t state[624]
void warning(const char *fmt,...)
static octave_value box(JNIEnv *jni_env, void *jobj, void *jcls_arg=0)
Convert the Java object pointed to by jobj_arg with class jcls_arg to an Octave value.
=val(i)}if ode{val(i)}occurs in table i
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 shortcut_dialog_finished(int)