# HG changeset patch # User Torsten # Date 1398596588 -7200 # Node ID 86eca5d178a669afb7a3664270212804dee13d37 # Parent c199304dfb2abea315c6f41b3d5d7aa8fb329453 disable some global shortcuts when editor gets focus to prevent conflicts * file-editor-tab.cc (constructor): connect signal from the qscintilla edit area about focus with the related new slot; (edit_area_has_focus): new slot for the focus signal from qscintilla edit area emitting a signal for enabling/disabling the common edit shortcuts * file-editor-tab.h: new slot edit_area_has_focus, new signal set_global_edit_shortcuts_signal * file-editor.cc (add_file_editor_tab ): connect new tab signal set_global_edit_shortcuts_signal with the related slot in main_window; (copyClipboard, pasteClipboard, selectAll): removed these functions because the related actions are triggered editor shortcuts * file-editor.h: remove copyClipboard, pasteClipboard, selectAll * octave-qscintilla.cc (focusInEvent, focusOutEvent): handlers emitting the signal about the focus state of the edit area * octave-qscintilla.h: new focus signal qsci_has_focus_signal, focus event handlers * main-window.cc (set_global_edit_shortcuts): new slot dis-/enabling the common edit shortcuts depending on focus of edit area * main-window.h: new slot set_global_edit_shortcuts diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Apr 27 13:03:08 2014 +0200 @@ -154,6 +154,9 @@ connect (_edit_area, SIGNAL (copyAvailable (bool)), this, SLOT (handle_copy_available (bool))); + connect (_edit_area, SIGNAL (qsci_has_focus_signal (bool)), + this, SLOT (edit_area_has_focus (bool))); + connect (&_file_system_watcher, SIGNAL (fileChanged (const QString&)), this, SLOT (file_has_changed (const QString&))); @@ -1664,4 +1667,10 @@ _col_indicator->setNum (col+1); } +void +file_editor_tab::edit_area_has_focus (bool focus) +{ + emit set_global_edit_shortcuts_signal (! focus); +} + #endif diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Apr 27 13:03:08 2014 +0200 @@ -121,6 +121,7 @@ void file_has_changed (const QString& fileName); void execute_command_in_terminal (const QString& command); + void edit_area_has_focus (bool foucs); signals: @@ -133,6 +134,7 @@ bool remove_on_success); void run_file_signal (const QFileInfo& info); void execute_command_in_terminal_signal (const QString&); + void set_global_edit_shortcuts_signal (bool); protected: diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/file-editor.cc Sun Apr 27 13:03:08 2014 +0200 @@ -1396,6 +1396,9 @@ connect (f, SIGNAL (execute_command_in_terminal_signal (const QString&)), main_win (), SLOT (execute_command_in_terminal (const QString&))); + connect (f, SIGNAL (set_global_edit_shortcuts_signal (bool)), + main_win (), SLOT (set_global_edit_shortcuts (bool))); + // Signals from the file_editor non-trivial operations connect (this, SIGNAL (fetab_settings_changed (const QSettings *)), f, SLOT (notice_settings (const QSettings *))); @@ -1527,38 +1530,6 @@ } void -file_editor::copyClipboard () -{ - QWidget * foc_w = focusWidget (); - - if (foc_w && foc_w->inherits ("octave_qscintilla")) - { - request_copy (true); - } -} -void -file_editor::pasteClipboard () -{ - QWidget * foc_w = focusWidget (); - - if (foc_w && foc_w->inherits ("octave_qscintilla")) - { - request_paste (true); - } -} -void -file_editor::selectAll () -{ - QWidget * foc_w = focusWidget (); - - if (foc_w && foc_w->inherits ("octave_qscintilla")) - { - request_selectall (true); - } -} - - -void file_editor::set_shortcuts () { // File menu diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/file-editor.h Sun Apr 27 13:03:08 2014 +0200 @@ -204,9 +204,6 @@ protected slots: - void copyClipboard (); - void pasteClipboard (); - void selectAll (); private slots: diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sun Apr 27 13:03:08 2014 +0200 @@ -247,4 +247,18 @@ emit execute_command_in_terminal_signal (commands.at (i)); } +void +octave_qscintilla::focusInEvent (QFocusEvent *focusEvent) +{ + emit qsci_has_focus_signal (true); + QsciScintilla::focusInEvent(focusEvent); +} + +void +octave_qscintilla::focusOutEvent (QFocusEvent *focusEvent) +{ + emit qsci_has_focus_signal (false); + QsciScintilla::focusOutEvent(focusEvent); +} + #endif diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.h Sun Apr 27 13:03:08 2014 +0200 @@ -50,6 +50,7 @@ signals: void execute_command_in_terminal_signal (const QString&); + void qsci_has_focus_signal (bool); private slots: @@ -59,6 +60,11 @@ void contextmenu_edit (bool); void contextmenu_run (bool); +protected: + + void focusInEvent (QFocusEvent *focusEvent); + void focusOutEvent (QFocusEvent *focusEvent); + private: QString _word_at_cursor; diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/main-window.cc Sun Apr 27 13:03:08 2014 +0200 @@ -2278,6 +2278,26 @@ } void +main_window::set_global_edit_shortcuts (bool enable) +{ + if (enable) + { + shortcut_manager::set_shortcut (_copy_action, "main_edit:copy"); + shortcut_manager::set_shortcut (_paste_action, "main_edit:paste"); + shortcut_manager::set_shortcut (_undo_action, "main_edit:undo"); + shortcut_manager::set_shortcut (_select_all_action, "main_edit:select_all"); + } + else + { + QKeySequence no_key = QKeySequence (); + _copy_action->setShortcut (no_key); + _paste_action->setShortcut (no_key); + _undo_action->setShortcut (no_key); + _select_all_action->setShortcut (no_key); + } +} + +void main_window::set_global_shortcuts (bool set_shortcuts) { if (set_shortcuts) diff -r c199304dfb2a -r 86eca5d178a6 libgui/src/main-window.h --- a/libgui/src/main-window.h Fri Apr 25 06:40:21 2014 +0200 +++ b/libgui/src/main-window.h Sun Apr 27 13:03:08 2014 +0200 @@ -194,6 +194,7 @@ // setting global shortcuts void set_global_shortcuts (bool enable); + void set_global_edit_shortcuts (bool enable); // handling the clipboard void clipboard_has_changed (QClipboard::Mode);