Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
		public NoteRenameDialog (IList<Note> notes, string oldTitle, Note renamedNote) :
			base (Catalog.GetString ("Rename Note Links?"), renamedNote.Window, 0)
		{
			this.DefaultResponse = ResponseType.Cancel;
			this.BorderWidth = 10;

			var renameButton = (Button)
				AddButton (Catalog.GetString ("_Rename Links"),
				           ResponseType.Yes);
			var dontRenameButton = (Button)
				AddButton (Catalog.GetString ("_Don't Rename Links"),
				           ResponseType.No);

			this.notes = notes;
			notesModel = new Gtk.TreeStore (typeof (bool), typeof (string), typeof (Note));
			foreach (var note in notes)
				notesModel.AppendValues (true, note.Title, note);

			var labelText = Catalog.GetString ("Rename links in other notes from \"<span underline=\"single\">{0}</span>\" " +
			                                   "to \"<span underline=\"single\">{1}</span>\"?\n\n" +
			                                   "If you do not rename the links, " +
			                                   "they will no longer link to anything.");
			var label = new Label ();
			label.UseMarkup = true;
			label.Markup = String.Format (labelText,
			                              GLib.Markup.EscapeText (oldTitle),
			                              GLib.Markup.EscapeText (renamedNote.Title));
			label.LineWrap = true;
			ContentArea.PackStart (label, false, true, 5);

			var notesView = new TreeView (notesModel);
			notesView.SetSizeRequest (-1, 200);
			var toggleCell = new CellRendererToggle ();
			toggleCell.Activatable = true;
			var column = new TreeViewColumn (Catalog.GetString ("Rename Links"),
			                                 toggleCell, "active", 0);
			column.SortColumnId = 0;
			column.Resizable = true;
			notesView.AppendColumn (column);
			toggleCell.Toggled += (o, args) => {
				TreeIter iter;
				if (!notesModel.GetIterFromString (out iter, args.Path))
					return;
				bool val = (bool) notesModel.GetValue (iter, 0);
				notesModel.SetValue (iter, 0, !val);
			};
			column = new TreeViewColumn (Catalog.GetString ("Note Title"),
			                             new CellRendererText (), "text", 1);
			column.SortColumnId = 1;
			column.Resizable = true;
			notesView.AppendColumn (column);

			notesView.RowActivated += (o, args) => {
				TreeIter iter;
				if (!notesModel.GetIter (out iter, args.Path))
					return;
				Note note = (Note) notesModel.GetValue (iter, 2);
				if (note != null) {
					note.Window.Present ();
					NoteFindBar find = note.Window.Find;
					find.ShowAll ();
					find.Visible = true;
					find.SearchText = "\"" + oldTitle + "\"";
				}
			};

			var notesBox = new VBox (false, 5);
			var selectAllButton = new Button ();
			// Translators: This button causes all notes in the list to be selected
			selectAllButton.Label = Catalog.GetString ("Select All");
			selectAllButton.Clicked += (o, e) => {
				notesModel.Foreach ((model, path, iter) => {
					notesModel.SetValue (iter, 0, true);
					return false;
				});
			};
			var selectNoneButton = new Button ();
			// Translators: This button causes all notes in the list to be unselected
			selectNoneButton.Label = Catalog.GetString ("Select None");
			selectNoneButton.Clicked += (o, e) => {
				notesModel.Foreach ((model, path, iter) => {
					notesModel.SetValue (iter, 0, false);
					return false;
				});
			};
			var notesButtonBox = new HButtonBox ();
			notesButtonBox.Add (selectNoneButton);
			notesButtonBox.Add (selectAllButton);
			notesButtonBox.Spacing = 5;
			notesButtonBox.LayoutStyle = ButtonBoxStyle.End;
			var notesScroll = new ScrolledWindow ();
			notesScroll.Add (notesView);
			notesBox.PackStart (notesScroll, true, true, 0);
			notesBox.PackStart (notesButtonBox, false, true, 0);

			var advancedExpander = new Expander (Catalog.GetString ("Ad_vanced"));
			var expandBox = new VBox ();
			expandBox.PackStart (notesBox, true, true, 0);
			alwaysShowDlgRadio = new RadioButton (Catalog.GetString ("Always show this _window"));
			alwaysShowDlgRadio.Clicked += (o, e) => {
				selectAllButton.Click ();
				notesBox.Sensitive = true;
				renameButton.Sensitive = true;
				dontRenameButton.Sensitive = true;
			};
			neverRenameRadio = new RadioButton (alwaysShowDlgRadio,
			                                    Catalog.GetString ("Never rename _links"));
			neverRenameRadio.Clicked += (o, e) => {
				selectNoneButton.Click ();
				notesBox.Sensitive = false;
				renameButton.Sensitive = false;
				dontRenameButton.Sensitive = true;
			};
			alwaysRenameRadio = new RadioButton (alwaysShowDlgRadio,
			                                     Catalog.GetString ("Alwa_ys rename links"));
			alwaysRenameRadio.Clicked += (o, e) => {
				selectAllButton.Click ();
				notesBox.Sensitive = false;
				renameButton.Sensitive = true;
				dontRenameButton.Sensitive = false;
			};
			expandBox.PackStart (alwaysShowDlgRadio, false, true, 0);
			expandBox.PackStart (neverRenameRadio, false, true, 0);
			expandBox.PackStart (alwaysRenameRadio, false, true, 0);
			advancedExpander.Add (expandBox);
			ContentArea.PackStart (advancedExpander, true, true, 5);

			advancedExpander.Activated += (o, e) =>
				this.Resizable = advancedExpander.Expanded;

			this.Focus = dontRenameButton;
			ContentArea.ShowAll ();
		}