Exemplo n.º 1
0
        protected TreeIter AddSection(TreeIter parentIter, OptionsDialogSection section, object dataObject)
        {
            TreeIter it;

            if (parentIter.Equals(TreeIter.Zero))
            {
                string sectionLabel = "<b>" + GLib.Markup.EscapeText(section.Label) + "</b>";
                it = store.AppendValues(section, null, sectionLabel, false, null);
            }
            else
            {
                string icon = section.Icon.IsNull ? "md-empty-category" : section.Icon.ToString();
                it = store.AppendValues(parentIter, section, icon, section.Label, true, null);
            }

            if (!section.CustomNode)
            {
                AddChildSections(it, section, dataObject);
            }

            // Remove the section if it doesn't have children nor panels
            SectionPage page = CreatePage(it, section, dataObject);
            TreeIter    cit;

            if (removeEmptySections && page.Panels.Count == 0 && !store.IterChildren(out cit, it))
            {
                store.Remove(ref it);
            }
            return(it);
        }
Exemplo n.º 2
0
        internal TreeIter AddSection(TreeIter parentIter, OptionsDialogSection section, object dataObject)
        {
            TreeIter it;

            if (parentIter.Equals(TreeIter.Zero))
            {
                it = store.AppendValues(section);
            }
            else
            {
                it = store.AppendValues(parentIter, section);
            }

            if (!section.CustomNode)
            {
                AddChildSections(it, section, dataObject);
            }

            // Remove the section if it doesn't have children nor panels
            SectionPage page = CreatePage(it, section, dataObject);
            TreeIter    cit;

            if (removeEmptySections && page.Panels.Count == 0 && !store.IterChildren(out cit, it))
            {
                store.Remove(ref it);
                pages.Remove(section);
                return(TreeIter.Zero);
            }
            return(it);
        }
        MimeTypePanelData AddPanel(string mt)
        {
            var chain = new List <string> (DesktopService.GetMimeTypeInheritanceChain(mt).Where(x => mimeTypesWithPolicies.Contains(x)));

            if (chain.Count == 0)
            {
                return(null);
            }
            MimeTypePanelData    data = new MimeTypePanelData();
            OptionsDialogSection sec  = new OptionsDialogSection(typeof(MimeTypePolicyOptionsSection));

            sec.Fill = true;
            Gdk.Pixbuf icon = DesktopService.GetPixbufForType(mt, Gtk.IconSize.Menu);
            sec.Icon             = ImageService.GetStockId(icon, Gtk.IconSize.Menu);
            data.Section         = sec;
            data.MimeType        = mt;
            data.TypeDescription = DesktopService.GetMimeTypeDescription(mt);
            if (string.IsNullOrEmpty(data.TypeDescription))
            {
                data.TypeDescription = mt;
            }
            data.DataObject      = DataObject;
            data.PolicyContainer = policyContainer;
            sec.Label            = data.TypeDescription;
            LoadPolicyTypeData(data, mt, chain);
            typeSections [mt] = data;
            ParentDialog.AddChildSection(this, sec, data);
            return(data);
        }
Exemplo n.º 4
0
        internal void RemoveSection(OptionsDialogSection section)
        {
            SectionPage page;

            if (pages.TryGetValue(section, out page))
            {
                RemoveSection(page.Iter);
            }
        }
Exemplo n.º 5
0
        void StoreLastPanel()
        {
            TreeIter it;

            if (tree.Selection.GetSelected(out it))
            {
                OptionsDialogSection section = (OptionsDialogSection)store.GetValue(it, 0);
                PropertyService.Set(extensionPath + "-lastPanel", section.Id);
            }
        }
Exemplo n.º 6
0
 internal virtual void AddChildSections(TreeIter parentIter, OptionsDialogSection section, object dataObject)
 {
     foreach (ExtensionNode nod in section.ChildNodes)
     {
         if (nod is OptionsDialogSection)
         {
             AddSection(parentIter, (OptionsDialogSection)nod, dataObject);
         }
     }
 }
Exemplo n.º 7
0
        void OnSelectionChanged(object s, EventArgs a)
        {
            TreeIter it;

            if (tree.Selection.GetSelected(out it))
            {
                OptionsDialogSection section = (OptionsDialogSection)store.GetValue(it, 0);
                ShowPage(section);
            }
        }
Exemplo n.º 8
0
        void RemoveSection(Gtk.TreeIter it)
        {
            Gtk.TreeIter ci;
            if (store.IterChildren(out ci, it))
            {
                do
                {
                    RemoveSection(ci);
                } while (store.IterNext(ref ci));
            }

            // If the this panel is the selection, select the parent before removing
            Gtk.TreeIter itsel;
            if (tree.Selection.GetSelected(out itsel))
            {
                if (store.GetPath(itsel).Equals(store.GetPath(it)))
                {
                    Gtk.TreeIter pi;
                    if (store.IterParent(out pi, it))
                    {
                        tree.Selection.SelectIter(pi);
                    }
                }
            }
            OptionsDialogSection section = (OptionsDialogSection)store.GetValue(it, 0);

            if (section != null)
            {
                SectionPage page;
                if (pages.TryGetValue(section, out page))
                {
                    foreach (PanelInstance pi in page.Panels)
                    {
                        panels.Remove(pi.Node);
                        IDisposable d = pi.Panel as IDisposable;
                        if (d != null)
                        {
                            d.Dispose();
                        }
                    }
                    pages.Remove(section);
                    if (page.Widget != null)
                    {
                        page.Widget.Destroy();
                    }
                }
            }
            store.Remove(ref it);
        }
Exemplo n.º 9
0
 internal void AddChildSection(IOptionsPanel parent, OptionsDialogSection section, object dataObject)
 {
     foreach (SectionPage page in pages.Values)
     {
         foreach (PanelInstance pi in page.Panels)
         {
             if (pi.Panel == parent)
             {
                 AddSection(page.Iter, section, dataObject);
                 return;
             }
         }
     }
     throw new InvalidOperationException("Parent options panel not found in the dialog.");
 }
Exemplo n.º 10
0
 void FillConfigurations(Gtk.TreeIter configIter)
 {
     foreach (string name in test.GetConfigurations())
     {
         Properties configNodeProperties = new Properties();
         configNodeProperties.Set("UnitTest", test);
         configNodeProperties.Set("Config", name);
         foreach (OptionsDialogSection section in configurationNode.ChildNodes)
         {
             OptionsDialogSection s = (OptionsDialogSection)section.Clone();
             if (firstSection == null)
             {
                 firstSection = s;
             }
             s.Label = StringParserService.Parse(section.Label, new string[, ] {
                 { "Configuration", name }
             });
             AddSection(configIter, s, configNodeProperties);
         }
     }
 }
Exemplo n.º 11
0
        bool HasVisiblePanel(OptionsDialogSection section)
        {
            SectionPage page;

            if (!pages.TryGetValue(section, out page))
            {
                return(false);
            }
            if (page.Panels.Count > 0)
            {
                return(true);
            }
            foreach (ExtensionNode node in section.ChildNodes)
            {
                if (node is OptionsDialogSection)
                {
                    if (HasVisiblePanel((OptionsDialogSection)node))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 12
0
        public UnitTestOptionsDialog(Gtk.Window parent, Properties properties) : base(parent, properties, "/MonoDevelop/NUnit/UnitTestOptions/GeneralOptions", false)
        {
            this.Title = GettextCatalog.GetString("Unit Test Options");

            test = properties.Get <UnitTest>("UnitTest");
            configurationNode = AddinManager.GetExtensionNode("/MonoDevelop/NUnit/UnitTestOptions/ConfigurationOptions");

            TreeIter iter;

            if (store.GetIterFirst(out iter))
            {
                OptionsDialogSection section = store.GetValue(iter, 0) as OptionsDialogSection;

                if (section != null && section.Id == "Configurations")
                {
                    FillConfigurations(iter);
                }
            }
            ExpandCategories();
            if (firstSection != null)
            {
                ShowPage(firstSection);
            }
        }
Exemplo n.º 13
0
        SectionPage CreatePage(TreeIter it, OptionsDialogSection section, object dataObject)
        {
            SectionPage page;

            if (pages.TryGetValue(section, out page))
            {
                return(page);
            }

            page            = new SectionPage();
            page.Iter       = it;
            page.Panels     = new List <PanelInstance> ();
            pages [section] = page;

            List <OptionsPanelNode> nodes = new List <OptionsPanelNode> ();

            if (!string.IsNullOrEmpty(section.TypeName) || section.CustomNode)
            {
                nodes.Add(section);
            }

            if (!section.CustomNode)
            {
                foreach (ExtensionNode nod in section.ChildNodes)
                {
                    OptionsPanelNode node = nod as OptionsPanelNode;
                    if (node != null && !(node is OptionsDialogSection))
                    {
                        nodes.Add(node);
                    }
                }
            }

            foreach (OptionsPanelNode node in nodes.ToArray())
            {
                if (!string.IsNullOrEmpty(node.Replaces))
                {
                    var replaced = nodes.FindIndex(n => n.Id == node.Replaces);
                    if (replaced != -1)
                    {
                        nodes.Remove(node);
                        nodes [replaced] = node;
                    }
                }
            }

            foreach (OptionsPanelNode node in nodes)
            {
                PanelInstance pi = null;
                if (panels.TryGetValue(node, out pi))
                {
                    if (pi.DataObject == dataObject)
                    {
                        // The panel can be reused
                        if (!pi.Panel.IsVisible())
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // If the data object has changed, this panel instance can't be
                        // reused anymore. Destroy it.
                        panels.Remove(node);
                        if (pi.Widget != null)
                        {
                            pi.Widget.Destroy();
                        }
                        IDisposable d = pi.Panel as IDisposable;
                        if (d != null)
                        {
                            d.Dispose();
                        }
                        pi = null;
                    }
                }
                if (pi == null)
                {
                    IOptionsPanel panel = node.CreatePanel();
                    pi            = new PanelInstance();
                    pi.Panel      = panel;
                    pi.Node       = node;
                    pi.DataObject = dataObject;
                    page.Panels.Add(pi);
                    panel.Initialize(this, dataObject);
                    if (!panel.IsVisible())
                    {
                        page.Panels.Remove(pi);
                        continue;
                    }
                    panels [node] = pi;
                }
                else
                {
                    page.Panels.Add(pi);
                }
            }
            return(page);
        }
Exemplo n.º 14
0
        internal void ShowPage(OptionsDialogSection section)
        {
            if (!IsRealized)
            {
                // Defer this until the dialog is realized due to the sizing logic in CreatePageWidget.
                EventHandler deferredShowPage = null;
                deferredShowPage = delegate {
                    ShowPage(section);
                    Realized -= deferredShowPage;
                };
                Realized += deferredShowPage;
                return;
            }
            SectionPage page;

            if (!pages.TryGetValue(section, out page))
            {
                return;
            }

            if (page.Panels.Count == 0)
            {
                foreach (ExtensionNode node in section.ChildNodes)
                {
                    if (node is OptionsDialogSection)
                    {
                        if (HasVisiblePanel((OptionsDialogSection)node))
                        {
                            ShowPage((OptionsDialogSection)node);
                            return;
                        }
                    }
                }
            }

            foreach (Gtk.Widget w in pageFrame.Children)
            {
                Container cc = w as Gtk.Container;
                if (cc != null)
                {
                    foreach (Gtk.Widget cw in cc)
                    {
                        cw.Hide();
                    }
                }
                pageFrame.Remove(w);
            }

            if (page.Widget == null)
            {
                CreatePageWidget(page);
            }

            if (section.HeaderImage == null)
            {
                labelTitle.Markup = "<span weight=\"bold\" size=\"large\">" + GLib.Markup.EscapeText(section.HeaderLabel) + "</span>";
                textHeader.Show();
                imageHeader.Hide();
            }
            else
            {
                imageHeader.SetImage(section.HeaderImage, section.HeaderFillerImageResource);
                imageHeader.Show();
                textHeader.Hide();
            }

/*			var algn = new HeaderBox ();
 *                      algn.SetPadding (12, 12, 12, 12);
 *                      if (page.Widget.Parent != null)
 *                              ((Gtk.Container)page.Widget).Remove (page.Widget);
 *                      algn.Add (page.Widget);*/
            pageFrame.PackStart(page.Widget, true, true, 0);

            // Ensures that the Shown event is fired for each panel
            Container c = page.Widget as Gtk.Container;

            if (c != null)
            {
                foreach (Gtk.Widget cw in c)
                {
                    cw.Show();
                }
                //HACK: weird bug - switching page away and back selects last tab. should preserve the selection.
                if (c is Notebook)
                {
                    ((Notebook)c).Page = 0;
                }
            }

            tree.ExpandToPath(store.GetPath(page.Iter));
            tree.Selection.SelectIter(page.Iter);
        }
Exemplo n.º 15
0
        public void ShowPage(OptionsDialogSection section)
        {
            SectionPage page;

            if (!pages.TryGetValue(section, out page))
            {
                return;
            }

            if (page.Panels.Count == 0)
            {
                foreach (ExtensionNode node in section.ChildNodes)
                {
                    if (node is OptionsDialogSection)
                    {
                        ShowPage((OptionsDialogSection)node);
                        return;
                    }
                }
            }

            foreach (Gtk.Widget w in pageFrame.Children)
            {
                Container cc = w as Gtk.Container;
                if (cc != null)
                {
                    foreach (Gtk.Widget cw in cc)
                    {
                        cw.Hide();
                    }
                }
                pageFrame.Remove(w);
            }

            if (page.Widget == null)
            {
                CreatePageWidget(page);
            }

            labelTitle.Markup = "<span weight=\"bold\" size=\"x-large\">" + GLib.Markup.EscapeText(section.Label) + "</span>";
            if (!string.IsNullOrEmpty(section.Icon))
            {
                image.Stock = section.Icon;
            }
            else
            {
                image.Stock = "md-empty-category";
            }
            pageFrame.PackStart(page.Widget, true, true, 0);

            // Ensures that the Shown event is fired for each panel
            Container c = page.Widget as Gtk.Container;

            if (c != null)
            {
                foreach (Gtk.Widget cw in c)
                {
                    cw.Show();
                }
            }

            tree.ExpandToPath(store.GetPath(page.Iter));
            tree.Selection.SelectIter(page.Iter);
        }
Exemplo n.º 16
0
 internal TreeIter AddSection(OptionsDialogSection section, object dataObject)
 {
     return(AddSection(TreeIter.Zero, section, dataObject));
 }
        public void ShowPage(OptionsDialogSection section)
        {
            SectionPage page;

            if (!pages.TryGetValue(section, out page))
            {
                return;
            }

            if (page.Panels.Count == 0)
            {
                foreach (ExtensionNode node in section.ChildNodes)
                {
                    if (node is OptionsDialogSection)
                    {
                        if (HasVisiblePanel((OptionsDialogSection)node))
                        {
                            ShowPage((OptionsDialogSection)node);
                            return;
                        }
                    }
                }
            }

            foreach (Gtk.Widget w in pageFrame.Children)
            {
                Container cc = w as Gtk.Container;
                if (cc != null)
                {
                    foreach (Gtk.Widget cw in cc)
                    {
                        cw.Hide();
                    }
                }
                pageFrame.Remove(w);
            }

            if (page.Widget == null)
            {
                CreatePageWidget(page);
            }

            labelTitle.Markup = "<span weight=\"bold\" size=\"x-large\">" + GLib.Markup.EscapeText(section.Label) + "</span>";

            //HACK: mimetype panels can't provide stock ID for mimetype images. Give this some awareness of mimetypes.
            var mimeSection = section as MonoDevelop.Ide.Projects.OptionPanels.MimetypeOptionsDialogSection;

            if (mimeSection != null && !string.IsNullOrEmpty(mimeSection.MimeType))
            {
                var pix = DesktopService.GetPixbufForType(mimeSection.MimeType, headerIconSize);
                if (pix != null)
                {
                    image.Pixbuf = pix;
                }
                else
                {
                    image.Pixbuf = ImageService.GetPixbuf(emptyCategoryIcon, headerIconSize);
                }
            }
            else
            {
                string icon = section.Icon.IsNull? emptyCategoryIcon : section.Icon.ToString();
                image.Pixbuf = ImageService.GetPixbuf(icon, headerIconSize);
            }

            pageFrame.PackStart(page.Widget, true, true, 0);

            // Ensures that the Shown event is fired for each panel
            Container c = page.Widget as Gtk.Container;

            if (c != null)
            {
                foreach (Gtk.Widget cw in c)
                {
                    cw.Show();
                }
                //HACK: weird bug - switching page away and back selects last tab. should preserve the selection.
                if (c is Notebook)
                {
                    ((Notebook)c).Page = 0;
                }
            }

            tree.ExpandToPath(store.GetPath(page.Iter));
            tree.Selection.SelectIter(page.Iter);
        }
Exemplo n.º 18
0
        internal void ShowPage(OptionsDialogSection section)
        {
            if (!IsRealized)
            {
                // Defer this until the dialog is realized due to the sizing logic in CreatePageWidget.
                EventHandler deferredShowPage = null;
                deferredShowPage = delegate {
                    ShowPage(section);
                    Realized -= deferredShowPage;
                };
                Realized += deferredShowPage;
                return;
            }
            SectionPage page;

            if (!pages.TryGetValue(section, out page))
            {
                return;
            }

            if (page.Panels.Count == 0)
            {
                foreach (ExtensionNode node in section.ChildNodes)
                {
                    if (node is OptionsDialogSection)
                    {
                        if (HasVisiblePanel((OptionsDialogSection)node))
                        {
                            ShowPage((OptionsDialogSection)node);
                            return;
                        }
                    }
                }
            }

            foreach (Gtk.Widget w in pageFrame.Children)
            {
                Container cc = w as Gtk.Container;
                if (cc != null)
                {
                    foreach (Gtk.Widget cw in cc)
                    {
                        cw.Hide();
                    }
                }
                pageFrame.Remove(w);
            }

            if (page.Widget == null)
            {
                CreatePageWidget(page);
            }

            if (section.HeaderImage == null)
            {
                labelTitle.Markup = "<span weight=\"bold\" size=\"large\">" + GLib.Markup.EscapeText(section.Label) + "</span>";
                textHeader.Show();
                imageHeader.Hide();
            }
            else
            {
                imageHeader.SetImage(section.HeaderImage, section.HeaderFillerImageResource);
                imageHeader.Show();
                textHeader.Hide();
            }

            //HACK: mimetype panels can't provide stock ID for mimetype images. Give this some awareness of mimetypes.
            var mimeSection = section as MonoDevelop.Ide.Projects.OptionPanels.MimetypeOptionsDialogSection;

            if (mimeSection != null && !string.IsNullOrEmpty(mimeSection.MimeType))
            {
                var pix = DesktopService.GetIconForType(mimeSection.MimeType, headerIconSize);
                if (pix != null)
                {
                    image.Image = pix;
                }
                else
                {
                    image.Image = ImageService.GetIcon(emptyCategoryIcon, headerIconSize);
                }
            }
            else
            {
                string icon = section.Icon.IsNull? emptyCategoryIcon : section.Icon.ToString();
                image.Image = ImageService.GetIcon(icon, headerIconSize);
            }

/*			var algn = new HeaderBox ();
 *                      algn.SetPadding (12, 12, 12, 12);
 *                      if (page.Widget.Parent != null)
 *                              ((Gtk.Container)page.Widget).Remove (page.Widget);
 *                      algn.Add (page.Widget);*/
            pageFrame.PackStart(page.Widget, true, true, 0);

            // Ensures that the Shown event is fired for each panel
            Container c = page.Widget as Gtk.Container;

            if (c != null)
            {
                foreach (Gtk.Widget cw in c)
                {
                    cw.Show();
                }
                //HACK: weird bug - switching page away and back selects last tab. should preserve the selection.
                if (c is Notebook)
                {
                    ((Notebook)c).Page = 0;
                }
            }

            tree.ExpandToPath(store.GetPath(page.Iter));
            tree.Selection.SelectIter(page.Iter);
        }