[evolution] EMFolderSelector: Add a "default-button-label" property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EMFolderSelector: Add a "default-button-label" property.
- Date: Thu, 27 Mar 2014 00:23:42 +0000 (UTC)
commit 76247306741e88fdb92780989751fc42c65c231a
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Mar 19 10:19:38 2014 -0400
EMFolderSelector: Add a "default-button-label" property.
Replaces the 'oklabel' argument when creating a new dialog, and can be
changed after the dialog is created.
This makes EMFolderSelector a little more "subclassable".
mail/e-mail-reader.c | 8 ++--
mail/em-composer-utils.c | 2 +-
mail/em-folder-selection-button.c | 3 +-
mail/em-folder-selector.c | 102 +++++++++++++++++++++++++++++++++---
mail/em-folder-selector.h | 8 ++-
mail/em-folder-utils.c | 3 +-
mail/em-vfolder-editor-rule.c | 4 +-
modules/mail/em-composer-prefs.c | 4 +-
8 files changed, 112 insertions(+), 22 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 77fa229..7ffda86 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -343,11 +343,11 @@ action_mail_copy_cb (GtkAction *action,
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
- window, model,
- _("Copy to Folder"), _("C_opy"));
+ window, model, _("Copy to Folder"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ em_folder_selector_set_default_button_label (selector, _("C_opy"));
folder_tree = em_folder_selector_get_folder_tree (selector);
@@ -844,11 +844,11 @@ action_mail_move_cb (GtkAction *action,
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
- window, model,
- _("Move to Folder"), _("_Move"));
+ window, model, _("Move to Folder"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ em_folder_selector_set_default_button_label (selector, _("_Move"));
folder_tree = em_folder_selector_get_folder_tree (selector);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 7cc8fa5..c8f57f0 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -3037,7 +3037,7 @@ post_header_clicked_cb (EComposerPostHeader *header,
dialog = em_folder_selector_new (
/* FIXME GTK_WINDOW (composer) */ NULL,
- model, _("Posting destination"), NULL);
+ model, _("Posting destination"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
diff --git a/mail/em-folder-selection-button.c b/mail/em-folder-selection-button.c
index e95835b..7ba1a1d 100644
--- a/mail/em-folder-selection-button.c
+++ b/mail/em-folder-selection-button.c
@@ -269,8 +269,7 @@ folder_selection_button_clicked (GtkButton *button)
if (model == NULL)
model = g_object_ref (em_folder_tree_model_get_default ());
- dialog = em_folder_selector_new (
- parent, model, priv->title, NULL);
+ dialog = em_folder_selector_new (parent, model, priv->title);
g_object_unref (model);
diff --git a/mail/em-folder-selector.c b/mail/em-folder-selector.c
index 51a2f55..7f1274c 100644
--- a/mail/em-folder-selector.c
+++ b/mail/em-folder-selector.c
@@ -24,7 +24,7 @@
#include <config.h>
#include <string.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
#include <e-util/e-util.h>
#include <libemail-engine/libemail-engine.h>
@@ -42,6 +42,8 @@
/* Dialog response code. */
#define EM_FOLDER_SELECTOR_RESPONSE_NEW 1
+#define DEFAULT_BUTTON_LABEL N_("_OK")
+
struct _EMFolderSelectorPrivate {
EMFolderTree *folder_tree; /* not referenced */
EMFolderTreeModel *model;
@@ -53,12 +55,14 @@ struct _EMFolderSelectorPrivate {
gboolean can_create;
gchar *caption;
+ gchar *default_button_label;
};
enum {
PROP_0,
PROP_CAN_CREATE,
PROP_CAPTION,
+ PROP_DEFAULT_BUTTON_LABEL,
PROP_MODEL
};
@@ -103,6 +107,12 @@ folder_selector_set_property (GObject *object,
g_value_get_string (value));
return;
+ case PROP_DEFAULT_BUTTON_LABEL:
+ em_folder_selector_set_default_button_label (
+ EM_FOLDER_SELECTOR (object),
+ g_value_get_string (value));
+ return;
+
case PROP_MODEL:
folder_selector_set_model (
EM_FOLDER_SELECTOR (object),
@@ -134,6 +144,13 @@ folder_selector_get_property (GObject *object,
EM_FOLDER_SELECTOR (object)));
return;
+ case PROP_DEFAULT_BUTTON_LABEL:
+ g_value_set_string (
+ value,
+ em_folder_selector_get_default_button_label (
+ EM_FOLDER_SELECTOR (object)));
+ return;
+
case PROP_MODEL:
g_value_set_object (
value,
@@ -169,6 +186,7 @@ folder_selector_finalize (GObject *object)
g_free (priv->selected_uri);
g_free (priv->caption);
+ g_free (priv->default_button_label);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (em_folder_selector_parent_class)->finalize (object);
@@ -276,6 +294,17 @@ em_folder_selector_class_init (EMFolderSelectorClass *class)
g_object_class_install_property (
object_class,
+ PROP_DEFAULT_BUTTON_LABEL,
+ g_param_spec_string (
+ "default-button-label",
+ "Default Button Label",
+ "Label for the dialog's default button",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
PROP_MODEL,
g_param_spec_object (
"model",
@@ -297,6 +326,9 @@ static void
em_folder_selector_init (EMFolderSelector *selector)
{
selector->priv = EM_FOLDER_SELECTOR_GET_PRIVATE (selector);
+
+ selector->priv->default_button_label =
+ g_strdup (gettext (DEFAULT_BUTTON_LABEL));
}
static void
@@ -347,8 +379,7 @@ folder_activated_cb (EMFolderTree *emft,
}
static GtkWidget *
-folder_selector_construct (EMFolderSelector *selector,
- const gchar *oklabel)
+folder_selector_construct (EMFolderSelector *selector)
{
EMailSession *session;
EMFolderTreeModel *model;
@@ -376,7 +407,7 @@ folder_selector_construct (EMFolderSelector *selector,
GTK_DIALOG (selector),
_("_New"), EM_FOLDER_SELECTOR_RESPONSE_NEW,
_("_Cancel"), GTK_RESPONSE_CANCEL,
- oklabel ? oklabel : _("_OK"), GTK_RESPONSE_OK, NULL);
+ selector->priv->default_button_label, GTK_RESPONSE_OK, NULL);
gtk_dialog_set_response_sensitive (
GTK_DIALOG (selector), GTK_RESPONSE_OK, FALSE);
@@ -391,6 +422,15 @@ folder_selector_construct (EMFolderSelector *selector,
widget, "visible",
G_BINDING_SYNC_CREATE);
+ widget = gtk_dialog_get_widget_for_response (
+ GTK_DIALOG (selector), GTK_RESPONSE_OK);
+
+ /* No need to synchronize properties. */
+ g_object_bind_property (
+ selector, "default-button-label",
+ widget, "label",
+ G_BINDING_DEFAULT);
+
widget = e_alert_bar_new ();
gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
selector->priv->alert_bar = g_object_ref (widget);
@@ -444,8 +484,7 @@ folder_selector_construct (EMFolderSelector *selector,
GtkWidget *
em_folder_selector_new (GtkWindow *parent,
EMFolderTreeModel *model,
- const gchar *title,
- const gchar *oklabel)
+ const gchar *title)
{
EMFolderSelector *selector;
@@ -456,7 +495,7 @@ em_folder_selector_new (GtkWindow *parent,
"transient-for", parent,
"title", title,
"model", model, NULL);
- folder_selector_construct (selector, oklabel);
+ folder_selector_construct (selector);
return GTK_WIDGET (selector);
}
@@ -507,9 +546,10 @@ em_folder_selector_create_new (GtkWindow *parent,
EM_TYPE_FOLDER_SELECTOR,
"transient-for", parent,
"title", title,
- "model", model, NULL);
+ "model", model,
+ "default-button-label", _("C_reate"), NULL);
- container = folder_selector_construct (selector, _("C_reate"));
+ container = folder_selector_construct (selector);
folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (folder_tree, EMFT_EXCLUDE_NOINFERIORS);
@@ -631,6 +671,50 @@ em_folder_selector_set_caption (EMFolderSelector *selector,
g_object_notify (G_OBJECT (selector), "caption");
}
+/**
+ * em_folder_selector_get_default_button_label:
+ * @selector: an #EMFolderSelector
+ *
+ * Returns the label for the dialog's default button, which triggers a
+ * #GTK_RESPONSE_OK response ID.
+ *
+ * Returns: the label for the default button
+ **/
+const gchar *
+em_folder_selector_get_default_button_label (EMFolderSelector *selector)
+{
+ g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (selector), NULL);
+
+ return selector->priv->default_button_label;
+}
+
+/**
+ * em_folder_selector_set_default_button_label:
+ * @selector: an #EMFolderSelector
+ * @button_label: the label for the default button, or %NULL
+ *
+ * Sets the label for the dialog's default button, which triggers a
+ * #GTK_RESPONSE_OK response ID. If @button_label is %NULL, the default
+ * button's label is reset to "OK".
+ **/
+void
+em_folder_selector_set_default_button_label (EMFolderSelector *selector,
+ const gchar *button_label)
+{
+ g_return_if_fail (EM_IS_FOLDER_SELECTOR (selector));
+
+ if (button_label == NULL)
+ button_label = gettext (DEFAULT_BUTTON_LABEL);
+
+ if (g_strcmp0 (button_label, selector->priv->default_button_label) == 0)
+ return;
+
+ g_free (selector->priv->default_button_label);
+ selector->priv->default_button_label = g_strdup (button_label);
+
+ g_object_notify (G_OBJECT (selector), "default-button-label");
+}
+
EMFolderTreeModel *
em_folder_selector_get_model (EMFolderSelector *selector)
{
diff --git a/mail/em-folder-selector.h b/mail/em-folder-selector.h
index a06572c..a6e78de 100644
--- a/mail/em-folder-selector.h
+++ b/mail/em-folder-selector.h
@@ -63,8 +63,7 @@ struct _EMFolderSelectorClass {
GType em_folder_selector_get_type (void);
GtkWidget * em_folder_selector_new (GtkWindow *parent,
EMFolderTreeModel *model,
- const gchar *title,
- const gchar *oklabel);
+ const gchar *title);
GtkWidget * em_folder_selector_create_new (GtkWindow *parent,
EMFolderTreeModel *model,
const gchar *title);
@@ -76,6 +75,11 @@ void em_folder_selector_set_can_create
const gchar * em_folder_selector_get_caption (EMFolderSelector *selector);
void em_folder_selector_set_caption (EMFolderSelector *selector,
const gchar *caption);
+const gchar * em_folder_selector_get_default_button_label
+ (EMFolderSelector *selector);
+void em_folder_selector_set_default_button_label
+ (EMFolderSelector *selector,
+ const gchar *button_label);
EMFolderTreeModel *
em_folder_selector_get_model (EMFolderSelector *selector);
EMFolderTree * em_folder_selector_get_folder_tree
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index 0eea5fe..15f6919 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -507,10 +507,11 @@ em_folder_utils_copy_folder (GtkWindow *parent,
model = em_folder_tree_model_get_default ();
- dialog = em_folder_selector_new (parent, model, title, label);
+ dialog = em_folder_selector_new (parent, model, title);
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ em_folder_selector_set_default_button_label (selector, label);
folder_tree = em_folder_selector_get_folder_tree (selector);
diff --git a/mail/em-vfolder-editor-rule.c b/mail/em-vfolder-editor-rule.c
index 8eac42d..7296d36 100644
--- a/mail/em-vfolder-editor-rule.c
+++ b/mail/em-vfolder-editor-rule.c
@@ -387,11 +387,11 @@ source_add (GtkWidget *widget,
model = em_folder_tree_model_get_default ();
- dialog = em_folder_selector_new (
- parent, model, _("Add Folder"), _("_Add"));
+ dialog = em_folder_selector_new (parent, model, _("Add Folder"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ em_folder_selector_set_default_button_label (selector, _("_Add"));
folder_tree = em_folder_selector_get_folder_tree (selector);
diff --git a/modules/mail/em-composer-prefs.c b/modules/mail/em-composer-prefs.c
index 4d852d8..efc740b 100644
--- a/modules/mail/em-composer-prefs.c
+++ b/modules/mail/em-composer-prefs.c
@@ -440,9 +440,11 @@ sao_folders_add_button_clicked_cb (GtkButton *button,
dialog = em_folder_selector_new (
window, em_folder_tree_model_get_default (),
- _("Select Folder to Add"), _("_Add"));
+ _("Select Folder to Add"));
selector = EM_FOLDER_SELECTOR (dialog);
+ em_folder_selector_set_default_button_label (selector, _("_Add"));
+
folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (folder_tree, EMFT_EXCLUDE_NOSELECT);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]