[evolution] EMFolderSelector: Add a "caption" property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EMFolderSelector: Add a "caption" property.
- Date: Thu, 27 Mar 2014 00:23:37 +0000 (UTC)
commit c70e8e9ea2b9b4319e6b2f6f5b31bbbfbffe9c91
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Mar 19 09:18:13 2014 -0400
EMFolderSelector: Add a "caption" property.
Replaces the 'text' 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 | 4 +-
mail/em-composer-utils.c | 9 ++--
mail/em-folder-selection-button.c | 4 +-
mail/em-folder-selector.c | 105 ++++++++++++++++++++++++++++++++-----
mail/em-folder-selector.h | 7 ++-
mail/em-folder-utils.c | 13 +++--
mail/em-vfolder-editor-rule.c | 3 +-
modules/mail/em-composer-prefs.c | 2 +-
8 files changed, 113 insertions(+), 34 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index fc9365e..77fa229 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -344,7 +344,7 @@ action_mail_copy_cb (GtkAction *action,
dialog = em_folder_selector_new (
window, model,
- _("Copy to Folder"), NULL, _("C_opy"));
+ _("Copy to Folder"), _("C_opy"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
@@ -845,7 +845,7 @@ action_mail_move_cb (GtkAction *action,
dialog = em_folder_selector_new (
window, model,
- _("Move to Folder"), NULL, _("_Move"));
+ _("Move to Folder"), _("_Move"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 74aa09e..7cc8fa5 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -3030,20 +3030,21 @@ post_header_clicked_cb (EComposerPostHeader *header,
EMFolderTree *folder_tree;
GtkWidget *dialog;
GList *list;
+ const gchar *caption;
/* FIXME Limit the folder tree to the NNTP account? */
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
/* FIXME GTK_WINDOW (composer) */ NULL,
- model,
- _("Posting destination"),
- _("Choose folders to post the message to."),
- NULL);
+ model, _("Posting destination"), NULL);
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ caption = _("Choose folders to post the message to.");
+ em_folder_selector_set_caption (selector, caption);
+
folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (
diff --git a/mail/em-folder-selection-button.c b/mail/em-folder-selection-button.c
index 83d5a62..e95835b 100644
--- a/mail/em-folder-selection-button.c
+++ b/mail/em-folder-selection-button.c
@@ -270,13 +270,13 @@ folder_selection_button_clicked (GtkButton *button)
model = g_object_ref (em_folder_tree_model_get_default ());
dialog = em_folder_selector_new (
- parent, model,
- priv->title, priv->caption, NULL);
+ parent, model, priv->title, NULL);
g_object_unref (model);
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
+ em_folder_selector_set_caption (selector, priv->caption);
folder_tree = em_folder_selector_get_folder_tree (selector);
diff --git a/mail/em-folder-selector.c b/mail/em-folder-selector.c
index e5427d9..51a2f55 100644
--- a/mail/em-folder-selector.c
+++ b/mail/em-folder-selector.c
@@ -46,16 +46,19 @@ struct _EMFolderSelectorPrivate {
EMFolderTree *folder_tree; /* not referenced */
EMFolderTreeModel *model;
GtkWidget *alert_bar;
+ GtkWidget *caption_label;
GtkEntry *name_entry;
gchar *selected_uri;
gboolean can_create;
+ gchar *caption;
};
enum {
PROP_0,
PROP_CAN_CREATE,
+ PROP_CAPTION,
PROP_MODEL
};
@@ -94,6 +97,12 @@ folder_selector_set_property (GObject *object,
g_value_get_boolean (value));
return;
+ case PROP_CAPTION:
+ em_folder_selector_set_caption (
+ EM_FOLDER_SELECTOR (object),
+ g_value_get_string (value));
+ return;
+
case PROP_MODEL:
folder_selector_set_model (
EM_FOLDER_SELECTOR (object),
@@ -118,6 +127,13 @@ folder_selector_get_property (GObject *object,
EM_FOLDER_SELECTOR (object)));
return;
+ case PROP_CAPTION:
+ g_value_set_string (
+ value,
+ em_folder_selector_get_caption (
+ EM_FOLDER_SELECTOR (object)));
+ return;
+
case PROP_MODEL:
g_value_set_object (
value,
@@ -138,6 +154,7 @@ folder_selector_dispose (GObject *object)
g_clear_object (&priv->model);
g_clear_object (&priv->alert_bar);
+ g_clear_object (&priv->caption_label);
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (em_folder_selector_parent_class)->dispose (object);
@@ -151,6 +168,7 @@ folder_selector_finalize (GObject *object)
priv = EM_FOLDER_SELECTOR_GET_PRIVATE (object);
g_free (priv->selected_uri);
+ g_free (priv->caption);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (em_folder_selector_parent_class)->finalize (object);
@@ -247,6 +265,17 @@ em_folder_selector_class_init (EMFolderSelectorClass *class)
g_object_class_install_property (
object_class,
+ PROP_CAPTION,
+ g_param_spec_string (
+ "caption",
+ "Caption",
+ "Brief description above folder tree",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
PROP_MODEL,
g_param_spec_object (
"model",
@@ -319,7 +348,6 @@ folder_activated_cb (EMFolderTree *emft,
static GtkWidget *
folder_selector_construct (EMFolderSelector *selector,
- const gchar *text,
const gchar *oklabel)
{
EMailSession *session;
@@ -395,13 +423,18 @@ folder_selector_construct (EMFolderSelector *selector,
container = vbox;
- if (text != NULL) {
- widget = gtk_label_new (text);
- gtk_widget_set_margin_top (widget, 6);
- gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_LEFT);
- gtk_box_pack_end (GTK_BOX (container), widget, FALSE, TRUE, 0);
- gtk_widget_show (widget);
- }
+ /* This can be made visible by setting the "caption" property. */
+ widget = gtk_label_new (NULL);
+ gtk_widget_set_margin_top (widget, 6);
+ gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_LEFT);
+ gtk_box_pack_end (GTK_BOX (container), widget, FALSE, TRUE, 0);
+ selector->priv->caption_label = g_object_ref (widget);
+ gtk_widget_hide (widget);
+
+ g_object_bind_property (
+ selector, "caption",
+ widget, "label",
+ G_BINDING_DEFAULT);
gtk_widget_grab_focus (GTK_WIDGET (selector->priv->folder_tree));
@@ -412,7 +445,6 @@ GtkWidget *
em_folder_selector_new (GtkWindow *parent,
EMFolderTreeModel *model,
const gchar *title,
- const gchar *text,
const gchar *oklabel)
{
EMFolderSelector *selector;
@@ -424,7 +456,7 @@ em_folder_selector_new (GtkWindow *parent,
"transient-for", parent,
"title", title,
"model", model, NULL);
- folder_selector_construct (selector, text, oklabel);
+ folder_selector_construct (selector, oklabel);
return GTK_WIDGET (selector);
}
@@ -461,8 +493,7 @@ folder_selector_create_name_activate (GtkEntry *entry,
GtkWidget *
em_folder_selector_create_new (GtkWindow *parent,
EMFolderTreeModel *model,
- const gchar *title,
- const gchar *text)
+ const gchar *title)
{
EMFolderSelector *selector;
EMFolderTree *folder_tree;
@@ -478,8 +509,7 @@ em_folder_selector_create_new (GtkWindow *parent,
"title", title,
"model", model, NULL);
- container = folder_selector_construct (
- selector, text, _("C_reate"));
+ container = folder_selector_construct (selector, _("C_reate"));
folder_tree = em_folder_selector_get_folder_tree (selector);
em_folder_tree_set_excluded (folder_tree, EMFT_EXCLUDE_NOINFERIORS);
@@ -554,6 +584,53 @@ em_folder_selector_set_can_create (EMFolderSelector *selector,
g_object_notify (G_OBJECT (selector), "can-create");
}
+/**
+ * em_folder_selector_get_caption:
+ * @selector: an #EMFolderSelector
+ *
+ * Returns the folder tree caption, which is an optional brief message
+ * instructing the user what to do. If no caption has been set, the
+ * function returns %NULL.
+ *
+ * Returns: the folder tree caption, or %NULL
+ **/
+const gchar *
+em_folder_selector_get_caption (EMFolderSelector *selector)
+{
+ g_return_val_if_fail (EM_IS_FOLDER_SELECTOR (selector), NULL);
+
+ return selector->priv->caption;
+}
+
+/**
+ * em_folder_selector_set_caption:
+ * @selector: an #EMFolderSelector
+ * @caption: the folder tree caption, or %NULL
+ *
+ * Sets the folder tree caption, which is an optional brief message
+ * instructing the user what to do. If @caption is %NULL or empty,
+ * the label widget is hidden so as not to waste vertical space.
+ **/
+void
+em_folder_selector_set_caption (EMFolderSelector *selector,
+ const gchar *caption)
+{
+ gboolean visible;
+
+ g_return_if_fail (EM_IS_FOLDER_SELECTOR (selector));
+
+ if (g_strcmp0 (caption, selector->priv->caption) == 0)
+ return;
+
+ g_free (selector->priv->caption);
+ selector->priv->caption = e_util_strdup_strip (caption);
+
+ visible = (selector->priv->caption != NULL);
+ gtk_widget_set_visible (selector->priv->caption_label, visible);
+
+ g_object_notify (G_OBJECT (selector), "caption");
+}
+
EMFolderTreeModel *
em_folder_selector_get_model (EMFolderSelector *selector)
{
diff --git a/mail/em-folder-selector.h b/mail/em-folder-selector.h
index 57351b6..a06572c 100644
--- a/mail/em-folder-selector.h
+++ b/mail/em-folder-selector.h
@@ -64,17 +64,18 @@ GType em_folder_selector_get_type (void);
GtkWidget * em_folder_selector_new (GtkWindow *parent,
EMFolderTreeModel *model,
const gchar *title,
- const gchar *text,
const gchar *oklabel);
GtkWidget * em_folder_selector_create_new (GtkWindow *parent,
EMFolderTreeModel *model,
- const gchar *title,
- const gchar *text);
+ const gchar *title);
gboolean em_folder_selector_get_can_create
(EMFolderSelector *selector);
void em_folder_selector_set_can_create
(EMFolderSelector *selector,
gboolean can_create);
+const gchar * em_folder_selector_get_caption (EMFolderSelector *selector);
+void em_folder_selector_set_caption (EMFolderSelector *selector,
+ const gchar *caption);
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 40db12b..0eea5fe 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -507,9 +507,7 @@ em_folder_utils_copy_folder (GtkWindow *parent,
model = em_folder_tree_model_get_default ();
- dialog = em_folder_selector_new (
- parent, model,
- title, NULL, label);
+ dialog = em_folder_selector_new (parent, model, title, label);
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
@@ -573,6 +571,7 @@ em_folder_utils_create_folder (GtkWindow *parent,
CamelStore *store = NULL;
GtkWidget *dialog;
GQueue queue = G_QUEUE_INIT;
+ const gchar *caption;
const gchar *folder_uri;
gchar *folder_name = NULL;
GError *error = NULL;
@@ -601,13 +600,15 @@ em_folder_utils_create_folder (GtkWindow *parent,
}
dialog = em_folder_selector_create_new (
- parent, model,
- _("Create Folder"),
- _("Specify where to create the folder:"));
+ parent, model, _("Create Folder"));
g_object_unref (model);
selector = EM_FOLDER_SELECTOR (dialog);
+
+ caption = _("Specify where to create the folder:");
+ em_folder_selector_set_caption (selector, caption);
+
folder_tree = em_folder_selector_get_folder_tree (selector);
if (initial_uri != NULL)
diff --git a/mail/em-vfolder-editor-rule.c b/mail/em-vfolder-editor-rule.c
index 6df9df8..8eac42d 100644
--- a/mail/em-vfolder-editor-rule.c
+++ b/mail/em-vfolder-editor-rule.c
@@ -388,8 +388,7 @@ source_add (GtkWidget *widget,
model = em_folder_tree_model_get_default ();
dialog = em_folder_selector_new (
- parent, model,
- _("Add Folder"), NULL, _("_Add"));
+ parent, model, _("Add Folder"), _("_Add"));
selector = EM_FOLDER_SELECTOR (dialog);
em_folder_selector_set_can_create (selector, TRUE);
diff --git a/modules/mail/em-composer-prefs.c b/modules/mail/em-composer-prefs.c
index 96c3c60..4d852d8 100644
--- a/modules/mail/em-composer-prefs.c
+++ b/modules/mail/em-composer-prefs.c
@@ -440,7 +440,7 @@ sao_folders_add_button_clicked_cb (GtkButton *button,
dialog = em_folder_selector_new (
window, em_folder_tree_model_get_default (),
- _("Select Folder to Add"), NULL, _("_Add"));
+ _("Select Folder to Add"), _("_Add"));
selector = EM_FOLDER_SELECTOR (dialog);
folder_tree = em_folder_selector_get_folder_tree (selector);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]