changeset 16737:e81084a745a9

GUI: change (un)comment handling of selection, allow (un)comment of current line * file_editor_tab.cc (do_comment_selected_text): (un)comment selected text and set selection to entrie block; allow (un)comment of the current line only wihtout any selection * file-editor.cc (construct): update toolbar actions text
author Thorsten Liebig <thorsten.liebig@gmx.de>
date Sat, 08 Jun 2013 21:57:07 +0200
parents 68ca4122e568
children 33ab01a26b80
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor.cc
diffstat 2 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun Jun 09 10:24:47 2013 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sat Jun 08 21:57:07 2013 +0200
@@ -740,18 +740,17 @@
 void
 file_editor_tab::do_comment_selected_text (bool comment)
 {
+  QString comment_str = comment_string (_edit_area->lexer ()->lexer ());
+  _edit_area->beginUndoAction ();
+
   if (_edit_area->hasSelectedText ())
     {
       int lineFrom, lineTo, colFrom, colTo;
       _edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo);
 
-      QString comment_str = comment_string (_edit_area->lexer ()->lexer ());
-
       if (colTo == 0)  // the beginning of last line is not selected
         lineTo--;        // stop at line above
 
-      _edit_area->beginUndoAction ();
-
       for (int i = lineFrom; i <= lineTo; i++)
         {
           if (comment)
@@ -766,9 +765,26 @@
                 }
             }
         }
-
-      _edit_area->endUndoAction ();
+      //set selection on (un)commented section
+      _edit_area->setSelection (lineFrom, 0, lineTo, _edit_area->text (lineTo).length ());
     }
+  else
+    {
+      int cpline, col;
+      _edit_area->getCursorPosition (&cpline, &col);
+      if (comment)
+        _edit_area->insertAt (comment_str, cpline, 0);
+      else
+        {
+          QString line (_edit_area->text (cpline));
+          if (line.startsWith (comment_str))
+            {
+              _edit_area->setSelection (cpline, 0, cpline, comment_str.length ());
+              _edit_area->removeSelectedText ();
+            }
+        }
+    }
+  _edit_area->endUndoAction ();
 }
 
 void
--- a/libgui/src/m-editor/file-editor.cc	Sun Jun 09 10:24:47 2013 +0200
+++ b/libgui/src/m-editor/file-editor.cc	Sat Jun 08 21:57:07 2013 +0200
@@ -802,10 +802,10 @@
                    tr ("&Remove All breakpoints"), _tool_bar);
 
   QAction *comment_selection_action
-    = new QAction (tr ("&Comment Selected Text"), _tool_bar);
+    = new QAction (tr ("&Comment"), _tool_bar);
 
   QAction *uncomment_selection_action
-    = new QAction (tr ("&Uncomment Selected Text"), _tool_bar);
+    = new QAction (tr ("&Uncomment"), _tool_bar);
 
   QAction *find_action = new QAction (QIcon (":/actions/icons/search.png"),
                                       tr ("&Find and Replace"), _tool_bar);