static void update_history (CajaHistorySidebar *sidebar) { GtkListStore *store; GtkTreeSelection *selection; CajaBookmark *bookmark; cairo_surface_t *surface; GtkTreeIter iter; char *name; GList *l, *history; store = GTK_LIST_STORE (gtk_tree_view_get_model (sidebar->tree_view)); gtk_list_store_clear (store); history = caja_window_info_get_history (sidebar->window); for (l = history; l != NULL; l = l->next) { bookmark = caja_bookmark_copy (l->data); surface = caja_bookmark_get_surface (bookmark, GTK_ICON_SIZE_MENU); name = caja_bookmark_get_name (bookmark); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, HISTORY_SIDEBAR_COLUMN_ICON, surface, HISTORY_SIDEBAR_COLUMN_NAME, name, HISTORY_SIDEBAR_COLUMN_BOOKMARK, bookmark, -1); g_object_unref (bookmark); if (surface != NULL) { cairo_surface_destroy (surface); } g_free (name); } g_list_free_full (history, g_object_unref); selection = GTK_TREE_SELECTION (gtk_tree_view_get_selection (sidebar->tree_view)); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { gtk_tree_selection_select_iter (selection, &iter); } }
static void on_selection_changed (GtkTreeSelection *treeselection, gpointer user_data) { CajaBookmark *selected; char *name = NULL, *entry_text = NULL; GFile *location; g_assert (GTK_IS_ENTRY (name_field)); g_assert (GTK_IS_ENTRY (uri_field)); selected = get_selected_bookmark (); if (selected) { name = caja_bookmark_get_name (selected); location = caja_bookmark_get_location (selected); entry_text = g_file_get_parse_name (location); g_object_unref (location); } /* Set the sensitivity of widgets that require a selection */ gtk_widget_set_sensitive (remove_button, selected != NULL); gtk_widget_set_sensitive (jump_button, selected != NULL); gtk_widget_set_sensitive (name_field, selected != NULL); gtk_widget_set_sensitive (uri_field, selected != NULL); g_signal_handler_block (name_field, name_field_changed_signal_id); caja_entry_set_text (CAJA_ENTRY (name_field), name ? name : ""); g_signal_handler_unblock (name_field, name_field_changed_signal_id); g_signal_handler_block (uri_field, uri_field_changed_signal_id); caja_entry_set_text (CAJA_ENTRY (uri_field), entry_text ? entry_text : ""); g_signal_handler_unblock (uri_field, uri_field_changed_signal_id); text_changed = FALSE; name_text_changed = FALSE; g_free (name); g_free (entry_text); }
void caja_menus_append_bookmark_to_menu (CajaWindow *window, CajaBookmark *bookmark, const char *parent_path, const char *parent_id, guint index_in_parent, GtkActionGroup *action_group, guint merge_id, GCallback refresh_callback, CajaBookmarkFailedCallback failed_callback) { BookmarkHolder *bookmark_holder; char action_name[128]; char *name; char *path; GdkPixbuf *pixbuf; GtkAction *action; GtkWidget *menuitem; g_assert (CAJA_IS_WINDOW (window)); g_assert (CAJA_IS_BOOKMARK (bookmark)); bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback); name = caja_bookmark_get_name (bookmark); /* Create menu item with pixbuf */ pixbuf = caja_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU); g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent); action = gtk_action_new (action_name, name, _("Go to the location specified by this bookmark"), NULL); g_object_set_data_full (G_OBJECT (action), "menu-icon", g_object_ref (pixbuf), g_object_unref); g_signal_connect_data (action, "activate", G_CALLBACK (activate_bookmark_in_menu_item), bookmark_holder, bookmark_holder_free_cover, 0); gtk_action_group_add_action (action_group, GTK_ACTION (action)); g_object_unref (action); gtk_ui_manager_add_ui (window->details->ui_manager, merge_id, parent_path, action_name, action_name, GTK_UI_MANAGER_MENUITEM, FALSE); path = g_strdup_printf ("%s/%s", parent_path, action_name); menuitem = gtk_ui_manager_get_widget (window->details->ui_manager, path); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (menuitem), TRUE); g_object_unref (pixbuf); g_free (path); g_free (name); }
static void repopulate (void) { CajaBookmark *selected; GtkListStore *store; GtkTreePath *path; GtkTreeRowReference *reference; guint index; g_assert (GTK_IS_TREE_VIEW (bookmark_list_widget)); g_assert (CAJA_IS_BOOKMARK_LIST (bookmarks)); store = GTK_LIST_STORE (bookmark_list_store); selected = get_selected_bookmark (); g_signal_handler_block (bookmark_selection, selection_changed_id); g_signal_handler_block (bookmark_list_store, row_deleted_signal_id); g_signal_handler_block (bookmark_list_widget, row_activated_signal_id); g_signal_handler_block (bookmark_list_widget, key_pressed_signal_id); g_signal_handler_block (bookmark_list_widget, button_pressed_signal_id); gtk_list_store_clear (store); g_signal_handler_unblock (bookmark_list_widget, row_activated_signal_id); g_signal_handler_unblock (bookmark_list_widget, key_pressed_signal_id); g_signal_handler_unblock (bookmark_list_widget, button_pressed_signal_id); g_signal_handler_unblock (bookmark_list_store, row_deleted_signal_id); g_signal_handler_unblock (bookmark_selection, selection_changed_id); /* Fill the list in with the bookmark names. */ g_signal_handler_block (store, row_changed_signal_id); reference = NULL; for (index = 0; index < caja_bookmark_list_length (bookmarks); ++index) { CajaBookmark *bookmark; char *bookmark_name; GdkPixbuf *bookmark_pixbuf; GtkTreeIter iter; bookmark = caja_bookmark_list_item_at (bookmarks, index); bookmark_name = caja_bookmark_get_name (bookmark); bookmark_pixbuf = caja_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, BOOKMARK_LIST_COLUMN_ICON, bookmark_pixbuf, BOOKMARK_LIST_COLUMN_NAME, bookmark_name, BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark, BOOKMARK_LIST_COLUMN_STYLE, PANGO_STYLE_NORMAL, -1); if (bookmark == selected) { /* save old selection */ GtkTreePath *path; path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path); gtk_tree_path_free (path); } g_free (bookmark_name); g_object_unref (bookmark_pixbuf); } g_signal_handler_unblock (store, row_changed_signal_id); if (reference != NULL) { /* restore old selection */ /* bookmarks_set_empty() will call the selection change handler, * so we block it here in case of selection change. */ g_signal_handler_block (bookmark_selection, selection_changed_id); g_assert (index != 0); g_assert (gtk_tree_row_reference_valid (reference)); path = gtk_tree_row_reference_get_path (reference); gtk_tree_selection_select_path (bookmark_selection, path); gtk_tree_row_reference_free (reference); gtk_tree_path_free (path); g_signal_handler_unblock (bookmark_selection, selection_changed_id); } bookmarks_set_empty (index == 0); }
static void update_bookmark_from_text (void) { if (text_changed) { CajaBookmark *bookmark, *bookmark_in_list; char *name; GdkPixbuf *pixbuf; guint selected_row; GtkTreeIter iter; GFile *location; g_assert (GTK_IS_ENTRY (name_field)); g_assert (GTK_IS_ENTRY (uri_field)); if (gtk_entry_get_text_length (GTK_ENTRY (uri_field)) == 0) { return; } location = g_file_parse_name (gtk_entry_get_text (GTK_ENTRY (uri_field))); bookmark = caja_bookmark_new (location, gtk_entry_get_text (GTK_ENTRY (name_field)), name_text_changed, NULL); g_object_unref (location); selected_row = get_selected_row (); /* turn off list updating 'cuz otherwise the list-reordering code runs * after repopulate(), thus reordering the correctly-ordered list. */ g_signal_handler_block (bookmarks, bookmark_list_changed_signal_id); caja_bookmark_list_delete_item_at (bookmarks, selected_row); caja_bookmark_list_insert_item (bookmarks, bookmark, selected_row); g_signal_handler_unblock (bookmarks, bookmark_list_changed_signal_id); g_object_unref (bookmark); /* We also have to update the bookmark pointer in the list store. */ gtk_tree_selection_get_selected (bookmark_selection, NULL, &iter); g_signal_handler_block (bookmark_list_store, row_changed_signal_id); bookmark_in_list = caja_bookmark_list_item_at (bookmarks, selected_row); name = caja_bookmark_get_name (bookmark_in_list); pixbuf = caja_bookmark_get_pixbuf (bookmark_in_list, GTK_ICON_SIZE_MENU); gtk_list_store_set (bookmark_list_store, &iter, BOOKMARK_LIST_COLUMN_BOOKMARK, bookmark_in_list, BOOKMARK_LIST_COLUMN_NAME, name, BOOKMARK_LIST_COLUMN_ICON, pixbuf, -1); g_signal_handler_unblock (bookmark_list_store, row_changed_signal_id); g_object_unref (pixbuf); g_free (name); } }