diff options
Diffstat (limited to 'widgets/menus')
-rw-r--r-- | widgets/menus/gal-view-instance.c | 139 | ||||
-rw-r--r-- | widgets/menus/gal-view-instance.h | 4 |
2 files changed, 143 insertions, 0 deletions
diff --git a/widgets/menus/gal-view-instance.c b/widgets/menus/gal-view-instance.c index 26e1f5546d..1cc0389f47 100644 --- a/widgets/menus/gal-view-instance.c +++ b/widgets/menus/gal-view-instance.c @@ -36,8 +36,10 @@ #include <gal/widgets/e-unicode.h> #include "gal-view-instance.h" #include "gal-view-instance-save-as-dialog.h" +#include "gal-define-views-dialog.h" #include <sys/stat.h> #include <unistd.h> +#include <gtk/gtkcheckmenuitem.h> #define GVI_CLASS(e) ((GalViewInstanceClass *)((GtkObject *)e)->klass) @@ -45,6 +47,10 @@ static GtkObjectClass *gal_view_instance_parent_class; +static const EPopupMenu separator = E_POPUP_SEPARATOR; +static const EPopupMenu terminator = E_POPUP_TERMINATOR; + + #define d(x) x enum { @@ -479,3 +485,136 @@ gal_view_instance_exists (GalViewInstance *instance) return FALSE; } + +typedef struct { + GalViewInstance *instance; + char *id; +} ListenerClosure; + +static void +view_item_cb (GtkWidget *widget, + gpointer user_data) +{ + ListenerClosure *closure = user_data; + + if (GTK_CHECK_MENU_ITEM (widget)->active) { + gal_view_instance_set_current_view_id (closure->instance, closure->id); + } +} + +static void +add_popup_radio_item (EPopupMenu *menu_item, + gchar *title, + void (*fn) (GtkWidget *widget, gpointer closure), + gpointer closure, + gboolean value) +{ + const EPopupMenu menu_item_struct = + E_POPUP_RADIO_ITEM_CC (title, + fn, + closure, + 0, + value); + + e_popup_menu_copy_1 (menu_item, &menu_item_struct); +} + +static void +add_popup_menu_item (EPopupMenu *menu_item, + gchar *title, + void (*fn) (GtkWidget *widget, gpointer closure), + gpointer closure) +{ + const EPopupMenu menu_item_struct = + E_POPUP_ITEM_CC (title, + fn, + closure, + 0); + + e_popup_menu_copy_1 (menu_item, &menu_item_struct); +} + +static void +define_views_dialog_clicked(GtkWidget *dialog, int button, GalViewInstance *instance) +{ + if (button == 0) { + gal_view_collection_save(instance->collection); + } + gnome_dialog_close(GNOME_DIALOG(dialog)); +} + +static void +define_views_cb(GtkWidget *widget, + GalViewInstance *instance) +{ + GtkWidget *dialog = gal_define_views_dialog_new(instance->collection); + gtk_signal_connect(GTK_OBJECT(dialog), "clicked", + GTK_SIGNAL_FUNC(define_views_dialog_clicked), instance); + gtk_widget_show(dialog); +} + +static void +save_current_view_cb(GtkWidget *widget, + GalViewInstance *instance) +{ + gal_view_instance_save_as (instance); +} + +EPopupMenu * +gal_view_instance_get_popup_menu (GalViewInstance *instance) +{ + EPopupMenu *ret_val; + int length; + int i; + gboolean found = FALSE; + char *id; + + length = gal_view_collection_get_count(instance->collection); + id = gal_view_instance_get_current_view_id (instance); + + ret_val = g_new (EPopupMenu, length + 6); + + for (i = 0; i < length; i++) { + gboolean value = FALSE; + GalViewCollectionItem *item = gal_view_collection_get_view_item(instance->collection, i); + ListenerClosure *closure; + + closure = g_new (ListenerClosure, 1); + closure->instance = instance; + closure->id = item->id; + gtk_object_ref (GTK_OBJECT(closure->instance)); + + if (!found && id && !strcmp (id, item->id)) { + found = TRUE; + value = TRUE; + } + + add_popup_radio_item (ret_val + i, item->title, GTK_SIGNAL_FUNC (view_item_cb), closure, value); + } + + if (!found) { + e_popup_menu_copy_1 (ret_val + i++, &separator); + + add_popup_radio_item (ret_val + i++, N_("Custom View"), NULL, NULL, TRUE); + add_popup_menu_item (ret_val + i++, N_("Save Custom View"), GTK_SIGNAL_FUNC (save_current_view_cb), instance); + } + + e_popup_menu_copy_1 (ret_val + i++, &separator); + add_popup_menu_item (ret_val + i++, N_("Define Views"), GTK_SIGNAL_FUNC (define_views_cb), instance); + e_popup_menu_copy_1 (ret_val + i++, &terminator); + + return ret_val; +} + +void +gal_view_instance_free_popup_menu (GalViewInstance *instance, EPopupMenu *menu) +{ + int i; + /* This depends on the first non-custom closure to be a separator or a terminator. */ + for (i = 0; menu[i].name && *(menu[i].name); i++) { + gtk_object_unref (GTK_OBJECT ( ((ListenerClosure *)(menu[i].closure))->instance)); + g_free (menu[i].closure); + } + + e_popup_menu_free (menu); +} diff --git a/widgets/menus/gal-view-instance.h b/widgets/menus/gal-view-instance.h index 9d0febf0f0..5e5ea6817e 100644 --- a/widgets/menus/gal-view-instance.h +++ b/widgets/menus/gal-view-instance.h @@ -26,6 +26,7 @@ #include <gtk/gtkobject.h> #include <gal/menus/gal-view-collection.h> +#include <gal/widgets/e-popup-menu.h> #include <libgnome/gnome-defs.h> BEGIN_GNOME_DECLS @@ -108,6 +109,9 @@ const char *gal_view_instance_get_default_view (GalViewInstance *inst void gal_view_instance_set_default_view (GalViewInstance *instance, const char *id); +EPopupMenu *gal_view_instance_get_popup_menu (GalViewInstance *instance); +void gal_view_instance_free_popup_menu (GalViewInstance *instance, + EPopupMenu *menu); END_GNOME_DECLS |