diff options
author | Jasmine Hassan <[email protected]> | 2012-10-27 11:21:31 +0200 |
---|---|---|
committer | Jasmine Hassan <[email protected]> | 2012-11-16 09:45:49 +0200 |
commit | 408fb6c29f23b58f5fba2704b378c2d58151490b (patch) | |
tree | 4d5fa37714625a3e1c76886f5530439ceeecbfc2 /src | |
parent | aaa289476ee990743ef573797736d7e42595a251 (diff) | |
download | caja-408fb6c29f23b58f5fba2704b378c2d58151490b.tar.bz2 caja-408fb6c29f23b58f5fba2704b378c2d58151490b.tar.xz |
[places-sidebar] Add highlight to eject icon
Add highlight to eject icon in places sidebar (#544103)
http://git.gnome.org/browse/nautilus/commit/?id=63b2cac301970847f76f7bdbd12835117958d9be
Diffstat (limited to 'src')
-rw-r--r-- | src/caja-places-sidebar.c | 158 |
1 files changed, 136 insertions, 22 deletions
diff --git a/src/caja-places-sidebar.c b/src/caja-places-sidebar.c index 13f06966..770c1e28 100644 --- a/src/caja-places-sidebar.c +++ b/src/caja-places-sidebar.c @@ -28,6 +28,7 @@ #include <eel/eel-glib-extensions.h> #include <eel/eel-string.h> #include <eel/eel-stock-dialogs.h> +#include <eel/eel-gdk-pixbuf-extensions.h> #include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include <glib/gi18n.h> @@ -90,6 +91,8 @@ typedef struct gboolean mounting; CajaWindowSlotInfo *go_to_after_mount_slot; CajaWindowOpenFlags go_to_after_mount_flags; + + GtkTreePath *eject_highlight_path; } CajaPlacesSidebar; typedef struct @@ -122,6 +125,7 @@ enum PLACES_SIDEBAR_COLUMN_BOOKMARK, PLACES_SIDEBAR_COLUMN_NO_BOOKMARK, PLACES_SIDEBAR_COLUMN_TOOLTIP, + PLACES_SIDEBAR_COLUMN_EJECT_ICON, PLACES_SIDEBAR_COLUMN_COUNT }; @@ -211,6 +215,30 @@ G_DEFINE_TYPE_WITH_CODE (CajaPlacesSidebarProvider, caja_places_sidebar_provider G_IMPLEMENT_INTERFACE (CAJA_TYPE_SIDEBAR_PROVIDER, sidebar_provider_iface_init)); +static GdkPixbuf * +get_eject_icon (gboolean highlighted) +{ + GdkPixbuf *eject; + GIcon *eject_icon; + CajaIconInfo *eject_icon_info; + int icon_size; + + icon_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); + + eject_icon = g_icon_new_for_string ("media-eject", NULL); + eject_icon_info = caja_icon_info_lookup (eject_icon, icon_size); + g_object_unref (eject_icon_info); + + eject = caja_icon_info_get_pixbuf_at_size (eject_icon_info, icon_size); + if (highlighted) { + GdkPixbuf *high; + high = eel_gdk_pixbuf_render (eject, 1, 255, 255, 0, 0); + g_object_unref (eject); + eject = high; + } + return eject; +} + static GtkTreeIter add_place (CajaPlacesSidebar *sidebar, PlaceType place_type, @@ -225,6 +253,7 @@ add_place (CajaPlacesSidebar *sidebar, { GdkPixbuf *pixbuf; GtkTreeIter iter, child_iter; + GdkPixbuf *eject; CajaIconInfo *icon_info; int icon_size; gboolean show_eject, show_unmount; @@ -252,6 +281,7 @@ add_place (CajaPlacesSidebar *sidebar, show_eject_button = (show_unmount || show_eject); } + eject = get_eject_icon (FALSE); gtk_list_store_append (sidebar->store, &iter); gtk_list_store_set (sidebar->store, &iter, PLACES_SIDEBAR_COLUMN_ICON, pixbuf, @@ -267,6 +297,7 @@ add_place (CajaPlacesSidebar *sidebar, PLACES_SIDEBAR_COLUMN_BOOKMARK, place_type != PLACES_BOOKMARK, PLACES_SIDEBAR_COLUMN_NO_BOOKMARK, place_type == PLACES_BOOKMARK, PLACES_SIDEBAR_COLUMN_TOOLTIP, tooltip, + PLACES_SIDEBAR_COLUMN_EJECT_ICON, eject, -1); if (pixbuf != NULL) @@ -732,11 +763,11 @@ drive_changed_callback (GVolumeMonitor *volume_monitor, } static gboolean -clicked_eject_button (CajaPlacesSidebar *sidebar, - GtkTreePath **path) +over_eject_button (CajaPlacesSidebar *sidebar, + gint x, + gint y, + GtkTreePath **path) { - GdkEvent *event = gtk_get_current_event (); - GdkEventButton *button_event = (GdkEventButton *) event; GtkTreeViewColumn *column; GtkTextDirection direction; int width, total_width; @@ -748,19 +779,16 @@ clicked_eject_button (CajaPlacesSidebar *sidebar, *path = NULL; model = gtk_tree_view_get_model (sidebar->tree_view); - if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) && - gtk_tree_view_get_path_at_pos (sidebar->tree_view, - button_event->x, button_event->y, - path, &column, NULL, NULL)) - { + if (gtk_tree_view_get_path_at_pos (sidebar->tree_view, + x, y, + path, &column, NULL, NULL)) { gtk_tree_model_get_iter (model, &iter, *path); gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_EJECT, &show_eject, -1); - if (!show_eject) - { + if (!show_eject) { goto out; } @@ -772,8 +800,7 @@ clicked_eject_button (CajaPlacesSidebar *sidebar, total_width += width / 2; direction = gtk_widget_get_direction (GTK_WIDGET (sidebar->tree_view)); - if (direction != GTK_TEXT_DIR_RTL) - { + if (direction != GTK_TEXT_DIR_RTL) { gtk_tree_view_column_cell_get_position (column, sidebar->icon_cell_renderer, NULL, &width); @@ -789,19 +816,29 @@ clicked_eject_button (CajaPlacesSidebar *sidebar, eject_button_size = caja_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); - if (button_event->x - total_width >= 0 && - button_event->x - total_width <= eject_button_size) - { + if (x - total_width >= 0 && + x - total_width <= eject_button_size) { return TRUE; } } out: - if (*path != NULL) - { - gtk_tree_path_free (*path); - } + return FALSE; +} +static gboolean +clicked_eject_button (CajaPlacesSidebar *sidebar, + GtkTreePath **path) +{ + GdkEvent *event = gtk_get_current_event (); + GdkEventButton *button_event = (GdkEventButton *) event; + + *path = NULL; + + if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) && + over_eject_button (sidebar, button_event->x, button_event->y, path)) { + return TRUE; + } return FALSE; } @@ -2606,6 +2643,80 @@ bookmarks_button_release_event_cb (GtkWidget *widget, return FALSE; } +static void +update_eject_buttons (CajaPlacesSidebar *sidebar, + GtkTreePath *path) +{ + GtkTreeIter iter; + + if (!path && !sidebar->eject_highlight_path) { + /* Both are null - highlight up to date */ + return; + } + + if (path && + sidebar->eject_highlight_path && + gtk_tree_path_compare (sidebar->eject_highlight_path, path) == 0) { + /* Same path - highlight up to date */ + return; + } + + /* Reset last path */ + if (sidebar->eject_highlight_path) { + gtk_tree_model_get_iter (GTK_TREE_MODEL (sidebar->store), + &iter, + sidebar->eject_highlight_path); + + gtk_list_store_set (GTK_LIST_STORE (sidebar->store), + &iter, + PLACES_SIDEBAR_COLUMN_EJECT_ICON, get_eject_icon (FALSE), + -1); + + gtk_tree_path_free (sidebar->eject_highlight_path); + } + + /* Update current path */ + if (path) { + gtk_tree_model_get_iter (GTK_TREE_MODEL (sidebar->store), + &iter, + path); + + gtk_list_store_set (GTK_LIST_STORE (sidebar->store), + &iter, + PLACES_SIDEBAR_COLUMN_EJECT_ICON, get_eject_icon (TRUE), + -1); + } + + if (path) { + sidebar->eject_highlight_path = gtk_tree_path_copy (path); + } else { + sidebar->eject_highlight_path = NULL; + } +} + +static gboolean +bookmarks_motion_event_cb (GtkWidget *widget, + GdkEventMotion *event, + CajaPlacesSidebar *sidebar) +{ + GtkTreePath *path; + GtkTreeModel *model; + + model = GTK_TREE_MODEL (sidebar->filter_model); + + if (over_eject_button (sidebar, event->x, event->y, &path)) { + update_eject_buttons (sidebar, path); + } else { + update_eject_buttons (sidebar, NULL); + } + + if (path) { + gtk_tree_path_free (path); + } + + return TRUE; +} + /* Callback used when a button is pressed on the shortcuts list. * We trap button 3 to bring up a popup menu, and button 2 to * open in a new tab. @@ -2751,13 +2862,13 @@ caja_places_sidebar_init (CajaPlacesSidebar *sidebar) cell = gtk_cell_renderer_pixbuf_new (); g_object_set (cell, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, - "icon-name", "media-eject", "stock-size", GTK_ICON_SIZE_MENU, "xpad", EJECT_BUTTON_XPAD, NULL); gtk_tree_view_column_pack_start (col, cell, FALSE); gtk_tree_view_column_set_attributes (col, cell, "visible", PLACES_SIDEBAR_COLUMN_EJECT, + "pixbuf", PLACES_SIDEBAR_COLUMN_EJECT_ICON, NULL); cell = gtk_cell_renderer_text_new (); @@ -2800,7 +2911,8 @@ caja_places_sidebar_init (CajaPlacesSidebar *sidebar) G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, - G_TYPE_STRING + G_TYPE_STRING, + GDK_TYPE_PIXBUF ); gtk_tree_view_set_tooltip_column (tree_view, PLACES_SIDEBAR_COLUMN_TOOLTIP); @@ -2847,6 +2959,8 @@ caja_places_sidebar_init (CajaPlacesSidebar *sidebar) G_CALLBACK (bookmarks_popup_menu_cb), sidebar); g_signal_connect (tree_view, "button-press-event", G_CALLBACK (bookmarks_button_press_event_cb), sidebar); + g_signal_connect (tree_view, "motion-notify-event", + G_CALLBACK (bookmarks_motion_event_cb), sidebar); g_signal_connect (tree_view, "button-release-event", G_CALLBACK (bookmarks_button_release_event_cb), sidebar); |