Add `Open' and `Open in a New Window' in places sidebar
- From: Stefano Teso <stefano teso gmail com>
- To: nautilus-list gnome org
- Subject: Add `Open' and `Open in a New Window' in places sidebar
- Date: Mon, 05 Mar 2007 14:21:38 +0100
Hi,
I just wrote my first Nautilus patch -- it adds functionality to the
places sidebar, in form of two new menu entries: `Open' and `Open in New
Window'. This is pretty standard functionality that I felt the places
sidebar really needed. I chose not to add yet another separator to the
menu, even if the `Remove' and the `Open in New Window' entries are
perhaps dangerously near.
I tried to follow the coding style guidelines, but I'm not sure
everything's allright; of course I'm open to suggestions. The patch
applies cleanly to svn trunk.
A bit OT: why the `Remove' and `Rename...' menu entries in the places
sidebar aren't called `Remove Bookmark' and `Rename Bookmark...'? That's
what they're called in Thunar. I think it's much less confusing to the
user.
An `Edit Bookmarks...' entry at the bottom of the menu would be useful
too, though I'd find it particularly heavy on the eye.
Thanks,
----
Stefano
Index: nautilus-places-sidebar.c
===================================================================
--- nautilus-places-sidebar.c (revision 12789)
+++ nautilus-places-sidebar.c (working copy)
@@ -58,6 +58,7 @@
#include "nautilus-bookmark-list.h"
#include "nautilus-places-sidebar.h"
+#include "nautilus-window.h"
#define NAUTILUS_PLACES_SIDEBAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PLACES_SIDEBAR, NautilusPlacesSidebarClass))
#define NAUTILUS_IS_PLACES_SIDEBAR(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PLACES_SIDEBAR))
@@ -1173,6 +1174,72 @@
bookmarks_check_popup_sensitivity (sidebar);
}
+static void
+open_file_or_folder (NautilusPlacesSidebar *sidebar,
+ gboolean open_in_new_window)
+{
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ char *uri;
+
+ model = gtk_tree_view_get_model (sidebar->tree_view);
+ gtk_tree_view_get_cursor (sidebar->tree_view, &path, NULL);
+
+ if (path != NULL) {
+
+ if (!gtk_tree_model_get_iter (model, &iter, path)) {
+ return;
+ }
+
+ gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_URI, &uri, -1);
+
+ if (uri != NULL) {
+
+ if (FALSE == open_in_new_window) {
+ nautilus_window_info_open_location (
+ sidebar->window, uri,
+ NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE,
+ 0, NULL);
+ } else {
+ NautilusWindow *cur, *new;
+ cur = NAUTILUS_WINDOW (sidebar->window);
+ new = nautilus_application_create_navigation_window (
+ cur->application,
+ NULL,
+ gtk_window_get_screen (GTK_WINDOW (cur)));
+ nautilus_window_go_to (new, uri);
+ }
+
+ g_free (uri);
+
+ } else {
+ GnomeVFSDrive *drive;
+ gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_DRIVE, &drive, -1);
+ if (drive != NULL) {
+ gnome_vfs_drive_mount (drive, volume_op_callback, sidebar);
+ gnome_vfs_drive_unref (drive);
+ }
+ }
+
+ gtk_tree_path_free (path);
+ }
+}
+
+static void
+open_shortcut_cb (GtkMenuItem *item,
+ NautilusPlacesSidebar *sidebar)
+{
+ open_file_or_folder (sidebar, FALSE);
+}
+
+static void
+open_in_new_window_shortcut_cb (GtkMenuItem *item,
+ NautilusPlacesSidebar *sidebar)
+{
+ open_file_or_folder (sidebar, TRUE);
+}
+
/* Rename the selected bookmark */
static void
rename_selected_bookmark (NautilusPlacesSidebar *sidebar)
@@ -1361,6 +1428,20 @@
GTK_WIDGET (sidebar),
bookmarks_popup_menu_detach_cb);
+ item = gtk_image_menu_item_new_with_label (_("Open"));
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+ gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (open_shortcut_cb), sidebar);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
+
+ item = gtk_menu_item_new_with_label (_("Open in New Window"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (open_in_new_window_shortcut_cb), sidebar);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
+
item = gtk_image_menu_item_new_with_label (_("Remove"));
sidebar->popup_menu_remove_item = item;
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]