Mercurial > hg > octave-lyh
changeset 16970:78116b88dbf5
enable readline key bindings in terminal widget of gui (bug #36986)
* TerminalView.cpp(constructor): connect signal indicating focus change to
related slot of main window for setting/resetting shortcuts,
(focusInEvent,focusOutEvent): emit focus change signal
* TerminalView.h: new signal set_global_shortcuts_signal for focus change
* QWinTerminalImpl.cpp(constructor): connect signal indicating focus change to
related slot in main window,
(focusInEvent,focusOutEvent): emit focus change signal
* QWinTerminalImpl.h: new signal set_global_shortcuts_signal for focus change
* main-window.cc(construct): connect signal emitted on terminal focus change
to related slot of the editor for setting/resetting shortcuts, call
new function set_global_shortcuts for initializing shortcuts
(construct_file_menu): add shortcut conext for open action, class variable
for exit action
(construct_new_menu): add shortcut conext for new action,
(construct_edit_menu): make find files action a class variable,
(set_global_shortcuts): new slot for setting or resetting some shortcuts,
also emits signal for child widgets
* main-window.h: new slot set_global_shortcuts,
new signal set_widget_shortcuts_signal,
class wide variables for find files and exit action
* file-editor.cc(construct): change QActions into class wide variables and
add _ before variale names, do not set shortcuts, call set_shortcuts instead,
(set_shortcuts): new function for setting or resetting shortcuts
* file-editor.h: new function set_shortcuts, new names for QActions
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 13 Jul 2013 10:28:57 +0200 |
parents | 58188d5a2587 |
children | 259c1f295a1e |
files | libgui/qterminal/libqterminal/unix/TerminalView.cpp libgui/qterminal/libqterminal/unix/TerminalView.h libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h |
diffstat | 8 files changed, 219 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/unix/TerminalView.cpp +++ b/libgui/qterminal/libqterminal/unix/TerminalView.cpp @@ -319,6 +319,10 @@ _gridLayout->setMargin(0); setLayout( _gridLayout ); + + connect (this, SIGNAL (set_global_shortcuts_signal (bool)), + parent->parent (), SLOT (set_global_shortcuts (bool))); + } TerminalView::~TerminalView() @@ -1058,6 +1062,8 @@ void TerminalView::focusInEvent(QFocusEvent *focusEvent) { + emit set_global_shortcuts_signal (false); // disable some shortcuts + setBlinkingCursorState(true); updateImage(); repaint(); @@ -1068,6 +1074,8 @@ void TerminalView::focusOutEvent(QFocusEvent *focusEvent) { + emit set_global_shortcuts_signal (true); // re-enable shortcuts + // Force the cursor to be redrawn. _cursorBlinking = true; setBlinkingCursorState(false);
--- a/libgui/qterminal/libqterminal/unix/TerminalView.h +++ b/libgui/qterminal/libqterminal/unix/TerminalView.h @@ -476,6 +476,12 @@ void tripleClicked( const QString& text ); + /** + * Emitted when focus changes + */ + void set_global_shortcuts_signal (bool); + + protected: virtual bool event( QEvent * );
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp @@ -1162,6 +1162,8 @@ QWinTerminalImpl::QWinTerminalImpl (QWidget* parent) : QTerminal (parent), d (new QConsolePrivate (this)) { + connect (this, SIGNAL (set_global_shortcuts_signal (bool)), + parent, SLOT (set_global_shortcuts (bool))); } ////////////////////////////////////////////////////////////////////////////// @@ -1332,6 +1334,8 @@ void QWinTerminalImpl::focusInEvent (QFocusEvent* event) { + emit set_global_shortcuts_signal (false); // disable some shortcuts + setBlinkingCursorState (true); QWidget::focusInEvent (event); @@ -1339,6 +1343,8 @@ void QWinTerminalImpl::focusOutEvent (QFocusEvent* event) { + emit set_global_shortcuts_signal (true); // re-enable shortcuts + // Force the cursor to be redrawn. d->m_cursorBlinking = true;
--- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h @@ -70,6 +70,7 @@ signals: void terminated (void); void titleChanged (const QString&); + void set_global_shortcuts_signal (bool); protected: void viewPaintEvent (QConsoleView*, QPaintEvent*);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -744,21 +744,19 @@ QAction *open_action = new QAction (QIcon (":/actions/icons/fileopen.png"), tr ("&Open File"), _tool_bar); - QAction *save_action = new QAction (QIcon (":/actions/icons/filesave.png"), + _save_action = new QAction (QIcon (":/actions/icons/filesave.png"), tr ("&Save File"), _tool_bar); - QAction *save_as_action - = new QAction (QIcon (":/actions/icons/filesaveas.png"), - tr ("Save File &As"), _tool_bar); + _save_as_action = new QAction (QIcon (":/actions/icons/filesaveas.png"), + tr ("Save File &As"), _tool_bar); - QAction *print_action - = new QAction ( QIcon (":/actions/icons/fileprint.png"), - tr ("Print"), _tool_bar); + _print_action = new QAction ( QIcon (":/actions/icons/fileprint.png"), + tr ("Print"), _tool_bar); - QAction *undo_action = new QAction (QIcon (":/actions/icons/undo.png"), + _undo_action = new QAction (QIcon (":/actions/icons/undo.png"), tr ("&Undo"), _tool_bar); - QAction *redo_action = new QAction (QIcon (":/actions/icons/redo.png"), + _redo_action = new QAction (QIcon (":/actions/icons/redo.png"), tr ("&Redo"), _tool_bar); _copy_action = new QAction (QIcon (":/actions/icons/editcopy.png"), @@ -767,18 +765,15 @@ _cut_action = new QAction (QIcon (":/actions/icons/editcut.png"), tr ("Cu&t"), _tool_bar); - QAction *paste_action + _paste_action = new QAction (QIcon (":/actions/icons/editpaste.png"), tr ("Paste"), _tool_bar); - QAction *next_bookmark_action - = new QAction (tr ("&Next Bookmark"), _tool_bar); + _next_bookmark_action = new QAction (tr ("&Next Bookmark"), _tool_bar); - QAction *previous_bookmark_action - = new QAction (tr ("Pre&vious Bookmark"), _tool_bar); + _previous_bookmark_action = new QAction (tr ("Pre&vious Bookmark"), _tool_bar); - QAction *toggle_bookmark_action - = new QAction (tr ("Toggle &Bookmark"), _tool_bar); + _toggle_bookmark_action = new QAction (tr ("Toggle &Bookmark"), _tool_bar); QAction *remove_bookmark_action = new QAction (tr ("&Remove All Bookmarks"), _tool_bar); @@ -796,19 +791,19 @@ = new QAction (QIcon (":/actions/icons/bp_rm_all.png"), tr ("&Remove All breakpoints"), _tool_bar); - QAction *comment_selection_action + _comment_selection_action = new QAction (tr ("&Comment"), _tool_bar); - QAction *uncomment_selection_action + _uncomment_selection_action = new QAction (tr ("&Uncomment"), _tool_bar); - QAction *find_action = new QAction (QIcon (":/actions/icons/search.png"), + _find_action = new QAction (QIcon (":/actions/icons/search.png"), tr ("&Find and Replace"), _tool_bar); _run_action = new QAction (QIcon (":/actions/icons/artsbuilderexecute.png"), tr ("Save File And Run"), _tool_bar); - QAction *goto_line_action = new QAction (tr ("Go&to Line"), _tool_bar); + _goto_line_action = new QAction (tr ("Go&to Line"), _tool_bar); // the mru-list and an empty array of actions QSettings *settings = resource_manager::get_settings (); @@ -823,46 +818,39 @@ // some actions are disabled from the beginning _copy_action->setEnabled (false); _cut_action->setEnabled (false); - _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R); + + // shortcuts + set_shortcuts (true); + _run_action->setShortcutContext (Qt::WindowShortcut); - save_action->setShortcut (QKeySequence::Save); - save_action->setShortcutContext (Qt::WindowShortcut); - save_as_action->setShortcut (QKeySequence::SaveAs); - save_as_action->setShortcutContext (Qt::WindowShortcut); - - print_action->setShortcut (QKeySequence::Print); - print_action->setShortcutContext (Qt::WindowShortcut); + _save_action->setShortcutContext (Qt::WindowShortcut); + _save_as_action->setShortcutContext (Qt::WindowShortcut); - next_bookmark_action->setShortcut (Qt::Key_F2); - next_bookmark_action->setShortcutContext (Qt::WindowShortcut); - previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); - previous_bookmark_action->setShortcutContext (Qt::WindowShortcut); - toggle_bookmark_action->setShortcut (Qt::Key_F7); - toggle_bookmark_action->setShortcutContext (Qt::WindowShortcut); - comment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_7); - comment_selection_action->setShortcutContext (Qt::WindowShortcut); - uncomment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_8); - uncomment_selection_action->setShortcutContext (Qt::WindowShortcut); - find_action->setShortcut (QKeySequence::Find); - find_action->setShortcutContext (Qt::WindowShortcut); - goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); - goto_line_action->setShortcutContext (Qt::WindowShortcut); + _print_action->setShortcutContext (Qt::WindowShortcut); + + _next_bookmark_action->setShortcutContext (Qt::WindowShortcut); + _previous_bookmark_action->setShortcutContext (Qt::WindowShortcut); + _toggle_bookmark_action->setShortcutContext (Qt::WindowShortcut); + _comment_selection_action->setShortcutContext (Qt::WindowShortcut); + _uncomment_selection_action->setShortcutContext (Qt::WindowShortcut); + _find_action->setShortcutContext (Qt::WindowShortcut); + _goto_line_action->setShortcutContext (Qt::WindowShortcut); // toolbar _tool_bar->addAction (new_action); _tool_bar->addAction (open_action); - _tool_bar->addAction (save_action); - _tool_bar->addAction (save_as_action); + _tool_bar->addAction (_save_action); + _tool_bar->addAction (_save_as_action); _tool_bar->addSeparator (); - _tool_bar->addAction (print_action); + _tool_bar->addAction (_print_action); _tool_bar->addSeparator (); - _tool_bar->addAction (undo_action); - _tool_bar->addAction (redo_action); + _tool_bar->addAction (_undo_action); + _tool_bar->addAction (_redo_action); _tool_bar->addAction (_copy_action); _tool_bar->addAction (_cut_action); - _tool_bar->addAction (paste_action); + _tool_bar->addAction (_paste_action); _tool_bar->addSeparator (); - _tool_bar->addAction (find_action); + _tool_bar->addAction (_find_action); _tool_bar->addAction (_run_action); _tool_bar->addSeparator (); _tool_bar->addAction (toggle_breakpoint_action); @@ -882,8 +870,8 @@ fileMenu->addMenu (_mru_file_menu); fileMenu->addSeparator (); - fileMenu->addAction (save_action); - fileMenu->addAction (save_as_action); + fileMenu->addAction (_save_action); + fileMenu->addAction (_save_as_action); fileMenu->addSeparator (); fileMenu->addAction (QIcon::fromTheme("window-close", @@ -901,30 +889,30 @@ this, SLOT (request_close_other_files (bool))); fileMenu->addSeparator (); - fileMenu->addAction (print_action); + fileMenu->addAction (_print_action); _menu_bar->addMenu (fileMenu); QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar); - editMenu->addAction (undo_action); - editMenu->addAction (redo_action); + editMenu->addAction (_undo_action); + editMenu->addAction (_redo_action); editMenu->addSeparator (); editMenu->addAction (_copy_action); editMenu->addAction (_cut_action); - editMenu->addAction (paste_action); + editMenu->addAction (_paste_action); editMenu->addSeparator (); - editMenu->addAction (find_action); + editMenu->addAction (_find_action); editMenu->addSeparator (); - editMenu->addAction (comment_selection_action); - editMenu->addAction (uncomment_selection_action); + editMenu->addAction (_comment_selection_action); + editMenu->addAction (_uncomment_selection_action); editMenu->addSeparator (); - editMenu->addAction (toggle_bookmark_action); - editMenu->addAction (next_bookmark_action); - editMenu->addAction (previous_bookmark_action); + editMenu->addAction (_toggle_bookmark_action); + editMenu->addAction (_next_bookmark_action); + editMenu->addAction (_previous_bookmark_action); editMenu->addAction (remove_bookmark_action); editMenu->addSeparator (); - editMenu->addAction (goto_line_action); + editMenu->addAction (_goto_line_action); _menu_bar->addMenu (editMenu); _debug_menu = new QMenu (tr ("&Debug"), _menu_bar); @@ -960,10 +948,10 @@ connect (open_action, SIGNAL (triggered ()), this, SLOT (request_open_file ())); - connect (undo_action, SIGNAL (triggered ()), + connect (_undo_action, SIGNAL (triggered ()), this, SLOT (request_undo ())); - connect (redo_action, SIGNAL (triggered ()), + connect (_redo_action, SIGNAL (triggered ()), this, SLOT (request_redo ())); connect (_copy_action, SIGNAL (triggered ()), @@ -972,28 +960,28 @@ connect (_cut_action, SIGNAL (triggered ()), this, SLOT (request_cut ())); - connect (paste_action, SIGNAL (triggered ()), + connect (_paste_action, SIGNAL (triggered ()), this, SLOT (request_paste ())); - connect (save_action, SIGNAL (triggered ()), + connect (_save_action, SIGNAL (triggered ()), this, SLOT (request_save_file ())); - connect (save_as_action, SIGNAL (triggered ()), + connect (_save_as_action, SIGNAL (triggered ()), this, SLOT (request_save_file_as ())); - connect (print_action, SIGNAL (triggered ()), + connect (_print_action, SIGNAL (triggered ()), this, SLOT (request_print_file ())); connect (_run_action, SIGNAL (triggered ()), this, SLOT (request_run_file ())); - connect (toggle_bookmark_action, SIGNAL (triggered ()), + connect (_toggle_bookmark_action, SIGNAL (triggered ()), this, SLOT (request_toggle_bookmark ())); - connect (next_bookmark_action, SIGNAL (triggered ()), + connect (_next_bookmark_action, SIGNAL (triggered ()), this, SLOT (request_next_bookmark ())); - connect (previous_bookmark_action, SIGNAL (triggered ()), + connect (_previous_bookmark_action, SIGNAL (triggered ()), this, SLOT (request_previous_bookmark ())); connect (remove_bookmark_action, SIGNAL (triggered ()), @@ -1011,16 +999,16 @@ connect (remove_all_breakpoints_action, SIGNAL (triggered ()), this, SLOT (request_remove_breakpoint ())); - connect (comment_selection_action, SIGNAL (triggered ()), + connect (_comment_selection_action, SIGNAL (triggered ()), this, SLOT (request_comment_selected_text ())); - connect (uncomment_selection_action, SIGNAL (triggered ()), + connect (_uncomment_selection_action, SIGNAL (triggered ()), this, SLOT (request_uncomment_selected_text ())); - connect (find_action, SIGNAL (triggered ()), + connect (_find_action, SIGNAL (triggered ()), this, SLOT (request_find ())); - connect (goto_line_action, SIGNAL (triggered ()), + connect (_goto_line_action, SIGNAL (triggered ()), this, SLOT (request_goto_line ())); connect (_mru_file_menu, SIGNAL (triggered (QAction *)), @@ -1198,4 +1186,62 @@ } } +void +file_editor::set_shortcuts (bool set) +{ + if (set) + { + _comment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_7); + _uncomment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_8); + + _copy_action->setShortcut (QKeySequence::Copy); + _cut_action->setShortcut (QKeySequence::Cut); + _paste_action->setShortcut (QKeySequence::Paste); + + _find_action->setShortcut (QKeySequence::Find); + _goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); + + _next_bookmark_action->setShortcut (Qt::Key_F2); + _previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); + _toggle_bookmark_action->setShortcut (Qt::Key_F7); + + _print_action->setShortcut (QKeySequence::Print); + _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R); + + _save_action->setShortcut (QKeySequence::Save); + _save_as_action->setShortcut (QKeySequence::SaveAs); + + _redo_action->setShortcut (QKeySequence::Redo); + _undo_action->setShortcut (QKeySequence::Undo); + } + else + { + QKeySequence no_key = QKeySequence (); + + _comment_selection_action->setShortcut (no_key); + _uncomment_selection_action->setShortcut (no_key); + + _copy_action->setShortcut (no_key); + _cut_action->setShortcut (no_key); + _paste_action->setShortcut (no_key); + + _find_action->setShortcut (no_key); + _goto_line_action->setShortcut (no_key); + + _next_bookmark_action->setShortcut (no_key); + _previous_bookmark_action->setShortcut (no_key); + _toggle_bookmark_action->setShortcut (no_key); + + _print_action->setShortcut (no_key); + _run_action->setShortcut (no_key); + + _save_action->setShortcut (no_key); + _save_as_action->setShortcut (no_key); + + _redo_action->setShortcut (no_key); + _undo_action->setShortcut (no_key); + } +} + + #endif
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -152,6 +152,10 @@ // Tells the editor to react on changed settings. void notice_settings (const QSettings *settings); + // Tells the ditor to dis- or enable some shortcuts + void set_shortcuts (bool set_shortcuts); + + protected slots: void copyClipboard (); void pasteClipboard (); @@ -178,10 +182,32 @@ QMenuBar *_menu_bar; QToolBar *_tool_bar; QMenu *_debug_menu; + + QAction *_comment_selection_action; + QAction *_uncomment_selection_action; + QAction *_copy_action; QAction *_cut_action; + QAction *_paste_action; + + QAction *_find_action; + QAction *_goto_line_action; + + QAction *_next_bookmark_action; + QAction *_previous_bookmark_action; + QAction *_toggle_bookmark_action; + + QAction *_print_action; QAction *_run_action; + + QAction *_save_action; + QAction *_save_as_action; + + QAction *_redo_action; + QAction *_undo_action; + QTabWidget *_tab_widget; + int _marker_breakpoint; enum { MaxMRUFiles = 10 };
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -799,6 +799,9 @@ connect (file_browser_window, SIGNAL (find_files_signal (const QString&)), this, SLOT (find_files (const QString&))); + connect (this, SIGNAL (set_widget_shortcuts_signal (bool)), + editor_window, SLOT (set_shortcuts (bool))); + connect_uiwidget_links (); setWindowTitle ("Octave"); @@ -835,6 +838,8 @@ construct_octave_qt_link (); + set_global_shortcuts (true); + #ifdef HAVE_QSCINTILLA connect (this, SIGNAL (insert_debugger_pointer_signal (const QString&, int)), @@ -966,6 +971,8 @@ _open_action = file_menu->addAction (QIcon (":/actions/icons/fileopen.png"), tr ("Open...")); + _open_action->setShortcutContext (Qt::ApplicationShortcut); + #ifdef HAVE_QSCINTILLA file_menu->addMenu (editor_window->get_mru_menu ()); @@ -987,8 +994,8 @@ file_menu->addSeparator (); - QAction *exit_action = file_menu->addAction (tr ("Exit")); - exit_action->setShortcut (QKeySequence::Quit); + _exit_action = file_menu->addAction (tr ("Exit")); + _exit_action->setShortcutContext (Qt::ApplicationShortcut); connect (preferences_action, SIGNAL (triggered ()), this, SLOT (process_settings_dialog_request ())); @@ -1004,7 +1011,7 @@ connect (save_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_save_workspace_request ())); - connect (exit_action, SIGNAL (triggered ()), + connect (_exit_action, SIGNAL (triggered ()), this, SLOT (close ())); } @@ -1016,6 +1023,7 @@ _new_script_action = new_menu->addAction (QIcon (":/actions/icons/filenew.png"), tr ("Script")); + _new_script_action->setShortcutContext (Qt::ApplicationShortcut); QAction *new_function_action = new_menu->addAction (tr ("Function")); new_function_action->setEnabled (true); @@ -1060,9 +1068,8 @@ edit_menu->addSeparator (); - QAction *find_files_action + _find_files_action = edit_menu->addAction (tr ("Find Files...")); - find_files_action->setShortcut (ctrl_shift + Qt::Key_F); edit_menu->addSeparator (); @@ -1075,7 +1082,7 @@ QAction *clear_workspace_action = edit_menu->addAction (tr ("Clear Workspace")); - connect (find_files_action, SIGNAL (triggered()), + connect (_find_files_action, SIGNAL (triggered()), this, SLOT (find_files ())); connect (clear_command_window_action, SIGNAL (triggered ()), @@ -1571,4 +1578,33 @@ } +void +main_window::set_global_shortcuts (bool set_shortcuts) +{ + if (set_shortcuts) + { + _open_action->setShortcut (QKeySequence::Open); + _new_script_action->setShortcut (QKeySequence::New); + + _exit_action->setShortcut (QKeySequence::Quit); + + _find_files_action->setShortcut (Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_F); + + } + else + { + + QKeySequence no_key = QKeySequence (); + + _open_action->setShortcut (no_key); + _new_script_action->setShortcut (no_key); + + _exit_action->setShortcut (no_key); + + _find_files_action->setShortcut (no_key); + + } + + emit set_widget_shortcuts_signal (set_shortcuts); +}
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -90,6 +90,8 @@ void copyClipboard_signal (void); void pasteClipboard_signal (void); + void set_widget_shortcuts_signal (bool); + public slots: void report_status_message (const QString& statusMessage); void handle_save_workspace_request (void); @@ -172,6 +174,10 @@ // find files dialog void find_files(const QString &startdir=QDir::currentPath()); void find_files_finished(int); + + // setting global shortcuts + void set_global_shortcuts (bool enable); + protected: void closeEvent (QCloseEvent * closeEvent); @@ -278,6 +284,9 @@ QAction *_paste_action; QAction *_undo_action; + QAction *_find_files_action; + QAction *_exit_action; + // Toolbars. QComboBox *_current_directory_combo_box; static const int current_directory_width = 300;