[banshee] Support /Banshee/ThickClient/ActionGroup addins



commit ba64b18a0f5d11d79bd6cb2bf6bd76b4d5b35a27
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Jul 1 15:09:36 2009 -0500

    Support /Banshee/ThickClient/ActionGroup addins
    
    Also simplify BansheeActionGroup API

 .../Banshee.Gui/GlobalActions.cs                   |    2 +-
 .../Banshee.Gui/InterfaceActionService.cs          |   61 ++++++++++++++-----
 .../Banshee.Gui/PlaybackActions.cs                 |    8 +-
 .../Banshee.Gui/SourceActions.cs                   |    2 +-
 .../Banshee.Gui/TrackActions.cs                    |    2 +-
 .../Banshee.ThickClient/Banshee.Gui/ViewActions.cs |    2 +-
 6 files changed, 53 insertions(+), 24 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs
index 92e0338..e314690 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/GlobalActions.cs
@@ -42,7 +42,7 @@ namespace Banshee.Gui
 {
     public class GlobalActions : BansheeActionGroup
     {
-        public GlobalActions (InterfaceActionService actionService) : base (actionService, "Global")
+        public GlobalActions () : base ("Global")
         {
             Add (new ActionEntry [] {
                 // Media Menu
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/InterfaceActionService.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/InterfaceActionService.cs
index edfc153..71633cd 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/InterfaceActionService.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/InterfaceActionService.cs
@@ -31,18 +31,23 @@ using System.IO;
 using System.Reflection;
 using System.Collections.Generic;
 
+using Mono.Addins;
+
 using Gtk;
 using Action = Gtk.Action;
 
+using Hyena;
+
 using Banshee.Sources;
 using Banshee.ServiceStack;
 
 namespace Banshee.Gui
 {
-    public class InterfaceActionService : IService
+    public class InterfaceActionService : IInitializeService
     {
-        private UIManager ui_manager = new UIManager ();    
+        private UIManager ui_manager;
         private Dictionary<string, ActionGroup> action_groups = new Dictionary<string, ActionGroup> ();
+        private Dictionary<string, ActionGroup> extension_actions = new Dictionary<string, ActionGroup> ();
 
         private GlobalActions   global_actions;
         private ViewActions     view_actions;
@@ -55,23 +60,23 @@ namespace Banshee.Gui
         
         public InterfaceActionService ()
         {
-            global_actions      = new GlobalActions (this);
-            view_actions        = new ViewActions (this);
-            playback_actions    = new PlaybackActions (this);
-            track_actions       = new TrackActions (this);
-            source_actions      = new SourceActions (this);
+            ui_manager = new UIManager ();
 
-            AddActionGroup (global_actions);
-            AddActionGroup (view_actions);
-            AddActionGroup (playback_actions);
-            AddActionGroup (track_actions);
-            AddActionGroup (source_actions);
-
-            ui_manager.AddUiFromResource ("core-ui-actions-layout.xml");    
-            
             ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged;
         }
-        
+
+        public void Initialize ()
+        {
+            AddActionGroup (global_actions      = new GlobalActions ());
+            AddActionGroup (view_actions        = new ViewActions ());
+            AddActionGroup (playback_actions    = new PlaybackActions ());
+            AddActionGroup (track_actions       = new TrackActions ());
+            AddActionGroup (source_actions      = new SourceActions ());
+            ui_manager.AddUiFromResource ("core-ui-actions-layout.xml");
+
+            AddinManager.AddExtensionNodeHandler ("/Banshee/ThickClient/ActionGroup", OnExtensionChanged);
+        }
+
         private void InnerAddActionGroup (ActionGroup group)
         {
             action_groups.Add (group.Name, group);
@@ -202,6 +207,30 @@ namespace Banshee.Gui
             active_source_uiid = AddUiFromFile (active_source.GetProperty<string> ("ActiveSourceUIResource", propagate), assembly);
         }
 
+        private void OnExtensionChanged (object o, ExtensionNodeEventArgs args) 
+        {
+            try {
+                TypeExtensionNode node = (TypeExtensionNode)args.ExtensionNode;
+                
+                if (args.Change == ExtensionChange.Add) {
+                    if (!extension_actions.ContainsKey (node.Id)) {
+                        ActionGroup group = (ActionGroup)node.CreateInstance (typeof (ActionGroup));
+                        extension_actions[node.Id] = group;
+                        AddActionGroup (group);
+                        Log.DebugFormat ("Extension actions loaded: {0}", node.Type);
+                    }
+                } else if (args.Change == ExtensionChange.Remove) {
+                    if (extension_actions.ContainsKey (node.Id)) {
+                        extension_actions[node.Id].Dispose ();
+                        extension_actions.Remove (node.Id);
+                        Log.DebugFormat ("Extension actions unloaded: {0}", node.Type);
+                    }
+                }
+            } catch (Exception e) {
+                Log.Exception (e);
+            }
+        }
+
         public uint AddUiFromFileInCurrentAssembly (string ui_file)
         {
             return AddUiFromFile (ui_file, Assembly.GetCallingAssembly ());
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackActions.cs
index bfa0330..789333c 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/PlaybackActions.cs
@@ -57,7 +57,7 @@ namespace Banshee.Gui
             get { return shuffle_actions; }
         }
         
-        public PlaybackActions (InterfaceActionService actionService) : base (actionService, "Playback")
+        public PlaybackActions () : base ("Playback")
         {
             ImportantByDefault = false;
 
@@ -94,7 +94,7 @@ namespace Banshee.Gui
                     OnStopWhenFinishedAction, false)
             });
             
-            actionService.GlobalActions.Add (new ActionEntry [] {
+            Actions.GlobalActions.Add (new ActionEntry [] {
                 new ActionEntry ("PlaybackMenuAction", null,
                     Catalog.GetString ("_Playback"), null, null, null),
             });
@@ -112,8 +112,8 @@ namespace Banshee.Gui
                 PlayerEvent.EndOfStream | 
                 PlayerEvent.StateChange);
             
-            repeat_actions = new PlaybackRepeatActions (actionService);
-            shuffle_actions = new PlaybackShuffleActions (actionService, this);
+            repeat_actions = new PlaybackRepeatActions (Actions);
+            shuffle_actions = new PlaybackShuffleActions (Actions, this);
         }
         
         private void OnPlayerEvent (PlayerEventArgs args)
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
index ee8e49a..b0b0a71 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
@@ -66,7 +66,7 @@ namespace Banshee.Gui
             get { return (SourceView.HighlightedSource as PrimarySource) ?? base.ActivePrimarySource; }
         }
 
-        public SourceActions (InterfaceActionService actionService) : base (actionService, "Source")
+        public SourceActions () : base ("Source")
         {
             Add (new ActionEntry [] {
                 new ActionEntry ("NewPlaylistAction", null,
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
index faf5252..ee5d596 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
@@ -57,7 +57,7 @@ namespace Banshee.Gui
         
         public event EventHandler SelectionChanged;
 
-        public TrackActions (InterfaceActionService actionService) : base (actionService, "Track")
+        public TrackActions () : base ("Track")
         {
             Add (new ActionEntry [] {
                 new ActionEntry("TrackContextMenuAction", null, 
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs
index 97fdef6..e260278 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/ViewActions.cs
@@ -55,7 +55,7 @@ namespace Banshee.Gui
             }
         }
     
-        public ViewActions (InterfaceActionService actionService) : base (actionService, "View")
+        public ViewActions () : base ("View")
         {
             Add (new ActionEntry [] {
                 new ActionEntry ("ViewMenuAction", null,



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