[Goodies-commits] r2909 - in xfce4-places-plugin/trunk: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Fri Jul 13 07:09:41 CEST 2007
Author: ongardie
Date: 2007-07-13 05:09:41 +0000 (Fri, 13 Jul 2007)
New Revision: 2909
Modified:
xfce4-places-plugin/trunk/ChangeLog
xfce4-places-plugin/trunk/panel-plugin/model.c
xfce4-places-plugin/trunk/panel-plugin/model.h
xfce4-places-plugin/trunk/panel-plugin/model_system.c
xfce4-places-plugin/trunk/panel-plugin/model_user.c
xfce4-places-plugin/trunk/panel-plugin/model_volumes.c
xfce4-places-plugin/trunk/panel-plugin/places.c
xfce4-places-plugin/trunk/panel-plugin/places.h
xfce4-places-plugin/trunk/panel-plugin/view.c
Log:
2007-07-13 Diego Ongaro <ongardie at gmail.com>
* Merged in umount branch at r1908 (now obsolete):
- added "actions" to bookmarks.
- added unmount/mount actions to volumes.
- added Open Terminal Here action.
Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/ChangeLog 2007-07-13 05:09:41 UTC (rev 2909)
@@ -1,3 +1,10 @@
+2007-07-13 Diego Ongaro <ongardie at gmail.com>
+
+ * Merged in umount branch at r1908 (now obsolete):
+ - added "actions" to bookmarks.
+ - added unmount/mount actions to volumes.
+ - added Open Terminal Here action.
+
2007-06-04 Diego Ongaro <ongardie at gmail.com>
* Fix BookmarkInfo-related memory leaks
Modified: xfce4-places-plugin/trunk/panel-plugin/model.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/model.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -141,4 +141,13 @@
g_free(bi);
}
+void
+places_bookmark_actions_list_destroy(GSList *actions)
+{
+ if(actions != NULL){
+ g_slist_foreach(actions, (GFunc) g_free, NULL);
+ g_slist_free(actions);
+ }
+}
+
// vim: ai et tabstop=4
Modified: xfce4-places-plugin/trunk/panel-plugin/model.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model.h 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/model.h 2007-07-13 05:09:41 UTC (rev 2909)
@@ -39,8 +39,19 @@
typedef struct
{
+ gchar *label;
+ gpointer pass_thru;
+ void (*action) (gpointer);
+} BookmarkAction;
+
+#define places_bookmark_action_call(act) (act->action(act->pass_thru))
+
+void places_bookmark_actions_list_destroy(GSList *actions);
+
+typedef struct
+{
gpointer pass_thru;
- void (*item) (gpointer, const gchar*, const gchar*, const gchar*);
+ void (*item) (gpointer, const gchar*, const gchar*, const gchar*, GSList *actions);
void (*separator) (gpointer);
} BookmarksVisitor;
Modified: xfce4-places-plugin/trunk/panel-plugin/model_system.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_system.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/model_system.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -137,7 +137,7 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
if(bi->show)
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon, NULL);
}
}
Modified: xfce4-places-plugin/trunk/panel-plugin/model_user.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_user.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/model_user.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -176,7 +176,7 @@
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
if(bi->show)
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon, NULL);
}
}
Modified: xfce4-places-plugin/trunk/panel-plugin/model_volumes.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/model_volumes.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/model_volumes.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -45,7 +45,7 @@
/********** ThunarVFS Callbacks **********/
-void
+static void
places_bookmarks_volumes_cb_changed(ThunarVfsVolume *volume,
BookmarksVolumes *b)
{
@@ -55,6 +55,7 @@
BookmarkInfo *bi;
GList *volumes;
guint k;
+ b->changed = FALSE;
if(places_bookmarks_volumes_show_volume(volume)){
@@ -87,14 +88,13 @@
g_object_unref(bi->data); // unref the volume
bi->data = NULL;
places_bookmark_info_free(bi);
-
b->changed = TRUE;
}
}
}
}
-void
+static void
places_bookmarks_volumes_cb_added(ThunarVfsVolumeManager *volume_manager,
const GList *volumes,
BookmarksVolumes *b)
@@ -104,7 +104,7 @@
b->changed = TRUE;
}
-void
+static void
places_bookmarks_volumes_cb_removed(ThunarVfsVolumeManager *volume_manager,
const GList *volumes,
BookmarksVolumes *b)
@@ -143,7 +143,27 @@
}
}
-// internal
+/********** Actions Callbacks **********/
+
+static void
+places_bookmarks_volumes_unmount(gpointer _volume)
+{
+ DBG("Unmount");
+ ThunarVfsVolume *volume = THUNAR_VFS_VOLUME(_volume);
+ if(thunar_vfs_volume_is_mounted(volume))
+ thunar_vfs_volume_unmount(volume, NULL, NULL);
+}
+
+static void
+places_bookmarks_volumes_mount(gpointer _volume)
+{
+ DBG("Mount");
+ ThunarVfsVolume *volume = THUNAR_VFS_VOLUME(_volume);
+ if(!thunar_vfs_volume_is_mounted(volume))
+ thunar_vfs_volume_mount(volume, NULL, NULL);
+}
+
+/********** Internal **********/
static gboolean
places_bookmarks_volumes_show_volume(ThunarVfsVolume *volume){
@@ -152,8 +172,7 @@
thunar_vfs_volume_is_removable(volume),
thunar_vfs_volume_is_present(volume));
- return thunar_vfs_volume_is_mounted(volume) &&
- thunar_vfs_volume_is_removable(volume) &&
+ return thunar_vfs_volume_is_removable(volume) &&
thunar_vfs_volume_is_present(volume);
}
@@ -188,7 +207,7 @@
}
}
-// external
+/********** External **********/
BookmarksVolumes*
places_bookmarks_volumes_init()
@@ -252,15 +271,44 @@
}
}
+
void
places_bookmarks_volumes_visit(BookmarksVolumes *b, BookmarksVisitor *visitor)
{
guint k;
BookmarkInfo *bi;
-
+ GSList *actions;
+ ThunarVfsVolume *volume;
+ gchar *uri;
+ BookmarkAction *toggle_mount;
+
for(k=0; k < b->bookmarks->len; k++){
bi = g_ptr_array_index(b->bookmarks, k);
- visitor->item(visitor->pass_thru, bi->label, bi->uri, bi->icon);
+ volume = THUNAR_VFS_VOLUME(bi->data);
+
+ toggle_mount = g_new0(BookmarkAction, 1); /* visitor will free */
+ toggle_mount->pass_thru = volume;
+ actions = g_slist_prepend(NULL, toggle_mount);
+
+ if(thunar_vfs_volume_is_mounted(volume)){
+
+ if(thunar_vfs_volume_is_disc(volume))
+ toggle_mount->label = _("Eject Volume");
+ else
+ toggle_mount->label = _("Unmount Volume");
+ toggle_mount->action = places_bookmarks_volumes_unmount;
+
+ uri = bi->uri;
+
+ }else{
+
+ toggle_mount->label = _("Mount Volume");
+ toggle_mount->action = places_bookmarks_volumes_mount;
+
+ uri = NULL;
+ }
+
+ visitor->item(visitor->pass_thru, bi->label, uri, bi->icon, actions);
}
}
Modified: xfce4-places-plugin/trunk/panel-plugin/places.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/places.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/places.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -24,11 +24,14 @@
#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libxfcegui4/libxfcegui4.h>
+#include <exo/exo.h>
#include "places.h"
#include "model.h"
#include "view.h"
+#include "string.h" // for strncmp
+
static void places_construct(XfcePanelPlugin*);
static void places_finalize(XfcePanelPlugin*, PlacesData*);
@@ -113,6 +116,41 @@
}
void
+places_load_terminal(const gchar *const_path)
+{
+ gchar *path = NULL;
+ gboolean path_owner = FALSE; /* whether this function "owns" path */
+
+ if(const_path != NULL){
+ if(strncmp(const_path, "trash://", 8) == 0){
+ DBG("Can't load terminal at trash:// URI's");
+ return;
+
+ }else if(strncmp(const_path, "file://", 7) == 0){
+ path = g_filename_from_uri(const_path, NULL, NULL);
+ path_owner = TRUE;
+
+ }else{
+ path = (gchar*) const_path;
+ /* (path_owner is FALSE) */
+
+ }
+ }
+
+ DBG("Open terminal emulator at %s", path);
+ exo_execute_preferred_application("TerminalEmulator", NULL, path, NULL, NULL);
+
+ if(path_owner && path != NULL)
+ g_free(path);
+}
+
+void
+places_load_file(const gchar *path)
+{
+ exo_url_show(path, NULL, NULL);
+}
+
+void
places_gui_exec(const gchar *cmd)
{
if(cmd != NULL)
Modified: xfce4-places-plugin/trunk/panel-plugin/places.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/places.h 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/places.h 2007-07-13 05:09:41 UTC (rev 2909)
@@ -51,7 +51,9 @@
};
-void places_load_thunar(const gchar*);
+void places_load_thunar(const gchar *path);
+void places_load_terminal(const gchar *path);
+void places_load_file(const gchar *path);
void places_gui_exec(const gchar *cmd);
Modified: xfce4-places-plugin/trunk/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.c 2007-07-13 05:02:00 UTC (rev 2908)
+++ xfce4-places-plugin/trunk/panel-plugin/view.c 2007-07-13 05:09:41 UTC (rev 2909)
@@ -38,6 +38,8 @@
#include <libxfce4panel/xfce-panel-convenience.h>
#include <libxfcegui4/libxfcegui4.h>
+#include <string.h>
+
#include "view.h"
#include "places.h"
#include "model.h"
@@ -63,7 +65,6 @@
gboolean *push_in,
PlacesData*);
static void places_view_cb_menu_deact(PlacesData*, GtkWidget *menu);
-static void places_view_cb_menu_item_open(GtkWidget *item, const gchar *uri);
// - Button
static gboolean places_view_cb_button_pressed(PlacesData*, GdkEventButton *);
@@ -76,11 +77,10 @@
// Model Visitor Callbacks
static void places_view_add_menu_item(gpointer _places_data,
- const gchar *label, const gchar *uri, const gchar *icon);
+ const gchar *label, const gchar *uri, const gchar *icon, GSList *actions);
static void places_view_lazy_add_menu_sep(gpointer _places_data);
/********** Initialization & Finalization **********/
-
void
places_view_init(PlacesData *pd)
{
@@ -499,12 +499,6 @@
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pd->view_button), FALSE);
}
-static void
-places_view_cb_menu_item_open(GtkWidget *widget, const gchar* uri)
-{
- places_load_thunar(uri);
-}
-
// Button
static gboolean
places_view_cb_button_pressed(PlacesData *pd, GdkEventButton *evt)
@@ -521,6 +515,62 @@
return FALSE;
}
+void
+places_view_cb_menu_item_context_act(GtkWidget *item, PlacesData *pd)
+{
+ // we want the menu gone - now - since it prevents mouse grabs
+ places_view_destroy_menu(pd);
+ g_main_context_iteration(NULL, FALSE);
+
+ BookmarkAction *action = (BookmarkAction*) g_object_get_data(G_OBJECT(item), "action");
+ places_bookmark_action_call(action);
+}
+
+gboolean
+places_view_cb_menu_item_press(GtkWidget *menu_item, GdkEventButton *event, PlacesData *pd)
+{
+
+ gboolean ctrl = (event->state & GDK_CONTROL_MASK) &&
+ !(event->state & (GDK_MOD1_MASK|GDK_SHIFT_MASK|GDK_MOD4_MASK));
+
+ if(event->button == 1 && !ctrl){
+ const gchar *uri = (const gchar*) g_object_get_data(G_OBJECT(menu_item), "uri");
+ if(uri != NULL){
+ places_load_thunar(uri);
+ return FALSE;
+ }
+ return TRUE;
+
+ }else if(event->button == 3 || (event->button == 1 && ctrl)){
+
+ const GSList *actions = (const GSList*) g_object_get_data(G_OBJECT(menu_item), "actions");
+ if(actions != NULL){
+
+ GtkWidget *context = gtk_menu_new();
+ gtk_widget_show(context);
+ while(actions != NULL){
+ BookmarkAction *action = (BookmarkAction*) actions->data;
+ GtkWidget *context_item = gtk_menu_item_new_with_label(action->label);
+ g_object_set_data(G_OBJECT(context_item), "action", action);
+ gtk_widget_show(context_item);
+ g_signal_connect(context_item, "activate",
+ G_CALLBACK(places_view_cb_menu_item_context_act), pd);
+ gtk_menu_shell_append(GTK_MENU_SHELL(context), context_item);
+ actions = actions->next;
+ }
+ gtk_menu_popup(GTK_MENU(context),
+ NULL, NULL,
+ NULL, NULL,
+ event->button, event->time);
+ g_signal_connect_swapped(context, "deactivate", G_CALLBACK(places_view_open_menu), pd);
+ }
+
+ return TRUE;
+ }
+
+ return TRUE;
+}
+
// Recent Documents
#if USE_RECENT_DOCUMENTS
@@ -528,7 +578,7 @@
places_view_cb_recent_item_open(GtkRecentChooser *chooser, PlacesData *pd)
{
gchar *uri = gtk_recent_chooser_get_current_uri(chooser);
- places_load_thunar(uri);
+ places_load_file(uri);
g_free(uri);
}
@@ -544,11 +594,16 @@
/********** Model Visitor Callbacks **********/
static void
-places_view_add_menu_item(gpointer _pd, const gchar *label, const gchar *uri, const gchar *icon)
+places_view_load_terminal_wrapper(gpointer path)
{
+ places_load_terminal((gchar*) path);
+}
+
+static void
+places_view_add_menu_item(gpointer _pd, const gchar *label, const gchar *uri, const gchar *icon, GSList *actions)
+{
g_assert(_pd != NULL);
g_return_if_fail(label != NULL && label != "");
- g_return_if_fail(uri != NULL && uri != "");
PlacesData *pd = (PlacesData*) _pd;
@@ -570,8 +625,26 @@
}
}
- g_signal_connect(item, "activate",
- G_CALLBACK(places_view_cb_menu_item_open), (gchar*) uri);
+ if(uri != NULL){
+
+ if(strncmp(uri, "trash://", 8) != 0){
+ g_object_set_data(G_OBJECT(item), "uri", (gchar*) uri);
+ BookmarkAction *terminal = g_new0(BookmarkAction, 1);
+ terminal->label = "Open Terminal Here";
+ terminal->pass_thru = (gchar*) uri;
+ terminal->action = places_view_load_terminal_wrapper;
+ actions = g_slist_append(actions, terminal);
+ }
+ }else
+ gtk_widget_set_sensitive(gtk_bin_get_child(GTK_BIN(item)), FALSE);
+
+
+ if(actions != NULL)
+ g_object_set_data_full(G_OBJECT(item), "actions", actions, (GDestroyNotify) places_bookmark_actions_list_destroy);
+
+ g_signal_connect(item, "button-release-event",
+ G_CALLBACK(places_view_cb_menu_item_press), pd);
+
gtk_menu_shell_append(GTK_MENU_SHELL(pd->view_menu), item);
}
More information about the Goodies-commits
mailing list