Updating branch refs/heads/ristretto-0.0 to 5964507a295a4c803066c758e94ead95b1509e73 (commit) from 5562dcd515df545490234466f9ab2c419de78868 (commit)
commit 5964507a295a4c803066c758e94ead95b1509e73 Author: Stephan Arts <step...@xfce.org> Date: Wed Sep 23 23:36:47 2009 +0200 Implement open-with menu with launcher menu-items ChangeLog | 7 +++ src/Makefile.am | 1 + src/app_menu_item.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/app_menu_item.h | 66 ++++++++++++++++++++++++ src/main_window.c | 8 +-- 5 files changed, 214 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77d4312..aab1ee2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-09-23 Stephan Arts <step...@xfce.org> + + * src/app_menu_item.c, + src/app_menu_item.h, + src/main_window.c, + src/Makefile.am: Implement open-with menu with launcher menu-items + 2009-09-22 Stephan Arts <step...@xfce.org> * src/main_window.c: Add initial code for implementation of the diff --git a/src/Makefile.am b/src/Makefile.am index c201e0f..9a88f24 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ ristretto_SOURCES = \ preferences_dialog.h preferences_dialog.c \ main_window_ui.h \ main_window.c main_window.h \ + app_menu_item.c app_menu_item.h \ thumbnail_bar.c thumbnail_bar.h \ thumbnail.c thumbnail.h \ main.c diff --git a/src/app_menu_item.c b/src/app_menu_item.c new file mode 100644 index 0000000..5ef2f65 --- /dev/null +++ b/src/app_menu_item.c @@ -0,0 +1,137 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> +#include <gio/gio.h> +#include <gtk/gtk.h> +#include <string.h> + +#include "app_menu_item.h" + +struct _RsttoAppMenuItemPriv +{ + GAppInfo *app_info; + GFile *file; +}; + +static GtkWidgetClass *parent_class = NULL; + +static void +rstto_app_menu_item_init(RsttoAppMenuItem *); +static void +rstto_app_menu_item_class_init(RsttoAppMenuItemClass *); +static void +rstto_app_menu_item_finalize(GObject *object); + +static void +rstto_app_menu_item_activate (GObject *object); + +GType +rstto_app_menu_item_get_type (void) +{ + static GType rstto_app_menu_item_type = 0; + + if (!rstto_app_menu_item_type) + { + static const GTypeInfo rstto_app_menu_item_info = + { + sizeof (RsttoAppMenuItemClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) rstto_app_menu_item_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (RsttoAppMenuItem), + 0, + (GInstanceInitFunc) rstto_app_menu_item_init, + NULL + }; + + rstto_app_menu_item_type = g_type_register_static (GTK_TYPE_IMAGE_MENU_ITEM, "RsttoAppMenuItem", &rstto_app_menu_item_info, 0); + } + return rstto_app_menu_item_type; +} + +static void +rstto_app_menu_item_init (RsttoAppMenuItem *menu_item) +{ + menu_item->priv = g_new0 (RsttoAppMenuItemPriv, 1); +} + +static void +rstto_app_menu_item_class_init(RsttoAppMenuItemClass *app_menu_item_class) +{ + GtkWidgetClass *widget_class; + GtkMenuItemClass *menu_item_class; + GObjectClass *object_class; + + object_class = (GObjectClass*)app_menu_item_class; + menu_item_class = (GtkMenuItemClass*)app_menu_item_class; + + parent_class = g_type_class_peek_parent (app_menu_item_class); + + object_class->finalize = rstto_app_menu_item_finalize; + menu_item_class->activate = rstto_app_menu_item_activate; +} + +static void +rstto_app_menu_item_finalize(GObject *object) +{ + RsttoAppMenuItem *menu_item = RSTTO_APP_MENU_ITEM(object); + if (menu_item->priv->app_info) + { + g_object_unref (menu_item->priv->app_info); + menu_item->priv->app_info = NULL; + } + if (menu_item->priv->file) + { + g_object_unref (menu_item->priv->file); + menu_item->priv->file = NULL; + } + +} + +static void +rstto_app_menu_item_activate (GObject *object) +{ + RsttoAppMenuItem *app_menu_item = RSTTO_APP_MENU_ITEM(object); + GList *files = g_list_append (NULL, app_menu_item->priv->file); + + g_app_info_launch (app_menu_item->priv->app_info, files, NULL, NULL); + + GTK_MENU_ITEM_CLASS(parent_class)->activate (RSTTO_APP_MENU_ITEM (object)); +} + + +GtkWidget * +rstto_app_menu_item_new (GAppInfo *app_info, GFile *file) +{ + RsttoAppMenuItem *menu_item; + + g_return_val_if_fail (app_info != NULL, NULL); + + menu_item = g_object_new (RSTTO_TYPE_APP_MENU_ITEM, NULL); + + menu_item->priv->app_info = app_info; + g_object_ref (app_info); + + menu_item->priv->file = file; + g_object_ref (file); + + gtk_menu_item_set_label (GTK_MENU_ITEM (menu_item), g_app_info_get_name (app_info)); + + return GTK_WIDGET (menu_item); +} diff --git a/src/app_menu_item.h b/src/app_menu_item.h new file mode 100644 index 0000000..d358f50 --- /dev/null +++ b/src/app_menu_item.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) Stephan Arts 2009 <step...@xfce.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __RISTRETTO_APP_MENU_ITEM_H__ +#define __RISTRETTO_APP_MENU_ITEM_H__ + +G_BEGIN_DECLS + +#define RSTTO_TYPE_APP_MENU_ITEM rstto_app_menu_item_get_type() + +#define RSTTO_APP_MENU_ITEM(obj)( \ + G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + RSTTO_TYPE_APP_MENU_ITEM, \ + RsttoAppMenuItem)) + +#define RSTTO_IS_APP_MENU_ITEM(obj)( \ + G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + RSTTO_TYPE_APP_MENU_ITEM)) + +#define RSTTO_APP_MENU_ITEM_CLASS(klass)( \ + G_TYPE_CHECK_CLASS_CAST ((klass), \ + RSTTO_TYPE_APP_MENU_ITEM, \ + RsttoAppMenuItemClass)) + +#define RSTTO_IS_APP_MENU_ITEM_CLASS(klass)( \ + G_TYPE_CHECK_CLASS_TYPE ((klass), \ + RSTTO_TYPE_APP_MENU_ITEM())) + +typedef struct _RsttoAppMenuItemPriv RsttoAppMenuItemPriv; + +typedef struct _RsttoAppMenuItem RsttoAppMenuItem; + +struct _RsttoAppMenuItem +{ + GtkImageMenuItem parent; + RsttoAppMenuItemPriv *priv; +}; + +typedef struct _RsttoAppMenuItemClass RsttoAppMenuItemClass; + +struct _RsttoAppMenuItemClass +{ + GtkImageMenuItemClass parent_class; +}; + +GType rstto_app_menu_item_get_type(); +GtkWidget *rstto_app_menu_item_new (GAppInfo *app_info, GFile *file); + +G_END_DECLS + +#endif /* __RISTRETTO_APP_MENU_ITEM_H__ */ diff --git a/src/main_window.c b/src/main_window.c index 2904117..97931a5 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -40,6 +40,7 @@ #include "thumbnail_bar.h" #include "preferences_dialog.h" +#include "app_menu_item.h" #define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d" @@ -726,13 +727,10 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window) for (iter = app_list; iter; iter = g_list_next (iter)) { - GtkWidget *menu_item = gtk_image_menu_item_new_with_label (g_app_info_get_name (iter->data)); + GtkWidget *menu_item = rstto_app_menu_item_new (iter->data, file); gtk_menu_shell_append (GTK_MENU_SHELL (open_with_menu), menu_item); - gtk_widget_set_sensitive (menu_item, FALSE); - - menu_item = gtk_image_menu_item_new_with_label (g_app_info_get_name (iter->data)); + menu_item = rstto_app_menu_item_new (iter->data, file); gtk_menu_shell_append (GTK_MENU_SHELL (open_with_window_menu), menu_item); - gtk_widget_set_sensitive (menu_item, FALSE); } gtk_widget_show_all (open_with_menu); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits