From 3207be12c43211d5b36d45f7bdf4b771cdd29253 Mon Sep 17 00:00:00 2001
From: Fangwen Yu <yynyygy@gmail.com>
Date: Thu, 10 Mar 2016 02:21:58 +0800
Subject: [PATCH] editor-frame: add right click menu options to the search
 entry

---
 libide/editor/ide-editor-frame.c | 88 ++++++++++++++++++++++++++++++++++------
 libide/ide-source-view.c         |  4 --
 2 files changed, 76 insertions(+), 16 deletions(-)

diff --git a/libide/editor/ide-editor-frame.c b/libide/editor/ide-editor-frame.c
index 0f2b137..4e6bc47 100644
--- a/libide/editor/ide-editor-frame.c
+++ b/libide/editor/ide-editor-frame.c
@@ -513,20 +513,8 @@ ide_editor_frame__search_key_press_event (IdeEditorFrame *self,
 
     default:
       {
-        GtkSourceSearchSettings *search_settings;
-        GtkSourceSearchContext *search_context;
-
         if (!ide_source_view_get_rubberband_search (self->source_view))
           ide_source_view_set_rubberband_search (self->source_view, TRUE);
-
-        /*
-         * Other modes, such as Vim emulation, want word boundaries, but we do
-         * not when searching from this entry. Sort of hacky, but gets the job
-         * done to just change that setting here.
-         */
-        search_context = ide_source_view_get_search_context (self->source_view);
-        search_settings = gtk_source_search_context_get_settings (search_context);
-        gtk_source_search_settings_set_at_word_boundaries (search_settings, FALSE);
       }
       break;
     }
@@ -664,6 +652,76 @@ ide_editor_frame__source_view_populate_popup (IdeEditorFrame *self,
 }
 
 static void
+ide_editor_frame__search_populate_popup (IdeEditorFrame *self,
+                                         GtkWidget      *popup,
+                                         GdTaggedEntry  *entry)
+{
+  g_assert (IDE_IS_EDITOR_FRAME (self));
+  g_assert (GTK_IS_WIDGET (popup));
+  g_assert (GD_IS_TAGGED_ENTRY (entry));
+
+  if (GTK_IS_MENU_SHELL (popup))
+    {
+      GtkSourceSearchContext *search_context;
+      GtkSourceSearchSettings *search_settings;
+      GtkWidget *item;
+      GtkWidget *sep;
+
+      sep = g_object_new (GTK_TYPE_SEPARATOR_MENU_ITEM,
+                          "visible", TRUE,
+                          NULL);
+      gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), sep);
+
+      search_context = ide_source_view_get_search_context (self->source_view);
+      search_settings = gtk_source_search_context_get_settings (search_context);
+
+      /* create "Wrap Around" menu item. */
+      item = g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
+                           "label", _("_Wrap Around"),
+                           "use-underline", TRUE,
+                           "visible", TRUE,
+                           NULL);
+      g_object_bind_property (search_settings, "wrap-around",
+                              item, "active",
+                              G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+      gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item);
+
+      /* create "Match as Regular Expression" menu item. */
+      item = g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
+                           "label", _("Match as _Regular Expression"),
+                           "use-underline", TRUE,
+                           "visible", TRUE,
+                           NULL);
+      g_object_bind_property (search_settings, "regex-enabled",
+                              item, "active",
+                              G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+      gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item);
+
+      /* create "Match Entire Word Only" menu item. */
+      item = g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
+                           "label", _("Match _Entire Word Only"),
+                           "use-underline", TRUE,
+                           "visible", TRUE,
+                           NULL);
+      g_object_bind_property (search_settings, "at-word-boundaries",
+                              item, "active",
+                              G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+      gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item);
+
+      /* create "Match Case" menu item. */
+      item = g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
+                           "label", _("_Match Case"),
+                           "use-underline", TRUE,
+                           "visible", TRUE,
+                           NULL);
+      g_object_bind_property (search_settings, "case-sensitive",
+                              item, "active",
+                              G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+      gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), item);
+    }
+}
+
+static void
 ide_editor_frame_constructed (GObject *object)
 {
   IdeEditorFrame *self = (IdeEditorFrame *)object;
@@ -699,6 +757,12 @@ ide_editor_frame_constructed (GObject *object)
                            G_CALLBACK (ide_editor_frame__search_key_press_event),
                            self,
                            G_CONNECT_SWAPPED);
+
+  g_signal_connect_object (self->search_entry,
+                           "populate-popup",
+                           G_CALLBACK (ide_editor_frame__search_populate_popup),
+                           self,
+                           G_CONNECT_SWAPPED);
 }
 
 static void
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 5ef80b5..78f6046 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -3607,10 +3607,6 @@ ide_source_view_real_move_search (IdeSourceView    *self,
   gtk_source_search_context_set_highlight (priv->search_context, TRUE);
 
   settings = gtk_source_search_context_get_settings (priv->search_context);
-
-  if (word_boundaries != gtk_source_search_settings_get_at_word_boundaries (settings))
-    gtk_source_search_settings_set_at_word_boundaries (settings, word_boundaries);
-
   search_text = gtk_source_search_settings_get_search_text (settings);
 
   if (search_text == NULL || search_text[0] == '\0')
-- 
2.5.0

