[gedit] EncodingsDialog: Reset button sensitivity
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] EncodingsDialog: Reset button sensitivity
- Date: Sun, 12 Apr 2015 10:06:05 +0000 (UTC)
commit 5bd8599efe60422155dd06878089fb5388de4217
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Apr 4 14:37:57 2015 +0200
EncodingsDialog: Reset button sensitivity
If there is nothing to reset (it's the default candidate encodings), set
the Reset button as insensitive.
gedit/gedit-encoding-items.c | 2 +-
gedit/gedit-encodings-dialog.c | 39 +++++++++++++++++++++++++--------------
gedit/gedit-settings.c | 12 +++++++++++-
gedit/gedit-settings.h | 2 +-
gedit/gedit-tab.c | 2 +-
5 files changed, 39 insertions(+), 18 deletions(-)
---
diff --git a/gedit/gedit-encoding-items.c b/gedit/gedit-encoding-items.c
index ad88a00..93bd488 100644
--- a/gedit/gedit-encoding-items.c
+++ b/gedit/gedit-encoding-items.c
@@ -78,7 +78,7 @@ gedit_encoding_items_get (void)
GSList *items = NULL;
GSList *l;
- encodings = gedit_settings_get_candidate_encodings ();
+ encodings = gedit_settings_get_candidate_encodings (NULL);
current_encoding = gtk_source_encoding_get_current ();
diff --git a/gedit/gedit-encodings-dialog.c b/gedit/gedit-encodings-dialog.c
index 27c112a..92d59ab 100644
--- a/gedit/gedit-encodings-dialog.c
+++ b/gedit/gedit-encodings-dialog.c
@@ -47,6 +47,7 @@ struct _GeditEncodingsDialogPrivate
GtkWidget *remove_button;
GtkWidget *up_button;
GtkWidget *down_button;
+ GtkWidget *reset_button;
guint modified : 1;
};
@@ -62,6 +63,18 @@ enum
G_DEFINE_TYPE_WITH_PRIVATE (GeditEncodingsDialog, gedit_encodings_dialog, GTK_TYPE_DIALOG)
static void
+set_modified (GeditEncodingsDialog *dialog,
+ gboolean modified)
+{
+ dialog->priv->modified = modified;
+
+ if (modified)
+ {
+ gtk_widget_set_sensitive (dialog->priv->reset_button, TRUE);
+ }
+}
+
+static void
gedit_encodings_dialog_dispose (GObject *object)
{
GeditEncodingsDialogPrivate *priv = GEDIT_ENCODINGS_DIALOG (object)->priv;
@@ -174,7 +187,7 @@ gedit_encodings_dialog_class_init (GeditEncodingsDialogClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GeditEncodingsDialog, remove_button);
gtk_widget_class_bind_template_child_private (widget_class, GeditEncodingsDialog, up_button);
gtk_widget_class_bind_template_child_private (widget_class, GeditEncodingsDialog, down_button);
- gtk_widget_class_bind_template_child_full (widget_class, "reset_button", FALSE, 0);
+ gtk_widget_class_bind_template_child_private (widget_class, GeditEncodingsDialog, reset_button);
}
static void
@@ -405,7 +418,7 @@ add_button_clicked_cb (GtkWidget *button,
dialog->priv->liststore_available,
dialog->priv->liststore_chosen);
- dialog->priv->modified = TRUE;
+ set_modified (dialog, TRUE);
/* For the treeview_available, it's more natural to unselect the added
* encodings.
@@ -475,7 +488,7 @@ remove_button_clicked_cb (GtkWidget *button,
dialog->priv->liststore_chosen,
dialog->priv->liststore_available);
- dialog->priv->modified = TRUE;
+ set_modified (dialog, TRUE);
g_list_free (selected_rows);
g_list_free_full (to_remove, (GDestroyNotify) gtk_tree_path_free);
@@ -514,7 +527,7 @@ up_button_clicked_cb (GtkWidget *button,
&iter,
&prev_iter);
- dialog->priv->modified = TRUE;
+ set_modified (dialog, TRUE);
update_chosen_buttons_sensitivity (dialog);
@@ -554,7 +567,7 @@ down_button_clicked_cb (GtkWidget *button,
&iter,
&next_iter);
- dialog->priv->modified = TRUE;
+ set_modified (dialog, TRUE);
update_chosen_buttons_sensitivity (dialog);
@@ -564,13 +577,16 @@ down_button_clicked_cb (GtkWidget *button,
static void
init_liststores (GeditEncodingsDialog *dialog)
{
+ gboolean default_candidates;
GSList *chosen_encodings;
GSList *all_encodings;
GSList *l;
/* Chosen encodings */
- chosen_encodings = gedit_settings_get_candidate_encodings ();
+ chosen_encodings = gedit_settings_get_candidate_encodings (&default_candidates);
+
+ gtk_widget_set_sensitive (dialog->priv->reset_button, !default_candidates);
for (l = chosen_encodings; l != NULL; l = l->next)
{
@@ -594,6 +610,8 @@ init_liststores (GeditEncodingsDialog *dialog)
append_encoding (dialog->priv->liststore_available, cur_encoding);
}
+ set_modified (dialog, FALSE);
+
g_slist_free (chosen_encodings);
g_slist_free (all_encodings);
}
@@ -629,7 +647,6 @@ reset_button_clicked_cb (GtkWidget *button,
gtk_list_store_clear (dialog->priv->liststore_chosen);
init_liststores (dialog);
- dialog->priv->modified = FALSE;
}
gtk_widget_destroy (GTK_WIDGET (msg_dialog));
@@ -639,7 +656,6 @@ static void
gedit_encodings_dialog_init (GeditEncodingsDialog *dialog)
{
GtkTreeSelection *selection;
- GtkButton *reset_button;
dialog->priv = gedit_encodings_dialog_get_instance_private (dialog);
@@ -650,7 +666,6 @@ gedit_encodings_dialog_init (GeditEncodingsDialog *dialog)
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
init_liststores (dialog);
- dialog->priv->modified = FALSE;
/* Tree view of available encodings */
@@ -698,11 +713,7 @@ gedit_encodings_dialog_init (GeditEncodingsDialog *dialog)
G_CALLBACK (down_button_clicked_cb),
dialog);
- reset_button = GTK_BUTTON (gtk_widget_get_template_child (GTK_WIDGET (dialog),
- GEDIT_TYPE_ENCODINGS_DIALOG,
- "reset_button"));
-
- g_signal_connect (reset_button,
+ g_signal_connect (dialog->priv->reset_button,
"clicked",
G_CALLBACK (reset_button_clicked_cb),
dialog);
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index 3a72eb3..02bf23f 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -538,7 +538,7 @@ encoding_strv_to_list (const gchar * const *encoding_strv)
* Returns: a list of GtkSourceEncodings. Free with g_slist_free().
*/
GSList *
-gedit_settings_get_candidate_encodings (void)
+gedit_settings_get_candidate_encodings (gboolean *default_candidates)
{
const GtkSourceEncoding *utf8_encoding;
const GtkSourceEncoding *current_encoding;
@@ -555,10 +555,20 @@ gedit_settings_get_candidate_encodings (void)
if (strv_is_empty (settings_strv))
{
+ if (default_candidates != NULL)
+ {
+ *default_candidates = TRUE;
+ }
+
candidates = gtk_source_encoding_get_default_candidates ();
}
else
{
+ if (default_candidates != NULL)
+ {
+ *default_candidates = FALSE;
+ }
+
candidates = encoding_strv_to_list ((const gchar * const *) settings_strv);
/* Ensure that UTF-8 is present. */
diff --git a/gedit/gedit-settings.h b/gedit/gedit-settings.h
index 2b54af6..cd4499b 100644
--- a/gedit/gedit-settings.h
+++ b/gedit/gedit-settings.h
@@ -63,7 +63,7 @@ GeditLockdownMask gedit_settings_get_lockdown (GeditSettings *gs);
gchar *gedit_settings_get_system_font (GeditSettings *gs);
-GSList *gedit_settings_get_candidate_encodings (void);
+GSList *gedit_settings_get_candidate_encodings (gboolean *default_candidates);
/* Utility functions */
GSList *gedit_settings_get_list (GSettings *settings,
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index c2f0d58..28cc4f6 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -1953,7 +1953,7 @@ get_candidate_encodings (GeditTab *tab)
gchar *metadata_charset;
const GtkSourceEncoding *file_encoding;
- candidates = gedit_settings_get_candidate_encodings ();
+ candidates = gedit_settings_get_candidate_encodings (NULL);
/* Prepend the encoding stored in the metadata. */
doc = gedit_tab_get_document (tab);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]