changeset 16719:0f6f14e3ac6a

commenting selected lines in the editor uses comment string depending on lexer * file-editor-tab.h: new function comment_string * file-editor-tab.cc(comment_string): returns comment string depending on lexer name (do_comment_selected_text): get actual lexer and its comment string
author Torsten <ttl@justmail.de>
date Sun, 02 Jun 2013 19:17:49 +0200
parents 0495339998f8
children 973fd2367d44
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun Jun 02 11:10:16 2013 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun Jun 02 19:17:49 2013 +0200
@@ -323,6 +323,21 @@
   _lexer_apis->savePrepared (_prep_apis_file);
 }
 
+QString
+file_editor_tab::comment_string (const QString& lexer)
+{
+  if (lexer == "octave" || lexer == "matlab")
+    return QString("%");
+  else if (lexer == "perl" || lexer == "bash" || lexer == "diff")
+    return QString("#");
+  else if (lexer == "cpp")
+    return ("//");
+  else if (lexer == "batch")
+    return ("REM ");
+  else
+    return ("%");  // should never happen
+}
+
 // slot for fetab_set_focus: sets the focus to the current edit area
 void
 file_editor_tab::set_focus (const QWidget *ID)
@@ -714,6 +729,8 @@
       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
 
@@ -722,13 +739,13 @@
       for (int i = lineFrom; i <= lineTo; i++)
         {
           if (comment)
-            _edit_area->insertAt ("%", i, 0);
+            _edit_area->insertAt (comment_str, i, 0);
           else
             {
               QString line (_edit_area->text (i));
-              if (line.startsWith ("%"))
+              if (line.startsWith (comment_str))
                 {
-                  _edit_area->setSelection (i, 0, i, 1);
+                  _edit_area->setSelection (i, 0, i, comment_str.length ());
                   _edit_area->removeSelectedText ();
                 }
             }
--- a/libgui/src/m-editor/file-editor-tab.h	Sun Jun 02 11:10:16 2013 +0200
+++ b/libgui/src/m-editor/file-editor-tab.h	Sun Jun 02 19:17:49 2013 +0200
@@ -176,6 +176,7 @@
 
   int check_file_modified ();
   void do_comment_selected_text (bool comment);
+  QString comment_string (const QString&);
 
   void add_breakpoint_callback (const bp_info& info);
   void remove_breakpoint_callback (const bp_info& info);