コード例 #1
0
		public DefaultPolicyOptionsDialog (Gtk.Window parentWindow)
			: base (parentWindow, new PolicySet (),
			        "/MonoDevelop/ProjectModel/Gui/DefaultPolicyPanels")
		{
			this.Title = GettextCatalog.GetString ("Custom Policies");
			editingSet = (PolicySet) DataObject;
			
			HBox topBar = new HBox ();
			topBar.Spacing = 3;
			topBar.PackStart (new Label (GettextCatalog.GetString ("Editing Policy:")), false, false, 0);
			
			policiesCombo = ComboBox.NewText ();
			topBar.PackStart (policiesCombo, false, false, 0);
			
			newButton = new Button (GettextCatalog.GetString ("Add Policy"));
			topBar.PackEnd (newButton, false, false, 0);
			
			deleteButton = new Button (GettextCatalog.GetString ("Delete Policy"));
			topBar.PackEnd (deleteButton, false, false, 0);
			
			Alignment align = new Alignment (0f, 0f, 1f, 1f);
			align.LeftPadding = 9;
			align.TopPadding = 9;
			align.RightPadding = 9;
			align.BottomPadding = 9;
			align.Add (topBar);
			
			HeaderBox ebox = new HeaderBox ();
			ebox.GradientBackround = true;
			ebox.SetMargins (0, 1, 0, 0);
			ebox.Add (align);
			
			ebox.ShowAll ();
			
			VBox.PackStart (ebox, false, false, 0);
			VBox.BorderWidth = 0;
			Box.BoxChild c = (Box.BoxChild) VBox [ebox];
			c.Position = 0;
			
			foreach (PolicySet ps in PolicyService.GetUserPolicySets ()) {
				PolicySet copy = ps.Clone ();
				originalSets [copy] = ps;
				sets.Add (copy);
			}
			FillPolicySets ();
			
			policiesCombo.Changed += HandlePoliciesComboChanged;
			newButton.Clicked += HandleNewButtonClicked;
			deleteButton.Clicked += HandleDeleteButtonClicked;
		}
		public override void Initialize (MonoDevelop.Ide.Gui.Dialogs.OptionsDialog dialog, object dataObject)
		{
			base.Initialize (dialog, dataObject);
			panelData = (MimeTypePanelData) dataObject;
			
			if (panelData.DataObject is SolutionItem) {
				bag = ((SolutionItem)panelData.DataObject).Policies;
			} else if (panelData.DataObject is Solution) {
				bag = ((Solution)panelData.DataObject).Policies;
			} else if (panelData.DataObject is PolicySet) {
				polSet = ((PolicySet)panelData.DataObject);
			}
			mimeType = panelData.MimeType;
			panelData.SectionPanel = this;
			isRoot = polSet != null || bag.IsRoot;
		}
コード例 #3
0
		public override void Initialize (MonoDevelop.Ide.Gui.Dialogs.OptionsDialog dialog, object dataObject)
		{
			base.Initialize (dialog, dataObject);
			panelData = (MimeTypePanelData) dataObject;
			
			IPolicyProvider provider = panelData.DataObject as IPolicyProvider;
			if (provider == null) {
				provider = PolicyService.GetUserDefaultPolicySet ();
				isGlobalPolicy = true;
			}
			
			bag = provider.Policies as PolicyBag;
			polSet = provider.Policies as PolicySet;
			mimeType = panelData.MimeType;
			panelData.SectionPanel = this;
			isRoot = polSet != null || bag.IsRoot;
			if (IsCustomUserPolicy)
				isRoot = false;
		}
コード例 #4
0
ファイル: PolicySet.cs プロジェクト: poke/monodevelop
        public void CopyFrom(PolicySet pset)
        {
            if (pset.policies == null && policies == null)
            {
                return;
            }

            // Add and update policies

            if (pset.policies != null)
            {
                foreach (KeyValuePair <PolicyKey, object> p in pset.policies)
                {
                    object oldVal;
                    if (policies == null || !policies.TryGetValue(p.Key, out oldVal) || oldVal == null || !oldVal.Equals(p.Value))
                    {
                        if (policies == null)
                        {
                            policies = new PolicyDictionary();
                        }
                        policies [p.Key] = p.Value;
                        OnPolicyChanged(p.Key.PolicyType, p.Key.Scope);
                    }
                }
            }

            // Remove policies

            if (policies != null)
            {
                foreach (PolicyKey k in policies.Keys.ToArray())
                {
                    if (pset.policies == null || !pset.policies.ContainsKey(k))
                    {
                        policies.Remove(k);
                        OnPolicyChanged(k.PolicyType, k.Scope);
                    }
                }
            }
        }
コード例 #5
0
		PolicySet GetPolicySet (bool notifyErrors)
		{
			if (radioCustom.Active) {
				return PolicyService.GetPolicySet (combPolicies.ActiveText);
			}
			else {
				if (string.IsNullOrEmpty (fileEntry.Path)) {
					if (notifyErrors)
						MessageService.ShowError (GettextCatalog.GetString ("File name not specified"));
					return null;
				}
				try {
					PolicySet pset = new PolicySet ();
					pset.LoadFromFile (fileEntry.Path);
					ExportProjectPolicyDialog.DefaultFileDialogPolicyDir = System.IO.Path.GetDirectoryName (fileEntry.Path);
					return pset;
				} catch (Exception ex) {
					if (notifyErrors)
						MessageService.ShowException (ex, GettextCatalog.GetString ("The policy set could not be loaded"));
					return null;
				}
			}
		}
コード例 #6
0
ファイル: PolicySet.cs プロジェクト: noah1510/dotdevelop
        internal void SaveToXml(XmlWriter xw, PolicySet diffBasePolicySet = null)
        {
            XmlConfigurationWriter cw = new XmlConfigurationWriter();

            cw.StoreAllInElements       = true;
            cw.StoreInElementExceptions = new String[] { "scope", "inheritsSet", "inheritsScope" };
            xw.WriteStartElement("PolicySet");
            if (!string.IsNullOrEmpty(Name))
            {
                xw.WriteAttributeString("name", Name);
            }
            if (!string.IsNullOrEmpty(Id))
            {
                xw.WriteAttributeString("id", Id);
            }
            if (policies != null)
            {
                foreach (KeyValuePair <PolicyKey, object> policyPair in policies)
                {
                    cw.Write(xw, PolicyService.DiffSerialize(policyPair.Key.PolicyType, policyPair.Value, policyPair.Key.Scope, diffBasePolicySet: diffBasePolicySet));
                }
            }
            xw.WriteEndElement();
        }
コード例 #7
0
		void HandlePoliciesComboChanged (object sender, EventArgs e)
		{
			if (!loading) {
				if (currentSet != null) {
					// Save current values
					if (ValidateChanges ()) {
						base.ApplyChanges ();
						currentSet.CopyFrom (editingSet);
					} else {
						// There are validation errors. Cancel the policy switch
						int last = policiesCombo.Active;
						Application.Invoke (delegate {
							loading = true;
							policiesCombo.Active = last;
							loading = false;
						});
						return;
					}
				}
			
				if (policiesCombo.Active != -1 && policiesCombo.Active < sets.Count) {
					// Load the new values
					currentSet = sets [policiesCombo.Active];
					editingSet.Name = currentSet.Name;
					editingSet.CopyFrom (currentSet);
				}
			}
		}
コード例 #8
0
		public void AssignPolicies (PolicySet pset)
		{
			useParentPolicy = false;
			foreach (IMimeTypePolicyOptionsPanel panel in Panels)
				panel.LoadSetPolicy (pset);
			if (SectionLoaded) {
				SectionPanel.FillPolicies ();
				SectionPanel.UpdateSelectedNamedPolicy ();
			}
		}
コード例 #9
0
		PolicySet CreatePolicySet ()
		{
			PolicySet pset = new PolicySet ();
			pset.Import (policyProvider.Policies, true);
			return pset;
		}
コード例 #10
0
		PolicySet GetPolicySet (bool notifyErrors)
		{
			if (radioCustom.Active) {
				return PolicyService.GetPolicySet (combPolicies.ActiveText);
			}
			
			var f = fileEntry.Path;
			if (string.IsNullOrEmpty (f) || !System.IO.File.Exists (f)) {
				return null;
			}
			
			var pset = new PolicySet ();
			pset.LoadFromFile (fileEntry.Path);
			ExportProjectPolicyDialog.DefaultFileDialogPolicyDir = System.IO.Path.GetDirectoryName (fileEntry.Path);
			return pset;
		}
コード例 #11
0
		public PolicySet Clone ()
		{
			PolicySet p = new PolicySet ();
			p.CopyFrom (this);
			p.Name = Name;
			return p;
		}
コード例 #12
0
		public void CopyFrom (PolicySet pset)
		{
			if (pset.policies == null && policies == null)
				return;

			// Add and update policies
			
			if (pset.policies != null) {
				foreach (KeyValuePair<PolicyKey, object> p in pset.policies) {
					object oldVal;
					if (policies == null || !policies.TryGetValue (p.Key, out oldVal) || oldVal == null || !oldVal.Equals (p.Value)) {
						if (policies == null)
							policies = new PolicyDictionary ();
						policies [p.Key] = p.Value;
						OnPolicyChanged (p.Key.PolicyType, p.Key.Scope);
					}
				}
			}
			
			// Remove policies
			
			if (policies != null) {
				foreach (PolicyKey k in policies.Keys.ToArray ()) {
					if (pset.policies == null || !pset.policies.ContainsKey (k)) {
						policies.Remove (k);
						OnPolicyChanged (k.PolicyType, k.Scope);
					}
				}
			}
		}
コード例 #13
0
		public DefaultPolicyOptionsDialog (Gtk.Window parentWindow)
			: base (parentWindow, new PolicySet (),
			        "/MonoDevelop/ProjectModel/Gui/DefaultPolicyPanels")
		{
			this.Title = GettextCatalog.GetString ("Custom Policies");
			editingSet = (PolicySet) DataObject;
			
			HBox topBar = new HBox ();
			topBar.Spacing = 3;
			topBar.PackStart (new Label (GettextCatalog.GetString ("Editing Policy:")), false, false, 0);
			
			policiesCombo = ComboBox.NewText ();
			topBar.PackStart (policiesCombo, false, false, 0);
			
			deleteButton = new Button (GettextCatalog.GetString ("Delete Policy"));
			topBar.PackEnd (deleteButton, false, false, 0);
			
			exportButton = new MenuButton ();
			exportButton.Label = GettextCatalog.GetString ("Export");
			exportButton.MenuCreator = delegate {
				Gtk.Menu menu = new Gtk.Menu ();
				MenuItem mi = new MenuItem (GettextCatalog.GetString ("To file..."));
				mi.Activated += HandleToFile;
				menu.Insert (mi, -1);
				mi = new MenuItem (GettextCatalog.GetString ("To project or solution..."));
				mi.Activated += HandleToProject;
				if (!IdeApp.Workspace.IsOpen)
					mi.Sensitive = false;
				menu.Insert (mi, -1);
				menu.ShowAll ();
				return menu;
			};
			topBar.PackEnd (exportButton, false, false, 0);
			
			newButton = new MenuButton ();
			newButton.Label = GettextCatalog.GetString ("Add Policy");
			newButton.MenuCreator = delegate {
				Gtk.Menu menu = new Gtk.Menu ();
				MenuItem mi = new MenuItem (GettextCatalog.GetString ("New policy..."));
				mi.Activated += HandleNewButtonClicked;
				menu.Insert (mi, -1);
				mi = new MenuItem (GettextCatalog.GetString ("From file..."));
				mi.Activated += HandleFromFile;
				menu.Insert (mi, -1);
				mi = new MenuItem (GettextCatalog.GetString ("From project or solution..."));
				mi.Activated += HandleFromProject;
				if (!IdeApp.Workspace.IsOpen)
					mi.Sensitive = false;
				menu.Insert (mi, -1);
				menu.ShowAll ();
				return menu;
			};
			topBar.PackEnd (newButton, false, false, 0);
			
			Alignment align = new Alignment (0f, 0f, 1f, 1f);
			align.LeftPadding = 9;
			align.TopPadding = 9;
			align.RightPadding = 9;
			align.BottomPadding = 9;
			align.Add (topBar);
			
			HeaderBox ebox = new HeaderBox ();
			ebox.GradientBackround = true;
			ebox.SetMargins (0, 1, 0, 0);
			ebox.Add (align);
			
			ebox.ShowAll ();
			
			VBox.PackStart (ebox, false, false, 0);
			VBox.BorderWidth = 0;
			Box.BoxChild c = (Box.BoxChild) VBox [ebox];
			c.Position = 0;
			
			foreach (PolicySet ps in PolicyService.GetUserPolicySets ()) {
				PolicySet copy = ps.Clone ();
				originalSets [copy] = ps;
				sets.Add (copy);
			}
			FillPolicySets ();
			
			policiesCombo.Changed += HandlePoliciesComboChanged;
			deleteButton.Clicked += HandleDeleteButtonClicked;
		}
コード例 #14
0
		void HandleDeleteButtonClicked (object sender, EventArgs e)
		{
			if (!MessageService.Confirm (GettextCatalog.GetString ("Are you sure you want to delete the policy '{0}'?", currentSet.Name), AlertButton.Delete))
				return;
			
			sets.Remove (currentSet);
			currentSet = null;
			FillPolicySets ();
		}
コード例 #15
0
		void FillPolicySets ()
		{
			loading = true;
			int current = policiesCombo.Active;
			
			((ListStore)policiesCombo.Model).Clear ();
			policiesCombo.WidthRequest = -1;
			
			sets.Sort ((p1, p2) => string.Compare (p1.Name, p2.Name, StringComparison.CurrentCulture));
			
			foreach (PolicySet pset in sets) {
				policiesCombo.AppendText (pset.Name ?? "");
			}
			if (current == -1 && sets.Count > 0)
				policiesCombo.Active = 0;
			else if (current >= sets.Count)
				policiesCombo.Active = sets.Count - 1;
			else
				policiesCombo.Active = current;
			
			if (policiesCombo.SizeRequest ().Width < 200)
				policiesCombo.WidthRequest = 200;
			
			loading = false;
			
			if (policiesCombo.Active != -1 && sets [policiesCombo.Active] != currentSet) {
				currentSet = sets [policiesCombo.Active];
				editingSet.Name = currentSet.Name;
				editingSet.CopyFrom (currentSet);
			}
			UpdateStatus ();
		}
コード例 #16
0
		void HandleFromFile (object sender, EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog (GettextCatalog.GetString ("Select Policy File"));
			dlg.Action = FileChooserAction.Open;
			dlg.TransientFor = this;
			dlg.AddFilter (BrandingService.BrandApplicationName (GettextCatalog.GetString ("MonoDevelop policy files")), "*.mdpolicy");
			dlg.AddAllFilesFilter ();
			dlg.CurrentFolder = ExportProjectPolicyDialog.DefaultFileDialogPolicyDir;
			if (dlg.Run ()) {
				try {
					PolicySet pset = new PolicySet ();
					pset.LoadFromFile (dlg.SelectedFile);
					if (string.IsNullOrEmpty (pset.Name))
						pset.Name = dlg.SelectedFile.FileNameWithoutExtension;
					pset.Name = GetUnusedName (pset.Name);
					sets.Add (pset);
					ExportProjectPolicyDialog.DefaultFileDialogPolicyDir = dlg.SelectedFile.ParentDirectory;
					FillPolicySets ();
					policiesCombo.Active = sets.IndexOf (pset);
				} catch (Exception ex) {
					MessageService.ShowException (ex, GettextCatalog.GetString ("The policy set could not be loaded"));
				}
			}
		}
コード例 #17
0
		void HandleFromProject (object sender, EventArgs e)
		{
			ImportProjectPolicyDialog dlg = new ImportProjectPolicyDialog ();
			try {
				if (MessageService.RunCustomDialog (dlg, this) == (int) Gtk.ResponseType.Ok) {
					PolicySet pset = new PolicySet ();
					pset.CopyFrom (dlg.SelectedItem.Policies);
					pset.Name = GetUnusedName (dlg.PolicyName);
					sets.Add (pset);
					FillPolicySets ();
					policiesCombo.Active = sets.IndexOf (pset);
				}
			} finally {
				dlg.Destroy ();
			}
		}
コード例 #18
0
		void HandleNewButtonClicked (object sender, EventArgs e)
		{
			HashSet<PolicySet> esets = new HashSet<PolicySet> (PolicyService.GetPolicySets ());
			esets.ExceptWith (PolicyService.GetUserPolicySets ());
			esets.UnionWith (sets);
			esets.RemoveWhere (p => !p.Visible);
			
			NewPolicySetDialog dlg = new NewPolicySetDialog (new List<PolicySet> (esets));
			try {
				if (MessageService.RunCustomDialog (dlg, this) == (int) ResponseType.Ok) {
					PolicySet pset = new PolicySet ();
					pset.CopyFrom (dlg.SourceSet);
					pset.Name = GetUnusedName (dlg.PolicyName);
					sets.Add (pset);
					FillPolicySets ();
					policiesCombo.Active = sets.IndexOf (pset);
				}
			} finally {
				dlg.Destroy ();
			}
		}