[gnome-builder/wip/mwleeds/replace: 32/32] Add plumbing so most of the search-and-replace buttons work.
- From: Matthew Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/mwleeds/replace: 32/32] Add plumbing so most of the search-and-replace buttons work.
- Date: Mon, 20 Jun 2016 16:03:18 +0000 (UTC)
commit 9807abdd3ed6e929975707f67c435df0c29fe354
Author: Matthew Leeds <mleeds redhat com>
Date: Mon Jun 20 11:42:49 2016 -0400
Add plumbing so most of the search-and-replace buttons work.
libide/editor/ide-editor-frame-actions.c | 76 ++++++++++++++++++++++-
libide/editor/ide-editor-frame-private.h | 6 ++
libide/editor/ide-editor-frame.c | 100 ++++++++++++++----------------
plugins/command-bar/gb-vim.c | 1 +
4 files changed, 128 insertions(+), 55 deletions(-)
---
diff --git a/libide/editor/ide-editor-frame-actions.c b/libide/editor/ide-editor-frame-actions.c
index 028c53b..683b7ad 100644
--- a/libide/editor/ide-editor-frame-actions.c
+++ b/libide/editor/ide-editor-frame-actions.c
@@ -176,6 +176,76 @@ ide_editor_frame_actions_select_all (GSimpleAction *action,
gtk_editable_select_region (GTK_EDITABLE (self->search_entry), 0, -1);
}
+static void
+ide_editor_frame_actions_toggle_search_replace (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorFrame *self = user_data;
+
+ g_assert (IDE_IS_EDITOR_FRAME (self));
+
+ if (gtk_widget_get_visible (GTK_WIDGET (self->replace_entry)))
+ {
+ gtk_widget_hide (GTK_WIDGET (self->replace_entry));
+ gtk_widget_hide (GTK_WIDGET (self->replace_button));
+ gtk_widget_hide (GTK_WIDGET (self->replace_all_button));
+ //gtk_widget_hide (GTK_WIDGET (self->project_replace_button));
+ }
+ else
+ {
+ gtk_widget_show (GTK_WIDGET (self->replace_entry));
+ gtk_widget_show (GTK_WIDGET (self->replace_button));
+ gtk_widget_show (GTK_WIDGET (self->replace_all_button));
+ //gtk_widget_show (GTK_WIDGET (self->project_replace_button));
+ }
+}
+
+static void
+ide_editor_frame_actions_toggle_search_options (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorFrame *self = user_data;
+
+ g_assert (IDE_IS_EDITOR_FRAME (self));
+
+ if (gtk_widget_get_visible (GTK_WIDGET (self->search_options)))
+ gtk_widget_hide (GTK_WIDGET (self->search_options));
+ else
+ gtk_widget_show_all (GTK_WIDGET (self->search_options));
+}
+
+static void
+ide_editor_frame_actions_exit_search (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorFrame *self = user_data;
+ GtkTextBuffer *buffer;
+
+ g_assert (IDE_IS_EDITOR_FRAME (self));
+
+ /* stash the search string for later */
+ g_free (self->previous_search_string);
+ g_object_get (self->search_entry, "text", &self->previous_search_string, NULL);
+
+ /* clear the highlights in the source view */
+ ide_source_view_clear_search (self->source_view);
+
+ /* disable rubberbanding and ensure insert mark is on screen */
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
+ ide_source_view_set_rubberband_search (self->source_view, FALSE);
+ ide_source_view_scroll_mark_onscreen (self->source_view,
+ gtk_text_buffer_get_insert (buffer),
+ TRUE,
+ 0.5,
+ 0.5);
+
+ /* finally we can focus the source view */
+ gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
+}
+
static const GActionEntry IdeEditorFrameActions[] = {
{ "find", ide_editor_frame_actions_find, "i" },
{ "next-search-result", ide_editor_frame_actions_next_search_result },
@@ -188,6 +258,9 @@ static const GActionEntry IdeEditorFrameSearchActions[] = {
{ "paste-clipboard", ide_editor_frame_actions_paste_clipboard, },
{ "delete-selection", ide_editor_frame_actions_delete_selection, },
{ "select-all", ide_editor_frame_actions_select_all },
+ { "toggle-search-replace", NULL, "b", "false", ide_editor_frame_actions_toggle_search_replace },
+ { "toggle-search-options", NULL, "b", "false", ide_editor_frame_actions_toggle_search_options },
+ { "exit-search", ide_editor_frame_actions_exit_search },
};
void
@@ -206,6 +279,7 @@ ide_editor_frame_actions_init (IdeEditorFrame *self)
group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (group), IdeEditorFrameSearchActions,
G_N_ELEMENTS (IdeEditorFrameSearchActions), self);
- gtk_widget_insert_action_group (GTK_WIDGET (self->search_entry), "search-entry", G_ACTION_GROUP (group));
+ gtk_widget_insert_action_group (GTK_WIDGET (self->search_frame), "search-entry", G_ACTION_GROUP (group));
+
g_object_unref (group);
}
diff --git a/libide/editor/ide-editor-frame-private.h b/libide/editor/ide-editor-frame-private.h
index 165e296..aad067e 100644
--- a/libide/editor/ide-editor-frame-private.h
+++ b/libide/editor/ide-editor-frame-private.h
@@ -41,7 +41,13 @@ struct _IdeEditorFrame
GtkLabel *overwrite_label;
GtkScrolledWindow *scrolled_window;
GtkRevealer *search_revealer;
+ GtkFrame *search_frame;
GdTaggedEntry *search_entry;
+ GtkSearchEntry *replace_entry;
+ GtkButton *replace_button;
+ GtkButton *replace_all_button;
+ //GtkButton *project_replace_button;
+ GtkGrid *search_options;
GdTaggedEntryTag *search_entry_tag;
IdeSourceView *source_view;
IdeEditorMapBin *source_map_container;
diff --git a/libide/editor/ide-editor-frame.c b/libide/editor/ide-editor-frame.c
index 51bf307..d3d2d1a 100644
--- a/libide/editor/ide-editor-frame.c
+++ b/libide/editor/ide-editor-frame.c
@@ -373,6 +373,37 @@ search_text_transform_from (GBinding *binding,
return TRUE;
}
+static void
+ide_editor_frame_add_search_actions (IdeEditorFrame *self,
+ GActionGroup *group)
+{
+ GPropertyAction *prop_action;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+
+ g_assert (IDE_IS_EDITOR_FRAME (self));
+ g_assert (G_IS_ACTION_GROUP (group));
+
+ search_context = ide_source_view_get_search_context (self->source_view);
+ search_settings = gtk_source_search_context_get_settings (search_context);
+
+ prop_action = g_property_action_new ("change-case-sensitive", search_settings, "case-sensitive");
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
+ g_object_unref (prop_action);
+
+ prop_action = g_property_action_new ("change-word-boundaries", search_settings, "at-word-boundaries");
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
+ g_object_unref (prop_action);
+
+ prop_action = g_property_action_new ("change-regex-enabled", search_settings, "regex-enabled");
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
+ g_object_unref (prop_action);
+
+ prop_action = g_property_action_new ("change-wrap-around", search_settings, "wrap-around");
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
+ g_object_unref (prop_action);
+}
+
void
ide_editor_frame_set_document (IdeEditorFrame *self,
IdeBuffer *buffer)
@@ -381,6 +412,7 @@ ide_editor_frame_set_document (IdeEditorFrame *self,
GtkSourceSearchSettings *search_settings;
GtkTextMark *mark;
GtkTextIter iter;
+ GActionGroup *group;
g_return_if_fail (IDE_IS_EDITOR_FRAME (self));
g_return_if_fail (IDE_IS_BUFFER (buffer));
@@ -416,6 +448,12 @@ ide_editor_frame_set_document (IdeEditorFrame *self,
G_CALLBACK (ide_editor_frame_on_search_occurrences_notify),
self,
G_CONNECT_SWAPPED);
+
+ /*
+ * Add search option property actions
+ */
+ group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");
+ ide_editor_frame_add_search_actions (self, group);
}
static gboolean
@@ -504,33 +542,13 @@ ide_editor_frame__search_key_press_event (IdeEditorFrame *self,
GdkEventKey *event,
GdTaggedEntry *entry)
{
- GtkTextBuffer *buffer;
-
g_assert (IDE_IS_EDITOR_FRAME (self));
g_assert (GD_IS_TAGGED_ENTRY (entry));
switch (event->keyval)
{
case GDK_KEY_Escape:
- /* stash the search string for later */
- g_free (self->previous_search_string);
- g_object_get (self->search_entry, "text", &self->previous_search_string, NULL);
-
- /* clear the highlights in the source view */
- ide_source_view_clear_search (self->source_view);
-
- /* disable rubberbanding and ensure insert mark is on screen */
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
- ide_source_view_set_rubberband_search (self->source_view, FALSE);
- ide_source_view_scroll_mark_onscreen (self->source_view,
- gtk_text_buffer_get_insert (buffer),
- TRUE,
- 0.5,
- 0.5);
-
- /* finally we can focus the source view */
- gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
-
+ ide_widget_action (GTK_WIDGET (self->search_frame), "search-entry", "exit-search", NULL);
return GDK_EVENT_STOP;
case GDK_KEY_KP_Enter:
@@ -692,37 +710,6 @@ ide_editor_frame__source_view_populate_popup (IdeEditorFrame *self,
}
static void
-ide_editor_frame_add_search_actions (IdeEditorFrame *self,
- GActionGroup *group)
-{
- GPropertyAction *prop_action;
- GtkSourceSearchContext *search_context;
- GtkSourceSearchSettings *search_settings;
-
- g_assert (IDE_IS_EDITOR_FRAME (self));
- g_assert (G_IS_ACTION_GROUP (group));
-
- search_context = ide_source_view_get_search_context (self->source_view);
- search_settings = gtk_source_search_context_get_settings (search_context);
-
- prop_action = g_property_action_new ("change-case-sensitive", search_settings, "case-sensitive");
- g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
- g_object_unref (prop_action);
-
- prop_action = g_property_action_new ("change-word-boundaries", search_settings, "at-word-boundaries");
- g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
- g_object_unref (prop_action);
-
- prop_action = g_property_action_new ("change-regex-enabled", search_settings, "regex-enabled");
- g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
- g_object_unref (prop_action);
-
- prop_action = g_property_action_new ("change-wrap-around", search_settings, "wrap-around");
- g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
- g_object_unref (prop_action);
-}
-
-static void
ide_editor_frame__search_populate_popup (IdeEditorFrame *self,
GtkWidget *popup,
GdTaggedEntry *entry)
@@ -741,8 +728,7 @@ ide_editor_frame__search_populate_popup (IdeEditorFrame *self,
gboolean clipboard_contains_text;
gboolean entry_has_selection;
- group = gtk_widget_get_action_group (GTK_WIDGET (entry), "search-entry");
- ide_editor_frame_add_search_actions (self, group);
+ group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");
menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "ide-editor-frame-search-menu");
gtk_menu_shell_bind_model (GTK_MENU_SHELL (popup), G_MENU_MODEL (menu), NULL, TRUE);
@@ -978,7 +964,13 @@ ide_editor_frame_class_init (IdeEditorFrameClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, mode_name_label);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, overwrite_label);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, scrolled_window);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, search_frame);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, search_entry);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, replace_entry);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, replace_button);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, replace_all_button);
+ //gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, project_replace_button);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, search_options);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, search_revealer);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, source_map_container);
gtk_widget_class_bind_template_child (widget_class, IdeEditorFrame, source_overlay);
diff --git a/plugins/command-bar/gb-vim.c b/plugins/command-bar/gb-vim.c
index 48701f1..36c51b3 100644
--- a/plugins/command-bar/gb-vim.c
+++ b/plugins/command-bar/gb-vim.c
@@ -1074,6 +1074,7 @@ gb_vim_command_search (GtkWidget *active_widget,
break;
/* what other options are supported? */
+ //TODO implement 'c' option
default:
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]