diff libgui/src/shortcut-manager.cc @ 18656:1b289f45187f gui-release

add some qscintilla actions to the menu and to the shortcut manager * file-editor.cc (request_delete_start_word, request_delete_end_word, request_delete_start_line, request_delete_end_line, request_delete_line, request_copy_line, request_cut_line, request_dupllicate_delection, request_transpose_line, request_upper_case, request_lower_case): new slots for the added actions; (construct): added submenus "Commands" and "Format" witht the new actions to the edit menu; (set_shortcuts): settings shortcuts for the new actions; (check_actions): enabling actions depending on existence of editor tabs; * file-editor.h: new slots, menus and actions * file-editor-tab.cc (scintilla_command): new slot for signals from file_editor indicating scintilla commands * file-editor-tab.h: new slot scintilla_command * octave_qscintilla (constructor): disabling shortcuts for actions handled by the gui editor; (get_global_textcursor_pos): remove unecessary namespace specification * shortcut-manager.cc (constructor): store settings objects in class variable; (do_init_data): initialization of new actions; (init, do_write_shortcuts, do_set_shortcut): code cleanup accessing settings; (shortcut_dialog_finished) fix writing to wring column of tree view * shortcut-manager.h: settings stored as class variable
author Torsten <ttl@justmail.de>
date Fri, 18 Apr 2014 13:43:55 +0200
parents c7df983b003a
children 777281eeb3d4
line wrap: on
line diff
--- a/libgui/src/shortcut-manager.cc	Thu Apr 17 09:01:03 2014 -0400
+++ b/libgui/src/shortcut-manager.cc	Fri Apr 18 13:43:55 2014 +0200
@@ -45,6 +45,8 @@
 shortcut_manager::shortcut_manager ()
 {
   setObjectName ("Shortcut_Manager");
+
+  _settings = resource_manager::get_settings ();
 }
 
 shortcut_manager::~shortcut_manager ()
@@ -113,10 +115,24 @@
   init (tr ("Paste"), "editor_edit:paste",  QKeySequence::Paste );
   init (tr ("Select All"), "editor_edit:select_all",  QKeySequence::SelectAll );
   init (tr ("Find and Replace"), "editor_edit:find_replace",  QKeySequence::Find );
+
+  init (tr ("Delete to Start of Word"), "editor_edit:delete_start_word",  QKeySequence::DeleteStartOfWord );
+  init (tr ("Delete to End of Word"), "editor_edit:delete_end_word",  QKeySequence::DeleteEndOfWord );
+  init (tr ("Delete to Start of Line"), "editor_edit:delete_start_line",  QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_Backspace) );
+  init (tr ("Delete to End of Line"), "editor_edit:delete_end_line",  QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_Delete) );
+  init (tr ("Delete Line"), "editor_edit:delete_line",  QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_L) );
+  init (tr ("Copy Line"), "editor_edit:copy_line",  QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_C) );
+  init (tr ("Cut Line"), "editor_edit:cut_line",  QKeySequence (Qt::ControlModifier + Qt::SHIFT + Qt::Key_X) );
+  init (tr ("Duplicate Selection/Line"), "editor_edit:duplicate_selection",  QKeySequence (Qt::ControlModifier + Qt::Key_D) );
+  init (tr ("Transpose Line"), "editor_edit:transpose_line",  QKeySequence (Qt::ControlModifier + Qt::Key_T) );
+
   init (tr ("Comment Selection"), "editor_edit:comment_selection",  QKeySequence (Qt::ControlModifier + Qt::Key_R) );
   init (tr ("Uncomment Selection"), "editor_edit:uncomment_selection",  QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_R) );
+  init (tr ("Uppercase Selection"), "editor_edit:upper_case",  QKeySequence (Qt::ControlModifier + Qt::Key_U) );
+  init (tr ("Lowercase Selection"), "editor_edit:lower_case",  QKeySequence (Qt::ControlModifier + Qt::AltModifier + Qt::Key_U) );
   init (tr ("Indent Selection"), "editor_edit:indent_selection",  QKeySequence (Qt::ControlModifier + Qt::Key_Tab) );
   init (tr ("Unindent Selection"), "editor_edit:unindent_selection",  QKeySequence (Qt::SHIFT + Qt::ControlModifier + Qt::Key_Tab) );
+
   init (tr ("Completion List"), "editor_edit:completion_list",  QKeySequence (Qt::ControlModifier + Qt::Key_Space) );
   init (tr ("Toggle Bookmark"), "editor_edit:toggle_bookmark",  QKeySequence (Qt::Key_F7) );
   init (tr ("Next Bookmark"), "editor_edit:next_bookmark",  QKeySequence (Qt::Key_F2) );
@@ -125,15 +141,12 @@
   init (tr ("Goto Line"), "editor_edit:goto_line",  QKeySequence (Qt::ControlModifier+ Qt::Key_G) );
   init (tr ("Preferences"), "editor_edit:preferences",  QKeySequence () );
   init (tr ("Styles Preferences"), "editor_edit:styles_preferences",  QKeySequence () );
-
 }
 
 void
 shortcut_manager::init (QString description, QString key, QKeySequence def_sc)
 {
-  QSettings *settings = resource_manager::get_settings ();
-
-  QKeySequence actual = QKeySequence (settings->value ("shortcuts/"+key, def_sc).toString ());
+  QKeySequence actual = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ());
 
   // append the new shortcut to the list
   shortcut_t shortcut_info;
@@ -209,31 +222,28 @@
 
   for (int i = 0; i < _sc.count (); i++)
     {
-      shortcut_t shortcut_info = _sc.at (i);
+      shortcut_t sc = _sc.at (i);
 
-      QTreeWidgetItem* section = _level_hash[shortcut_info.settings_key.section(':',0,0)];
+      QTreeWidgetItem* section = _level_hash[sc.settings_key.section(':',0,0)];
       QTreeWidgetItem* tree_item = new QTreeWidgetItem (section);
 
-      tree_item->setText (0, shortcut_info.description);
-      tree_item->setText (1, shortcut_info.default_sc);
-      tree_item->setText (2, shortcut_info.actual_sc);
+      tree_item->setText (0, sc.description);
+      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;
     }
+
 }
 
 void
 shortcut_manager::do_write_shortcuts ()
 {
-  QSettings *settings = resource_manager::get_settings ();
+  for (int i = 0; i < _sc.count (); i++)
+    _settings->setValue("shortcuts/"+_sc.at (i).settings_key, _sc.at (i).actual_sc.toString ());
 
-  settings->beginGroup ("shortcuts");
-  for (int i = 0; i < _sc.count (); i++)
-    settings->setValue(_sc.at (i).settings_key, _sc.at (i).actual_sc.toString ());
-  settings->endGroup ();
-
-  settings->sync ();
+  _settings->sync ();
 
   delete _dialog;
 }
@@ -241,12 +251,11 @@
 void
 shortcut_manager::do_set_shortcut (QAction* action, const QString& key)
 {
-  QSettings *settings = resource_manager::get_settings ();
+  int index = _action_hash[key] - 1;
 
-  int index = _action_hash[key] - 1;
   if (index > -1 && index < _sc.count ())
-    action->setShortcut (
-      settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ());
+    action->setShortcut ( QKeySequence (
+      _settings->value ("shortcuts/" + key, _sc.at (index).default_sc).toString ()));
   else
     qDebug () << "Key: " << key << " not found in _action_hash";
 }
@@ -359,7 +368,7 @@
           shortcut_t double_shortcut = _sc.at (double_index);
           double_shortcut.actual_sc = QKeySequence ();
           _sc.replace (double_index, double_shortcut);
-          _index_item_hash[double_index]->setText (1, QKeySequence ());
+          _index_item_hash[double_index]->setText (2, QKeySequence ());
         }
       else
         return;