Example #1
0
        void LoadPolicyTypeData(MimeTypePanelData data, string mimeType, List <string> types)
        {
            List <IMimeTypePolicyOptionsPanel> panels = new List <IMimeTypePolicyOptionsPanel> ();

            bool useParentPolicy = false;

            foreach (MimeTypeOptionsPanelNode node in AddinManager.GetExtensionNodes("/MonoDevelop/ProjectModel/Gui/MimeTypePolicyPanels"))
            {
                if (!types.Contains(node.MimeType))
                {
                    continue;
                }

                IMimeTypePolicyOptionsPanel panel = (IMimeTypePolicyOptionsPanel)node.CreateInstance(typeof(IMimeTypePolicyOptionsPanel));
                panel.Initialize(ParentDialog, DataObject);
                panel.InitializePolicy(policyContainer, defaultPolicyContainer, mimeType, mimeType == node.MimeType);
                panel.Label = GettextCatalog.GetString(node.Label);
                if (!panel.IsVisible())
                {
                    continue;
                }

                if (!panel.HasCustomPolicy)
                {
                    useParentPolicy = true;
                }

                panels.Add(panel);
            }
            data.Panels = panels;
            if (!policyContainer.IsRoot || ParentDialog is DefaultPolicyOptionsDialog)
            {
                data.UseParentPolicy = useParentPolicy;
            }
        }
Example #2
0
        void OnSetPolicyData(Gtk.TreeViewColumn treeColumn, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            MimeTypePanelData mt = (MimeTypePanelData)store.GetValue(iter, 0);

            string selection;

            if (mt.UseParentPolicy)
            {
                selection = panel.IsCustomUserPolicy ? systemPolicyText : parentPolicyText;
            }
            else
            {
                PolicySet matchingSet = mt.GetMatchingSet(GetCandidateSets(mt));
                if (matchingSet != null)
                {
                    selection = matchingSet.Name;
                }
                else
                {
                    selection = customPolicyText;
                }
            }

            CellRendererComboBox comboCell = (CellRendererComboBox)cell;

            comboCell.Values = GetComboOptions(mt);
            comboCell.Text   = selection;
        }
Example #3
0
        void RemovePanel(string mt)
        {
            MimeTypePanelData data = typeSections [mt];

            typeSections.Remove(mt);
            ParentDialog.RemoveSection(data.Section);
        }
Example #4
0
        MimeTypePanelData AddPanel(string mt)
        {
            var chain = new List <string> (DesktopService.GetMimeTypeInheritanceChain(mt).Where(mimeTypesWithPolicies.Contains));

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

            sec.Fill             = true;
            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);
        }
        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);
        }
Example #6
0
 protected void OnButtonEditClicked(object sender, System.EventArgs e)
 {
     Gtk.TreeIter iter;
     if (tree.Selection.GetSelected(out iter))
     {
         MimeTypePanelData mt = (MimeTypePanelData)store.GetValue(iter, 0);
         dialog.ShowPage(mt.Section);
     }
 }
Example #7
0
 protected virtual void OnButtonRemoveClicked(object sender, System.EventArgs e)
 {
     Gtk.TreeIter iter;
     if (tree.Selection.GetSelected(out iter))
     {
         MimeTypePanelData mt = (MimeTypePanelData)store.GetValue(iter, 0);
         if (MessageService.Confirm(GettextCatalog.GetString("Are you sure you want to remove the formatting policy for the type '{0}'?", mt.TypeDescription), AlertButton.Delete))
         {
             panel.RemoveGlobalMimeType(mt.MimeType);
             store.Remove(ref iter);
         }
     }
 }
Example #8
0
 void UpdateButtons()
 {
     Gtk.TreeIter iter;
     if (tree.Selection.GetSelected(out iter))
     {
         MimeTypePanelData mt = (MimeTypePanelData)store.GetValue(iter, 0);
         if (panel.IsUserMimeType(mt.MimeType))
         {
             buttonRemove.Sensitive = buttonEdit.Sensitive = true;
             return;
         }
     }
     buttonRemove.Sensitive = buttonEdit.Sensitive = false;
 }
Example #9
0
        string[] GetComboOptions(MimeTypePanelData mt)
        {
            List <string> values = new List <string> ();

            if (!this.panel.PolicyContainer.IsRoot || panel.IsCustomUserPolicy)
            {
                values.Add(panel.IsCustomUserPolicy ? systemPolicyText : parentPolicyText);
            }

            values.AddRange(GetCandidateSets(mt).Select(p => p.Name));

            values.Add(customPolicyText);
            return(values.ToArray());
        }
Example #10
0
        protected virtual void OnButtonAddClicked(object sender, System.EventArgs e)
        {
            AddMimeTypeDialog dlg = new AddMimeTypeDialog(panel.GetItemMimeTypes());

            try {
                if (MessageService.RunCustomDialog(dlg, this.Toplevel as Gtk.Window) == (int)Gtk.ResponseType.Ok)
                {
                    MimeTypePanelData mt = panel.AddGlobalMimeType(dlg.MimeType);
                    store.AppendValues(mt, DesktopService.GetIconForType(mt.MimeType, Gtk.IconSize.Menu), mt.TypeDescription);
                }
            } finally {
                dlg.Destroy();
            }
        }
Example #11
0
        string[] GetComboOptions(MimeTypePanelData mt)
        {
            List <string> values = new List <string> ();

            if (!this.panel.PolicyContainer.IsRoot)
            {
                values.Add(parentPolicyText);
            }

            foreach (PolicySet set in mt.GetSupportedPolicySets())
            {
                values.Add(set.Name);
            }

            values.Add(customPolicyText);
            return(values.ToArray());
        }
Example #12
0
        IEnumerable <PolicySet> GetCandidateSets(MimeTypePanelData mt)
        {
            var pset = mt.PolicyContainer as PolicySet;

            foreach (PolicySet set in mt.GetSupportedPolicySets())
            {
                // The combo already has the System Default option, so no need to show the Defaut policy set.
                if (panel.IsCustomUserPolicy && set.Name == "Default")
                {
                    continue;
                }

                // Don't allow selecting the set that is being edited
                if (pset != null && set.Name == pset.Name)
                {
                    continue;
                }
                yield return(set);
            }
        }
Example #13
0
 void OnPolicySelectionChanged(object s, ComboSelectionChangedArgs args)
 {
     Gtk.TreeIter iter;
     if (store.GetIter(out iter, new Gtk.TreePath(args.Path)))
     {
         MimeTypePanelData mt = (MimeTypePanelData)store.GetValue(iter, 0);
         if (args.Active != -1)
         {
             string sel = args.ActiveText;
             if (sel == (panel.IsCustomUserPolicy ? systemPolicyText : parentPolicyText))
             {
                 mt.UseParentPolicy = true;
             }
             else if (sel != customPolicyText)
             {
                 PolicySet pset = PolicyService.GetPolicySet(sel);
                 mt.AssignPolicies(pset);
             }
         }
     }
 }