[banshee] [TrackActions] Open containing folder (bgo#609315)



commit c2b3814959b632c82726595cd65cdaa0aeea309c
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Mon Feb 15 17:34:07 2010 +1100

    [TrackActions] Open containing folder (bgo#609315)
    
    Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>

 .../Banshee.Gui/TrackActions.cs                    |   47 +++++++++++++++++++-
 .../Resources/core-ui-actions-layout.xml           |    3 +
 2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
index fde8ee8..0470d0f 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
@@ -53,8 +53,8 @@ namespace Banshee.Gui
 
         private static readonly string [] require_selection_actions = new string [] {
             "TrackContextMenuAction", "TrackPropertiesAction", "AddToPlaylistAction",
-            "RemoveTracksAction", "RemoveTracksFromLibraryAction", "DeleteTracksFromDriveAction",
-            "RateTracksAction", "SelectNoneAction"
+            "RemoveTracksAction", "RemoveTracksFromLibraryAction", "OpenContainingFolderAction",
+            "DeleteTracksFromDriveAction", "RateTracksAction", "SelectNoneAction"
         };
 
         public event EventHandler SelectionChanged;
@@ -99,6 +99,10 @@ namespace Banshee.Gui
                     Catalog.GetString ("Remove From _Library"), "",
                     Catalog.GetString ("Remove selected track(s) from library"), OnRemoveTracksFromLibrary),
 
+                new ActionEntry ("OpenContainingFolderAction", null,
+                    Catalog.GetString ("_Open Containing Folder"), null,
+                    Catalog.GetString ("Open the folder that contains the selected item"), OnOpenContainingFolder),
+
                 new ActionEntry ("DeleteTracksFromDriveAction", null,
                     Catalog.GetString ("_Delete From Drive"), null,
                     Catalog.GetString ("Permanently delete selected item(s) from medium"), OnDeleteTracksFromDrive),
@@ -229,6 +233,10 @@ namespace Banshee.Gui
 
                     UpdateAction ("RemoveTracksAction", is_track_source && track_source.CanRemoveTracks, has_selection, source);
                     UpdateAction ("DeleteTracksFromDriveAction", is_track_source && track_source.CanDeleteTracks, has_selection, source);
+
+                    //if it can delete tracks, most likely it can open their folder
+                    UpdateAction ("OpenContainingFolderAction", is_track_source && track_source.CanDeleteTracks, has_single_selection, source);
+
                     UpdateAction ("RemoveTracksFromLibraryAction", source.Parent is LibrarySource, has_selection, null);
 
                     UpdateAction ("TrackPropertiesAction", source.HasViewableTrackProperties, has_selection, source);
@@ -403,6 +411,41 @@ namespace Banshee.Gui
             }
         }
 
+        private void OnOpenContainingFolder (object o, EventArgs args)
+        {
+            var source = ActiveSource as ITrackModelSource;
+
+            if (source == null ||
+                source.TrackModel == null ||
+                source.TrackModel.SelectedItems == null ||
+                source.TrackModel.SelectedItems.Count != 1) {
+                Log.Error ("Could not open containing folder");
+                return;
+            }
+
+            foreach (var track in source.TrackModel.SelectedItems) {
+                var path = System.IO.Path.GetDirectoryName (track.Uri.AbsolutePath);
+                if (Banshee.IO.Directory.Exists (path)) {
+                    System.Diagnostics.Process.Start (path);
+                    return;
+                }
+            }
+
+            var md = new HigMessageDialog (
+                ServiceManager.Get<GtkElementsService> ("GtkElementsService").PrimaryWindow,
+                DialogFlags.DestroyWithParent, MessageType.Warning,
+                ButtonsType.None, Catalog.GetString ("The folder could not be found."),
+                Catalog.GetString ("Please check that the track's location is accessible by the system.")
+            );
+            md.AddButton ("gtk-ok", ResponseType.Ok, true);
+
+            try {
+                md.Run ();
+            } finally {
+                md.Destroy ();
+            }
+        }
+
         private void OnDeleteTracksFromDrive (object o, EventArgs args)
         {
             ITrackModelSource source = ActiveSource as ITrackModelSource;
diff --git a/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml b/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml
index de1e3bf..5621503 100644
--- a/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml
+++ b/src/Core/Banshee.ThickClient/Resources/core-ui-actions-layout.xml
@@ -46,6 +46,8 @@
       <menuitem name="RemoveTracksFromLibrary" action="RemoveTracksFromLibraryAction"/>
       <menuitem name="DeleteTracksFromDrive" action="DeleteTracksFromDriveAction"/>
       <separator/>
+      <menuitem name="OpenContainingFolder" action="OpenContainingFolderAction"/>
+      <separator/>
       <menuitem name="RenameSource" action="RenameSourceAction"/>
       <menuitem name="RefreshSmartPlaylist" action="RefreshSmartPlaylistAction"/>
       <menuitem name="ExportPlaylist" action="ExportPlaylistAction"/>
@@ -154,6 +156,7 @@
     <menuitem name="RemoveTracksFromLibrary" action="RemoveTracksFromLibraryAction"/>
     <menuitem name="DeleteTracksFromDrive" action="DeleteTracksFromDriveAction"/>
     <separator/>
+    <menuitem name="OpenContainingFolder" action="OpenContainingFolderAction"/>
     <menu name="SearchMenu" action="SearchMenuAction">
       <menuitem name="SearchForSameArtist" action="SearchForSameArtistAction"/>
       <menuitem name="SearchForSameAlbum" action="SearchForSameAlbumAction"/>



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