[banshee/extension-prefs: 1/2] [Prefs] Replace the extensions prefs UI



commit 7420596e33e17ec0cd76d5c714c545e5547ad9f9
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Mon Dec 14 22:57:33 2009 -0800

    [Prefs] Replace the extensions prefs UI
    
    The new UI has a dropdown to filter addins based on if they're enabled,
    a search box, and a TreeView with alphabetical categories and subitems.
    
    Still needs UI to enable/disable addins - probably a checkbox.  And
    needs more UI work for displaying description, etc.

 .../Banshee.Addins.Gui/AddinTile.cs                |  225 -----------------
 .../Banshee.Addins.Gui/AddinView.cs                |  260 ++++++++------------
 .../DefaultPreferenceWidgets.cs                    |   11 +-
 .../Banshee.ThickClient/Banshee.ThickClient.csproj |    1 -
 src/Core/Banshee.ThickClient/Makefile.am           |    1 -
 5 files changed, 104 insertions(+), 394 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Addins.Gui/AddinView.cs b/src/Core/Banshee.ThickClient/Banshee.Addins.Gui/AddinView.cs
index 7fb361a..2acaab1 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Addins.Gui/AddinView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Addins.Gui/AddinView.cs
@@ -27,179 +27,125 @@
 //
 
 using System;
+using System.Linq;
 using System.Collections.Generic;
 using Gtk;
 
+using Mono.Unix;
 using Mono.Addins;
 
+using Hyena;
+
 namespace Banshee.Addins.Gui
 {
-    public class AddinView : EventBox
+    public class AddinView : VBox
     {
-        private List<AddinTile> tiles = new List<AddinTile> ();
-        private VBox box = new VBox ();
-
-        private int selected_index = -1;
+        private TreeView tree_view;
 
         public AddinView ()
         {
-            CanFocus = true;
-            VisibleWindow = false;
-
-            box.Show ();
-            Add (box);
-
-            LoadAddins ();
-        }
-
-        private void LoadAddins ()
-        {
-            foreach (Addin addin in AddinManager.Registry.GetAddins ()) {
-                if (addin.Name != addin.Id && addin.Description != null &&
-                    addin.Description.Category != null && !addin.Description.Category.StartsWith ("required:") &&
-                    (!addin.Description.Category.Contains ("Debug") || Banshee.Base.ApplicationContext.Debugging)) {
-                    AppendAddin (addin);
-                }
-            }
-
-            if (tiles.Count > 0) {
-                tiles[tiles.Count - 1].Last = true;
-            }
-        }
-
-        private bool changing_styles = false;
-
-        protected override void OnStyleSet (Style previous_style)
-        {
-            if (changing_styles) {
-                return;
-            }
-
-            changing_styles = true;
-            base.OnStyleSet (previous_style);
-            Parent.ModifyBg (StateType.Normal, Style.Base (StateType.Normal));
-            changing_styles = false;
-        }
-
-        private void AppendAddin (Addin addin)
-        {
-            AddinTile tile = new AddinTile (addin);
-            tile.ActiveChanged += OnAddinActiveChanged;
-            tile.SizeAllocated += OnAddinSizeAllocated;
-            tile.Show ();
-            tiles.Add (tile);
-
-            box.PackStart (tile, false, false, 0);
-        }
-
-        private void OnAddinActiveChanged (object o, EventArgs args)
-        {
-            foreach (AddinTile tile in tiles) {
-                tile.UpdateState ();
-            }
-        }
-
-        private void OnAddinSizeAllocated (object o, SizeAllocatedArgs args)
-        {
-            ScrolledWindow scroll;
-
-            if (Parent == null || (scroll = Parent.Parent as ScrolledWindow) == null) {
-                return;
-            }
-
-            AddinTile tile = (AddinTile)o;
-
-            if (tiles.IndexOf (tile) != selected_index) {
-                return;
-            }
-
-            Gdk.Rectangle ta = ((AddinTile)o).Allocation;
-            Gdk.Rectangle va = new Gdk.Rectangle (0, (int)scroll.Vadjustment.Value,
-                Allocation.Width, Parent.Allocation.Height);
-
-            if (!va.Contains (ta)) {
-                double delta = 0.0;
-                if (ta.Bottom > va.Bottom) {
-                    delta = ta.Bottom - va.Bottom;
-                } else if (ta.Top < va.Top) {
-                    delta = ta.Top - va.Top;
-                }
-                scroll.Vadjustment.Value += delta;
-                QueueDraw();
-            }
-        }
-
-        protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
-        {
-            HasFocus = true;
-
-            ClearSelection ();
-
-            for (int i = 0; i < tiles.Count; i++) {
-                if (tiles[i].Allocation.Contains ((int)evnt.X, (int)evnt.Y)) {
-                    Select (i);
-                    break;
+            var hbox = new HBox () { Spacing = 6 };
+
+            var filter_label = new Label (Catalog.GetString ("Show:"));
+            var filter_combo = ComboBox.NewText ();
+            filter_combo.AppendText (Catalog.GetString ("All"));
+            filter_combo.AppendText (Catalog.GetString ("Enabled"));
+            filter_combo.AppendText (Catalog.GetString ("Not Enabled"));
+            filter_combo.Active = 0;
+
+            var search_label = new Label (Catalog.GetString ("Search:"));
+            var search_entry = new Banshee.Widgets.SearchEntry () {
+                WidthRequest = 160,
+                Visible = true,
+                Ready = true
+            };
+
+            hbox.PackStart (filter_label, false, false, 0);
+            hbox.PackStart (filter_combo, false, false, 0);
+            hbox.PackEnd   (search_entry, false, false, 0);
+            hbox.PackEnd   (search_label, false, false, 0);
+
+            var model = new TreeStore (typeof (string));
+
+            var addins = AddinManager.Registry.GetAddins ().Where (a => { return
+                a.Name != a.Id && a.Description != null &&
+                !String.IsNullOrEmpty (a.Description.Category) && !a.Description.Category.StartsWith ("required:") &&
+                (!a.Description.Category.Contains ("Debug") || Banshee.Base.ApplicationContext.Debugging);
+            });
+
+            var categorized_addins = addins.GroupBy<Addin, string> (a => a.Description.Category)
+                                           .Select (c => new {
+                                                Addins = c.OrderBy (a => Catalog.GetString (a.Name)).ToList (),
+                                                Name = c.Key,
+                                                NameLocalized = Catalog.GetString (c.Key) })
+                                           .OrderBy (c => c.NameLocalized)
+                                           .ToList ();
+
+            tree_view = new TreeView () {
+                FixedHeightMode = false,
+                HeadersVisible = false,
+                SearchColumn = 0,
+                //EnableGridLines = TreeViewGridLines.Horizontal,
+                //EnableTreeLines = true,
+                //RulesHint = true,
+                //ShowExpanders = false,
+                //SearchEntry = search_entry.InnerEntry,
+                Model = model
+            };
+            tree_view.AppendColumn ("title", new CellRendererText (), "markup", 0);
+
+            var update_model = new System.Action (() => {
+                string search = search_entry.Query;
+                bool? enabled = filter_combo.Active > 0 ? (bool?) (filter_combo.Active == 1 ? true : false) : null;
+                model.Clear ();
+                foreach (var cat in categorized_addins) {
+                    var cat_iter = model.AppendValues (String.Format ("<b>{0}</b>", GLib.Markup.EscapeText (cat.NameLocalized)));
+                    bool any = false;
+                    foreach (var a in cat.Addins.Matching (search)) {
+                        if (enabled == null || (a.Enabled == enabled.Value)) {
+                            model.AppendValues (cat_iter, GLib.Markup.EscapeText (Catalog.GetString (a.Name)));
+                            any = true;
+                        }
+                    }
+
+                    if (!any) {
+                        model.Remove (ref cat_iter);
+                    }
                 }
-            }
-
-            QueueDraw ();
-
-            return base.OnButtonPressEvent (evnt);
-        }
-
-        protected override bool OnKeyPressEvent (Gdk.EventKey evnt)
-        {
-            int index = selected_index;
-
-            switch (evnt.Key) {
-                 case Gdk.Key.Up:
-                 case Gdk.Key.uparrow:
-                     index--;
-                     if (index < 0) {
-                         index = 0;
-                     }
-                     break;
-                 case Gdk.Key.Down:
-                 case Gdk.Key.downarrow:
-                     index++;
-                     if (index > tiles.Count - 1) {
-                         index = tiles.Count - 1;
-                     }
-                     break;
-            }
-
-            if (index != selected_index) {
-                ClearSelection ();
-                Select (index);
-                return true;
-            }
-
-            return base.OnKeyPressEvent (evnt);
+                tree_view.ExpandAll ();
+            });
+
+            update_model ();
+            search_entry.Changed += (o, a) => update_model ();
+            filter_combo.Changed += (o, a) => update_model ();
+
+            var tree_scroll = new Gtk.ScrolledWindow () {
+                HscrollbarPolicy = PolicyType.Never
+            };
+            tree_scroll.AddWithViewport (tree_view);
+
+            Spacing = 6;
+            PackStart (hbox, false, false, 0);
+            PackStart (tree_scroll, true, true, 0);
+            ShowAll ();
         }
 
-        private void Select (int index)
-        {
-            if (index >= 0 && index < tiles.Count) {
-                selected_index = index;
-                tiles[index].Select (true);
-            } else {
-                ClearSelection ();
-            }
-
-            if (Parent != null && Parent.IsRealized) {
-                Parent.GdkWindow.InvalidateRect (Parent.Allocation, true);
-            }
-
-            QueueResize ();
-        }
+    }
 
-        private void ClearSelection ()
+    internal static class AddinExtensions
+    {
+        public static IEnumerable<Addin> Matching (this IEnumerable<Addin> addins, string search)
         {
-            if (selected_index >= 0 && selected_index < tiles.Count) {
-                tiles[selected_index].Select (false);
-            }
-
-            selected_index = -1;
+            search = StringUtil.SearchKey (search);
+
+            return addins.Where (a => { return
+                StringUtil.SearchKey (a.Name).Contains (search) ||
+                StringUtil.SearchKey (a.Description.Description).Contains (search) ||
+                StringUtil.SearchKey (Catalog.GetString (a.Name)).Contains (search) ||
+                StringUtil.SearchKey (Catalog.GetString (a.Description.Description)).Contains (search) ||
+                StringUtil.SearchKey (a.Description.Category).Contains (search) ||
+                StringUtil.SearchKey (Catalog.GetString (a.Description.Category)).Contains (search);
+            });
         }
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Preferences.Gui/DefaultPreferenceWidgets.cs b/src/Core/Banshee.ThickClient/Banshee.Preferences.Gui/DefaultPreferenceWidgets.cs
index 5edc31b..08e4d7f 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Preferences.Gui/DefaultPreferenceWidgets.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Preferences.Gui/DefaultPreferenceWidgets.cs
@@ -64,16 +64,7 @@ namespace Banshee.Preferences.Gui
             PreferenceBase pattern_display = music["file-system"].FindOrAdd (new VoidPreference ("file_folder_pattern"));
             pattern_display.DisplayWidget = new PatternDisplay (folder_pattern.DisplayWidget, file_pattern.DisplayWidget);
 
-            // Set up the extensions tab UI
-            Banshee.Addins.Gui.AddinView view = new Banshee.Addins.Gui.AddinView ();
-            view.Show ();
-
-            Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow ();
-            scroll.HscrollbarPolicy = PolicyType.Never;
-            scroll.AddWithViewport (view);
-            scroll.Show ();
-
-            service["extensions"].DisplayWidget = scroll;
+            service["extensions"].DisplayWidget = new Banshee.Addins.Gui.AddinView ();
         }
 
         private class LibraryLocationButton : HBox
diff --git a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
index a7fb52e..af964c2 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
+++ b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
@@ -220,7 +220,6 @@
     <Compile Include="Banshee.Preferences.Gui\WidgetFactory.cs" />
     <Compile Include="Banshee.Preferences.Gui\DefaultPreferenceWidgets.cs" />
     <Compile Include="Banshee.Addins.Gui\AddinDetailsDialog.cs" />
-    <Compile Include="Banshee.Addins.Gui\AddinTile.cs" />
     <Compile Include="Banshee.Addins.Gui\AddinView.cs" />
     <Compile Include="Banshee.Sources.Gui\SourceModel.cs" />
     <Compile Include="Banshee.Sources.Gui\SourceComboBox.cs" />
diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am
index e9f7d4a..3e7308a 100644
--- a/src/Core/Banshee.ThickClient/Makefile.am
+++ b/src/Core/Banshee.ThickClient/Makefile.am
@@ -5,7 +5,6 @@ LINK = $(REF_BANSHEE_THICKCLIENT)
 
 SOURCES =  \
 	Banshee.Addins.Gui/AddinDetailsDialog.cs \
-	Banshee.Addins.Gui/AddinTile.cs \
 	Banshee.Addins.Gui/AddinView.cs \
 	Banshee.Collection.Gui/AlbumListView.cs \
 	Banshee.Collection.Gui/ArtistListView.cs \



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