[Xfce4-commits] <mousepad:master> * mousepad/mousepad-utils.{c, h}: Add iter function to move the iter in front of text. Code used from one of the indentation functions. * mousepad/mousepad-view.c: Add code for a smart home button: when the cursor starts a line and the home button is pressed, it will move to the start of the text. * mousepad/mousepad-view.c: Key bindings Ctrl + {Home, End} to jump to the start and end of a document.

Nick Schermer noreply at xfce.org
Sat May 5 21:30:47 CEST 2012


Updating branch refs/heads/master
         to b01842db991e385a4a2373da1eaac1191197d9af (commit)
       from a75d9920d838e508c10dfd17908233d45dc20e6c (commit)

commit b01842db991e385a4a2373da1eaac1191197d9af
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Oct 18 09:04:31 2007 +0000

    * mousepad/mousepad-utils.{c,h}: Add iter function to move the iter
      in front of text. Code used from one of the indentation functions.
    * mousepad/mousepad-view.c: Add code for a smart home button: when
      the cursor starts a line and the home button is pressed, it will
      move to the start of the text.
    * mousepad/mousepad-view.c: Key bindings Ctrl + {Home,End} to jump
      to the start and end of a document.
    
    
    (Old svn revision: 26144)

 ChangeLog                |   18 ++++++++--
 mousepad/mousepad-util.c |   28 +++++++++++++++-
 mousepad/mousepad-util.h |    3 ++
 mousepad/mousepad-view.c |   80 +++++++++++++++++++++++++++++++++------------
 4 files changed, 102 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 26390f6..9ea6287 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,19 +1,29 @@
-2007-10-17      Nick Schermer <nick at xfce.org>
+2007-10-18	Nick Schermer <nick at xfce.org>
+	* mousepad/mousepad-utils.{c,h}: Add iter function to move the iter
+	  in front of text. Code used from one of the indentation functions.
+	* mousepad/mousepad-view.c: Add code for a smart home button: when
+	  the cursor starts a line and the home button is pressed, it will
+	  move to the start of the text.
+	* mousepad/mousepad-view.c: Key bindings Ctrl + {Home,End} to jump
+	  to the start and end of a document.
+
+
+2007-10-17	Nick Schermer <nick at xfce.org>
 	* mousepad/mousepad-window.c: Cleanup some code and get rid of the
 	  multiple action groups.
 
 
-2007-10-17      Nick Schermer <nick at xfce.org>
+2007-10-17	Nick Schermer <nick at xfce.org>
 	* mousepad/mousepad-window.c: Decrease the menu lock when a window
 	  is closed and disconnect the recent manager handler (this is a
 	  bug since 2.12 because the manager is a floating object).
 
 
-2007-10-17      Nick Schermer <nick at xfce.org>
+2007-10-17	Nick Schermer <nick at xfce.org>
 	* mousepad/mousepad-{window,util}.c: Fix compiler warnings.
 
 
-2007-10-16      Nick Schermer <nick at xfce.org>
+2007-10-16	Nick Schermer <nick at xfce.org>
 	* mousepad/mousepad-dialogs.c: Set the correct default return
 	  in the jump dialog.
 	* mousepad/mousepad-replace-{dialog,window,preferences}.{c,h}:
diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c
index 1cd89e3..61808e8 100644
--- a/mousepad/mousepad-util.c
+++ b/mousepad/mousepad-util.c
@@ -173,6 +173,32 @@ mousepad_util_get_real_line_offset (const GtkTextIter *iter,
 
 
 
+gboolean
+mousepad_util_forward_iter_to_text (GtkTextIter       *iter,
+                                    const GtkTextIter *limit)
+{
+  gunichar c;
+
+  do
+    {
+      /* get the iter character */
+      c = gtk_text_iter_get_char (iter);
+
+      /* break if the character is not a space */
+      if (!g_unichar_isspace (c) || c == '\n' || c == '\r')
+        break;
+
+      /* break when we reached the limit iter */
+      if (limit && gtk_text_iter_equal (iter, limit))
+        return FALSE;
+    }
+  while (gtk_text_iter_forward_char (iter));
+
+  return TRUE;
+}
+
+
+
 GType
 mousepad_util_search_flags_get_type (void)
 {
@@ -487,7 +513,7 @@ mousepad_util_search (GtkTextBuffer       *buffer,
   mark_start = gtk_text_buffer_create_mark (buffer, NULL, &start, TRUE);
   mark_iter  = gtk_text_buffer_create_mark (buffer, NULL, &iter, TRUE);
   mark_end   = gtk_text_buffer_create_mark (buffer, NULL, &end, TRUE);
-  
+
   /* some to make the code easier to read */
   search_backwards = ((flags & MOUSEPAD_SEARCH_FLAGS_DIR_BACKWARD) != 0);
   wrap_around = ((flags & MOUSEPAD_SEARCH_FLAGS_WRAP_AROUND) != 0 && !gtk_text_iter_equal (&start, &iter));
diff --git a/mousepad/mousepad-util.h b/mousepad/mousepad-util.h
index 4f3f575..cbb686e 100644
--- a/mousepad/mousepad-util.h
+++ b/mousepad/mousepad-util.h
@@ -75,6 +75,9 @@ void       mousepad_util_set_tooltip            (GtkWidget           *widget,
 gint       mousepad_util_get_real_line_offset   (const GtkTextIter   *iter,
                                                  gint                 tab_width);
 
+gboolean   mousepad_util_forward_iter_to_text   (GtkTextIter         *iter,
+                                                 const GtkTextIter   *limit);
+
 GType      mousepad_util_search_flags_get_type  (void) G_GNUC_CONST;
 
 gint       mousepad_util_highlight              (GtkTextBuffer       *buffer,
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 2c0a7fe..5b79429 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -339,7 +339,7 @@ mousepad_view_key_press_event (GtkWidget   *widget,
   MousepadView  *view = MOUSEPAD_VIEW (widget);
   GtkTextBuffer *buffer;
   GtkTextIter    iter;
-  GtkTextMark   *mark;
+  GtkTextMark   *cursor;
   guint          modifiers;
   gchar         *string;
 
@@ -357,8 +357,8 @@ mousepad_view_key_press_event (GtkWidget   *widget,
         if (!(event->state & GDK_SHIFT_MASK) && view->auto_indent)
           {
             /* get the iter position of the cursor */
-            mark = gtk_text_buffer_get_insert (buffer);
-            gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+            cursor = gtk_text_buffer_get_insert (buffer);
+            gtk_text_buffer_get_iter_at_mark (buffer, &iter, cursor);
 
             /* get the string of tabs and spaces we're going to indent */
             string = mousepad_view_indentation_string (buffer, &iter);
@@ -387,6 +387,57 @@ mousepad_view_key_press_event (GtkWidget   *widget,
           }
         break;
 
+      case GDK_End:
+      case GDK_KP_End:
+        if (modifiers & GDK_CONTROL_MASK)
+          {
+            /* get the end iter */
+            gtk_text_buffer_get_end_iter (buffer, &iter);
+
+            /* get the cursor mark */
+            cursor = gtk_text_buffer_get_insert (buffer);
+
+            goto move_cursor;
+          }
+        break;
+
+      case GDK_Home:
+      case GDK_KP_Home:
+        /* get the cursor mark */
+        cursor = gtk_text_buffer_get_insert (buffer);
+
+        /* when control is pressed, we jump to the start of the document */
+        if (modifiers & GDK_CONTROL_MASK)
+          {
+            /* get the start iter */
+            gtk_text_buffer_get_start_iter (buffer, &iter);
+
+            goto move_cursor;
+          }
+
+        /* get the iter position of the cursor */
+        gtk_text_buffer_get_iter_at_mark (buffer, &iter, cursor);
+
+        /* if the cursor starts a line, try to move it in front of the text */
+        if (gtk_text_iter_starts_line (&iter)
+            && mousepad_util_forward_iter_to_text (&iter, NULL))
+          {
+             /* label for the ctrl home/end events */
+             move_cursor:
+
+             /* move the cursor */
+             if (modifiers & GDK_SHIFT_MASK)
+               gtk_text_buffer_move_mark (buffer, cursor, &iter);
+             else
+               gtk_text_buffer_place_cursor (buffer, &iter);
+
+             /* make sure the cursor is visible for the user */
+             mousepad_view_put_cursor_on_screen (view);
+
+             return TRUE;
+          }
+        break;
+
       case GDK_Tab:
       case GDK_KP_Tab:
       case GDK_ISO_Left_Tab:
@@ -400,14 +451,12 @@ mousepad_view_key_press_event (GtkWidget   *widget,
         else if (view->insert_spaces)
           {
             /* get the iter position of the cursor */
-            mark = gtk_text_buffer_get_insert (buffer);
-            gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+            cursor = gtk_text_buffer_get_insert (buffer);
+            gtk_text_buffer_get_iter_at_mark (buffer, &iter, cursor);
 
             /* insert spaces */
             mousepad_view_increase_indent_iter (view, &iter, TRUE);
 
-            /* TODO cursor position? */
-
             return TRUE;
           }
 
@@ -911,7 +960,6 @@ mousepad_view_indentation_string (GtkTextBuffer     *buffer,
 {
   GtkTextIter start, end;
   gint        line;
-  gunichar    c;
 
   /* get the line of the iter */
   line = gtk_text_iter_get_line (iter);
@@ -922,20 +970,8 @@ mousepad_view_indentation_string (GtkTextBuffer     *buffer,
   /* set the end iter */
   end = start;
 
-  /* forward to text */
-  do
-    {
-      /* get the iter character */
-      c = gtk_text_iter_get_char (&end);
-
-      /* break if the character is not a space or equal to the iter */
-      if (!g_unichar_isspace (c) || gtk_text_iter_equal (&end, iter))
-        break;
-    }
-  while (gtk_text_iter_forward_char (&end));
-
-  /* return NULL if the iters are the same */
-  if (gtk_text_iter_equal (&start, &end))
+  /* forward until we hit text */
+  if (mousepad_util_forward_iter_to_text (&end, iter) == FALSE)
     return NULL;
 
   /* return the text between the iters */


More information about the Xfce4-commits mailing list