[gnome-builder] editor: move search bar actions into separate file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: move search bar actions into separate file
- Date: Wed, 26 Jul 2017 01:17:03 +0000 (UTC)
commit 88709c4f51cca86b139fd4d255ddc155eefab79a
Author: Christian Hergert <chergert redhat com>
Date: Tue Jul 25 18:16:54 2017 -0700
editor: move search bar actions into separate file
This follows more closely our current plan to break actions into a
-actions.c file and shortcuts into a -shortcuts.c file.
libide/editor/ide-editor-private.h | 26 ++++
libide/editor/ide-editor-search-bar-actions.c | 154 +++++++++++++++++++++++++
libide/editor/ide-editor-search-bar.c | 149 +-----------------------
libide/editor/ide-editor-search-bar.h | 1 +
libide/meson.build | 1 +
5 files changed, 185 insertions(+), 146 deletions(-)
---
diff --git a/libide/editor/ide-editor-private.h b/libide/editor/ide-editor-private.h
index 9c982d1..b595eef 100644
--- a/libide/editor/ide-editor-private.h
+++ b/libide/editor/ide-editor-private.h
@@ -18,7 +18,9 @@
#pragma once
+#include <dazzle.h>
#include <libpeas/peas.h>
+#include <libgd/gd-tagged-entry.h>
#include "editor/ide-editor-perspective.h"
#include "editor/ide-editor-properties.h"
@@ -81,10 +83,34 @@ struct _IdeEditorView
guint show_map : 1;
};
+struct _IdeEditorSearchBar
+{
+ DzlBin parent_instance;
+
+ /* Owned references */
+ DzlSignalGroup *buffer_signals;
+ GtkSourceSearchContext *context;
+ DzlSignalGroup *context_signals;
+ GtkSourceSearchSettings *settings;
+ DzlSignalGroup *settings_signals;
+ GdTaggedEntryTag *search_entry_tag;
+
+ /* Template widgets */
+ GtkCheckButton *case_sensitive;
+ GtkButton *replace_all_button;
+ GtkButton *replace_button;
+ GtkSearchEntry *replace_entry;
+ GdTaggedEntry *search_entry;
+ GtkGrid *search_options;
+ GtkCheckButton *use_regex;
+ GtkCheckButton *whole_word;
+};
+
void _ide_editor_view_init_actions (IdeEditorView *self);
void _ide_editor_view_init_settings (IdeEditorView *self);
void _ide_editor_view_init_shortcuts (IdeEditorView *self);
void _ide_editor_view_update_actions (IdeEditorView *self);
+void _ide_editor_search_bar_init_actions (IdeEditorSearchBar *self);
void _ide_editor_sidebar_set_open_pages (IdeEditorSidebar *self,
GListModel *open_pages);
void _ide_editor_perspective_show_properties (IdeEditorPerspective *self,
diff --git a/libide/editor/ide-editor-search-bar-actions.c b/libide/editor/ide-editor-search-bar-actions.c
new file mode 100644
index 0000000..e1b3990
--- /dev/null
+++ b/libide/editor/ide-editor-search-bar-actions.c
@@ -0,0 +1,154 @@
+/* ide-editor-search-bar-actions.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-editor-search-bar-actions"
+
+#include <libgd/gd-tagged-entry.h>
+
+#include "editor/ide-editor-search-bar.h"
+#include "editor/ide-editor-private.h"
+
+static void
+ide_editor_search_bar_actions_toggle_search_options (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorSearchBar *self = user_data;
+ gboolean visible;
+
+ g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+ visible = !gtk_widget_get_visible (GTK_WIDGET (self->search_options));
+ gtk_widget_set_visible (GTK_WIDGET (self->search_options), visible);
+}
+
+static void
+ide_editor_search_bar_actions_toggle_search_replace (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorSearchBar *self = user_data;
+
+ g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+ ide_editor_search_bar_set_replace_mode (self, !ide_editor_search_bar_get_replace_mode (self));
+}
+
+static void
+ide_editor_search_bar_actions_replace (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorSearchBar *self = user_data;
+ g_autofree gchar *unescaped_replace_text = NULL;
+ g_autoptr(GError) error = NULL;
+ GtkSourceBuffer *buffer;
+ const gchar *replace_text;
+ const gchar *search_text;
+ GtkTextIter begin;
+ GtkTextIter end;
+ gint position;
+
+ g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+ if (self->settings == NULL || self->context == NULL)
+ return;
+
+ search_text = gtk_source_search_settings_get_search_text (self->settings);
+ replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));
+
+ if (ide_str_empty0 (search_text) || replace_text == NULL)
+ return;
+
+ unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text);
+
+ buffer = gtk_source_search_context_get_buffer (self->context);
+ gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end);
+ position = gtk_source_search_context_get_occurrence_position (self->context, &begin, &end);
+
+ if (position > 0)
+ {
+ /* Temporarily disable updating the search position label to prevent flickering */
+ dzl_signal_group_block (self->buffer_signals);
+
+ gtk_source_search_context_replace2 (self->context, &begin, &end,
+ unescaped_replace_text, -1, &error);
+
+ /* Re-enable updating the search position label. The next-search-result action
+ * below will cause it to update. */
+ dzl_signal_group_unblock (self->buffer_signals);
+
+ if (error != NULL)
+ g_warning ("%s", error->message);
+
+ dzl_gtk_widget_action (GTK_WIDGET (self), "editor-view", "move-next-search-result", NULL);
+ }
+}
+
+static void
+ide_editor_search_bar_actions_replace_all (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ IdeEditorSearchBar *self = user_data;
+ g_autofree gchar *unescaped_replace_text = NULL;
+ g_autoptr(GError) error = NULL;
+ const gchar *replace_text;
+ const gchar *search_text;
+
+ g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+ if (self->settings == NULL || self->context == NULL)
+ return;
+
+ search_text = gtk_source_search_settings_get_search_text (self->settings);
+ replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));
+
+ if (ide_str_empty0 (search_text) || replace_text == NULL)
+ return;
+
+ unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text);
+ gtk_source_search_context_replace_all (self->context, unescaped_replace_text, -1, &error);
+
+ if (error != NULL)
+ g_warning ("%s", error->message);
+}
+
+static const GActionEntry search_bar_actions[] = {
+ { "toggle-search-options", NULL, "b", "false",
+ ide_editor_search_bar_actions_toggle_search_options },
+ { "toggle-search-replace", NULL, "b", "false",
+ ide_editor_search_bar_actions_toggle_search_replace },
+ { "replace", ide_editor_search_bar_actions_replace },
+ { "replace-all", ide_editor_search_bar_actions_replace_all },
+};
+
+void
+_ide_editor_search_bar_init_actions (IdeEditorSearchBar *self)
+{
+ g_autoptr(GSimpleActionGroup) actions = NULL;
+
+ g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
+
+ actions = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (actions),
+ search_bar_actions,
+ G_N_ELEMENTS (search_bar_actions),
+ self);
+ gtk_widget_insert_action_group (GTK_WIDGET (self), "search-bar", G_ACTION_GROUP (actions));
+}
diff --git a/libide/editor/ide-editor-search-bar.c b/libide/editor/ide-editor-search-bar.c
index 64ff896..2009528 100644
--- a/libide/editor/ide-editor-search-bar.c
+++ b/libide/editor/ide-editor-search-bar.c
@@ -19,36 +19,13 @@
#define G_LOG_DOMAIN "ide-editor-search-bar"
#include <glib/gi18n.h>
-#include <libgd/gd-tagged-entry.h>
#include "ide-macros.h"
#include "application/ide-application.h"
+#include "editor/ide-editor-private.h"
#include "editor/ide-editor-search-bar.h"
-struct _IdeEditorSearchBar
-{
- DzlBin parent_instance;
-
- /* Owned references */
- DzlSignalGroup *buffer_signals;
- GtkSourceSearchContext *context;
- DzlSignalGroup *context_signals;
- GtkSourceSearchSettings *settings;
- DzlSignalGroup *settings_signals;
- GdTaggedEntryTag *search_entry_tag;
-
- /* Template widgets */
- GtkCheckButton *case_sensitive;
- GtkButton *replace_all_button;
- GtkButton *replace_button;
- GtkSearchEntry *replace_entry;
- GdTaggedEntry *search_entry;
- GtkGrid *search_options;
- GtkCheckButton *use_regex;
- GtkCheckButton *whole_word;
-};
-
enum {
PROP_0,
PROP_CONTEXT,
@@ -66,20 +43,6 @@ G_DEFINE_TYPE (IdeEditorSearchBar, ide_editor_search_bar, DZL_TYPE_BIN)
static GParamSpec *properties [N_PROPS];
static guint signals [N_SIGNALS];
-static void
-ide_editor_search_bar_toggle_search_options (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- IdeEditorSearchBar *self = user_data;
- gboolean visible;
-
- g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
-
- visible = !gtk_widget_get_visible (GTK_WIDGET (self->search_options));
- gtk_widget_set_visible (GTK_WIDGET (self->search_options), visible);
-}
-
gboolean
ide_editor_search_bar_get_replace_mode (IdeEditorSearchBar *self)
{
@@ -99,98 +62,6 @@ ide_editor_search_bar_set_replace_mode (IdeEditorSearchBar *self,
gtk_widget_set_visible (GTK_WIDGET (self->replace_all_button), replace_mode);
}
-static void
-ide_editor_search_bar_toggle_search_replace (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- IdeEditorSearchBar *self = user_data;
-
- g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
-
- ide_editor_search_bar_set_replace_mode (self, !ide_editor_search_bar_get_replace_mode (self));
-}
-
-static void
-ide_editor_search_bar_replace (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- IdeEditorSearchBar *self = user_data;
- g_autofree gchar *unescaped_replace_text = NULL;
- g_autoptr(GError) error = NULL;
- GtkSourceBuffer *buffer;
- const gchar *replace_text;
- const gchar *search_text;
- GtkTextIter begin;
- GtkTextIter end;
- gint position;
-
- g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
-
- if (self->settings == NULL || self->context == NULL)
- return;
-
- search_text = gtk_source_search_settings_get_search_text (self->settings);
- replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));
-
- if (ide_str_empty0 (search_text) || replace_text == NULL)
- return;
-
- unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text);
-
- buffer = gtk_source_search_context_get_buffer (self->context);
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &begin, &end);
- position = gtk_source_search_context_get_occurrence_position (self->context, &begin, &end);
-
- if (position > 0)
- {
- /* Temporarily disable updating the search position label to prevent flickering */
- dzl_signal_group_block (self->buffer_signals);
-
- gtk_source_search_context_replace2 (self->context, &begin, &end,
- unescaped_replace_text, -1, &error);
-
- /* Re-enable updating the search position label. The next-search-result action
- * below will cause it to update. */
- dzl_signal_group_unblock (self->buffer_signals);
-
- if (error != NULL)
- g_warning ("%s", error->message);
-
- dzl_gtk_widget_action (GTK_WIDGET (self), "editor-view", "move-next-search-result", NULL);
- }
-}
-
-static void
-ide_editor_search_bar_replace_all (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- IdeEditorSearchBar *self = user_data;
- g_autofree gchar *unescaped_replace_text = NULL;
- g_autoptr(GError) error = NULL;
- const gchar *replace_text;
- const gchar *search_text;
-
- g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
-
- if (self->settings == NULL || self->context == NULL)
- return;
-
- search_text = gtk_source_search_settings_get_search_text (self->settings);
- replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));
-
- if (ide_str_empty0 (search_text) || replace_text == NULL)
- return;
-
- unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text);
- gtk_source_search_context_replace_all (self->context, unescaped_replace_text, -1, &error);
-
- if (error != NULL)
- g_warning ("%s", error->message);
-}
-
static gboolean
maybe_escape_regex (GBinding *binding,
const GValue *from_value,
@@ -695,18 +566,9 @@ ide_editor_search_bar_class_init (IdeEditorSearchBarClass *klass)
g_type_ensure (GD_TYPE_TAGGED_ENTRY);
}
-static const GActionEntry search_bar_actions[] = {
- { "toggle-search-options", NULL, "b", "false", ide_editor_search_bar_toggle_search_options },
- { "toggle-search-replace", NULL, "b", "false", ide_editor_search_bar_toggle_search_replace },
- { "replace", ide_editor_search_bar_replace },
- { "replace-all", ide_editor_search_bar_replace_all },
-};
-
static void
ide_editor_search_bar_init (IdeEditorSearchBar *self)
{
- g_autoptr(GSimpleActionGroup) actions = NULL;
-
gtk_widget_init_template (GTK_WIDGET (self));
self->buffer_signals = dzl_signal_group_new (IDE_TYPE_BUFFER);
@@ -755,13 +617,6 @@ ide_editor_search_bar_init (IdeEditorSearchBar *self)
G_CALLBACK (ide_editor_search_bar_bind_settings),
self);
- actions = g_simple_action_group_new ();
- g_action_map_add_action_entries (G_ACTION_MAP (actions),
- search_bar_actions,
- G_N_ELEMENTS (search_bar_actions),
- self);
- gtk_widget_insert_action_group (GTK_WIDGET (self), "search-bar", G_ACTION_GROUP (actions));
-
dzl_widget_action_group_attach (self->search_entry, "entry");
g_signal_connect_swapped (self->search_entry,
@@ -773,6 +628,8 @@ ide_editor_search_bar_init (IdeEditorSearchBar *self)
"stop-search",
G_CALLBACK (search_entry_stop_search),
self);
+
+ _ide_editor_search_bar_init_actions (self);
}
GtkWidget *
diff --git a/libide/editor/ide-editor-search-bar.h b/libide/editor/ide-editor-search-bar.h
index 28360cb..41ad333 100644
--- a/libide/editor/ide-editor-search-bar.h
+++ b/libide/editor/ide-editor-search-bar.h
@@ -32,6 +32,7 @@ G_DECLARE_FINAL_TYPE (IdeEditorSearchBar, ide_editor_search_bar, IDE, EDITOR_SEA
GtkWidget *ide_editor_search_bar_new (void);
void ide_editor_search_bar_set_search_text (IdeEditorSearchBar *self,
const gchar *word);
+gboolean ide_editor_search_bar_get_replace_mode (IdeEditorSearchBar *self);
void ide_editor_search_bar_set_replace_mode (IdeEditorSearchBar *self,
gboolean replace_mode);
void ide_editor_search_bar_set_context (IdeEditorSearchBar *self,
diff --git a/libide/meson.build b/libide/meson.build
index cb03960..5afabf0 100644
--- a/libide/meson.build
+++ b/libide/meson.build
@@ -484,6 +484,7 @@ libide_sources = libide_generated_headers + libide_public_sources + [
'editor/ide-editor-properties.c',
'editor/ide-editor-properties.h',
'editor/ide-editor-search-bar.c',
+ 'editor/ide-editor-search-bar-actions.c',
'editor/ide-editor-search-bar.h',
'editor/ide-editor-view-actions.c',
'editor/ide-editor-view-settings.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]