Mercurial > hg > octave-nkf
changeset 18345:106da7544504 gui-release
gui: Add indent/unindent edit menu to editor (Bug #41223)
* libgui/src/m-editor/file-editor.h
(file_editor::private): Add _indent_selection_action, _unindent_selection_action menus.
(file_editor::request_indent_selected_text): New function.
(file_editor::request_indent_selected_text): New function.
(file_editor::fetab_indent_selected_text): New signal.
(file_editor::fetab_indent_selected_text): New signal.
* libgui/src/m-editor/file-editor.cc
(file_editor::request_indent_selected_text): New function.
(file_editor::request_unindent_selected_text): New function.
(file_editor::contruct: Create indent menus and connect signals.
(file_editor::set_shortcuts): Enable/disable indent menus and shortcuts.
(file_editor::check_actions): Enable indent menus if have editor tabs.
* libgui/src/m-editor/file-editor-tab.h
(file-editor-tab::indent_selected_text): New function.
(file-editor-tab::unindent_selected_text): New function.
(file-editor-tab::do_indent_selected_text): New function.
* libgui/src/m-editor/file-editor-tab.cc
(file-editor-tab::indent_selected_text): New function.
(file-editor-tab::unindent_selected_text): New function.
(file-editor-tab::do_indent_selected_text): New function.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sat, 18 Jan 2014 08:50:03 -0500 |
parents | e8176099889c |
children | 024940bd5b77 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h |
diffstat | 4 files changed, 116 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -746,6 +746,25 @@ } void +file_editor_tab::indent_selected_text (const QWidget *ID) +{ + if (ID != this) + return; + + do_indent_selected_text (true); +} + +void +file_editor_tab::unindent_selected_text (const QWidget *ID) +{ + if (ID != this) + return; + + do_indent_selected_text (false); +} + + +void file_editor_tab::handle_find_dialog_finished (int) { // Find dialog is going to hide. Save location of window for @@ -813,6 +832,43 @@ _edit_area->setCursorPosition (line-1, 0); } +void +file_editor_tab::do_indent_selected_text (bool indent) +{ + // TODO + _edit_area->beginUndoAction (); + + if (_edit_area->hasSelectedText ()) + { + int lineFrom, lineTo, colFrom, colTo; + _edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + + if (colTo == 0) // the beginning of last line is not selected + lineTo--; // stop at line above + + for (int i = lineFrom; i <= lineTo; i++) + { + if (indent) + _edit_area->indent (i); + else + _edit_area->unindent (i); + } + //set selection on (un)indented section + _edit_area->setSelection (lineFrom, 0, lineTo, + _edit_area->text (lineTo).length ()); + } + else + { + int cpline, col; + _edit_area->getCursorPosition (&cpline, &col); + if (indent) + _edit_area->indent (cpline); + else + _edit_area->unindent (cpline); + } + + _edit_area->endUndoAction (); +} void file_editor_tab::do_comment_selected_text (bool comment)
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -93,6 +93,10 @@ void comment_selected_text (const QWidget *ID); void uncomment_selected_text (const QWidget *ID); + + void indent_selected_text (const QWidget *ID); + void unindent_selected_text (const QWidget *ID); + void find (const QWidget *ID); void goto_line (const QWidget *ID, int line = -1); @@ -186,6 +190,7 @@ int check_file_modified (); void do_comment_selected_text (bool comment); QString comment_string (const QString&); + void do_indent_selected_text (bool indent); void add_breakpoint_callback (const bp_info& info); void remove_breakpoint_callback (const bp_info& info);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -670,6 +670,19 @@ } void +file_editor::request_indent_selected_text (void) +{ + emit fetab_indent_selected_text (_tab_widget->currentWidget ()); +} + +void +file_editor::request_unindent_selected_text (void) +{ + emit fetab_unindent_selected_text (_tab_widget->currentWidget ()); +} + + +void file_editor::request_find (void) { emit fetab_find (_tab_widget->currentWidget ()); @@ -945,6 +958,11 @@ _uncomment_selection_action = new QAction (tr ("&Uncomment"), _tool_bar); + _indent_selection_action + = new QAction (tr ("&Indent"), _tool_bar); + _unindent_selection_action + = new QAction (tr ("&Unindent"), _tool_bar); + _find_action = new QAction (QIcon (":/actions/icons/find.png"), tr ("&Find and Replace..."), _tool_bar); @@ -978,6 +996,8 @@ _toggle_bookmark_action->setShortcutContext (Qt::WindowShortcut); _comment_selection_action->setShortcutContext (Qt::WindowShortcut); _uncomment_selection_action->setShortcutContext (Qt::WindowShortcut); + _indent_selection_action->setShortcutContext (Qt::WindowShortcut); + _unindent_selection_action->setShortcutContext (Qt::WindowShortcut); _find_action->setShortcutContext (Qt::WindowShortcut); _goto_line_action->setShortcutContext (Qt::WindowShortcut); @@ -1058,6 +1078,9 @@ editMenu->addAction (_comment_selection_action); editMenu->addAction (_uncomment_selection_action); editMenu->addSeparator (); + editMenu->addAction (_indent_selection_action); + editMenu->addAction (_unindent_selection_action); + editMenu->addSeparator (); editMenu->addAction (_toggle_bookmark_action); editMenu->addAction (_next_bookmark_action); editMenu->addAction (_previous_bookmark_action); @@ -1187,6 +1210,12 @@ connect (_uncomment_selection_action, SIGNAL (triggered ()), this, SLOT (request_uncomment_selected_text ())); + connect (_indent_selection_action, SIGNAL (triggered ()), + this, SLOT (request_indent_selected_text ())); + + connect (_unindent_selection_action, SIGNAL (triggered ()), + this, SLOT (request_unindent_selected_text ())); + connect (_find_action, SIGNAL (triggered ()), this, SLOT (request_find ())); @@ -1340,6 +1369,12 @@ connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)), f, SLOT (uncomment_selected_text (const QWidget*))); + connect (this, SIGNAL (fetab_indent_selected_text (const QWidget*)), + f, SLOT (indent_selected_text (const QWidget*))); + + connect (this, SIGNAL (fetab_unindent_selected_text (const QWidget*)), + f, SLOT (unindent_selected_text (const QWidget*))); + connect (this, SIGNAL (fetab_find (const QWidget*)), f, SLOT (find (const QWidget*))); @@ -1395,6 +1430,11 @@ + Qt::ControlModifier + Qt::Key_R); + _indent_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_Tab); + _unindent_selection_action->setShortcut (Qt::SHIFT + + Qt::ControlModifier + + Qt::Key_Tab); + _copy_action->setShortcut (QKeySequence::Copy); _cut_action->setShortcut (QKeySequence::Cut); _paste_action->setShortcut (QKeySequence::Paste); @@ -1427,6 +1467,9 @@ _comment_selection_action->setShortcut (no_key); _uncomment_selection_action->setShortcut (no_key); + _indent_selection_action->setShortcut (no_key); + _unindent_selection_action->setShortcut (no_key); + _copy_action->setShortcut (no_key); _cut_action->setShortcut (no_key); _paste_action->setShortcut (no_key); @@ -1461,6 +1504,9 @@ _comment_selection_action->setEnabled (have_tabs); _uncomment_selection_action->setEnabled (have_tabs); + _indent_selection_action->setEnabled (have_tabs); + _unindent_selection_action->setEnabled (have_tabs); + _paste_action->setEnabled (have_tabs); _context_help_action->setEnabled (have_tabs); _context_doc_action->setEnabled (have_tabs);
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -91,6 +91,8 @@ void fetab_remove_all_breakpoints (const QWidget* ID); void fetab_comment_selected_text (const QWidget* ID); void fetab_uncomment_selected_text (const QWidget* ID); + void fetab_indent_selected_text (const QWidget* ID); + void fetab_unindent_selected_text (const QWidget* ID); void fetab_find (const QWidget* ID); void fetab_goto_line (const QWidget* ID, int line = -1); void fetab_insert_debugger_pointer (const QWidget* ID, int line = -1); @@ -139,6 +141,10 @@ void request_comment_selected_text (void); void request_uncomment_selected_text (void); + + void request_indent_selected_text (void); + void request_unindent_selected_text (void); + void request_find (void); void request_goto_line (void); @@ -201,6 +207,9 @@ QAction *_comment_selection_action; QAction *_uncomment_selection_action; + QAction *_indent_selection_action; + QAction *_unindent_selection_action; + QAction *_copy_action; QAction *_cut_action; QAction *_paste_action;