Mercurial > octave
changeset 20685:be130eb147f8
provide only one set of gui shortcuts at a time
* settings-dialog.cc (settings_dialog): remove initializations of all items
related to the second shortcut set;
(write_changed_settings): remove storing the values of the second set;
(import_shortcut_set, export_shortcut_set): renamed slots for import/export;
(import_shortcut_set2, export_shortcut_set2): removed slots of second set
* settings-dialog.h: renamed and remoced slots for import/export of shortcuts
* settings-dialog.ui: removed all items related to the second shortcut set
* shortcut-manager.cc (do_init_data): shortcut structure and the used hash
only stores on shortcut now;
(do_fill_treewidget): adapt filling the table in the settings dialog;
(do_write_shortcuts): Only write the one shortcut set into the settings file;
(do_set_shortcut): Do not check for active shortcut set;
(handle_double_clicked): slot for changing a shortcut adapted to the new
table in the settings dialog;
(shortcut_dialog, shortcut_dialog_finish): only considering one shortcut set;
(import_shortcuts, do_import_export): do not consider a second set to import
or export
* shortcut-manager.h (write_shortcuts, do_write_shortcuts, import_export,
do_import_export, import_shortcuts): remove function parameter for shortcut
set;
(shortcut_t): no more arrays of QKeySequence in the structure for storing
the shortcuts;
removed class variable _selected_set
author | Torsten <ttl@justmail.de> |
---|---|
date | Sun, 08 Nov 2015 11:59:50 +0100 |
parents | e4593adad5cc |
children | e468e4211df9 |
files | libgui/src/settings-dialog.cc libgui/src/settings-dialog.h libgui/src/settings-dialog.ui libgui/src/shortcut-manager.cc libgui/src/shortcut-manager.h |
diffstat | 5 files changed, 89 insertions(+), 252 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/settings-dialog.cc Sat Nov 07 17:24:02 2015 -0800 +++ b/libgui/src/settings-dialog.cc Sun Nov 08 11:59:50 2015 +0100 @@ -540,22 +540,15 @@ ui->cb_prevent_readline_conflicts->setChecked ( settings->value ("shortcuts/prevent_readline_conflicts", true).toBool ()); - int set = settings->value ("shortcuts/set",0).toInt (); - ui->rb_sc_set1->setChecked (set == 0); - ui->rb_sc_set2->setChecked (set == 1); // initialize the tree view with all shortcut data shortcut_manager::fill_treewidget (ui->shortcuts_treewidget); // connect the buttons for import/export of the shortcut sets - connect (ui->btn_import_shortcut_set1, SIGNAL (clicked ()), - this, SLOT (import_shortcut_set1 ())); - connect (ui->btn_export_shortcut_set1, SIGNAL (clicked ()), - this, SLOT (export_shortcut_set1 ())); - connect (ui->btn_import_shortcut_set2, SIGNAL (clicked ()), - this, SLOT (import_shortcut_set2 ())); - connect (ui->btn_export_shortcut_set2, SIGNAL (clicked ()), - this, SLOT (export_shortcut_set2 ())); + connect (ui->btn_import_shortcut_set, SIGNAL (clicked ()), + this, SLOT (import_shortcut_set ())); + connect (ui->btn_export_shortcut_set, SIGNAL (clicked ()), + this, SLOT (export_shortcut_set ())); #ifdef HAVE_QSCINTILLA @@ -912,11 +905,7 @@ // shortcuts settings->setValue ("shortcuts/prevent_readline_conflicts", ui->cb_prevent_readline_conflicts->isChecked ()); - int set = 0; - if (ui->rb_sc_set2->isChecked ()) - set = 1; - settings->setValue ("shortcuts/set",set); - shortcut_manager::write_shortcuts (0, settings, closing); // 0: write both sets + shortcut_manager::write_shortcuts (settings, closing); // settings dialog's geometry settings->setValue ("settings/last_tab",ui->tabWidget->currentIndex ()); @@ -1022,25 +1011,13 @@ // slots for import/export of shortcut sets void -settings_dialog::import_shortcut_set1 () +settings_dialog::import_shortcut_set () { - shortcut_manager::import_export (true,1); + shortcut_manager::import_export (true); } void -settings_dialog::export_shortcut_set1 () -{ - shortcut_manager::import_export (false,1); -} - -void -settings_dialog::import_shortcut_set2 () +settings_dialog::export_shortcut_set () { - shortcut_manager::import_export (true,2); -} - -void -settings_dialog::export_shortcut_set2 () -{ - shortcut_manager::import_export (false,2); -} + shortcut_manager::import_export (false); +} \ No newline at end of file
--- a/libgui/src/settings-dialog.h Sat Nov 07 17:24:02 2015 -0800 +++ b/libgui/src/settings-dialog.h Sun Nov 08 11:59:50 2015 +0100 @@ -55,10 +55,8 @@ void button_clicked (QAbstractButton *button); // slots for import/export-buttons of shortcut sets - void import_shortcut_set1 (); - void export_shortcut_set1 (); - void import_shortcut_set2 (); - void export_shortcut_set2 (); + void import_shortcut_set (); + void export_shortcut_set (); private: Ui::settings_dialog * ui;
--- a/libgui/src/settings-dialog.ui Sat Nov 07 17:24:02 2015 -0800 +++ b/libgui/src/settings-dialog.ui Sun Nov 08 11:59:50 2015 +0100 @@ -32,7 +32,7 @@ </size> </property> <property name="currentIndex"> - <number>4</number> + <number>6</number> </property> <widget class="QWidget" name="tab_general"> <property name="enabled"> @@ -52,7 +52,7 @@ <rect> <x>0</x> <y>0</y> - <width>570</width> + <width>662</width> <height>382</height> </rect> </property> @@ -1461,8 +1461,8 @@ <rect> <x>0</x> <y>0</y> - <width>488</width> - <height>236</height> + <width>678</width> + <height>378</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_7"> @@ -1875,8 +1875,8 @@ <rect> <x>0</x> <y>0</y> - <width>203</width> - <height>79</height> + <width>678</width> + <height>378</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_19"> @@ -1944,8 +1944,8 @@ <rect> <x>0</x> <y>0</y> - <width>368</width> - <height>244</height> + <width>678</width> + <height>378</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_25"> @@ -1986,52 +1986,14 @@ <property name="topMargin"> <number>10</number> </property> - <item row="3" column="0"> + <item row="2" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_16"> <property name="topMargin"> <number>0</number> </property> </layout> </item> - <item row="1" column="2"> - <widget class="QRadioButton" name="rb_sc_set2"> - <property name="text"> - <string>Use this set</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_23"> - <property name="text"> - <string>Set 1:</string> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="QPushButton" name="btn_export_shortcut_set2"> - <property name="text"> - <string>Export</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QPushButton" name="btn_import_shortcut_set2"> - <property name="text"> - <string>Import</string> - </property> - </widget> - </item> <item row="0" column="2"> - <widget class="QRadioButton" name="rb_sc_set1"> - <property name="text"> - <string>Use this set</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="0" column="5"> <spacer name="horizontalSpacer_26"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -2044,43 +2006,20 @@ </property> </spacer> </item> - <item row="0" column="4"> - <widget class="QPushButton" name="btn_export_shortcut_set1"> - <property name="text"> - <string>Export</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <widget class="QPushButton" name="btn_import_shortcut_set1"> + <item row="0" column="0"> + <widget class="QPushButton" name="btn_import_shortcut_set"> <property name="text"> <string>Import</string> </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_24"> + <item row="0" column="1"> + <widget class="QPushButton" name="btn_export_shortcut_set"> <property name="text"> - <string>Set 2:</string> + <string>Export</string> </property> </widget> </item> - <item row="0" column="1"> - <spacer name="horizontalSpacer_33"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> - </item> </layout> </item> <item> @@ -2128,7 +2067,7 @@ <bool>false</bool> </property> <property name="columnCount"> - <number>5</number> + <number>3</number> </property> <attribute name="headerCascadingSectionResizes"> <bool>false</bool> @@ -2157,27 +2096,12 @@ </column> <column> <property name="text"> - <string>Set 1 Default</string> - </property> - </column> - <column> - <property name="text"> - <string>Set 1 Actual</string> + <string>Default</string> </property> </column> <column> <property name="text"> - <string>Set 2 Default</string> - </property> - <property name="font"> - <font> - <italic>false</italic> - </font> - </property> - </column> - <column> - <property name="text"> - <string>Set 2 Actual</string> + <string>Actual</string> </property> </column> </widget> @@ -2207,8 +2131,8 @@ <rect> <x>0</x> <y>0</y> - <width>529</width> - <height>204</height> + <width>678</width> + <height>378</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_20">
--- a/libgui/src/shortcut-manager.cc Sat Nov 07 17:24:02 2015 -0800 +++ b/libgui/src/shortcut-manager.cc Sun Nov 08 11:59:50 2015 +0100 @@ -321,29 +321,21 @@ void shortcut_manager::init (QString description, QString key, QKeySequence def_sc) { - QKeySequence actual_0 + QKeySequence actual = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ()); - QKeySequence actual_1 - = QKeySequence (_settings->value ("shortcuts/"+key+"_1", def_sc).toString ()); // append the new shortcut to the list shortcut_t shortcut_info; shortcut_info.description = description; shortcut_info.settings_key = key; - shortcut_info.actual_sc [0] = actual_0; - shortcut_info.actual_sc [1] = actual_1; - shortcut_info.default_sc [0] = def_sc; - shortcut_info.default_sc [1] = def_sc; // TODO: Different defaults + shortcut_info.actual_sc = actual; + shortcut_info.default_sc = def_sc; _sc << shortcut_info; // insert shortcut prepended by widget in order check for duplicates later QString widget = key.section ('_',0,0); // get widget that uses the shortcut - if (! actual_0.isEmpty ()) - _shortcut_hash[widget + ":" + actual_0.toString ()] = - _sc.count (); // offset of 1 to avoid 0 - if (! actual_1.isEmpty ()) - _shortcut_hash[widget + "_1:" + actual_1.toString ()] = - _sc.count (); // offset of 1 to avoid 0 + if (! actual.isEmpty ()) + _shortcut_hash[widget + ":" + actual.toString ()] = _sc.count (); // offset of 1 to avoid 0 _action_hash[key] = _sc.count (); // offset of 1 to avoid 0 } @@ -415,14 +407,11 @@ QColor fg = QColor (tree_item->foreground (1).color ()); fg.setAlpha (128); tree_item->setForeground (1, QBrush (fg)); - tree_item->setForeground (3, QBrush (fg)); // write the shortcuts tree_item->setText (0, sc.description); - tree_item->setText (1, sc.default_sc [0]); - tree_item->setText (2, sc.actual_sc [0]); - tree_item->setText (3, sc.default_sc [1]); - tree_item->setText (4, sc.actual_sc [1]); + tree_item->setText (1, sc.default_sc); + tree_item->setText (2, sc.actual_sc); _item_index_hash[tree_item] = i + 1; // index+1 to avoid 0 _index_item_hash[i] = tree_item; @@ -432,36 +421,18 @@ // write one or all actual shortcut set(s) into a settings file void -shortcut_manager::do_write_shortcuts (int set, QSettings* settings, +shortcut_manager::do_write_shortcuts (QSettings* settings, bool closing) { - if (set) - { - // set is not zero, only write the desired set (index = set-1) - // into the settings file that the user has selected for this export - 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[set-1].toString ()); - } - } - else + for (int i = 0; i < _sc.count (); i++) // loop over all shortcuts { - // set is zero, write all sets into the normal octave settings file - // (this is only the case when called from the closing settings dialog) - 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[0].toString ()); - settings->setValue("shortcuts/"+_sc.at (i).settings_key+"_1", - _sc.at (i).actual_sc[1].toString ()); - } - - if (closing) - { - delete _dialog; // the dialog for key sequences can be removed now - _dialog = 0; // make sure it is zero again - } + settings->setValue("shortcuts/"+_sc.at (i).settings_key, + _sc.at (i).actual_sc.toString ()); + } + if (closing) + { + delete _dialog; // the dialog for key sequences can be removed now + _dialog = 0; // make sure it is zero again } settings->sync (); // sync the settings file @@ -470,35 +441,22 @@ void shortcut_manager::do_set_shortcut (QAction* action, const QString& key) { - int set = _settings->value ("shortcuts/set",0).toInt (); int index; index = _action_hash[key] - 1; - QString key_set = key; - if (set == 1) - key_set = key+"_1"; - if (index > -1 && index < _sc.count ()) action->setShortcut (QKeySequence ( - _settings->value ("shortcuts/" + key_set, _sc.at (index).default_sc[set]).toString ())); + _settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ())); else - qDebug () << "Key: " << key_set << " not found in _action_hash"; + qDebug () << "Key: " << key << " not found in _action_hash"; } void shortcut_manager::handle_double_clicked (QTreeWidgetItem* item, int col) { - switch (col) - { - case 2: - case 4: - _selected_set = col/2 - 1; - break; - - default: - return; - } + if (col != 2) + return; int i = _item_index_hash[item]; if (i == 0) @@ -514,8 +472,7 @@ { _dialog = new QDialog (this); - _dialog->setWindowTitle (tr ("Enter new Shortcut for Set %1") - .arg (_selected_set + 1)); + _dialog->setWindowTitle (tr ("Enter new Shortcut")); QVBoxLayout *box = new QVBoxLayout(_dialog); @@ -569,8 +526,8 @@ } - _edit_actual->setText (_sc.at (index).actual_sc[_selected_set]); - _label_default->setText (_sc.at (index).default_sc[_selected_set]); + _edit_actual->setText (_sc.at (index).actual_sc); + _label_default->setText (_sc.at (index).default_sc); _handled_index = index; _edit_actual->setFocus (); @@ -590,8 +547,6 @@ QString widget = _sc.at (_handled_index).settings_key.section ('_',0,0); // and look for shortcut QString sep = ":"; - if (_selected_set) - sep = "_1:"; int double_index = _shortcut_hash[widget + sep + _edit_actual->text()] - 1; @@ -609,26 +564,25 @@ if (ret == QMessageBox::Yes) { shortcut_t double_shortcut = _sc.at (double_index); - double_shortcut.actual_sc[_selected_set] = QKeySequence (); + double_shortcut.actual_sc = QKeySequence (); _sc.replace (double_index, double_shortcut); - _index_item_hash[double_index]->setText ((_selected_set + 1)*2, QKeySequence ()); + _index_item_hash[double_index]->setText (2, QKeySequence ()); } else return; } shortcut_t shortcut = _sc.at (_handled_index); - if (! shortcut.actual_sc[_selected_set].isEmpty ()) + if (! shortcut.actual_sc.isEmpty ()) _shortcut_hash.remove (widget + sep + - shortcut.actual_sc[_selected_set].toString ()); - shortcut.actual_sc[_selected_set] = _edit_actual->text(); + shortcut.actual_sc.toString ()); + shortcut.actual_sc = _edit_actual->text(); _sc.replace (_handled_index, shortcut); - _index_item_hash[_handled_index]->setText ((_selected_set + 1)*2, - shortcut.actual_sc[_selected_set]); + _index_item_hash[_handled_index]->setText (2, shortcut.actual_sc); - if (! shortcut.actual_sc[_selected_set].isEmpty ()) - _shortcut_hash[widget + sep + shortcut.actual_sc[_selected_set].toString ()] = + if (! shortcut.actual_sc.isEmpty ()) + _shortcut_hash[widget + sep + shortcut.actual_sc.toString ()] = _handled_index + 1; } @@ -640,27 +594,27 @@ // import a shortcut set from a given settings file and refresh the tree view void -shortcut_manager::import_shortcuts (int set, QSettings *settings) +shortcut_manager::import_shortcuts (QSettings *settings) { for (int i = 0; i < _sc.count (); i++) { // update the list of all shortcuts shortcut_t sc = _sc.at (i); // make a copy - sc.actual_sc[set-1] = QKeySequence ( // get new shortcut from settings - settings->value ("shortcuts/"+sc.settings_key,sc.actual_sc[set-1]). + sc.actual_sc = QKeySequence ( // get new shortcut from settings + settings->value ("shortcuts/"+sc.settings_key,sc.actual_sc). toString ()); // and use the old one as default _sc.replace (i,sc); // replace the old with the new one // update the tree view QTreeWidgetItem* tree_item = _index_item_hash[i]; // get related tree item - tree_item->setText (2*set, sc.actual_sc [set-1]); // display new shortcut + tree_item->setText (2, sc.actual_sc); // display new shortcut } } // import or export of shortcut sets, // called from settings dialog when related buttons are clicked void -shortcut_manager::do_import_export (bool import, int set) +shortcut_manager::do_import_export (bool import) { QString file; @@ -669,13 +623,13 @@ if (import) { file = QFileDialog::getOpenFileName (this, - tr ("Import shortcut set %1 from file ...").arg (set), QString (), + tr ("Import shortcuts from file ..."), QString (), tr ("Octave Shortcut Files (*.osc);;All Files (*)")); } else { file = QFileDialog::getSaveFileName (this, - tr ("Export shortcut set %1 into file ...").arg (set), QString (), + tr ("Export shortcuts into file ..."), QString (), tr ("Octave Shortcut Files (*.osc);;All Files (*)")); } @@ -685,9 +639,9 @@ { // the settings object was successfully created: carry on if (import) - import_shortcuts (set, osc_settings); // import (special action) + import_shortcuts (osc_settings); // import (special action) else - do_write_shortcuts (set, osc_settings, false); // export, (saving settings) + do_write_shortcuts (osc_settings, false); // export, (saving settings) } else qWarning () << tr ("Failed to open %1 as octave shortcut file"). arg (file);
--- a/libgui/src/shortcut-manager.h Sat Nov 07 17:24:02 2015 -0800 +++ b/libgui/src/shortcut-manager.h Sun Nov 08 11:59:50 2015 +0100 @@ -63,10 +63,10 @@ instance->do_init_data (); } - static void write_shortcuts (int set, QSettings *settings, bool closing) + static void write_shortcuts (QSettings *settings, bool closing) { if (instance_ok ()) - instance->do_write_shortcuts (set, settings, closing); + instance->do_write_shortcuts (settings, closing); } static void set_shortcut (QAction *action, const QString& key) @@ -81,10 +81,10 @@ instance->do_fill_treewidget (tree_view); } - static void import_export (bool import, int set) + static void import_export (bool import) { if (instance_ok ()) - instance->do_import_export (import, set); + instance->do_import_export (import); } public slots: @@ -113,12 +113,12 @@ void init (QString, QString, QKeySequence); void do_init_data (); - void do_write_shortcuts (int set, QSettings *settings, bool closing); + void do_write_shortcuts (QSettings *settings, bool closing); void do_set_shortcut (QAction *action, const QString& key); void do_fill_treewidget (QTreeWidget *tree_view); - void do_import_export (bool import, int set); + void do_import_export (bool import); void shortcut_dialog (int); - void import_shortcuts (int set, QSettings *settings); + void import_shortcuts (QSettings *settings); class shortcut_t { @@ -126,25 +126,15 @@ shortcut_t (void) : tree_item (0), description (), settings_key (), - actual_sc (new QKeySequence[2]), default_sc (new QKeySequence[2]) - { - actual_sc[0] = QKeySequence (); - actual_sc[1] = QKeySequence (); - - default_sc[0] = QKeySequence (); - default_sc[1] = QKeySequence (); - } + actual_sc (QKeySequence ()), default_sc (QKeySequence ()) + { } shortcut_t (const shortcut_t& x) : tree_item (x.tree_item), description (x.description), - settings_key (x.settings_key), - actual_sc (new QKeySequence[2]), default_sc (new QKeySequence[2]) + settings_key (x.settings_key) { - actual_sc[0] = x.actual_sc[0]; - actual_sc[1] = x.actual_sc[1]; - - default_sc[0] = x.default_sc[0]; - default_sc[1] = x.default_sc[1]; + actual_sc = x.actual_sc; + default_sc = x.default_sc; } shortcut_t& operator = (const shortcut_t& x) @@ -155,14 +145,11 @@ description = x.description; settings_key = x.settings_key; - actual_sc = new QKeySequence[2]; - default_sc = new QKeySequence[2]; + actual_sc = QKeySequence (); + default_sc = QKeySequence (); - actual_sc[0] = x.actual_sc[0]; - actual_sc[1] = x.actual_sc[1]; - - default_sc[0] = x.default_sc[0]; - default_sc[1] = x.default_sc[1]; + actual_sc = x.actual_sc; + default_sc = x.default_sc; } return *this; @@ -170,15 +157,13 @@ ~shortcut_t (void) { - delete [] actual_sc; - delete [] default_sc; } QTreeWidgetItem *tree_item; QString description; QString settings_key; - QKeySequence *actual_sc; - QKeySequence *default_sc; + QKeySequence actual_sc; + QKeySequence default_sc; }; QList<shortcut_t> _sc; @@ -194,7 +179,6 @@ int _handled_index; QSettings *_settings; - int _selected_set; };