[rhythmbox] clipboard: use the source's specified deletion action



commit 942b8a093966ada2fa884901cba5e6c1478fbe2f
Author: Jonathan Matthew <jonathan d14n org>
Date:   Wed Jan 13 22:52:26 2010 +1000

    clipboard: use the source's specified deletion action
    
    When the selected source changes, ask the new source for its deletion
    action, then add that into various placeholders.

 data/ui/rhythmbox-ui.xml   |    8 ++++----
 shell/rb-shell-clipboard.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/rhythmbox-ui.xml b/data/ui/rhythmbox-ui.xml
index cc8246b..86ea706 100644
--- a/data/ui/rhythmbox-ui.xml
+++ b/data/ui/rhythmbox-ui.xml
@@ -29,7 +29,6 @@
       <menuitem name="EditCutMenu" action="EditCut"/>
       <menuitem name="EditCopyMenu" action="EditCopy"/>
       <menuitem name="EditPasteMenu" action="EditPaste"/>
-      <menuitem name="EditDeleteMenu" action="EditDelete"/>
       <separator/>
       <menuitem name="EditSelectAllMenu" action="EditSelectAll"/>
       <menuitem name="EditSelectNoneMenu" action="EditSelectNone"/>
@@ -41,6 +40,7 @@
         <placeholder name="EditPlaylistAddPlaceholder"/>
       </menu>
       <separator/>
+      <placeholder name="DeleteActionPlaceholder" />
       <menuitem name="EditMovetoTrash" action="EditMovetoTrash"/>
       <separator/>
       <menuitem name="EditPluginsMenu" action="EditPlugins"/>
@@ -121,7 +121,7 @@
     </menu>
     <menuitem name="CopyLibraryPopup" action="EditCopy"/>
     <separator/>
-    <menuitem name="DeleteLibraryPopup" action="EditDelete"/>
+    <placeholder name="DeleteActionPlaceholder" />
     <menuitem name="MovetoTrashPopup" action="EditMovetoTrash"/>
     <separator/>
     <menuitem name="BrowseGenreLibraryPopup" action="BrowserSrcChooseGenre"/>
@@ -134,7 +134,7 @@
   </popup>
 
   <popup name="ImportErrorsViewPopup">
-    <menuitem name="DeleteLibraryPopup" action="EditDelete"/>
+    <menuitem name="DeleteLibraryPopup" action="EditRemove"/>
     <menuitem name="MovetoTrashPopup" action="EditMovetoTrash"/>
     <separator/>
     <placeholder name="PluginPlaceholder"/>
@@ -262,7 +262,7 @@
   </popup>
 
   <popup name="MissingFilesViewPopup">
-    <menuitem name="DeleteMissingFilesPopup" action="EditDelete"/>
+    <menuitem name="DeleteMissingFilesPopup" action="EditRemove"/>
     <menuitem name="PropertiesMissingFilesPopup" action="MusicProperties"/>
     <separator/>
     <placeholder name="PluginPlaceholder"/>
diff --git a/shell/rb-shell-clipboard.c b/shell/rb-shell-clipboard.c
index 5a4df18..c09f98f 100644
--- a/shell/rb-shell-clipboard.c
+++ b/shell/rb-shell-clipboard.c
@@ -121,6 +121,9 @@ struct RBShellClipboardPrivate
 	GtkActionGroup *actiongroup;
 	guint playlist_menu_ui_id;
 
+	guint delete_action_ui_id;
+	GtkAction *delete_action;
+
 	GHashTable *signal_hash;
 
 	GAsyncQueue *deleted_queue;
@@ -190,6 +193,11 @@ static GtkActionEntry rb_shell_clipboard_actions [] =
 };
 static guint rb_shell_clipboard_n_actions = G_N_ELEMENTS (rb_shell_clipboard_actions);
 
+static const char *delete_action_paths[] = {
+	"/MenuBar/EditMenu/DeleteActionPlaceholder",
+	"/BrowserSourceViewPopup/DeleteActionPlaceholder",
+};
+
 static const char *playlist_menu_paths[] = {
 	"/MenuBar/EditMenu/EditPlaylistAddMenu/EditPlaylistAddPlaceholder",
 	"/BrowserSourceViewPopup/BrowserSourcePopupPlaylistAdd/BrowserSourcePopupPlaylistAddPlaceholder",
@@ -281,6 +289,9 @@ unset_source_internal (RBShellClipboard *clipboard)
 							      G_CALLBACK (rb_shell_clipboard_entries_changed_cb),
 							      clipboard);
 		}
+
+		gtk_ui_manager_remove_ui (clipboard->priv->ui_mgr,
+					  clipboard->priv->delete_action_ui_id);
 	}
 	clipboard->priv->source = NULL;
 }
@@ -346,6 +357,7 @@ rb_shell_clipboard_set_source_internal (RBShellClipboard *clipboard,
 
 	if (clipboard->priv->source != NULL) {
 		RBEntryView *songs = rb_source_get_entry_view (clipboard->priv->source);
+		char *delete_action;
 
 		if (songs) {
 			g_signal_connect_object (G_OBJECT (songs),
@@ -365,6 +377,28 @@ rb_shell_clipboard_set_source_internal (RBShellClipboard *clipboard,
 						 G_CALLBACK (rb_shell_clipboard_entryview_changed_cb),
 						 clipboard, 0);
 		}
+
+		delete_action = rb_source_get_delete_action (source);
+		if (delete_action != NULL) {
+			char *path;
+			int i;
+			for (i = 0; i < G_N_ELEMENTS (delete_action_paths); i++) {
+				gtk_ui_manager_add_ui (clipboard->priv->ui_mgr,
+						       clipboard->priv->delete_action_ui_id,
+						       delete_action_paths[i],
+						       delete_action,
+						       delete_action,
+						       GTK_UI_MANAGER_AUTO,
+						       FALSE);
+			}
+			gtk_ui_manager_ensure_update (clipboard->priv->ui_mgr);
+
+			/* locate action too */
+			path = g_strdup_printf ("%s/%s", delete_action_paths[0], delete_action);
+			clipboard->priv->delete_action = gtk_ui_manager_get_action (clipboard->priv->ui_mgr, path);
+			g_free (path);
+		}
+		g_free (delete_action);
 	}
 
 	rebuild_playlist_menu (clipboard);
@@ -399,6 +433,9 @@ rb_shell_clipboard_set_property (GObject *object,
 		break;
 	case PROP_UI_MANAGER:
 		clipboard->priv->ui_mgr = g_value_get_object (value);
+		clipboard->priv->delete_action_ui_id =
+			gtk_ui_manager_new_merge_id (clipboard->priv->ui_mgr);
+
 		break;
 	case PROP_PLAYLIST_MANAGER:
 		if (clipboard->priv->playlist_manager != NULL) {
@@ -579,8 +616,9 @@ rb_shell_clipboard_sync (RBShellClipboard *clipboard)
 	action = gtk_action_group_get_action (clipboard->priv->actiongroup, "EditCut");
 	g_object_set (G_OBJECT (action), "sensitive", can_cut, NULL);
 
-	action = gtk_action_group_get_action (clipboard->priv->actiongroup, "EditDelete");
-	g_object_set (G_OBJECT (action), "sensitive", can_delete, NULL);
+	if (clipboard->priv->delete_action != NULL) {
+		g_object_set (clipboard->priv->delete_action, "sensitive", can_delete, NULL);
+	}
 
 	action = gtk_action_group_get_action (clipboard->priv->actiongroup, "EditMovetoTrash");
 	g_object_set (G_OBJECT (action), "sensitive", can_move_to_trash, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]