[banshee] [Banshee.ThickClient] Position source switcher on SourceView



commit 681d5178212db22e95477aa504dcce67b9f26a3f
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Sun Apr 4 13:56:48 2010 -0700

    [Banshee.ThickClient] Position source switcher on SourceView
    
    Disable the SourceView's TreeView search, replacing it with our own,
    activated with the g keybinding.

 .../Banshee.Gui/SourceActions.cs                   |   88 +------------------
 .../Banshee.Sources.Gui/SourceView.cs              |   93 ++++++++++++++++++++
 2 files changed, 94 insertions(+), 87 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
index 3e956d1..4b4f8c1 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
@@ -110,7 +110,7 @@ namespace Banshee.Gui
                 new ActionEntry ("OpenSourceSwitcher", null,
                     Catalog.GetString ("Switch Source"), "G",
                     Catalog.GetString ("Switch to a source by typing its name"),
-                    OnOpenSourceSwitcher),
+                    null),
 
                 new ActionEntry ("SourcePreferencesAction", null, Catalog.GetString ("Preferences"), null,
                     Catalog.GetString ("Edit preferences related to this source"), OnSourcePreferences),
@@ -341,92 +341,6 @@ namespace Banshee.Gui
             }
         }
 
-        private void OnOpenSourceSwitcher (object o, EventArgs args)
-        {
-            var popup = new Hyena.Widgets.EntryPopup ();
-
-            // FIXME not sure if it's possible to do auto-complete w/o a Model
-            /*var completion = new EntryCompletion () {
-                InlineSelection = true,
-                InlineCompletion = true,
-                PopupCompletion = true,
-                PopupSingleMatch = true,
-                MinimumKeyLength = 2
-            };
-
-            popup.Entry.Completion = completion;
-            completion.ActionActivated += (o2, a) => {
-                try {
-                    var src = SourceSwitcherMatches (popup.Text).Skip (a.Index).FirstOrDefault ();
-                    if (src != null) {
-                        ServiceManager.SourceManager.SetActiveSource (src);
-                    }
-                } catch {}
-            };
-
-            popup.Changed += delegate {
-                completion.Clear ();
-                completion.Complete ();
-
-                int i = 0;
-                foreach (var src in SourceSwitcherMatches (popup.Text)) {
-                    completion.InsertActionText (i++, src.Name);
-                }
-            };*/
-
-            popup.Entry.Activated += delegate {
-                try {
-                    var src = SourceSwitcherMatches (popup.Text).FirstOrDefault ();
-                    if (src != null) {
-                        ServiceManager.SourceManager.SetActiveSource (src);
-                    }
-                } catch {}
-            };
-
-            var label = new Label (Catalog.GetString ("Switch to source:")) { Visible = true };
-            popup.Box.PackStart (label, false, false, 0);
-            popup.Box.ReorderChild (label, 0);
-
-            popup.Position (ServiceManager.Get<GtkElementsService> ().PrimaryWindow.GdkWindow);
-            popup.HasFocus = true;
-            popup.Show ();
-        }
-
-        private IEnumerable<Source> SourceSwitcherMatches (string query)
-        {
-            query = StringUtil.SearchKey (query);
-            if (String.IsNullOrEmpty (query)) {
-                return Enumerable.Empty<Source> ();
-            }
-
-            return ServiceManager.SourceManager.Sources
-                                               .Select  (s => new { Source = s, Priority = SourceSwitcherPriority (s, query) })
-                                               .Where   (s => s.Priority > 0)
-                                               .OrderBy (s => s.Priority)
-                                               .Select  (s => s.Source);
-        }
-
-        private int SourceSwitcherPriority (Source s, string query)
-        {
-            int priority = 0;
-            var name = StringUtil.SearchKey (s.Name);
-            if (name != null) {
-                if (name.StartsWith (query)) {
-                    priority = 1;
-                } else {
-                    var split_name = name.Split (' ');
-                    if (split_name.Length == query.Length &&
-                        Enumerable.Range (0, query.Length).All (i => split_name[i][0] == query[i])) {
-                        priority = 2;
-                    } else if (name.Contains (query)) {
-                        priority = 3;
-                    }
-                }
-            }
-
-            return priority;
-        }
-
         private void OnSourcePreferences (object o, EventArgs args)
         {
             try {
diff --git a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
index d83adbd..4c70f1c 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
@@ -27,6 +27,7 @@
 //
 
 using System;
+using System.Linq;
 using System.Collections.Generic;
 
 using Gtk;
@@ -75,6 +76,7 @@ namespace Banshee.Sources.Gui
             store.SourceRowRemoved += OnSourceRowRemoved;
             store.RowChanged += OnRowChanged;
             Model = store;
+            EnableSearch = false;
 
             ConfigureDragAndDrop ();
             store.Refresh ();
@@ -140,6 +142,10 @@ namespace Banshee.Sources.Gui
                 }
                 return true;
             };
+
+            ServiceManager.Get<InterfaceActionService> ().SourceActions["OpenSourceSwitcher"].Activated += delegate {
+                OpenSourceSwitcher ();
+            };
         }
 
 #endregion
@@ -226,6 +232,93 @@ namespace Banshee.Sources.Gui
             return base.OnButtonPressEvent (press);
         }
 
+        private void OpenSourceSwitcher ()
+        {
+            var popup = new Hyena.Widgets.EntryPopup ();
+
+            // FIXME not sure if it's possible to do auto-complete w/o a Model
+            /*var completion = new EntryCompletion () {
+                InlineSelection = true,
+                InlineCompletion = true,
+                PopupCompletion = true,
+                PopupSingleMatch = true,
+                MinimumKeyLength = 2
+            };
+
+            popup.Entry.Completion = completion;
+            completion.ActionActivated += (o2, a) => {
+                try {
+                    var src = SourceSwitcherMatches (popup.Text).Skip (a.Index).FirstOrDefault ();
+                    if (src != null) {
+                        ServiceManager.SourceManager.SetActiveSource (src);
+                    }
+                } catch {}
+            };
+
+            popup.Changed += delegate {
+                completion.Clear ();
+                completion.Complete ();
+
+                int i = 0;
+                foreach (var src in SourceSwitcherMatches (popup.Text)) {
+                    completion.InsertActionText (i++, src.Name);
+                }
+            };*/
+
+            popup.Entry.Activated += delegate {
+                try {
+                    var src = SourceSwitcherMatches (popup.Text).FirstOrDefault ();
+                    if (src != null) {
+                        ServiceManager.SourceManager.SetActiveSource (src);
+                    }
+                } catch {}
+            };
+
+            /*var label = new Label (Catalog.GetString ("Switch to source:")) { Visible = true };
+            popup.Box.PackStart (label, false, false, 0);
+            popup.Box.ReorderChild (label, 0);*/
+
+            popup.Position (GdkWindow);
+            popup.HasFocus = true;
+            popup.Show ();
+        }
+
+        private IEnumerable<Source> SourceSwitcherMatches (string query)
+        {
+            query = StringUtil.SearchKey (query);
+            if (String.IsNullOrEmpty (query)) {
+                return Enumerable.Empty<Source> ();
+            }
+
+            return ServiceManager.SourceManager.Sources
+                                               .Select  (s => new { Source = s, Priority = SourceSwitcherPriority (s, query) })
+                                               .Where   (s => s.Priority > 0)
+                                               .OrderBy (s => s.Priority)
+                                               .Select  (s => s.Source);
+        }
+
+        private int SourceSwitcherPriority (Source s, string query)
+        {
+            int priority = 0;
+            var name = StringUtil.SearchKey (s.Name);
+            if (name != null) {
+                if (name.StartsWith (query)) {
+                    priority = 1;
+                } else {
+                    var split_name = name.Split (' ');
+                    if (split_name.Length == query.Length &&
+                        Enumerable.Range (0, query.Length).All (i => split_name[i][0] == query[i])) {
+                        priority = 2;
+                    } else if (name.Contains (query)) {
+                        priority = 3;
+                    }
+                }
+            }
+
+            return priority;
+        }
+
+
         protected override bool OnPopupMenu ()
         {
             ServiceManager.Get<InterfaceActionService> ().SourceActions["SourceContextMenuAction"].Activate ();



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