# HG changeset patch # User Torsten # Date 1397821435 -7200 # Node ID 1b289f45187f443b72bf32d3073ac53ba60df77a # Parent 41489b96ebca033df32c9b60096bf11973466297 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 diff -r 41489b96ebca -r 1b289f45187f libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri Apr 18 13:43:55 2014 +0200 @@ -739,6 +739,15 @@ } void +file_editor_tab::scintilla_command (const QWidget *ID, unsigned int sci_msg) +{ + if (ID != this) + return; + + _edit_area->SendScintilla (sci_msg); +} + +void file_editor_tab::comment_selected_text (const QWidget *ID) { if (ID != this) diff -r 41489b96ebca -r 1b289f45187f libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/m-editor/file-editor-tab.h Fri Apr 18 13:43:55 2014 +0200 @@ -92,6 +92,8 @@ void previous_breakpoint (const QWidget *ID); void remove_all_breakpoints (const QWidget *ID); + void scintilla_command (const QWidget *, unsigned int); + void comment_selected_text (const QWidget *ID); void uncomment_selected_text (const QWidget *ID); diff -r 41489b96ebca -r 1b289f45187f libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/m-editor/file-editor.cc Fri Apr 18 13:43:55 2014 +0200 @@ -41,6 +41,7 @@ #include #include #include +#include #include "octave-link.h" #include "utils.h" @@ -701,18 +702,85 @@ emit fetab_remove_all_breakpoints (_tab_widget->currentWidget ()); } +// slots for Edit->Commands actions +void +file_editor::request_delete_start_word (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::DeleteWordLeft); +} +void +file_editor::request_delete_end_word (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::DeleteWordRight); +} +void +file_editor::request_delete_start_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::DeleteLineLeft); +} +void +file_editor::request_delete_end_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::DeleteLineRight); +} +void +file_editor::request_delete_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::LineDelete); +} +void +file_editor::request_copy_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::LineCopy); +} +void +file_editor::request_cut_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::LineCut); +} +void +file_editor::request_duplicate_selection (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::SelectionDuplicate); +} +void +file_editor::request_transpose_line (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::LineTranspose); +} void file_editor::request_comment_selected_text (void) { emit fetab_comment_selected_text (_tab_widget->currentWidget ()); } - void file_editor::request_uncomment_selected_text (void) { emit fetab_uncomment_selected_text (_tab_widget->currentWidget ()); } +// slots for Edit->Format actions +void +file_editor::request_upper_case (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::SelectionUpperCase); +} +void +file_editor::request_lower_case (bool) +{ + emit fetab_scintilla_command (_tab_widget->currentWidget (), + QsciCommand::SelectionLowerCase); +} void file_editor::request_indent_selected_text (void) { @@ -1153,7 +1221,6 @@ _menu_bar->addMenu (fileMenu); - QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar); editMenu->addAction (_undo_action); editMenu->addAction (_redo_action); @@ -1166,10 +1233,44 @@ editMenu->addSeparator (); editMenu->addAction (_find_action); editMenu->addSeparator (); - editMenu->addAction (_comment_selection_action); - editMenu->addAction (_uncomment_selection_action); - editMenu->addAction (_indent_selection_action); - editMenu->addAction (_unindent_selection_action); + + _edit_cmd_menu = editMenu->addMenu (tr ("&Commands")); + + _delete_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Delete Line"), this, SLOT (request_delete_line (bool))); + _copy_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Copy Line"), this, SLOT (request_copy_line (bool))); + _cut_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Cut Line"), this, SLOT (request_cut_line (bool))); + + _edit_cmd_menu->addSeparator (); + + _delete_start_word_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Delete to Start of Word"), this, SLOT (request_delete_start_word (bool))); + _delete_end_word_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Delete to End of Word"), this, SLOT (request_delete_end_word (bool))); + _delete_start_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Delete to Start of Line"), this, SLOT (request_delete_start_line (bool))); + _delete_end_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Delete to End of Line"), this, SLOT (request_delete_end_line (bool))); + + _edit_cmd_menu->addSeparator (); + + _duplicate_selection_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Duplicate Selection/Line"), this, SLOT (request_duplicate_selection (bool))); + _transpose_line_action = _edit_cmd_menu->addAction ( + QIcon (), tr ("Transpose Line"), this, SLOT (request_transpose_line (bool))); + + _edit_fmt_menu = editMenu->addMenu (tr ("&Format")); + _upper_case_action = _edit_fmt_menu->addAction ( + QIcon (), tr ("&Uppercase Selection"), this, SLOT (request_upper_case (bool))); + _lower_case_action = _edit_fmt_menu->addAction ( + QIcon (), tr ("&Lowercase Selection"), this, SLOT (request_lower_case (bool))); + _edit_fmt_menu->addAction (_comment_selection_action); + _edit_fmt_menu->addAction (_uncomment_selection_action); + _edit_fmt_menu->addAction (_indent_selection_action); + _edit_fmt_menu->addAction (_unindent_selection_action); + editMenu->addSeparator (); editMenu->addAction (_completion_action); editMenu->addSeparator (); @@ -1480,6 +1581,9 @@ connect (this, SIGNAL (fetab_remove_all_breakpoints (const QWidget*)), f, SLOT (remove_all_breakpoints (const QWidget*))); + connect (this, SIGNAL (fetab_scintilla_command (const QWidget *, unsigned int)), + f, SLOT (scintilla_command (const QWidget *, unsigned int))); + connect (this, SIGNAL (fetab_comment_selected_text (const QWidget*)), f, SLOT (comment_selected_text (const QWidget*))); @@ -1574,8 +1678,21 @@ shortcut_manager::set_shortcut (_paste_action, "editor_edit:paste"); shortcut_manager::set_shortcut (_selectall_action, "editor_edit:select_all"); shortcut_manager::set_shortcut (_find_action, "editor_edit:find_replace"); + + shortcut_manager::set_shortcut (_delete_start_word_action, "editor_edit:delete_start_word"); + shortcut_manager::set_shortcut (_delete_end_word_action, "editor_edit:delete_end_word"); + shortcut_manager::set_shortcut (_delete_start_line_action, "editor_edit:delete_start_line"); + shortcut_manager::set_shortcut (_delete_end_line_action, "editor_edit:delete_end_line"); + shortcut_manager::set_shortcut (_delete_line_action, "editor_edit:delete_line"); + shortcut_manager::set_shortcut (_copy_line_action, "editor_edit:copy_line"); + shortcut_manager::set_shortcut (_cut_line_action, "editor_edit:cut_line"); + shortcut_manager::set_shortcut (_duplicate_selection_action, "editor_edit:duplicate_selection"); + shortcut_manager::set_shortcut (_transpose_line_action, "editor_edit:transpose_line"); shortcut_manager::set_shortcut (_comment_selection_action, "editor_edit:comment_selection"); shortcut_manager::set_shortcut (_uncomment_selection_action, "editor_edit:uncomment_selection"); + + shortcut_manager::set_shortcut (_upper_case_action, "editor_edit:upper_case"); + shortcut_manager::set_shortcut (_lower_case_action, "editor_edit:lower_case"); shortcut_manager::set_shortcut (_indent_selection_action, "editor_edit:indent_selection"); shortcut_manager::set_shortcut (_unindent_selection_action, "editor_edit:unindent_selection"); shortcut_manager::set_shortcut (_completion_action, "editor_edit:completion_list"); @@ -1624,10 +1741,24 @@ _paste_action->setShortcut (no_key); _selectall_action->setShortcut (no_key); _find_action->setShortcut (no_key); + + _delete_start_word_action->setShortcut (no_key); + _delete_end_word_action->setShortcut (no_key); + _delete_end_line_action->setShortcut (no_key); + _delete_start_line_action->setShortcut (no_key); + _delete_line_action->setShortcut (no_key); + _copy_line_action->setShortcut (no_key); + _cut_line_action->setShortcut (no_key); + _duplicate_selection_action->setShortcut (no_key); + _transpose_line_action->setShortcut (no_key); _comment_selection_action->setShortcut (no_key); _uncomment_selection_action->setShortcut (no_key); + + _upper_case_action->setShortcut (no_key); + _lower_case_action->setShortcut (no_key); _indent_selection_action->setShortcut (no_key); _unindent_selection_action->setShortcut (no_key); + _completion_action->setShortcut (no_key); _toggle_bookmark_action->setShortcut (no_key); _next_bookmark_action->setShortcut (no_key); @@ -1657,6 +1788,9 @@ { bool have_tabs = _tab_widget->count () > 0; + _edit_cmd_menu->setEnabled (have_tabs); + _edit_fmt_menu->setEnabled (have_tabs); + _comment_selection_action->setEnabled (have_tabs); _uncomment_selection_action->setEnabled (have_tabs); @@ -1692,6 +1826,7 @@ _undo_action->setEnabled (have_tabs); _redo_action->setEnabled (have_tabs); + _selectall_action->setEnabled (have_tabs); } // empty_script determines whether we have to create an empty script diff -r 41489b96ebca -r 1b289f45187f libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/m-editor/file-editor.h Fri Apr 18 13:43:55 2014 +0200 @@ -107,6 +107,7 @@ void fetab_do_breakpoint_marker (bool insert, const QWidget* ID, int line = -1); void fetab_set_focus (const QWidget* ID); + void fetab_scintilla_command (const QWidget* ID, unsigned int sci_msg); void fetab_zoom_in (const QWidget* ID); void fetab_zoom_out (const QWidget* ID); @@ -152,9 +153,21 @@ void request_previous_breakpoint (void); void request_remove_breakpoint (void); + void request_delete_start_word (bool); + void request_delete_end_word (bool); + void request_delete_start_line (bool); + void request_delete_end_line (bool); + void request_delete_line (bool); + void request_copy_line (bool); + void request_cut_line (bool); + void request_duplicate_selection (bool); + void request_transpose_line (bool); + void request_comment_selected_text (void); void request_uncomment_selected_text (void); + void request_upper_case (bool); + void request_lower_case (bool); void request_indent_selected_text (void); void request_unindent_selected_text (void); @@ -232,9 +245,10 @@ QToolBar *_tool_bar; QMenu *_debug_menu; + QAction *_upper_case_action; + QAction *_lower_case_action; QAction *_comment_selection_action; QAction *_uncomment_selection_action; - QAction *_indent_selection_action; QAction *_unindent_selection_action; @@ -249,6 +263,16 @@ QAction *_zoom_out_action; QAction *_zoom_normal_action; + QAction *_delete_start_word_action; + QAction *_delete_end_word_action; + QAction *_delete_start_line_action; + QAction *_delete_end_line_action; + QAction *_delete_line_action; + QAction *_copy_line_action; + QAction *_cut_line_action; + QAction *_duplicate_selection_action; + QAction *_transpose_line_action; + QAction *_find_action; QAction *_goto_line_action; QAction *_completion_action; @@ -275,6 +299,9 @@ QAction *_preferences_action; QAction *_styles_preferences_action; + QMenu *_edit_cmd_menu; + QMenu *_edit_fmt_menu; + QTabWidget *_tab_widget; int _marker_breakpoint; diff -r 41489b96ebca -r 1b289f45187f libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/m-editor/octave-qscintilla.cc Fri Apr 18 13:43:55 2014 +0200 @@ -29,18 +29,33 @@ #ifdef HAVE_QSCINTILLA #include +#include #include #include "octave-qscintilla.h" #include "file-editor-tab.h" +#include "shortcut-manager.h" octave_qscintilla::octave_qscintilla (QWidget *p) : QsciScintilla (p) { - // disable zoom-in/out shortcuts, these are handled by octave - SendScintilla (QsciScintillaBase::SCI_CLEARCMDKEY, '+' + (QsciScintillaBase::SCMOD_CTRL << 16) ); - SendScintilla (QsciScintillaBase::SCI_CLEARCMDKEY, '-' + (QsciScintillaBase::SCMOD_CTRL << 16) ); - SendScintilla (QsciScintillaBase::SCI_CLEARCMDKEY, '/' + (QsciScintillaBase::SCMOD_CTRL << 16) ); + // clear scintilla edit shortcuts that are handled by the editor + QsciCommandSet *cmd_set = standardCommands (); + cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0); + cmd_set->find (QsciCommand::LineTranspose)->setKey (0); + cmd_set->find (QsciCommand::Undo)->setKey (0); + cmd_set->find (QsciCommand::Redo)->setKey (0); + cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0); + cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0); + cmd_set->find (QsciCommand::ZoomIn)->setKey (0); + cmd_set->find (QsciCommand::ZoomOut)->setKey (0); + cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0); + cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0); + cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0); + cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0); + cmd_set->find (QsciCommand::LineDelete)->setKey (0); + cmd_set->find (QsciCommand::LineCut)->setKey (0); + cmd_set->find (QsciCommand::LineCopy)->setKey (0); } octave_qscintilla::~octave_qscintilla () @@ -50,11 +65,11 @@ octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos) { - long position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); + long position = SendScintilla (SCI_GETCURRENTPOS); long point_x = SendScintilla - (QsciScintillaBase::SCI_POINTXFROMPOSITION,0,position); + (SCI_POINTXFROMPOSITION,0,position); long point_y = SendScintilla - (QsciScintillaBase::SCI_POINTYFROMPOSITION,0,position); + (SCI_POINTYFROMPOSITION,0,position); *local_pos = QPoint (point_x,point_y); // local cursor position *global_pos = mapToGlobal (*local_pos); // global position of cursor } diff -r 41489b96ebca -r 1b289f45187f libgui/src/shortcut-manager.cc --- 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; diff -r 41489b96ebca -r 1b289f45187f libgui/src/shortcut-manager.h --- a/libgui/src/shortcut-manager.h Thu Apr 17 09:01:03 2014 -0400 +++ b/libgui/src/shortcut-manager.h Fri Apr 18 13:43:55 2014 +0200 @@ -28,7 +28,7 @@ #include #include #include - +#include class enter_shortcut : public QLineEdit { @@ -133,6 +133,8 @@ QLabel *_label_default; int _handled_index; + QSettings *_settings; + };