Mercurial > octave-nkf
diff libgui/src/m-editor/file-editor-tab.cc @ 18303: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 | 6736fc9bce24 |
children | 6e8188effddf |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Sat Jan 18 09:25:33 2014 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat Jan 18 08:50:03 2014 -0500 @@ -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)