[gnote] Ident selected lines on tab



commit b19f1275a7e173ffb3c3d10cd3e53e48cfd80916
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Mon Jul 6 22:16:48 2015 +0300

    Ident selected lines on tab
    
    Depth is increased on all selected lines on tab and decreased on
    shift+tab.
    Requested in Bug 632457.

 src/notebuffer.cpp |   56 ++++++++++++++++++++++++++++-----------------------
 src/notebuffer.hpp |    4 ++-
 2 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/src/notebuffer.cpp b/src/notebuffer.cpp
index 0bfb8b9..81a2703 100644
--- a/src/notebuffer.cpp
+++ b/src/notebuffer.cpp
@@ -503,42 +503,48 @@ namespace gnote {
     return false;
   }
 
-  // Returns true if the depth of the line was increased 
-  bool NoteBuffer::add_tab()
+  bool NoteBuffer::handle_tab(DepthAction depth_action)
   {
-    Glib::RefPtr<Gtk::TextMark> insert_mark = get_insert();
-    Gtk::TextIter iter = get_iter_at_mark(insert_mark);
-    iter.set_line_offset(0);
+    // if we have something selected, then tab increases ident for selected lines
+    Gtk::TextIter start, end;
+    if(get_selection_bounds(start, end)) {
+      start.set_line_offset(0);
+      for(int end_line = end.get_line(); start.get_line() <= end_line;) {
+        (*this.*depth_action)(start);
+        if(!start.forward_line()) {
+          break;
+        }
+      }
+      return true;
+    }
+    else {
+      Glib::RefPtr<Gtk::TextMark> insert_mark = get_insert();
+      Gtk::TextIter iter = get_iter_at_mark(insert_mark);
+      iter.set_line_offset(0);
 
-    DepthNoteTag::Ptr depth = find_depth_tag(iter);
+      DepthNoteTag::Ptr depth = find_depth_tag(iter);
 
-    // If the cursor is at a line with a depth and a tab has been
-    // inserted then we increase the indent depth of that line.
-    if (depth) {
-      increase_depth(iter);
-      return true;
+      // If the cursor is at a line with a depth and a tab has been
+      // inserted then we increase the indent depth of that line.
+      if (depth) {
+        (*this.*depth_action)(iter);
+        return true;
+      }
     }
     return false;
   }
 
+  // Returns true if the depth of the line was increased
+  bool NoteBuffer::add_tab()
+  {
+    return handle_tab(&NoteBuffer::increase_depth);
+  }
+
 
   // Returns true if the depth of the line was decreased
   bool NoteBuffer::remove_tab()
   {
-    Glib::RefPtr<Gtk::TextMark> insert_mark = get_insert();
-    Gtk::TextIter iter = get_iter_at_mark(insert_mark);
-    iter.set_line_offset(0);
-
-    DepthNoteTag::Ptr depth = find_depth_tag(iter);
-
-    // If the cursor is at a line with depth and a tab has been
-    // inserted, then we decrease the depth of that line.
-    if (depth) {
-      decrease_depth(iter);
-      return true;
-    }
-
-    return false;
+    return handle_tab(&NoteBuffer::decrease_depth);
   }
 
 
diff --git a/src/notebuffer.hpp b/src/notebuffer.hpp
index 8e68f65..131e495 100644
--- a/src/notebuffer.hpp
+++ b/src/notebuffer.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2014 Aurimas Cernius
+ * Copyright (C) 2011-2015 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -133,6 +133,8 @@ private:
   void widget_swap (const NoteTag::Ptr & tag, const Gtk::TextIter & start,
                     const Gtk::TextIter & end_iter, bool adding);
   void change_cursor_depth(bool increase);
+  typedef void (NoteBuffer::*DepthAction)(Gtk::TextIter & iter);
+  bool handle_tab(DepthAction depth_action);
 
   UndoManager           *m_undomanager;
   static const gunichar s_indent_bullets[];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]