diff options
Diffstat (limited to 'main/src')
5 files changed, 35 insertions, 17 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs index 7b4925d6de..0e7b6e5b61 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicyService.cs @@ -41,8 +41,6 @@ using System.Globalization; namespace MonoDevelop.Projects.Policies { - - public static class PolicyService { const string TYPE_EXT_POINT = "/MonoDevelop/ProjectModel/PolicyTypes"; @@ -1122,6 +1120,13 @@ namespace MonoDevelop.Projects.Policies /// </param> public static void AddUserPolicySet (PolicySet pset) { + if (pset.Id != null) + throw new ArgumentException ("User policy cannot have ID"); + if (string.IsNullOrEmpty (pset.Name)) + throw new ArgumentException ("User policy cannot have null or empty name"); + if (sets.Any (ps => ps.Name == pset.Name)) + throw new ArgumentException ("There is already a policy with the name ' " + pset.Name + "'"); + userSets.Add (pset); sets.Add (pset); } @@ -1200,7 +1205,14 @@ namespace MonoDevelop.Projects.Policies if (Directory.Exists (PoliciesFolder)) { foreach (var file in Directory.GetFiles (PoliciesFolder, "*.mdpolicy.xml")) { - LoadPolicy (file); + try { + LoadPolicy (file); + } catch (Exception ex) { + LoggingService.LogError ( + string.Format ("Failed to load policy file '{0}'", Path.GetFileName (file)), + ex + ); + } } } @@ -1225,11 +1237,10 @@ namespace MonoDevelop.Projects.Policies while (xr.NodeType != XmlNodeType.EndElement) { PolicySet pset = new PolicySet (); pset.LoadFromXml (xr); - if (pset.Id == "Default") + if (pset.Id == "Default") { defaultPolicies = pset; - else { - userSets.Add (pset); - sets.Add (pset); + } else { + AddUserPolicySet (pset); } xr.MoveToContent (); } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs index abcead1ca2..d8b62e1387 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Policies/PolicySet.cs @@ -156,7 +156,7 @@ namespace MonoDevelop.Projects.Policies internal void LoadFromFile (StreamReader reader) { - var xr = System.Xml.XmlReader.Create (reader); + var xr = XmlReader.Create (reader); LoadFromXml (xr); } @@ -180,8 +180,9 @@ namespace MonoDevelop.Projects.Policies foreach (ScopedPolicy policyPair in PolicyService.DiffDeserializeXml (reader)) { PolicyKey key = new PolicyKey (policyPair.PolicyType, policyPair.Scope); if (policies.ContainsKey (key)) - throw new InvalidOperationException ("Cannot add second policy of type '" + - key.ToString () + "' to policy set '" + Id + "'"); + throw new InvalidOperationException ( + "Cannot add second policy of type '" + key + "' to policy set '" + Id + "'" + ); policies[key] = policyPair.Policy; } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/DefaultPolicyOptionsDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/DefaultPolicyOptionsDialog.cs index 91e259e80b..eaac1af0c3 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/DefaultPolicyOptionsDialog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/DefaultPolicyOptionsDialog.cs @@ -179,10 +179,10 @@ namespace MonoDevelop.Ide.Projects NewPolicySetDialog dlg = new NewPolicySetDialog (new List<PolicySet> (esets)); try { - if (MessageService.RunCustomDialog (dlg, this) == (int) Gtk.ResponseType.Ok) { + if (MessageService.RunCustomDialog (dlg, this) == (int) ResponseType.Ok) { PolicySet pset = new PolicySet (); pset.CopyFrom (dlg.SourceSet); - pset.Name = dlg.PolicyName; + pset.Name = GetUnusedName (dlg.PolicyName); sets.Add (pset); FillPolicySets (); policiesCombo.Active = sets.IndexOf (pset); @@ -199,7 +199,7 @@ namespace MonoDevelop.Ide.Projects if (MessageService.RunCustomDialog (dlg, this) == (int) Gtk.ResponseType.Ok) { PolicySet pset = new PolicySet (); pset.CopyFrom (dlg.SelectedItem.Policies); - pset.Name = GetValidName (dlg.PolicyName); + pset.Name = GetUnusedName (dlg.PolicyName); sets.Add (pset); FillPolicySets (); policiesCombo.Active = sets.IndexOf (pset); @@ -223,7 +223,7 @@ namespace MonoDevelop.Ide.Projects pset.LoadFromFile (dlg.SelectedFile); if (string.IsNullOrEmpty (pset.Name)) pset.Name = dlg.SelectedFile.FileNameWithoutExtension; - pset.Name = GetValidName (pset.Name); + pset.Name = GetUnusedName (pset.Name); sets.Add (pset); ExportProjectPolicyDialog.DefaultFileDialogPolicyDir = dlg.SelectedFile.ParentDirectory; FillPolicySets (); @@ -234,7 +234,7 @@ namespace MonoDevelop.Ide.Projects } } - string GetValidName (string name) + string GetUnusedName (string name) { string finalName = name; int n = 1; @@ -292,7 +292,7 @@ namespace MonoDevelop.Ide.Projects ((ListStore)policiesCombo.Model).Clear (); policiesCombo.WidthRequest = -1; - sets.Sort ((p1,p2) => p1.Name.CompareTo(p2.Name)); + sets.Sort ((p1, p2) => string.Compare (p1.Name, p2.Name, StringComparison.CurrentCulture)); foreach (PolicySet pset in sets) { policiesCombo.AppendText (pset.Name ?? ""); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/ExportProjectPolicyDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/ExportProjectPolicyDialog.cs index 9863154e32..576b13aa4f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/ExportProjectPolicyDialog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/ExportProjectPolicyDialog.cs @@ -96,7 +96,7 @@ namespace MonoDevelop.Ide.Projects UpdateWidgets (); } - protected void OnButtonOkClicked (object sender, System.EventArgs e) + protected void OnButtonOkClicked (object sender, EventArgs e) { if (radioCustom.Active) { if (entryName.Text.Length == 0) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewPolicySetDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewPolicySetDialog.cs index ba0451c16e..43933126e2 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewPolicySetDialog.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewPolicySetDialog.cs @@ -36,10 +36,16 @@ namespace MonoDevelop.Ide.Projects public NewPolicySetDialog (List<PolicySet> sets) { this.Build (); + this.sets = sets; foreach (var ps in sets) comboSets.AppendText (ps.Name); comboSets.Active = 0; + + buttonOk.Sensitive = false; + entryName.Changed += delegate { + buttonOk.Sensitive = !string.IsNullOrWhiteSpace (entryName.Text); + }; } public string PolicyName { |