[evolution] Bug #320976 - Remember last New button choice in Calendar view
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug #320976 - Remember last New button choice in Calendar view
- Date: Thu, 16 Feb 2012 16:23:20 +0000 (UTC)
commit 83d001baa23d3cce1d983dbc7946a7c5375c05f2
Author: Milan Crha <mcrha redhat com>
Date: Thu Feb 16 17:22:28 2012 +0100
Bug #320976 - Remember last New button choice in Calendar view
calendar/gui/calendar-config.c | 19 +++
calendar/gui/calendar-config.h | 2 +
calendar/gui/e-day-view.c | 6 +-
calendar/gui/e-week-view.c | 3 +-
data/org.gnome.evolution.calendar.gschema.xml.in | 5 +
modules/calendar/e-cal-shell-backend.c | 14 ++-
modules/calendar/e-cal-shell-settings.c | 5 +
shell/e-shell-backend.c | 93 ++++++++++++++-
shell/e-shell-backend.h | 5 +
shell/e-shell-window.c | 103 ++++++++++++++++
shell/e-shell-window.h | 5 +
widgets/misc/e-menu-tool-button.c | 139 +++++++++++++++++++++-
widgets/misc/e-menu-tool-button.h | 9 +-
13 files changed, 395 insertions(+), 13 deletions(-)
---
diff --git a/calendar/gui/calendar-config.c b/calendar/gui/calendar-config.c
index 3943154..e293a6e 100644
--- a/calendar/gui/calendar-config.c
+++ b/calendar/gui/calendar-config.c
@@ -434,3 +434,22 @@ calendar_config_add_notification_day_second_zone (CalendarConfigChangedFunc func
g_signal_connect (G_OBJECT (config), "changed::day-second-zone",
G_CALLBACK (func), data);
}
+
+gboolean
+calendar_config_get_prefer_meeting (void)
+{
+ EShell *shell;
+ EShellSettings *shell_settings;
+ gchar *prefer_new_item;
+ gboolean prefer_meeting;
+
+ shell = e_shell_get_default ();
+ shell_settings = e_shell_get_shell_settings (shell);
+
+ prefer_new_item = e_shell_settings_get_string (shell_settings, "cal-prefer-new-item");
+ prefer_meeting = g_strcmp0 (prefer_new_item, "event-meeting-new") == 0;
+
+ g_free (prefer_new_item);
+
+ return prefer_meeting;
+}
diff --git a/calendar/gui/calendar-config.h b/calendar/gui/calendar-config.h
index 483fbbd..81f8534 100644
--- a/calendar/gui/calendar-config.h
+++ b/calendar/gui/calendar-config.h
@@ -90,4 +90,6 @@ void calendar_config_add_notification_day_second_zone (CalendarConfigChangedFu
gboolean calendar_config_get_month_scroll_by_week (void);
void calendar_config_add_notification_month_scroll_by_week (CalendarConfigChangedFunc func, gpointer data);
+gboolean calendar_config_get_prefer_meeting (void);
+
#endif /* _CALENDAR_CONFIG_H_ */
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index 8af5ffb..cb19db0 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -50,6 +50,7 @@
#include "dialogs/recur-comp.h"
#include "dialogs/goto-dialog.h"
#include "print.h"
+#include "calendar-config.h"
#include "comp-util.h"
#include "itip-utils.h"
#include "e-cal-model-calendar.h"
@@ -3073,9 +3074,10 @@ e_day_view_on_top_canvas_button_press (GtkWidget *widget,
dtend = day_view->before_click_dtend;
e_day_view_set_selected_time_range ((ECalendarView *) day_view, dtstart, dtend);
}
+
e_calendar_view_new_appointment_for (E_CALENDAR_VIEW (day_view),
dtstart, dtend,
- TRUE, FALSE);
+ TRUE, calendar_config_get_prefer_meeting ());
return TRUE;
}
@@ -3214,7 +3216,7 @@ e_day_view_on_main_canvas_button_press (GtkWidget *widget,
}
e_calendar_view_new_appointment_for (E_CALENDAR_VIEW (day_view),
dtstart, dtend,
- FALSE, FALSE);
+ FALSE, calendar_config_get_prefer_meeting ());
return TRUE;
}
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 4b2eeb0..45917c1 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -48,6 +48,7 @@
#include "dialogs/cancel-comp.h"
#include "dialogs/recur-comp.h"
#include "dialogs/goto-dialog.h"
+#include "calendar-config.h"
#include "comp-util.h"
#include "itip-utils.h"
#include <libecal/e-cal-time-util.h>
@@ -2417,7 +2418,7 @@ e_week_view_on_button_press (GtkWidget *widget,
if (dtstart < week_view->before_click_dtend && dtend > week_view->before_click_dtstart) {
e_week_view_set_selected_time_range ((ECalendarView *) week_view, week_view->before_click_dtstart, week_view->before_click_dtend);
}
- e_calendar_view_new_appointment_full (E_CALENDAR_VIEW (week_view), FALSE, FALSE, FALSE);
+ e_calendar_view_new_appointment_full (E_CALENDAR_VIEW (week_view), FALSE, FALSE, calendar_config_get_prefer_meeting ());
return TRUE;
}
diff --git a/data/org.gnome.evolution.calendar.gschema.xml.in b/data/org.gnome.evolution.calendar.gschema.xml.in
index f1c9385..cc66fbb 100644
--- a/data/org.gnome.evolution.calendar.gschema.xml.in
+++ b/data/org.gnome.evolution.calendar.gschema.xml.in
@@ -185,6 +185,11 @@
<_summary>Show display reminders in notification tray</_summary>
<_description>Whether or not to use the notification tray for display reminders</_description>
</key>
+ <key name="prefer-new-item" type="s">
+ <default>''</default>
+ <_summary>Preferred New button item</_summary>
+ <_description>Name of the preferred New toolbar button item</_description>
+ </key>
<key name="primary-calendar" type="s">
<default>''</default>
<_summary>Primary calendar</_summary>
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index f13cc2d..f940070 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -357,6 +357,8 @@ action_event_new_cb (GtkAction *action,
const gchar *action_name;
gchar *uid;
+ action_name = gtk_action_get_name (action);
+
/* With a 'calendar' active shell view pass the new appointment
* request to it, thus the event will inherit selected time from
* the view. */
@@ -367,6 +369,7 @@ action_event_new_cb (GtkAction *action,
GnomeCalendarViewType view_type;
ECalendarView *view;
+ shell_backend = e_shell_view_get_shell_backend (shell_view);
shell_content = e_shell_view_get_shell_content (shell_view);
gcal = e_cal_shell_content_get_calendar (
@@ -376,7 +379,7 @@ action_event_new_cb (GtkAction *action,
view = gnome_calendar_get_calendar_view (gcal, view_type);
if (view) {
- action_name = gtk_action_get_name (action);
+ g_object_set (G_OBJECT (shell_backend), "prefer-new-item", action_name, NULL);
e_calendar_view_new_appointment_full (
view,
@@ -412,9 +415,10 @@ action_event_new_cb (GtkAction *action,
g_return_if_fail (E_IS_SOURCE (source));
+ g_object_set (G_OBJECT (shell_backend), "prefer-new-item", action_name, NULL);
+
/* Use a callback function appropriate for the action.
* FIXME Need to obtain a better default time zone. */
- action_name = gtk_action_get_name (action);
if (strcmp (action_name, "event-all-day-new") == 0)
e_client_utils_open_new (source, source_type, FALSE, NULL,
e_client_utils_authenticate_handler, GTK_WINDOW (shell_window),
@@ -796,6 +800,12 @@ cal_shell_backend_constructed (GObject *object)
e_calendar_preferences_new,
600);
+ g_object_bind_property (
+ e_shell_get_shell_settings (shell), "cal-prefer-new-item",
+ shell_backend, "prefer-new-item",
+ G_BINDING_BIDIRECTIONAL |
+ G_BINDING_SYNC_CREATE);
+
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_cal_shell_backend_parent_class)->constructed (object);
}
diff --git a/modules/calendar/e-cal-shell-settings.c b/modules/calendar/e-cal-shell-settings.c
index 9810d81..0c77063 100644
--- a/modules/calendar/e-cal-shell-settings.c
+++ b/modules/calendar/e-cal-shell-settings.c
@@ -714,6 +714,11 @@ e_cal_shell_backend_init_settings (EShell *shell)
CALENDAR_SCHEMA,
"working-days");
+ e_shell_settings_install_property_for_key (
+ "cal-prefer-new-item",
+ CALENDAR_SCHEMA,
+ "prefer-new-item");
+
/* These properties use transform functions to convert
* GConf values to forms more useful to Evolution. We
* have to use separate properties because GConfBridge
diff --git a/shell/e-shell-backend.c b/shell/e-shell-backend.c
index fed85cd..f4baca7 100644
--- a/shell/e-shell-backend.c
+++ b/shell/e-shell-backend.c
@@ -58,13 +58,15 @@ struct _EShellBackendPrivate {
gchar *config_dir;
gchar *data_dir;
+ gchar *prefer_new_item;
guint started : 1;
};
enum {
PROP_0,
- PROP_BUSY
+ PROP_BUSY,
+ PROP_PREFER_NEW_ITEM
};
enum {
@@ -164,6 +166,30 @@ shell_backend_get_property (GObject *object,
value, e_shell_backend_is_busy (
E_SHELL_BACKEND (object)));
return;
+
+ case PROP_PREFER_NEW_ITEM:
+ g_value_set_string (
+ value,
+ e_shell_backend_get_prefer_new_item (
+ E_SHELL_BACKEND (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+shell_backend_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PREFER_NEW_ITEM:
+ e_shell_backend_set_prefer_new_item (
+ E_SHELL_BACKEND (object),
+ g_value_get_string (value));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -181,6 +207,11 @@ shell_backend_dispose (GObject *object)
priv->shell_view_class = NULL;
}
+ if (priv->prefer_new_item) {
+ g_free (priv->prefer_new_item);
+ priv->prefer_new_item = NULL;
+ }
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_shell_backend_parent_class)->dispose (object);
}
@@ -253,6 +284,7 @@ e_shell_backend_class_init (EShellBackendClass *class)
object_class = G_OBJECT_CLASS (class);
object_class->constructor = shell_backend_constructor;
object_class->get_property = shell_backend_get_property;
+ object_class->set_property = shell_backend_set_property;
object_class->dispose = shell_backend_dispose;
object_class->finalize = shell_backend_finalize;
@@ -278,6 +310,21 @@ e_shell_backend_class_init (EShellBackendClass *class)
G_PARAM_READABLE));
/**
+ * EShellBackend:prefer-new-item
+ *
+ * Name of an item to prefer in New toolbar button; can be NULL
+ **/
+ g_object_class_install_property (
+ object_class,
+ PROP_PREFER_NEW_ITEM,
+ g_param_spec_string (
+ "prefer-new-item",
+ "Prefer New Item",
+ "Name of an item to prefer in New toolbar button",
+ NULL,
+ G_PARAM_READWRITE));
+
+ /**
* EShellBackend::activity-added
* @shell_backend: the #EShellBackend that emitted the signal
* @activity: an #EActivity
@@ -455,6 +502,50 @@ e_shell_backend_is_busy (EShellBackend *shell_backend)
}
/**
+ * e_shell_backend_set_prefer_new_item:
+ * @shell_backend: an #EShellBackend
+ * @prefer_new_item: name of an item
+ *
+ * Sets name of a preferred item in New toolbar button. Use %NULL or
+ * an empty string for no preference.
+ *
+ * Since: 3.4
+ **/
+void
+e_shell_backend_set_prefer_new_item (EShellBackend *shell_backend,
+ const gchar *prefer_new_item)
+{
+ g_return_if_fail (shell_backend != NULL);
+ g_return_if_fail (E_IS_SHELL_BACKEND (shell_backend));
+
+ if (g_strcmp0 (shell_backend->priv->prefer_new_item, prefer_new_item) == 0)
+ return;
+
+ g_free (shell_backend->priv->prefer_new_item);
+ shell_backend->priv->prefer_new_item = g_strdup (prefer_new_item);
+
+ g_object_notify (G_OBJECT (shell_backend), "prefer-new-item");
+}
+
+/**
+ * e_shell_backend_get_prefer_new_item:
+ * @shell_backend: an #EShellBackend
+ *
+ * Returns: Name of a preferred item in New toolbar button, %NULL or
+ * an empty string for no preference.
+ *
+ * Since: 3.4
+ **/
+const gchar *
+e_shell_backend_get_prefer_new_item (EShellBackend *shell_backend)
+{
+ g_return_val_if_fail (shell_backend != NULL, NULL);
+ g_return_val_if_fail (E_IS_SHELL_BACKEND (shell_backend), NULL);
+
+ return shell_backend->priv->prefer_new_item;
+}
+
+/**
* e_shell_backend_cancel_all:
* @shell_backend: an #EShellBackend
*
diff --git a/shell/e-shell-backend.h b/shell/e-shell-backend.h
index ae600ba..759a3bd 100644
--- a/shell/e-shell-backend.h
+++ b/shell/e-shell-backend.h
@@ -126,6 +126,11 @@ struct _EShell *e_shell_backend_get_shell (EShellBackend *shell_backend);
void e_shell_backend_add_activity (EShellBackend *shell_backend,
EActivity *activity);
gboolean e_shell_backend_is_busy (EShellBackend *shell_backend);
+void e_shell_backend_set_prefer_new_item
+ (EShellBackend *shell_backend,
+ const gchar *prefer_new_item);
+const gchar * e_shell_backend_get_prefer_new_item
+ (EShellBackend *shell_backend);
void e_shell_backend_cancel_all (EShellBackend *shell_backend);
void e_shell_backend_start (EShellBackend *shell_backend);
gboolean e_shell_backend_is_started (EShellBackend *shell_backend);
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
index 19178f8..a8b44e6 100644
--- a/shell/e-shell-window.c
+++ b/shell/e-shell-window.c
@@ -81,6 +81,10 @@ shell_window_menubar_update_new_menu (EShellWindow *shell_window)
gtk_widget_show (widget);
}
+static void shell_window_backend_prefer_item_changed_cb (EShellBackend *backend,
+ GParamSpec *pspec,
+ EShellWindow *shell_window);
+
static void
shell_window_toolbar_update_new_menu (EShellWindow *shell_window,
GParamSpec *pspec,
@@ -91,6 +95,44 @@ shell_window_toolbar_update_new_menu (EShellWindow *shell_window,
/* Update the "New" menu tool button submenu. */
menu = e_shell_window_create_new_menu (shell_window);
gtk_menu_tool_button_set_menu (menu_tool_button, menu);
+
+ if (pspec && g_strcmp0 (pspec->name, "active-view") == 0) {
+ EShellView *shell_view;
+ EShellBackend *shell_backend;
+
+ shell_view = e_shell_window_peek_shell_view (shell_window,
+ e_shell_window_get_active_view (shell_window));
+ g_return_if_fail (shell_view != NULL);
+
+ shell_backend = e_shell_view_get_shell_backend (shell_view);
+
+ g_signal_handlers_disconnect_by_func (shell_backend,
+ shell_window_backend_prefer_item_changed_cb, shell_window);
+ g_signal_connect (shell_backend, "notify::prefer-new-item",
+ G_CALLBACK (shell_window_backend_prefer_item_changed_cb), shell_window);
+
+ shell_window_backend_prefer_item_changed_cb (shell_backend, NULL, shell_window);
+ }
+}
+
+static void
+shell_window_backend_prefer_item_changed_cb (EShellBackend *backend,
+ GParamSpec *pspec,
+ EShellWindow *shell_window)
+{
+ EShellView *shell_view;
+ EShellBackend *shell_backend;
+
+ shell_view = e_shell_window_peek_shell_view (shell_window,
+ e_shell_window_get_active_view (shell_window));
+ g_return_if_fail (shell_view != NULL);
+
+ shell_backend = e_shell_view_get_shell_backend (shell_view);
+ if (shell_backend != backend)
+ return;
+
+ e_shell_window_set_toolbar_new_prefer_item (shell_window,
+ e_shell_backend_get_prefer_new_item (shell_backend));
}
static void
@@ -456,6 +498,11 @@ shell_window_construct_toolbar (EShellWindow *shell_window)
G_CALLBACK (shell_window_toolbar_update_new_menu),
GTK_MENU_TOOL_BUTTON (item));
+ g_signal_connect_swapped (
+ item, "notify::prefer-item",
+ G_CALLBACK (shell_window_toolbar_update_new_menu),
+ shell_window);
+
gtk_box_pack_start (GTK_BOX (box), toolbar, TRUE, TRUE, 0);
toolbar = e_shell_window_get_managed_widget (
@@ -1503,6 +1550,62 @@ e_shell_window_set_toolbar_visible (EShellWindow *shell_window,
}
/**
+ * e_shell_window_set_toolbar_new_prefer_item:
+ * @shell_window: an #EShellWindow
+ * @prefer_item: prefer-item name to be set
+ *
+ * Sets prefer item on the New button for current view.
+ *
+ * Since: 3.4
+ **/
+void
+e_shell_window_set_toolbar_new_prefer_item (EShellWindow *shell_window,
+ const gchar *prefer_item)
+{
+ GtkWidget *toolbar;
+ GtkToolItem *item;
+
+ g_return_if_fail (shell_window != NULL);
+ g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
+
+ toolbar = e_shell_window_get_managed_widget (shell_window, "/main-toolbar");
+ g_return_if_fail (toolbar != NULL);
+
+ item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0);
+ g_return_if_fail (item != NULL);
+ g_return_if_fail (E_IS_MENU_TOOL_BUTTON (item));
+
+ e_menu_tool_button_set_prefer_item (E_MENU_TOOL_BUTTON (item), prefer_item);
+}
+
+/**
+ * e_shell_window_get_toolbar_new_prefer_item:
+ * @shell_window: an #EShellWindow
+ *
+ * Returns: name of preferred item on the New button for current view.
+ *
+ * Since: 3.4
+ **/
+const gchar *
+e_shell_window_get_toolbar_new_prefer_item (EShellWindow *shell_window)
+{
+ GtkWidget *toolbar;
+ GtkToolItem *item;
+
+ g_return_val_if_fail (shell_window != NULL, NULL);
+ g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL);
+
+ toolbar = e_shell_window_get_managed_widget (shell_window, "/main-toolbar");
+ g_return_val_if_fail (toolbar != NULL, NULL);
+
+ item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0);
+ g_return_val_if_fail (item != NULL, NULL);
+ g_return_val_if_fail (E_IS_MENU_TOOL_BUTTON (item), NULL);
+
+ return e_menu_tool_button_get_prefer_item (E_MENU_TOOL_BUTTON (item));
+}
+
+/**
* e_shell_window_register_new_item_actions:
* @shell_window: an #EShellWindow
* @backend_name: name of an #EShellBackend
diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h
index 25e039a..366a218 100644
--- a/shell/e-shell-window.h
+++ b/shell/e-shell-window.h
@@ -135,6 +135,11 @@ gboolean e_shell_window_get_toolbar_visible
void e_shell_window_set_toolbar_visible
(EShellWindow *shell_window,
gboolean toolbar_visible);
+void e_shell_window_set_toolbar_new_prefer_item
+ (EShellWindow *shell_window,
+ const gchar *prefer_item);
+const gchar * e_shell_window_get_toolbar_new_prefer_item
+ (EShellWindow *shell_window);
/* These should be called from the shell backend's window_created() handler. */
diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c
index 0c5ef95..5a052a1 100644
--- a/widgets/misc/e-menu-tool-button.c
+++ b/widgets/misc/e-menu-tool-button.c
@@ -25,6 +25,16 @@
#include "e-menu-tool-button.h"
+enum {
+ PROP_0,
+ PROP_PREFER_ITEM
+};
+
+struct _EMenuToolButtonPrivate
+{
+ gchar *prefer_item;
+};
+
G_DEFINE_TYPE (
EMenuToolButton,
e_menu_tool_button,
@@ -48,11 +58,12 @@ menu_tool_button_clone_image (GtkWidget *source)
}
static GtkMenuItem *
-menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button)
+menu_tool_button_get_prefer_menu_item (GtkMenuToolButton *menu_tool_button)
{
GtkWidget *menu;
- GtkMenuItem *item;
+ GtkMenuItem *item = NULL;
GList *children;
+ const gchar *prefer_item;
menu = gtk_menu_tool_button_get_menu (menu_tool_button);
if (!GTK_IS_MENU (menu))
@@ -62,7 +73,29 @@ menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button)
if (children == NULL)
return NULL;
- item = GTK_MENU_ITEM (children->data);
+ prefer_item = e_menu_tool_button_get_prefer_item (E_MENU_TOOL_BUTTON (menu_tool_button));
+ if (prefer_item && *prefer_item) {
+ GtkAction *action;
+ GList *iter;
+
+ for (iter = children; iter != NULL; iter = iter->next) {
+ item = GTK_MENU_ITEM (iter->data);
+
+ if (!item)
+ continue;
+
+ action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
+ if (action && g_strcmp0 (gtk_action_get_name (action), prefer_item) == 0)
+ break;
+ else if (!action && g_strcmp0 (gtk_widget_get_name (GTK_WIDGET (item)), prefer_item) == 0)
+ break;
+
+ item = NULL;
+ }
+ }
+
+ if (!item)
+ item = GTK_MENU_ITEM (children->data);
g_list_free (children);
@@ -80,7 +113,7 @@ menu_tool_button_update_button (GtkToolButton *tool_button)
gchar *tooltip = NULL;
menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button);
- menu_item = menu_tool_button_get_first_menu_item (menu_tool_button);
+ menu_item = menu_tool_button_get_prefer_menu_item (menu_tool_button);
if (!GTK_IS_IMAGE_MENU_ITEM (menu_item))
return;
@@ -110,24 +143,95 @@ menu_tool_button_clicked (GtkToolButton *tool_button)
GtkMenuToolButton *menu_tool_button;
menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button);
- menu_item = menu_tool_button_get_first_menu_item (menu_tool_button);
+ menu_item = menu_tool_button_get_prefer_menu_item (menu_tool_button);
if (GTK_IS_MENU_ITEM (menu_item))
gtk_menu_item_activate (menu_item);
}
static void
+menu_tool_button_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PREFER_ITEM:
+ e_menu_tool_button_set_prefer_item (
+ E_MENU_TOOL_BUTTON (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+menu_tool_button_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_PREFER_ITEM:
+ g_value_set_string (
+ value, e_menu_tool_button_get_prefer_item (
+ E_MENU_TOOL_BUTTON (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+menu_tool_button_dispose (GObject *object)
+{
+ EMenuToolButtonPrivate *priv = E_MENU_TOOL_BUTTON (object)->priv;
+
+ if (priv->prefer_item) {
+ g_free (priv->prefer_item);
+ priv->prefer_item = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_menu_tool_button_parent_class)->dispose (object);
+}
+
+static void
e_menu_tool_button_class_init (EMenuToolButtonClass *class)
{
+ GObjectClass *object_class;
GtkToolButtonClass *tool_button_class;
+ g_type_class_add_private (class, sizeof (EMenuToolButtonPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = menu_tool_button_set_property;
+ object_class->get_property = menu_tool_button_get_property;
+ object_class->dispose = menu_tool_button_dispose;
+
tool_button_class = GTK_TOOL_BUTTON_CLASS (class);
tool_button_class->clicked = menu_tool_button_clicked;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_PREFER_ITEM,
+ g_param_spec_string (
+ "prefer-item",
+ "Prefer Item",
+ "Name of an item to show instead of the first",
+ NULL,
+ G_PARAM_READWRITE));
}
static void
e_menu_tool_button_init (EMenuToolButton *button)
{
+ button->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+ button, E_TYPE_MENU_TOOL_BUTTON, EMenuToolButtonPrivate);
+
+ button->priv->prefer_item = NULL;
+
g_signal_connect (
button, "notify::menu",
G_CALLBACK (menu_tool_button_update_button), NULL);
@@ -138,3 +242,28 @@ e_menu_tool_button_new (const gchar *label)
{
return g_object_new (E_TYPE_MENU_TOOL_BUTTON, "label", label, NULL);
}
+
+void
+e_menu_tool_button_set_prefer_item (EMenuToolButton *button,
+ const gchar *prefer_item)
+{
+ g_return_if_fail (button != NULL);
+ g_return_if_fail (E_IS_MENU_TOOL_BUTTON (button));
+
+ if (g_strcmp0 (button->priv->prefer_item, prefer_item) == 0)
+ return;
+
+ g_free (button->priv->prefer_item);
+ button->priv->prefer_item = g_strdup (prefer_item);
+
+ g_object_notify (G_OBJECT (button), "prefer-item");
+}
+
+const gchar *
+e_menu_tool_button_get_prefer_item (EMenuToolButton *button)
+{
+ g_return_val_if_fail (button != NULL, NULL);
+ g_return_val_if_fail (E_IS_MENU_TOOL_BUTTON (button), NULL);
+
+ return button->priv->prefer_item;
+}
diff --git a/widgets/misc/e-menu-tool-button.h b/widgets/misc/e-menu-tool-button.h
index 214f5ab..803ec8f 100644
--- a/widgets/misc/e-menu-tool-button.h
+++ b/widgets/misc/e-menu-tool-button.h
@@ -50,18 +50,23 @@
G_BEGIN_DECLS
typedef struct _EMenuToolButton EMenuToolButton;
+typedef struct _EMenuToolButtonPrivate EMenuToolButtonPrivate;
typedef struct _EMenuToolButtonClass EMenuToolButtonClass;
struct _EMenuToolButton {
GtkMenuToolButton parent;
+ EMenuToolButtonPrivate *priv;
};
struct _EMenuToolButtonClass {
GtkMenuToolButtonClass parent_class;
};
-GType e_menu_tool_button_get_type (void);
-GtkToolItem * e_menu_tool_button_new (const gchar *label);
+GType e_menu_tool_button_get_type (void);
+GtkToolItem * e_menu_tool_button_new (const gchar *label);
+void e_menu_tool_button_set_prefer_item (EMenuToolButton *button,
+ const gchar *prefer_item);
+const gchar * e_menu_tool_button_get_prefer_item (EMenuToolButton *button);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]