# HG changeset patch # User Thorsten Liebig # Date 1370721427 -7200 # Node ID e81084a745a9f44e80f97b28dfebea1fe100dc5d # Parent 68ca4122e5688200b3048a6cb27396be606498a4 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 diff -r 68ca4122e568 -r e81084a745a9 libgui/src/m-editor/file-editor-tab.cc --- 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 diff -r 68ca4122e568 -r e81084a745a9 libgui/src/m-editor/file-editor.cc --- 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);