Author: nick
Date: 2007-10-18 09:04:31 +0000 (Thu, 18 Oct 2007)
New Revision: 26144
Modified:
mousepad/branches/nick_0_3/ChangeLog
mousepad/branches/nick_0_3/mousepad/mousepad-util.c
mousepad/branches/nick_0_3/mousepad/mousepad-util.h
mousepad/branches/nick_0_3/mousepad/mousepad-view.c
Log:
* 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.
Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog 2007-10-17 20:15:58 UTC (rev
26143)
+++ mousepad/branches/nick_0_3/ChangeLog 2007-10-18 09:04:31 UTC (rev
26144)
@@ -1,19 +1,29 @@
-2007-10-17 Nick Schermer <[EMAIL PROTECTED]>
+2007-10-18 Nick Schermer <[EMAIL PROTECTED]>
+ * 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 <[EMAIL PROTECTED]>
* mousepad/mousepad-window.c: Cleanup some code and get rid of the
multiple action groups.
-2007-10-17 Nick Schermer <[EMAIL PROTECTED]>
+2007-10-17 Nick Schermer <[EMAIL PROTECTED]>
* 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 <[EMAIL PROTECTED]>
+2007-10-17 Nick Schermer <[EMAIL PROTECTED]>
* mousepad/mousepad-{window,util}.c: Fix compiler warnings.
-2007-10-16 Nick Schermer <[EMAIL PROTECTED]>
+2007-10-16 Nick Schermer <[EMAIL PROTECTED]>
* mousepad/mousepad-dialogs.c: Set the correct default return
in the jump dialog.
* mousepad/mousepad-replace-{dialog,window,preferences}.{c,h}:
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-util.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-util.c 2007-10-17 20:15:58 UTC
(rev 26143)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-util.c 2007-10-18 09:04:31 UTC
(rev 26144)
@@ -173,6 +173,32 @@
+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 @@
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));
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-util.h
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-util.h 2007-10-17 20:15:58 UTC
(rev 26143)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-util.h 2007-10-18 09:04:31 UTC
(rev 26144)
@@ -75,6 +75,9 @@
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,
Modified: mousepad/branches/nick_0_3/mousepad/mousepad-view.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-view.c 2007-10-17 20:15:58 UTC
(rev 26143)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-view.c 2007-10-18 09:04:31 UTC
(rev 26144)
@@ -339,7 +339,7 @@
MousepadView *view = MOUSEPAD_VIEW (widget);
GtkTextBuffer *buffer;
GtkTextIter iter;
- GtkTextMark *mark;
+ GtkTextMark *cursor;
guint modifiers;
gchar *string;
@@ -357,8 +357,8 @@
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 @@
}
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 @@
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 @@
{
GtkTextIter start, end;
gint line;
- gunichar c;
/* get the line of the iter */
line = gtk_text_iter_get_line (iter);
@@ -922,20 +970,8 @@
/* 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 */
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits