From a718dec073135b0dac15e0f36e9a7ac6b9b9ddfa Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Thu, 1 Jun 2000 00:56:00 +0000 Subject: Implemented right-click menus for the shell's shortcut bar (the user can remove shortcuts now) and added status bar to the shell view. Also, added an API call to EShortcutBar to get the view type for a specified group. svn path=/trunk/; revision=3318 --- shell/ChangeLog | 32 ++++++ shell/e-shell-view.c | 23 +++- shell/e-shell-view.h | 1 + shell/e-shortcuts-view.c | 199 +++++++++++++++++++++++++++++++++- shell/e-shortcuts.c | 76 ++++++++++++- shell/e-shortcuts.h | 9 +- widgets/shortcut-bar/ChangeLog | 4 + widgets/shortcut-bar/e-shortcut-bar.c | 17 +++ widgets/shortcut-bar/e-shortcut-bar.h | 52 ++++----- 9 files changed, 375 insertions(+), 38 deletions(-) diff --git a/shell/ChangeLog b/shell/ChangeLog index 5b5eef1e1e..2be202631e 100644 --- a/shell/ChangeLog +++ b/shell/ChangeLog @@ -1,3 +1,35 @@ +2000-06-01 Ettore Perazzoli + + * e-shell-view-menu.c (e_shell_view_menu_setup): Set the + statusbar. + + * e-shell-view.c: New member `appbar' for `EShellViewPrivate'. + (init): Initialize to NULL. + (setup_widgets): Install a status bar and set `appbar' to point to + it. + (setup_bonobo_ui_handler): Make the BonoboUIHandler use `appbar' + as its statusbar. + (e_shell_view_get_appbar): New function. + (e_shell_view_construct): Set up the BonoboUIHandler after setting + up the widgets. + + * e-shortcuts.c (class_init): Add new signals "new_shortcut", + "removed_shortcut", "new_group", "removed_group". + (e_shortcuts_remove_shortcut): Emit "remove_shortcut". + (e_shortcuts_add_shortcut): Emit "new_shortcut". + (e_shortcuts_remove_group): Emit "remove_group". + (e_shortcuts_add_group): Emit "new_group". + (unload_shortcuts): Emit "remove_group" for all the groups. + + * e-shortcuts.h: New signals "new_shortcut", "removed_shortcut", + "new_group", "removed_group". + + * e-shortcuts-view.c (pop_up_right_click_menu): New function to + pop up the right-click menu for the shortcut bar. + (pop_up_right_click_menu_for_shortcut): New function. + (selected_item): Pop up right click menu when appropriate. Don't + activate the shortcut when right-clicking. + 2000-05-31 Ettore Perazzoli * evolution-storage.h: #include 'Evolution.h". diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 0157b72b0b..a003f10c8f 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -63,6 +63,7 @@ struct _EShellViewPrivate { char *uri; /* The widgetry. */ + GtkWidget *appbar; GtkWidget *hpaned; GtkWidget *view_vbox; GtkWidget *view_title_bar; @@ -227,6 +228,11 @@ setup_widgets (EShellView *shell_view) priv = shell_view->priv; + /* The application bar. */ + + priv->appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_NEVER); + gnome_app_set_statusbar (GNOME_APP (shell_view), priv->appbar); + /* The shortcut bar. */ priv->shortcut_bar = e_shortcuts_new_view (e_shell_get_shortcuts (priv->shell)); @@ -304,6 +310,7 @@ setup_bonobo_ui_handler (EShellView *shell_view) bonobo_ui_handler_set_app (uih, GNOME_APP (shell_view)); bonobo_ui_handler_create_menubar (uih); + bonobo_ui_handler_set_statusbar (uih, priv->appbar); priv->uih = uih; } @@ -386,6 +393,7 @@ init (EShellView *shell_view) priv->uih = NULL; priv->uri = NULL; + priv->appbar = NULL; priv->hpaned = NULL; priv->view_hpaned = NULL; priv->contents = NULL; @@ -417,15 +425,15 @@ e_shell_view_construct (EShellView *shell_view, g_return_if_fail (shell != NULL); g_return_if_fail (E_IS_SHELL (shell)); - gnome_app_construct (GNOME_APP (shell_view), "evolution", "Evolution"); - priv = shell_view->priv; + gnome_app_construct (GNOME_APP (shell_view), "evolution", "Evolution"); + gtk_object_ref (GTK_OBJECT (shell)); priv->shell = shell; - setup_bonobo_ui_handler (shell_view); setup_widgets (shell_view); + setup_bonobo_ui_handler (shell_view); e_shell_view_menu_setup (shell_view); } @@ -944,5 +952,14 @@ e_shell_view_get_bonobo_ui_handler (EShellView *shell_view) return shell_view->priv->uih; } +GtkWidget * +e_shell_view_get_appbar (EShellView *shell_view) +{ + g_return_val_if_fail (shell_view != NULL, NULL); + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + + return shell_view->priv->appbar; +} + E_MAKE_TYPE (e_shell_view, "EShellView", EShellView, class_init, init, PARENT_TYPE) diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h index 5bc936a7bf..53ce8a59a7 100644 --- a/shell/e-shell-view.h +++ b/shell/e-shell-view.h @@ -88,6 +88,7 @@ EShellViewSubwindowMode e_shell_view_get_folder_bar_mode (EShellView EShell *e_shell_view_get_shell (EShellView *shell_view); BonoboUIHandler *e_shell_view_get_bonobo_ui_handler (EShellView *shell_view); +GtkWidget *e_shell_view_get_appbar (EShellView *shell_view); #ifdef __cplusplus } diff --git a/shell/e-shortcuts-view.c b/shell/e-shortcuts-view.c index 8e4bbea50c..e5184129f6 100644 --- a/shell/e-shortcuts-view.c +++ b/shell/e-shortcuts-view.c @@ -180,6 +180,182 @@ icon_callback (EShortcutBar *shortcut_bar, return pixbuf; } + +/* Shortcut bar right-click menu. */ + +struct _RightClickMenuData { + EShortcutsView *shortcuts_view; + int group_num; +}; +typedef struct _RightClickMenuData RightClickMenuData; + +static void +toggle_large_icons_cb (GtkWidget *widget, + void *data) +{ + RightClickMenuData *menu_data; + + g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (widget)); + + if (data == NULL) + return; + + menu_data = (RightClickMenuData *) data; + + if (! GTK_CHECK_MENU_ITEM (widget)->active) + return; + + e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (menu_data->shortcuts_view), + menu_data->group_num, + E_ICON_BAR_LARGE_ICONS); +} + +static void +toggle_small_icons_cb (GtkWidget *widget, + void *data) +{ + RightClickMenuData *menu_data; + + g_return_if_fail (GTK_IS_RADIO_MENU_ITEM (widget)); + + if (data == NULL) + return; + + menu_data = (RightClickMenuData *) data; + + if (! GTK_CHECK_MENU_ITEM (widget)->active) + return; + + e_shortcut_bar_set_view_type (E_SHORTCUT_BAR (menu_data->shortcuts_view), + menu_data->group_num, + E_ICON_BAR_SMALL_ICONS); +} + +static GnomeUIInfo icon_size_radio_group_uiinfo[] = { + { GNOME_APP_UI_ITEM, N_("_Small icons"), + N_("Show the shortcuts as small icons"), toggle_small_icons_cb, NULL, + NULL, 0, 0, 0, 0 }, + { GNOME_APP_UI_ITEM, N_("_Large icons"), + N_("Show the shortcuts as large icons"), toggle_large_icons_cb, NULL, + NULL, 0, 0, 0, 0 }, + + GNOMEUIINFO_END +}; + +static GnomeUIInfo right_click_menu_uiinfo[] = { + GNOMEUIINFO_RADIOLIST (icon_size_radio_group_uiinfo), + GNOMEUIINFO_END +}; + +static void +pop_up_right_click_menu_for_group (EShortcutsView *shortcuts_view, + GdkEventButton *event, + int group_num) +{ + RightClickMenuData *menu_data; + GtkWidget *popup_menu; + + menu_data = g_new (RightClickMenuData, 1); + menu_data->shortcuts_view = shortcuts_view; + menu_data->group_num = group_num; + + popup_menu = gnome_popup_menu_new (right_click_menu_uiinfo); + + if (e_shortcut_bar_get_view_type (E_SHORTCUT_BAR (shortcuts_view), group_num) + == E_ICON_BAR_SMALL_ICONS) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (icon_size_radio_group_uiinfo[0].widget), + TRUE); + else + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (icon_size_radio_group_uiinfo[1].widget), + TRUE); + + gnome_popup_menu_do_popup_modal (popup_menu, NULL, NULL, event, menu_data); + + g_free (menu_data); + gtk_widget_destroy (popup_menu); +} + + +/* Shortcut right-click menu. */ + +struct _ShortcutRightClickMenuData { + EShortcutsView *shortcuts_view; + int group_num; + int item_num; +}; +typedef struct _ShortcutRightClickMenuData ShortcutRightClickMenuData; + +static void +activate_shortcut_cb (GtkWidget *widget, + void *data) +{ + ShortcutRightClickMenuData *menu_data; + EShortcutsView *shortcuts_view; + EShortcuts *shortcuts; + const char *uri; + + menu_data = (ShortcutRightClickMenuData *) data; + shortcuts_view = menu_data->shortcuts_view; + shortcuts = shortcuts_view->priv->shortcuts; + + uri = e_shortcuts_get_uri (shortcuts, menu_data->group_num, menu_data->item_num); + if (uri == NULL) + return; + + gtk_signal_emit (GTK_OBJECT (shortcuts_view), signals[ACTIVATE_SHORTCUT], + shortcuts, uri); +} + +static void +remove_shortcut_cb (GtkWidget *widget, + void *data) +{ + ShortcutRightClickMenuData *menu_data; + EShortcutsView *shortcuts_view; + EShortcuts *shortcuts; + + menu_data = (ShortcutRightClickMenuData *) data; + shortcuts_view = menu_data->shortcuts_view; + shortcuts = shortcuts_view->priv->shortcuts; + + e_shortcuts_remove_shortcut (shortcuts, menu_data->group_num, menu_data->item_num); + + /* FIXME not real model-view. */ + e_shortcut_bar_remove_item (E_SHORTCUT_BAR (shortcuts_view), + menu_data->group_num, menu_data->item_num); +} + +static GnomeUIInfo shortcut_right_click_menu_uiinfo[] = { + GNOMEUIINFO_ITEM (N_("Activate"), N_("Activate this shortcut"), + activate_shortcut_cb, NULL), + GNOMEUIINFO_SEPARATOR, + GNOMEUIINFO_ITEM_STOCK (N_("Remove"), N_("Remove this shortcut from the shortcut bar"), + remove_shortcut_cb, GNOME_STOCK_MENU_CLOSE), + GNOMEUIINFO_END +}; + +static void +pop_up_right_click_menu_for_shortcut (EShortcutsView *shortcuts_view, + GdkEventButton *event, + int group_num, + int item_num) +{ + ShortcutRightClickMenuData *menu_data; + GtkWidget *popup_menu; + + menu_data = g_new (ShortcutRightClickMenuData, 1); + menu_data->shortcuts_view = shortcuts_view; + menu_data->group_num = group_num; + menu_data->item_num = item_num; + + popup_menu = gnome_popup_menu_new (shortcut_right_click_menu_uiinfo); + + gnome_popup_menu_do_popup_modal (popup_menu, NULL, NULL, event, menu_data); + + g_free (menu_data); + gtk_widget_destroy (popup_menu); +} + /* GtkObject methods. */ @@ -207,17 +383,32 @@ selected_item (EShortcutBar *shortcut_bar, int item_num) { EShortcuts *shortcuts; + EShortcutsView *shortcuts_view; const char *uri; - shortcuts = E_SHORTCUTS_VIEW (shortcut_bar)->priv->shortcuts; + shortcuts_view = E_SHORTCUTS_VIEW (shortcut_bar); + shortcuts = shortcuts_view->priv->shortcuts; - uri = e_shortcuts_get_uri (shortcuts, group_num, item_num); + if (event->button.button == 3) { + if (item_num < 0) + pop_up_right_click_menu_for_group (shortcuts_view, &event->button, + group_num); + else + pop_up_right_click_menu_for_shortcut (shortcuts_view, &event->button, + group_num, item_num); + return; + } else if (event->button.button != 1) { + return; + } - /* Lame EShortcutBar. This can happen. */ + if (item_num < 0) + return; + + uri = e_shortcuts_get_uri (shortcuts, group_num, item_num); if (uri == NULL) return; - gtk_signal_emit (GTK_OBJECT (shortcut_bar), signals[ACTIVATE_SHORTCUT], + gtk_signal_emit (GTK_OBJECT (shortcuts_view), signals[ACTIVATE_SHORTCUT], shortcuts, uri); } diff --git a/shell/e-shortcuts.c b/shell/e-shortcuts.c index 414e5d2da9..4d3b51cc13 100644 --- a/shell/e-shortcuts.c +++ b/shell/e-shortcuts.c @@ -100,36 +100,52 @@ struct _EShortcutsPrivate { GHashTable *title_to_group; }; +enum { + NEW_GROUP, + REMOVE_GROUP, + NEW_SHORTCUT, + REMOVE_SHORTCUT, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + static void unload_shortcuts (EShortcuts *shortcuts) { EShortcutsPrivate *priv; + GList *orig_groups; GList *p, *q; priv = shortcuts->priv; + orig_groups = priv->groups; for (p = priv->groups; p != NULL; p = p->next) { ShortcutGroup *group; + gtk_signal_emit (GTK_OBJECT (shortcuts), signals[REMOVE_GROUP], 0); + group = (ShortcutGroup *) p->data; - g_free (group->title); + + g_hash_table_remove (priv->title_to_group, group->title); for (q = group->shortcuts; q != NULL; q = q->next) g_free (q->data); + g_free (group->title); g_list_free (group->shortcuts); + + priv->groups = priv->groups->next; } - if (priv->groups != NULL) - g_list_free (priv->groups); + if (orig_groups != NULL) + g_list_free (orig_groups); priv->groups = NULL; g_hash_table_destroy (priv->title_to_group); priv->title_to_group = g_hash_table_new (g_str_hash, g_str_equal); - - /* FIXME update the views. */ } static gboolean @@ -141,6 +157,8 @@ load_shortcuts (EShortcuts *shortcuts, xmlNode *root; xmlNode *p, *q; + /* FIXME: Update the views by emitting the appropriate signals. */ + priv = shortcuts->priv; doc = xmlParseFile (file_name); @@ -355,6 +373,46 @@ class_init (EShortcutsClass *klass) object_class->destroy = destroy; parent_class = gtk_type_class (gtk_object_get_type ()); + + signals[NEW_GROUP] + = gtk_signal_new ("new_group", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutsClass, new_group), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, + GTK_TYPE_INT); + + signals[REMOVE_GROUP] + = gtk_signal_new ("remove_group", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutsClass, remove_group), + gtk_marshal_NONE__INT, + GTK_TYPE_NONE, 1, + GTK_TYPE_INT); + + signals[NEW_SHORTCUT] + = gtk_signal_new ("new_shortcut", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutsClass, new_shortcut), + gtk_marshal_NONE__INT_INT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, + GTK_TYPE_INT); + + signals[REMOVE_SHORTCUT] + = gtk_signal_new ("remove_shortcut", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (EShortcutsClass, remove_shortcut), + gtk_marshal_NONE__INT_INT, + GTK_TYPE_NONE, 2, + GTK_TYPE_INT, + GTK_TYPE_INT); + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); } @@ -609,6 +667,8 @@ e_shortcuts_remove_shortcut (EShortcuts *shortcuts, p = g_list_nth (group->shortcuts, num); g_return_if_fail (p != NULL); + gtk_signal_emit (GTK_OBJECT (shortcuts), signals[REMOVE_SHORTCUT], group_num, num); + uri = (char *) p->data; g_free (uri); @@ -639,6 +699,8 @@ e_shortcuts_add_shortcut (EShortcuts *shortcuts, group->shortcuts = g_list_insert (group->shortcuts, g_strdup (uri), num); + gtk_signal_emit (GTK_OBJECT (shortcuts), signals[NEW_SHORTCUT], group_num, num); + make_dirty (shortcuts); } @@ -658,6 +720,8 @@ e_shortcuts_remove_group (EShortcuts *shortcuts, p = g_list_nth (priv->groups, group_num); g_return_if_fail (p != NULL); + gtk_signal_emit (GTK_OBJECT (shortcuts), signals[REMOVE_GROUP], group_num); + group = (ShortcutGroup *) p->data; e_free_string_list (group->shortcuts); @@ -686,6 +750,8 @@ e_shortcuts_add_group (EShortcuts *shortcuts, priv->groups = g_list_insert (priv->groups, group, group_num); + gtk_signal_emit (GTK_OBJECT (shortcuts), signals[NEW_GROUP], group_num); + make_dirty (shortcuts); } diff --git a/shell/e-shortcuts.h b/shell/e-shortcuts.h index f450728b51..da4dfc1fa0 100644 --- a/shell/e-shortcuts.h +++ b/shell/e-shortcuts.h @@ -57,7 +57,14 @@ struct _EShortcuts { struct _EShortcutsClass { GtkObjectClass parent_class; -}; + + /* Signals. */ + + void (* new_group) (EShortcuts *shortcuts, int group_num); + void (* remove_group) (EShortcuts *shortcuts, int group_num); + void (* new_shortcut) (EShortcuts *shortcuts, int group_num, int item_num); + void (* remove_shortcut) (EShortcuts *shortcuts, int group_num, int item_num);} +; GtkType e_shortcuts_get_type (void); diff --git a/widgets/shortcut-bar/ChangeLog b/widgets/shortcut-bar/ChangeLog index 5033b6da94..f3baab779a 100644 --- a/widgets/shortcut-bar/ChangeLog +++ b/widgets/shortcut-bar/ChangeLog @@ -1,3 +1,7 @@ +2000-06-01 Ettore Perazzoli + + * e-shortcut-bar.c (e_shortcut_bar_get_view_type): New function. + 2000-05-25 Ettore Perazzoli * e-shortcut-bar.c (e_shortcut_bar_load_image): Leak plug: free diff --git a/widgets/shortcut-bar/e-shortcut-bar.c b/widgets/shortcut-bar/e-shortcut-bar.c index d668516338..f3af57d659 100644 --- a/widgets/shortcut-bar/e-shortcut-bar.c +++ b/widgets/shortcut-bar/e-shortcut-bar.c @@ -422,6 +422,23 @@ e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, } +EIconBarViewType +e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar, + gint group_num) +{ + EShortcutBarGroup *group; + + g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), E_ICON_BAR_SMALL_ICONS); + g_return_val_if_fail (group_num >= 0, E_ICON_BAR_SMALL_ICONS); + g_return_val_if_fail (group_num < shortcut_bar->groups->len, E_ICON_BAR_SMALL_ICONS); + + group = &g_array_index (shortcut_bar->groups, + EShortcutBarGroup, group_num); + + return E_ICON_BAR (group->icon_bar)->view_type; +} + + static void e_shortcut_bar_item_selected (EIconBar *icon_bar, GdkEvent *event, diff --git a/widgets/shortcut-bar/e-shortcut-bar.h b/widgets/shortcut-bar/e-shortcut-bar.h index b02626fdef..8d151b0a4e 100644 --- a/widgets/shortcut-bar/e-shortcut-bar.h +++ b/widgets/shortcut-bar/e-shortcut-bar.h @@ -103,39 +103,41 @@ struct _EShortcutBarClass }; -GtkType e_shortcut_bar_get_type (void); -GtkWidget* e_shortcut_bar_new (void); +GtkType e_shortcut_bar_get_type (void); +GtkWidget* e_shortcut_bar_new (void); /* Adds a new group, returning the index. */ -gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, - const gchar *group_name); -void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, - gint group_num); - -/* Sets the view type for the group. */ -void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, - gint group_num, - EIconBarViewType view_type); +gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, + const gchar *group_name); +void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, + gint group_num); + +/* Sets/gets the view type for the group. */ +void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, + gint group_num, + EIconBarViewType view_type); +EIconBarViewType e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar, + gint group_num); /* Adds a new item to a group, returning the index within the group. */ -gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, - gint group_num, - const gchar *item_url, - const gchar *item_name); - -void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); -void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); +gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, + gint group_num, + const gchar *item_url, + const gchar *item_name); + +void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, + gint group_num, + gint item_num); +void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, + gint group_num, + gint item_num); /* Sets the callback which is called to return the icon to use for a particular URL. This callback must be set before any items are added. If the callback returns NULL the default icon is used. */ -void e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar, - EShortcutBarIconCallback cb, - gpointer data); +void e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar, + EShortcutBarIconCallback cb, + gpointer data); #ifdef __cplusplus } -- cgit