[Xfce4-commits] r25736 - in mousepad/branches/nick_0_3: . mousepad

Nick Schermer nick at xfce.org
Sun May 20 20:44:12 CEST 2007


Author: nick
Date: 2007-05-20 18:44:10 +0000 (Sun, 20 May 2007)
New Revision: 25736

Modified:
   mousepad/branches/nick_0_3/ChangeLog
   mousepad/branches/nick_0_3/mousepad/mousepad-document.c
   mousepad/branches/nick_0_3/mousepad/mousepad-preferences.c
   mousepad/branches/nick_0_3/mousepad/mousepad-search-bar.c
   mousepad/branches/nick_0_3/mousepad/mousepad-types.h
Log:
	* mousepad/mousepad-{preferences,search-bar,document}.c,
	  mousepad/mousepad-types.h: Add match whole word option.

Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog	2007-05-20 17:48:28 UTC (rev 25735)
+++ mousepad/branches/nick_0_3/ChangeLog	2007-05-20 18:44:10 UTC (rev 25736)
@@ -1,4 +1,9 @@
 2007-05-20	Nick Schermer <nick at xfce.org>
+	* mousepad/mousepad-{preferences,search-bar,document}.c,
+	  mousepad/mousepad-types.h: Add match whole word option.
+
+
+2007-05-20	Nick Schermer <nick at xfce.org>
 	* mousepad/Makefile.am: Use the new exo-csource
 	  --strip-comments and --strip-content arguments.
 

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-document.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-document.c	2007-05-20 17:48:28 UTC (rev 25735)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-document.c	2007-05-20 18:44:10 UTC (rev 25736)
@@ -750,12 +750,29 @@
           /* we've hit the end of the search string, so we had a full match */
           if (G_UNLIKELY (*str == '\0'))
             {
-              /* forward one character */
               if (G_LIKELY (search_forward))
-                gtk_text_iter_forward_char (&iter);
+                {
+                  /* forward one character */
+                  gtk_text_iter_forward_char (&iter);
+
+                  /* check if we match a whole word */
+                  if (flags & MOUSEPAD_SEARCH_WHOLE_WORD
+                      && !(gtk_text_iter_starts_word (&begin)
+                           && gtk_text_iter_ends_word (&iter)))
+                    goto reset_match;
+                }
               else
-                gtk_text_iter_forward_char (&begin);
+                {
+                  /* 'backward' one character */
+                  gtk_text_iter_forward_char (&begin);
 
+                  /* check if we match a whole word */
+                  if (flags & MOUSEPAD_SEARCH_WHOLE_WORD
+                      && !(gtk_text_iter_starts_word (&iter)
+                           && gtk_text_iter_ends_word (&begin)))
+                    goto reset_match;
+                }
+
               /* set the start and end iters */
               *match_start = begin;
               *match_end   = iter;
@@ -767,6 +784,7 @@
         }
       else if (G_UNLIKELY (str_offset > 0))
         {
+          reset_match:
           /* go back to the first character in the string */
           for (;str_offset > 0; str_offset--)
             str = g_utf8_prev_char (str);

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-preferences.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-preferences.c	2007-05-20 17:48:28 UTC (rev 25735)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-preferences.c	2007-05-20 18:44:10 UTC (rev 25736)
@@ -52,6 +52,7 @@
   PROP_LAST_AUTO_INDENT,
   PROP_LAST_LINE_NUMBERS,
   PROP_LAST_MATCH_CASE,
+  PROP_LAST_MATCH_WHOLE_WORD,
   PROP_LAST_STATUSBAR_VISIBLE,
   PROP_LAST_WINDOW_HEIGHT,
   PROP_LAST_WINDOW_WIDTH,
@@ -232,6 +233,19 @@
                                                          FALSE,
                                                          MOUSEPAD_PARAM_READWRITE));
 
+    /**
+   * MousepadPreferences:last-match-whole-word
+   *
+   * Whether to enable match case in the search bar.
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_LAST_MATCH_WHOLE_WORD,
+                                   g_param_spec_boolean ("last-match-whole-word",
+                                                         "last-match-whole-word",
+                                                         "last-match-whole-word",
+                                                         FALSE,
+                                                         MOUSEPAD_PARAM_READWRITE));
+
   /**
    * MousepadPreferences:last-statusbar-visible
    *
@@ -432,7 +446,10 @@
 
   dst = preferences->values + prop_id;
   if (G_UNLIKELY (!G_IS_VALUE (dst)))
-    g_value_init (dst, pspec->value_type);
+    {
+      g_value_init (dst, pspec->value_type);
+      g_param_value_set_default (pspec, dst);
+    }
 
   if (g_param_values_cmp (pspec, value, dst) != 0)
     {

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-search-bar.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-search-bar.c	2007-05-20 17:48:28 UTC (rev 25735)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-search-bar.c	2007-05-20 18:44:10 UTC (rev 25736)
@@ -53,8 +53,12 @@
                                                                  MousepadSearchBar       *search_bar);
 static void      mousepad_search_bar_wrap_around_toggled        (GtkWidget               *button,
                                                                  MousepadSearchBar       *search_bar);
+static void      mousepad_search_bar_match_whole_word_toggled   (GtkWidget               *button,
+                                                                 MousepadSearchBar       *search_bar);
 static void      mousepad_search_bar_menuitem_toggled           (GtkCheckMenuItem        *item,
                                                                  GtkToggleButton         *button);
+static void      mousepad_search_bar_highlight_idle             (MousepadSearchBar       *search_bar,
+                                                                 gboolean                 forced);
 static gboolean  mousepad_search_bar_highlight_timeout          (gpointer                 user_data);
 static void      mousepad_search_bar_highlight_timeout_destroy  (gpointer                 user_data);
 static void      mousepad_search_bar_nothing_found              (MousepadSearchBar       *search_bar,
@@ -87,6 +91,7 @@
   /* menu entries */
   GtkWidget           *match_case_entry;
   GtkWidget           *wrap_around_entry;
+  GtkWidget           *match_whole_word_entry;
 
   /* if something was found */
   guint                nothing_found : 1;
@@ -95,6 +100,7 @@
   guint                highlight_all : 1;
   guint                match_case : 1;
   guint                wrap_around : 1;
+  guint                match_whole_word : 1;
 
   /* timeout for highlighting while typing */
   guint                highlight_id;
@@ -203,7 +209,7 @@
 {
   GtkWidget   *label, *image, *check, *menuitem;
   GtkToolItem *item;
-  gboolean     match_case, wrap_around;
+  gboolean     match_case, wrap_around, match_whole_word;
 
   /* preferences */
   search_bar->preferences = mousepad_preferences_get ();
@@ -212,6 +218,7 @@
   g_object_get (G_OBJECT (search_bar->preferences),
                 "last-match-case", &match_case,
                 "last-wrap-around", &wrap_around,
+                "last-match-whole-word", &match_whole_word,
                 NULL);
 
   /* init variables */
@@ -219,6 +226,7 @@
   search_bar->highlight_id = 0;
   search_bar->match_case = match_case;
   search_bar->wrap_around = wrap_around;
+  search_bar->match_whole_word = match_whole_word;
 
   /* the close button */
   item = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
@@ -328,6 +336,28 @@
   gtk_widget_show (menuitem);
   g_signal_connect (G_OBJECT (menuitem), "toggled",
                     G_CALLBACK (mousepad_search_bar_menuitem_toggled), check);
+
+  /* check button for match whole word, including the proxy menu item */
+  item = gtk_tool_item_new ();
+  g_signal_connect_object (G_OBJECT (search_bar), "destroy", G_CALLBACK (gtk_widget_destroy), item, G_CONNECT_SWAPPED);
+  gtk_toolbar_insert (GTK_TOOLBAR (search_bar), item, -1);
+  gtk_widget_show (GTK_WIDGET (item));
+
+  check = gtk_check_button_new_with_mnemonic (_("Match _Whole Word"));
+  g_signal_connect_object (G_OBJECT (search_bar), "destroy", G_CALLBACK (gtk_widget_destroy), item, G_CONNECT_SWAPPED);
+  gtk_container_add (GTK_CONTAINER (item), check);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), match_whole_word);
+  gtk_widget_show (check);
+  g_signal_connect (G_OBJECT (check), "toggled",
+                    G_CALLBACK (mousepad_search_bar_match_whole_word_toggled), search_bar);
+
+  search_bar->match_whole_word_entry = menuitem = gtk_check_menu_item_new_with_mnemonic (_("Match _Whole Word"));
+  g_signal_connect_object (G_OBJECT (search_bar), "destroy", G_CALLBACK (gtk_widget_destroy), item, G_CONNECT_SWAPPED);
+  gtk_tool_item_set_proxy_menu_item (item, "case-sensitive", menuitem);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), match_whole_word);
+  gtk_widget_show (menuitem);
+  g_signal_connect (G_OBJECT (menuitem), "toggled",
+                    G_CALLBACK (mousepad_search_bar_menuitem_toggled), check);
 }
 
 
@@ -364,6 +394,10 @@
   if (search_bar->wrap_around)
     flags |= MOUSEPAD_SEARCH_WRAP_AROUND;
 
+  /* wrap around flag */
+  if (search_bar->match_whole_word)
+    flags |= MOUSEPAD_SEARCH_WHOLE_WORD;
+
   /* get the entry string */
   string = gtk_entry_get_text (GTK_ENTRY (search_bar->entry));
 
@@ -400,13 +434,8 @@
   if (search_bar->highlight_id != 0)
     g_source_remove (search_bar->highlight_id);
 
-  if (search_bar->highlight_all)
-    {
-      /* start a new highlight timeout */
-      search_bar->highlight_id = g_timeout_add_full (G_PRIORITY_LOW, HIGHTLIGHT_TIMEOUT,
-                                                           mousepad_search_bar_highlight_timeout, search_bar,
-                                                           mousepad_search_bar_highlight_timeout_destroy);
-    }
+  /* re-run the highlight */
+  mousepad_search_bar_highlight_idle (search_bar, FALSE);
 
   /* find */
   mousepad_search_bar_find_string (search_bar, 0);
@@ -432,9 +461,8 @@
   /* save the state */
   search_bar->highlight_all = active;
 
-  /* invoke the highlight function to update the buffer */
-  search_bar->highlight_id = g_idle_add_full (G_PRIORITY_LOW, mousepad_search_bar_highlight_timeout,
-                                              search_bar, mousepad_search_bar_highlight_timeout_destroy);
+  /* re-run the highlight */
+  mousepad_search_bar_highlight_idle (search_bar, TRUE);
 }
 
 
@@ -459,12 +487,8 @@
   /* save the setting */
   g_object_set (G_OBJECT (search_bar->preferences), "last-match-case", active, NULL);
 
-  if (search_bar->highlight_all)
-    {
-      /* invoke the highlight function to update the buffer */
-      search_bar->highlight_id = g_idle_add_full (G_PRIORITY_LOW, mousepad_search_bar_highlight_timeout,
-                                                  search_bar, mousepad_search_bar_highlight_timeout_destroy);
-    }
+  /* re-run the highlight */
+  mousepad_search_bar_highlight_idle (search_bar, FALSE);
 }
 
 
@@ -493,6 +517,32 @@
 
 
 static void
+mousepad_search_bar_match_whole_word_toggled (GtkWidget         *button,
+                                              MousepadSearchBar *search_bar)
+{
+  gboolean active;
+
+  _mousepad_return_if_fail (MOUSEPAD_IS_SEARCH_BAR (search_bar));
+
+  /* get the state of the toggle button */
+  active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+
+  /* set the state of the menu item */
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (search_bar->match_whole_word_entry), active);
+
+  /* save the state */
+  search_bar->match_whole_word = active;
+
+  /* save the setting */
+  g_object_set (G_OBJECT (search_bar->preferences), "last-match-whole-word", active, NULL);
+
+  /* re-run the highlight */
+  mousepad_search_bar_highlight_idle (search_bar, FALSE);
+}
+
+
+
+static void
 mousepad_search_bar_menuitem_toggled (GtkCheckMenuItem *item,
                                       GtkToggleButton  *button)
 {
@@ -504,6 +554,20 @@
 
 
 
+static void
+mousepad_search_bar_highlight_idle (MousepadSearchBar *search_bar,
+                                    gboolean           forced)
+{
+  if ((forced || search_bar->highlight_all) && search_bar->highlight_id == 0)
+    {
+      /* invoke the highlight function to update the buffer */
+      search_bar->highlight_id = g_idle_add_full (G_PRIORITY_LOW, mousepad_search_bar_highlight_timeout,
+                                                  search_bar, mousepad_search_bar_highlight_timeout_destroy);
+    }
+}
+
+
+
 static gboolean
 mousepad_search_bar_highlight_timeout (gpointer user_data)
 {
@@ -518,6 +582,10 @@
   if (!search_bar->match_case)
     flags |= MOUSEPAD_SEARCH_CASE_INSENSITIVE;
 
+  /* wrap around flag */
+  if (search_bar->match_whole_word)
+    flags |= MOUSEPAD_SEARCH_WHOLE_WORD;
+
   /* set the entry string or a 0 string to remove the highlight */
   if (search_bar->highlight_all)
     string = gtk_entry_get_text (GTK_ENTRY (search_bar->entry));

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-types.h
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-types.h	2007-05-20 17:48:28 UTC (rev 25735)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-types.h	2007-05-20 18:44:10 UTC (rev 25736)
@@ -28,6 +28,7 @@
   MOUSEPAD_SEARCH_WRAP_AROUND      = 1 << 2,
   MOUSEPAD_SEARCH_FORWARDS         = 1 << 3,
   MOUSEPAD_SEARCH_BACKWARDS        = 1 << 4,
+  MOUSEPAD_SEARCH_WHOLE_WORD       = 1 << 5,
 } MousepadSearchFlags;
 
 G_END_DECLS



More information about the Xfce4-commits mailing list