changeset 16389:f5204f486a29

gui: add shortcut for goto line action in the editor and center the target line * file-editor.cc(construct): add shortcut Ctrl-G for goto line action * file-editor-tab.cc(center_current_line): new function, centering current line * file-editor-tab.cc(set_debugger_position): use center_current_line * file-editor-tab.cc(goto_line): call center_current_line only if goto_line was called from goto line action * file-editor-tab.h: new function center_current_line
author Torsten <ttl@justmail.de>
date Thu, 28 Mar 2013 17:01:43 +0100
parents 75a6716b72a2
children 1834b91292ab
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc
diffstat 3 files changed, 32 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc
+++ b/libgui/src/m-editor/file-editor-tab.cc
@@ -620,23 +620,23 @@
   if (ID != this)
     return;
 
-  bool ok = true;
-
-  if (line <= 0)
+  if (line <= 0)  // ask for desired line
     {
-      ok = false;
-
+      bool ok = false;
       int index;
-
       _edit_area->getCursorPosition(&line, &index);
-
-
-      line = QInputDialog::getInt (_edit_area, "Goto line", "Line number", 
+      line = QInputDialog::getInt (_edit_area, tr("Goto line"), tr("Line number"),
                                    line+1, 1, _edit_area->lines(), 1, &ok);
+      if (ok)
+        {
+          _edit_area->setCursorPosition (line-1, 0);
+          center_current_line ();
+        }
     }
-
-  if (ok)
-    _edit_area->setCursorPosition (line-1, 0);
+  else  // go to given line without dialog
+    {
+      _edit_area->setCursorPosition (line-1, 0);
+    }
 }
 
 
@@ -1142,11 +1142,7 @@
   if (line > 0)
     {
       _edit_area->markerAdd (line, debugger_position);
-      int first_line = _edit_area->firstVisibleLine ();
-      long int visible_lines = _edit_area->SendScintilla
-                                        (QsciScintillaBase::SCI_LINESONSCREEN);
-      first_line = first_line + (line - first_line - visible_lines/2);
-      _edit_area->setFirstVisibleLine (first_line);
+      center_current_line ();
     }
 }
 
@@ -1165,4 +1161,20 @@
     }
 }
 
+
+void
+file_editor_tab::center_current_line ()
+{
+  long int visible_lines = _edit_area->SendScintilla
+                                    (QsciScintillaBase::SCI_LINESONSCREEN);
+  if (visible_lines > 2)
+    {
+      int line, index;
+      _edit_area->getCursorPosition(&line,&index);
+      int first_line = _edit_area->firstVisibleLine ();
+      first_line = first_line + (line - first_line - (visible_lines-1)/2);
+      _edit_area->setFirstVisibleLine (first_line);
+    }
+}
+
 #endif
--- a/libgui/src/m-editor/file-editor-tab.h
+++ b/libgui/src/m-editor/file-editor-tab.h
@@ -142,6 +142,7 @@
   void add_breakpoint_callback (const bp_info& info);
   void remove_breakpoint_callback (const bp_info& info);
   void remove_all_breakpoints_callback (const bp_info& info);
+  void center_current_line ();
 
   QsciScintilla *       _edit_area;
 
--- a/libgui/src/m-editor/file-editor.cc
+++ b/libgui/src/m-editor/file-editor.cc
@@ -658,6 +658,8 @@
   uncomment_selection_action->setShortcutContext(Qt::WindowShortcut);
   find_action->setShortcut                      (QKeySequence::Find);
   find_action->setShortcutContext               (Qt::WindowShortcut);
+  goto_line_action->setShortcut                 (Qt::ControlModifier+ Qt::Key_G);
+  goto_line_action->setShortcutContext          (Qt::WindowShortcut);
 
   // toolbar
   _tool_bar->addAction (new_action);