[Xfce4-commits] [apps/mousepad] 07/45: Use GSettings for MousepadReplaceDialog search settings
noreply at xfce.org
noreply at xfce.org
Fri Jul 11 13:03:12 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit 19182c7830191676f638c23d0892ba2bdee6f32d
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Sun Jul 6 14:33:01 2014 -0700
Use GSettings for MousepadReplaceDialog search settings
Add new setting "search-replace-all" to control the checkbox for it
in the dialog. Refactor "search-replace-all" callback into _changed()
function.
---
mousepad/mousepad-replace-dialog.c | 229 ++++++++++++--------------------
mousepad/org.xfce.Mousepad.gschema.xml | 9 ++
2 files changed, 92 insertions(+), 146 deletions(-)
diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c
index 1f29863..9828d3e 100644
--- a/mousepad/mousepad-replace-dialog.c
+++ b/mousepad/mousepad-replace-dialog.c
@@ -32,23 +32,16 @@
-static void mousepad_replace_dialog_unrealize (GtkWidget *widget);
-static void mousepad_replace_dialog_finalize (GObject *object);
-static void mousepad_replace_dialog_response (GtkWidget *widget,
- gint response_id);
-static void mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_case_sensitive_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_whole_word_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_replace_all_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_search_location_changed (GtkComboBox *combo,
- MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_direction_changed (GtkComboBox *combo,
- MousepadReplaceDialog *dialog);
-static void mousepad_replace_dialog_history_combo_box (GtkComboBox *combo_box);
-static void mousepad_replace_dialog_history_insert_text (const gchar *text);
+static void mousepad_replace_dialog_unrealize (GtkWidget *widget);
+static void mousepad_replace_dialog_finalize (GObject *object);
+static void mousepad_replace_dialog_response (GtkWidget *widget,
+ gint response_id);
+static void mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog);
+static void mousepad_replace_dialog_settings_changed (MousepadReplaceDialog *dialog,
+ gchar *key,
+ MousepadSettings *settings);
+static void mousepad_replace_dialog_history_combo_box (GtkComboBox *combo_box);
+static void mousepad_replace_dialog_history_insert_text (const gchar *text);
@@ -68,13 +61,6 @@ struct _MousepadReplaceDialog
GtkWidget *replace_button;
GtkWidget *search_location_combo;
GtkWidget *hits_label;
-
- /* search flags */
- guint search_direction;
- guint match_case : 1;
- guint match_whole_word : 1;
- guint replace_all : 1;
- guint replace_all_location;
};
enum
@@ -133,27 +119,36 @@ mousepad_replace_dialog_class_init (MousepadReplaceDialogClass *klass)
static void
-mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
+mousepad_replace_dialog_bind_setting (MousepadReplaceDialog *dialog,
+ const gchar *key,
+ gpointer object,
+ const gchar *property)
{
- GtkWidget *vbox, *hbox, *combo, *label, *check;
- GtkSizeGroup *size_group;
- gboolean match_whole_word, match_case;
- gint search_direction, replace_all_location;
+ gchar *signal_name;
+
+ g_settings_bind (MOUSEPAD_GSETTINGS,
+ key,
+ object,
+ property,
+ G_SETTINGS_BIND_DEFAULT);
+
+ signal_name = g_strdup_printf ("changed::%s", key);
+
+ g_signal_connect_swapped (MOUSEPAD_GSETTINGS,
+ signal_name,
+ G_CALLBACK (mousepad_replace_dialog_settings_changed),
+ dialog);
+
+ g_free (signal_name);
+}
- /* initialize some variables */
- dialog->replace_all = FALSE;
- /* read the preferences */
- match_whole_word = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-match-whole-word");
- match_case = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-match-case");
- search_direction = g_settings_get_int (MOUSEPAD_GSETTINGS, "search-direction");
- replace_all_location = g_settings_get_int (MOUSEPAD_GSETTINGS, "search-replace-all-location");
- /* set some flags */
- dialog->match_whole_word = match_whole_word;
- dialog->match_case = match_case;
- dialog->search_direction = search_direction;
- dialog->replace_all_location = replace_all_location;
+static void
+mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
+{
+ GtkWidget *vbox, *hbox, *combo, *label, *check;
+ GtkSizeGroup *size_group;
/* set dialog properties */
gtk_window_set_title (GTK_WINDOW (dialog), _("Replace"));
@@ -234,27 +229,27 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Up"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Down"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Both"));
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), search_direction);
- g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (mousepad_replace_dialog_direction_changed), dialog);
gtk_widget_show (combo);
+ mousepad_replace_dialog_bind_setting (dialog, "search-direction", combo, "active");
+
/* release size group */
g_object_unref (G_OBJECT (size_group));
/* case sensitive */
check = gtk_check_button_new_with_mnemonic (_("Case sensi_tive"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), match_case);
- g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (mousepad_replace_dialog_case_sensitive_toggled), dialog);
gtk_widget_show (check);
+ mousepad_replace_dialog_bind_setting (dialog, "search-match-case", check, "active");
+
/* match whole word */
check = gtk_check_button_new_with_mnemonic (_("_Match whole word"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), match_whole_word);
- g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (mousepad_replace_dialog_whole_word_toggled), dialog);
gtk_widget_show (check);
+ mousepad_replace_dialog_bind_setting (dialog, "search-match-whole-word", check, "active");
+
/* horizontal box for the replace all options */
hbox = gtk_hbox_new (FALSE, 8);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@@ -262,22 +257,26 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
check = gtk_check_button_new_with_mnemonic (_("Replace _all in:"));
gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0);
- g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (mousepad_replace_dialog_replace_all_toggled), dialog);
gtk_widget_show (check);
+ mousepad_replace_dialog_bind_setting (dialog, "search-replace-all", check, "active");
+
combo = dialog->search_location_combo = gtk_combo_box_new_text ();
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Selection"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Document"));
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("All Documents"));
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), replace_all_location);
gtk_widget_set_sensitive (combo, FALSE);
- g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (mousepad_replace_dialog_search_location_changed), dialog);
gtk_widget_show (combo);
+ mousepad_replace_dialog_bind_setting (dialog, "search-replace-all-location", combo, "active");
+
label = dialog->hits_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
+
+ /* update the state of the widgets */
+ mousepad_replace_dialog_changed (dialog);
}
@@ -321,34 +320,40 @@ mousepad_replace_dialog_response (GtkWidget *widget,
gint matches;
const gchar *search_str, *replace_str;
gchar *message;
+ gint search_direction, replace_all_location;
+ gboolean match_case, match_whole_word, replace_all;
+
+ /* read the search settings */
+ search_direction = g_settings_get_int (MOUSEPAD_GSETTINGS, "search-direction");
+ replace_all_location = g_settings_get_int (MOUSEPAD_GSETTINGS, "search-replace-all-location");
+ match_case = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-match-case");
+ match_whole_word = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-match-whole-word");
+ replace_all = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-replace-all");
/* close dialog */
if (response_id == MOUSEPAD_RESPONSE_CLOSE)
goto destroy_dialog;
/* search direction */
- if (dialog->search_direction == DIRECTION_UP
- && dialog->replace_all == FALSE)
+ if (search_direction == DIRECTION_UP && ! replace_all)
flags = MOUSEPAD_SEARCH_FLAGS_DIR_BACKWARD;
else
flags = MOUSEPAD_SEARCH_FLAGS_DIR_FORWARD;
/* case sensitive searching */
- if (dialog->match_case)
+ if (match_case)
flags |= MOUSEPAD_SEARCH_FLAGS_MATCH_CASE;
/* only match whole words */
- if (dialog->match_whole_word)
+ if (match_whole_word)
flags |= MOUSEPAD_SEARCH_FLAGS_WHOLE_WORD;
/* wrap around */
- if (dialog->search_direction == DIRECTION_BOTH
- && dialog->replace_all == FALSE)
+ if (search_direction == DIRECTION_BOTH && ! replace_all)
flags |= MOUSEPAD_SEARCH_FLAGS_WRAP_AROUND;
/* search area */
- if (dialog->replace_all
- && dialog->replace_all_location == IN_SELECTION)
+ if (replace_all && replace_all_location == IN_SELECTION)
flags |= MOUSEPAD_SEARCH_FLAGS_AREA_SELECTION;
else
flags |= MOUSEPAD_SEARCH_FLAGS_AREA_DOCUMENT;
@@ -359,7 +364,7 @@ mousepad_replace_dialog_response (GtkWidget *widget,
/* no visible actions */
flags |= MOUSEPAD_SEARCH_FLAGS_ACTION_NONE;
- if (dialog->replace_all)
+ if (replace_all)
goto replace_flags;
else
goto search_flags;
@@ -382,7 +387,7 @@ mousepad_replace_dialog_response (GtkWidget *widget,
/* replace matches */
flags |= MOUSEPAD_SEARCH_FLAGS_ACTION_REPLACE;
- if (dialog->replace_all)
+ if (replace_all)
{
replace_flags:
@@ -391,7 +396,7 @@ mousepad_replace_dialog_response (GtkWidget *widget,
| MOUSEPAD_SEARCH_FLAGS_ENTIRE_AREA;
/* search all opened documents (flag used in mousepad-window.c) */
- if (dialog->replace_all_location == IN_ALL_DOCUMENTS)
+ if (replace_all_location == IN_ALL_DOCUMENTS)
flags |= MOUSEPAD_SEARCH_FLAGS_ALL_DOCUMENTS;
}
else
@@ -422,14 +427,14 @@ mousepad_replace_dialog_response (GtkWidget *widget,
g_signal_emit (G_OBJECT (dialog), dialog_signals[SEARCH], 0, flags, search_str, replace_str, &matches);
/* reset counter */
- if (response_id == MOUSEPAD_RESPONSE_REPLACE && dialog->replace_all)
+ if (response_id == MOUSEPAD_RESPONSE_REPLACE && replace_all)
matches = 0;
/* update entry color */
mousepad_util_entry_error (dialog->search_entry, matches == 0);
/* update counter */
- if (dialog->replace_all)
+ if (replace_all)
{
message = g_strdup_printf (ngettext ("%d occurence", "%d occurences", matches), matches);
gtk_label_set_markup (GTK_LABEL (dialog->hits_label), message);
@@ -443,6 +448,16 @@ mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
{
const gchar *text;
gboolean sensitive;
+ gboolean replace_all;
+
+ replace_all = g_settings_get_boolean (MOUSEPAD_GSETTINGS, "search-replace-all");
+
+ /* set the sensitivity of some dialog widgets */
+ gtk_widget_set_sensitive (dialog->search_location_combo, replace_all);
+
+ /* set new label of the replace button */
+ gtk_button_set_label (GTK_BUTTON (dialog->replace_button),
+ replace_all ? _("_Replace All") : _("_Replace"));
/* get the search entry text */
text = gtk_entry_get_text (GTK_ENTRY (dialog->search_entry));
@@ -475,92 +490,14 @@ mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
static void
-mousepad_replace_dialog_case_sensitive_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog)
-{
- /* get the toggle button state */
- dialog->match_case = gtk_toggle_button_get_active (button);
-
- /* save the setting */
- g_settings_set_boolean (MOUSEPAD_GSETTINGS, "search-match-case", dialog->match_case);
-
- /* update dialog */
- mousepad_replace_dialog_changed (dialog);
-}
-
-
-
-static void
-mousepad_replace_dialog_whole_word_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog)
-{
- /* get the toggle button state */
- dialog->match_whole_word = gtk_toggle_button_get_active (button);
-
- /* save the setting */
- g_settings_set_boolean (MOUSEPAD_GSETTINGS, "search-match-whole-word", dialog->match_whole_word);
-
- /* update dialog */
- mousepad_replace_dialog_changed (dialog);
-}
-
-
-
-static void
-mousepad_replace_dialog_replace_all_toggled (GtkToggleButton *button,
- MousepadReplaceDialog *dialog)
+mousepad_replace_dialog_settings_changed (MousepadReplaceDialog *dialog,
+ gchar *key,
+ MousepadSettings *settings)
{
- gboolean active;
-
- /* get the toggle button state */
- active = gtk_toggle_button_get_active (button);
-
- /* save flags */
- dialog->replace_all = active;
-
- /* set the sensitivity of some dialog widgets */
- gtk_widget_set_sensitive (dialog->search_location_combo, active);
-
/* reset occurences label */
- gtk_label_set_text (GTK_LABEL (dialog->hits_label), NULL);
-
- /* set new label of the replace button */
- gtk_button_set_label (GTK_BUTTON (dialog->replace_button),
- active ? _("_Replace All") : _("_Replace"));
-
- /* update dialog */
- mousepad_replace_dialog_changed (dialog);
-}
-
-
-
-static void
-mousepad_replace_dialog_search_location_changed (GtkComboBox *combo,
- MousepadReplaceDialog *dialog)
-{
- /* get the selected action */
- dialog->replace_all_location = gtk_combo_box_get_active (combo);
-
- /* save setting */
- g_settings_set_int (MOUSEPAD_GSETTINGS, "search-replace-all-location", dialog->replace_all_location);
-
- /* update dialog */
- mousepad_replace_dialog_changed (dialog);
-}
-
-
-
-static void
-mousepad_replace_dialog_direction_changed (GtkComboBox *combo,
- MousepadReplaceDialog *dialog)
-{
- /* get the selected item */
- dialog->search_direction = gtk_combo_box_get_active (combo);
-
- /* save the last direction */
- g_settings_set_int (MOUSEPAD_GSETTINGS, "search-direction", dialog->search_direction);
+ if (g_strcmp0 (key, "search-replace-all") == 0)
+ gtk_label_set_text (GTK_LABEL (dialog->hits_label), NULL);
- /* update dialog */
mousepad_replace_dialog_changed (dialog);
}
diff --git a/mousepad/org.xfce.Mousepad.gschema.xml b/mousepad/org.xfce.Mousepad.gschema.xml
index 4b9adf9..37756f4 100644
--- a/mousepad/org.xfce.Mousepad.gschema.xml
+++ b/mousepad/org.xfce.Mousepad.gschema.xml
@@ -32,6 +32,15 @@
</description>
</key>
+ <key name="search-replace-all" type="b">
+ <default>false</default>
+ <summary>Replace all</summary>
+ <description>
+ When true the Replace search dialog is in "replace-all" mode, when
+ false the dialog is in "replace-one-at-a-time" mode.
+ </description>
+ </key>
+
<key name="search-replace-all-location" type="i">
<range min="0" max="2"/>
<default>1</default>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list