Esempio n. 1
0
        private void BuildSearchEntry()
        {
            var entry = search_entry = new Banshee.Widgets.SearchEntry()
            {
                WidthRequest = 150,
                Visible      = true,
                EmptyMessage = String.Format(Catalog.GetString("Optional Query"))
            };

            source.Properties.Set <Banshee.Widgets.SearchEntry> ("Nereid.SearchEntry", entry);

            entry.Activated += (o, a) => { search_button.Activate(); };

            // Add 'filter' items
            var filter_fields = new List <IA.Field> ();
            int i             = 0;

            foreach (var field in IA.Field.Fields.Where(f => (f != IA.Field.Collection && f != IA.Field.Identifier)))
            {
                filter_fields.Add(field);
                entry.AddFilterOption(i++, field.Name);
            }

            // Add the Help item
            entry.Menu.Append(new SeparatorMenuItem());
            var help_item = new ImageMenuItem(Catalog.GetString("_Help"))
            {
                Image = new Image("gtk-help", IconSize.Menu)
            };

            help_item.Activated += delegate { Banshee.Web.Browser.Open("http://www.archive.org/advancedsearch.php"); };
            entry.Menu.Append(help_item);
            entry.Menu.ShowAll();

            entry.FilterChanged += (o, a) => {
                // Only prepend the filter: part if the query doesn't already end in a :
                string prev_query = entry.Query.EndsWith(":") ? null : entry.Query;
                entry.Query = String.Format("{0}:{1}", filter_fields[entry.ActiveFilterID].Id, prev_query);

                var editable = entry as IEditable;
                if (editable != null)
                {
                    editable.Position = entry.Query.Length;
                }
            };

            PackStart(entry, true, true, 0);
        }
Esempio n. 2
0
        public AddinView()
        {
            var hbox = new HBox()
            {
                Spacing = 6
            };

            var filter_label = new Label(Catalog.GetString("Show:"));
            var filter_combo = new ComboBoxText();

            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(bool), typeof(bool), typeof(string), typeof(Addin));

            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") || 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    = 1,
                RulesHint       = true,
                Model           = model
            };

            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(false, false, String.Format("<b>{0}</b>", GLib.Markup.EscapeText(cat.NameLocalized)), null);
                    bool any     = false;
                    foreach (var a in cat.Addins.Matching(search))
                    {
                        if (enabled == null || (a.Enabled == enabled.Value))
                        {
                            model.AppendValues(cat_iter, true,
                                               a.Enabled,
                                               String.Format(
                                                   "<b>{0}</b>\n<small>{1}</small>",
                                                   GLib.Markup.EscapeText(Catalog.GetString(a.Name)),
                                                   GLib.Markup.EscapeText(Catalog.GetString(a.Description.Description))),
                                               a
                                               );
                            any = true;
                        }
                    }

                    if (!any)
                    {
                        model.Remove(ref cat_iter);
                    }
                }
                tree_view.ExpandAll();
            });

            var txt_cell = new CellRendererText()
            {
                WrapMode = Pango.WrapMode.Word
            };

            tree_view.AppendColumn("Name", txt_cell, "markup", Columns.Name);

            var check_cell = new CellRendererToggle()
            {
                Activatable = true
            };

            tree_view.AppendColumn("Enable", check_cell, "visible", Columns.IsAddin, "active", Columns.IsEnabled);
            check_cell.Toggled += (o, a) => {
                TreeIter iter;
                if (model.GetIter(out iter, new TreePath(a.Path)))
                {
                    var  addin   = model.GetValue(iter, 3) as Addin;
                    bool enabled = (bool)model.GetValue(iter, 1);
                    addin.Enabled = !enabled;
                    model.SetValue(iter, 1, addin.Enabled);
                    model.Foreach(delegate(ITreeModel current_model, TreePath path, TreeIter current_iter) {
                        var an = current_model.GetValue(current_iter, 3) as Addin;
                        if (an != null)
                        {
                            current_model.SetValue(current_iter, 1, an.Enabled);
                        }
                        return(false);
                    });
                }
            };

            update_model();
            search_entry.Changed += (o, a) => update_model();
            filter_combo.Changed += (o, a) => update_model();

            var tree_scroll = new Hyena.Widgets.ScrolledWindow()
            {
                HscrollbarPolicy = PolicyType.Never
            };

            tree_scroll.AddWithFrame(tree_view);

            Spacing = 6;
            PackStart(hbox, false, false, 0);
            PackStart(tree_scroll, true, true, 0);
            ShowAll();
            search_entry.GrabFocus();

            txt_cell.WrapWidth = 300;
        }
Esempio n. 3
0
        private void BuildSearchEntry ()
        {
            var entry = search_entry = new Banshee.Widgets.SearchEntry () {
                WidthRequest = 150,
                Visible = true,
                EmptyMessage = String.Format (Catalog.GetString ("Optional Query"))
            };

            source.Properties.Set<Banshee.Widgets.SearchEntry> ("Nereid.SearchEntry", entry);

            entry.Activated += (o, a) => { search_button.Activate (); };

            // Add 'filter' items
            var filter_fields = new List<IA.Field> ();
            int i = 0;
            foreach (var field in IA.Field.Fields.Where (f => (f != IA.Field.Collection && f != IA.Field.Identifier))) {
                filter_fields.Add (field);
                entry.AddFilterOption (i++, field.Name);
            }

            // Add the Help item
            entry.Menu.Append (new SeparatorMenuItem ());
            var help_item = new ImageMenuItem (Catalog.GetString ("_Help")) {
                Image = new Image ("gtk-help", IconSize.Menu)
            };
            help_item.Activated += delegate { Banshee.Web.Browser.Open ("http://www.archive.org/advancedsearch.php"); };
            entry.Menu.Append (help_item);
            entry.Menu.ShowAll ();

            entry.FilterChanged += (o, a) => {
                // Only prepend the filter: part if the query doesn't already end in a :
                string prev_query = entry.Query.EndsWith (":") ? null : entry.Query;
                entry.Query = String.Format ("{0}:{1}", filter_fields[entry.ActiveFilterID].Id, prev_query);

                var editable = entry.InnerEntry as Editable;
                if (editable != null) {
                    editable.Position = entry.Query.Length;
                }
            };

            PackStart (entry, true, true, 0);
        }
Esempio n. 4
0
        public AddinView()
        {
            var hbox = new HBox () { Spacing = 6 };

            var filter_label = new Label (Catalog.GetString ("Show:"));
            var filter_combo = new ComboBoxText ();
            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(bool), typeof(bool), typeof (string), typeof (Addin));

            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") || 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 = 1,
                RulesHint = true,
                Model = model
            };

            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 (false, false, String.Format ("<b>{0}</b>", GLib.Markup.EscapeText (cat.NameLocalized)), null);
                    bool any = false;
                    foreach (var a in cat.Addins.Matching (search)) {
                        if (enabled == null || (a.Enabled == enabled.Value)) {
                            model.AppendValues (cat_iter, true,
                                a.Enabled,
                                String.Format (
                                    "<b>{0}</b>\n<small>{1}</small>",
                                    GLib.Markup.EscapeText (Catalog.GetString (a.Name)),
                                    GLib.Markup.EscapeText (Catalog.GetString (a.Description.Description))),
                                a
                            );
                            any = true;
                        }
                    }

                    if (!any) {
                        model.Remove (ref cat_iter);
                    }
                }
                tree_view.ExpandAll ();
            });

            var txt_cell = new CellRendererText () { WrapMode = Pango.WrapMode.Word };
            tree_view.AppendColumn ("Name", txt_cell , "markup", Columns.Name);

            var check_cell = new CellRendererToggle () { Activatable = true };
            tree_view.AppendColumn ("Enable", check_cell, "visible", Columns.IsAddin, "active", Columns.IsEnabled);
            check_cell.Toggled += (o, a) => {
                TreeIter iter;
                if (model.GetIter (out iter, new TreePath (a.Path))) {
                    var addin = model.GetValue (iter, 3) as Addin;
                    bool enabled = (bool) model.GetValue (iter, 1);
                    addin.Enabled = !enabled;
                    model.SetValue (iter, 1, addin.Enabled);
                    model.Foreach (delegate (ITreeModel current_model, TreePath path, TreeIter current_iter) {
                        var an = current_model.GetValue (current_iter, 3) as Addin;
                        if (an != null) {
                            current_model.SetValue (current_iter, 1, an.Enabled);
                        }
                        return false;
                    });
                }
            };

            update_model ();
            search_entry.Changed += (o, a) => update_model ();
            filter_combo.Changed += (o, a) => update_model ();

            var tree_scroll = new Hyena.Widgets.ScrolledWindow () {
                HscrollbarPolicy = PolicyType.Never
            };
            tree_scroll.AddWithFrame (tree_view);

            Spacing = 6;
            PackStart (hbox, false, false, 0);
            PackStart (tree_scroll, true, true, 0);
            ShowAll ();
            search_entry.GrabFocus ();

            txt_cell.WrapWidth = 300;
        }