Mercurial > octave
changeset 20987:f99cbd86a0f9
Prevent closing GUI by Ctrl+D in terminal (bug #46661)
* QTerminal.cc (set_global_shortcuts): (un)set shortcut Ctrl-D for dummy action;
(notice_settings): do not consider obsolete shortcut sets, check whether
Ctrl+D is used as global shortcut and enable the dummy action accordingly
* QTerminal.h (QTerminal): new dummy action with shortcut Ctrl+D
* shortcut-manager.cc (do_init_data): reset flag for global Ctrl-D usage;
(init, do_write_shortcuts): check for Ctrl-D usage as global shortcut and
set the flag in settings accordingly
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 26 Dec 2015 08:49:41 +0100 |
parents | 00835323fb44 |
children | 8b8d8c6c0e64 |
files | libgui/qterminal/libqterminal/QTerminal.cc libgui/qterminal/libqterminal/QTerminal.h libgui/src/shortcut-manager.cc |
diffstat | 3 files changed, 44 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/QTerminal.cc Fri Dec 25 22:31:23 2015 +0100 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Sat Dec 26 08:49:41 2015 +0100 @@ -76,10 +76,17 @@ QTerminal::set_global_shortcuts (bool focus_out) { if (focus_out) - _interrupt_action->setShortcut (QKeySequence ()); + { + _interrupt_action->setShortcut (QKeySequence ()); + _nop_action->setShortcut (QKeySequence ()); + } else - _interrupt_action->setShortcut ( + { + _interrupt_action->setShortcut ( QKeySequence (Qt::ControlModifier + Qt::Key_C)); + _nop_action->setShortcut ( + QKeySequence (Qt::ControlModifier + Qt::Key_D)); + } } void @@ -131,24 +138,20 @@ QVariant (colors.at (3))).value<QColor> ()); setScrollBufferSize (settings->value ("terminal/history_buffer",1000).toInt () ); - // check whether Copy shoretcut is Ctrl-C - int set = settings->value ("shortcuts/set",0).toInt (); - QKeySequence copy; - QString key = QString ("shortcuts/main_edit:copy"); - if (set) - key.append ("_1"); // if second set is active - copy = QKeySequence (settings->value (key).toString ()); // the copy shortcut + // check whether Copy shortcut is Ctrl-C + QKeySequence sc; + sc = QKeySequence (settings->value ("shortcuts/main_edit:copy").toString ()); - // if copy is empty, shortcuts are not yet in the settings (take the default) - if (copy.isEmpty ()) // QKeySequence::Copy as second argument in - copy = QKeySequence::Copy; // settings->value () does not work! + // if sc is empty, shortcuts are not yet in the settings (take the default) + if (sc.isEmpty ()) // QKeySequence::Copy as second argument in + sc = QKeySequence::Copy; // settings->value () does not work! // dis- or enable extra interrupt action - QKeySequence ctrl; - ctrl = Qt::ControlModifier; - - bool extra_ir_action = (copy != QKeySequence (ctrl + Qt::Key_C)); - + bool extra_ir_action = (sc != QKeySequence (Qt::ControlModifier + Qt::Key_C)); _interrupt_action->setEnabled (extra_ir_action); has_extra_interrupt (extra_ir_action); + + // check whether shortcut Ctrl-D is in use by the main-window + bool ctrld = settings->value ("shortcuts/main_ctrld",false).toBool (); + _nop_action->setEnabled (! ctrld); }
--- a/libgui/qterminal/libqterminal/QTerminal.h Fri Dec 25 22:31:23 2015 +0100 +++ b/libgui/qterminal/libqterminal/QTerminal.h Sat Dec 26 08:49:41 2015 +0100 @@ -179,6 +179,13 @@ connect (_interrupt_action, SIGNAL (triggered ()), this, SLOT (terminal_interrupt ())); + + // dummy (nop) action catching Ctrl-D in terminal, no connection + _nop_action = new QAction (this); + addAction (_nop_action); + + _nop_action->setShortcut ( + QKeySequence (Qt::ControlModifier + Qt::Key_D)); } private: @@ -189,6 +196,7 @@ QAction * _selectall_action; QAction *_interrupt_action; + QAction *_nop_action; }; #endif // QTERMINAL_H
--- a/libgui/src/shortcut-manager.cc Fri Dec 25 22:31:23 2015 +0100 +++ b/libgui/src/shortcut-manager.cc Sat Dec 26 08:49:41 2015 +0100 @@ -105,6 +105,8 @@ // actions of the main window + _settings->setValue ("shortcuts/main_ctrld",false); // reset use fo ctrl-d + // file init (tr ("New File"), "main_file:new_file", QKeySequence::New); init (tr ("New Function"), "main_file:new_function", @@ -343,6 +345,11 @@ if (! actual.isEmpty ()) _shortcut_hash[actual.toString ()] = _sc.count (); _action_hash[key] = _sc.count (); + + // check whether ctrl+d is used from main window, i.e. is a global shortcut + if (key.startsWith ("main_") + && actual == QKeySequence (Qt::ControlModifier+Qt::Key_D)) + _settings->setValue ("shortcuts/main_ctrld",true); } void @@ -433,11 +440,20 @@ shortcut_manager::do_write_shortcuts (QSettings* settings, bool closing) { + bool sc_ctrld = false; + for (int i = 0; i < _sc.count (); i++) // loop over all shortcuts { settings->setValue("shortcuts/"+_sc.at (i).settings_key, _sc.at (i).actual_sc.toString ()); + // special: check main-window for Ctrl-D (Terminal) + if (_sc.at (i).settings_key.startsWith ("main_") + && _sc.at (i).actual_sc == QKeySequence (Qt::ControlModifier+Qt::Key_D)) + sc_ctrld = true; } + + settings->setValue ("shortcuts/main_ctrld",sc_ctrld); + if (closing) { delete _dialog; // the dialog for key sequences can be removed now