[mono/monodevelop] d0926115: Fixed 'Bug 14898 - Cant edit no any highlight scheme'.

Mike Krüger ([email protected]) <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141b7fdc0e3-3cfb1b30-4609-43bf-afbc-8689942ac4bd-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/b970f4a86dd1...d0926115623c

   Commit: d0926115623cb23d21c57c402c52ac3628a967f6
   Author: Mike Krüger <[email protected]> (mkrueger)
     Date: 2013-10-14 12:37:20 GMT
      URL: https://github.com/mono/monodevelop/commit/d0926115623cb23d21c57c402c52ac3628a967f6

Fixed 'Bug 14898 - Cant edit no any highlight scheme'.

Changed paths:
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/ColorShemeEditor.cs
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/NewColorShemeDialog.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs
  M main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/ColorShemeEditor.cs
===================================================================
@@ -242,7 +242,7 @@ public void SetSheme (ColorScheme style)
 		{
 			if (style == null)
 				throw new ArgumentNullException ("style");
-			this.fileName = Mono.TextEditor.Highlighting.SyntaxModeService.GetFileNameForStyle (style);
+			this.fileName = style.FileName;
 			this.colorSheme = style;
 			this.entryName.Text = style.Name;
 			this.entryDescription.Text = style.Description;

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs
===================================================================
@@ -99,7 +99,7 @@ void HandleStyleTreeviewSelectionChanged (object sender, EventArgs e)
 			if (sheme == null)
 				return;
 			this.buttonExport.Sensitive = true;
-			string fileName = Mono.TextEditor.Highlighting.SyntaxModeService.GetFileNameForStyle (sheme);
+			string fileName = sheme.FileName;
 			if (fileName == null)
 				return;
 			this.removeButton.Sensitive = true;
@@ -111,7 +111,8 @@ void HandleButtonEdithandleClicked (object sender, EventArgs e)
 			TreeIter selectedIter;
 			if (styleTreeview.Selection.GetSelected (out selectedIter)) {
 				var editor = new ColorShemeEditor (this);
-				editor.SetSheme ((Mono.TextEditor.Highlighting.ColorScheme)this.styleStore.GetValue (selectedIter, 1));
+				var colorScheme = (Mono.TextEditor.Highlighting.ColorScheme)this.styleStore.GetValue (selectedIter, 1);
+				editor.SetSheme (colorScheme);
 				MessageService.RunCustomDialog (editor, dialog);
 				editor.Destroy ();
 			}
@@ -140,7 +141,7 @@ internal void ShowStyles ()
 				string name = style.Name ?? "";
 				string description = style.Description ?? "";
 				// translate only build-in sheme names
-				if (string.IsNullOrEmpty (Mono.TextEditor.Highlighting.SyntaxModeService.GetFileNameForStyle (style))) {
+				if (string.IsNullOrEmpty (style.FileName)) {
 					try {
 						name = GettextCatalog.GetString (name);
 						if (!string.IsNullOrEmpty (description))
@@ -160,11 +161,11 @@ void RemoveColorScheme (object sender, EventArgs args)
 			TreeIter selectedIter;
 			if (!styleTreeview.Selection.GetSelected (out selectedIter)) 
 				return;
-			var sheme = (Mono.TextEditor.Highlighting.ColorScheme)this.styleStore.GetValue (selectedIter, 1);
+			var sheme = (ColorScheme)this.styleStore.GetValue (selectedIter, 1);
 			
-			string fileName = Mono.TextEditor.Highlighting.SyntaxModeService.GetFileNameForStyle (sheme);
+			string fileName = sheme.FileName;
 			
-			if (fileName != null && fileName.StartsWith (SourceEditorDisplayBinding.SyntaxModePath)) {
+			if (fileName != null && fileName.StartsWith (SourceEditorDisplayBinding.SyntaxModePath, StringComparison.Ordinal)) {
 				Mono.TextEditor.Highlighting.SyntaxModeService.Remove (sheme);
 				File.Delete (fileName);
 				ShowStyles ();

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/NewColorShemeDialog.cs
===================================================================
@@ -76,7 +76,8 @@ void HandleButtonOkClicked (object sender, EventArgs e)
 			string fileName = System.IO.Path.Combine (path, baseName + "Style.json");
 			try {
 				style.Save (fileName);
-				Mono.TextEditor.Highlighting.SyntaxModeService.AddStyle (fileName, style);
+				style.FileName = fileName;
+				Mono.TextEditor.Highlighting.SyntaxModeService.AddStyle (style);
 			} catch (Exception ex) {
 				MonoDevelop.Ide.MessageService.ShowException (ex);
 			}

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/ColorScheme.cs
===================================================================
@@ -42,6 +42,7 @@ public class ColorScheme
 		public string Description { get; set; }
 		public string Originator { get; set; }
 		public string BaseScheme { get; set; }
+		public string FileName { get; set; }
 
 		#region Ambient Colors
 		[ColorDescription("Background(Read Only)",VSSetting="color=Plain Text/Background")]

Modified: main/src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs
===================================================================
@@ -43,8 +43,7 @@ public static class SyntaxModeService
 		static Dictionary<string, ColorScheme> styles      = new Dictionary<string, ColorScheme> ();
 		static Dictionary<string, IStreamProvider> syntaxModeLookup = new Dictionary<string, IStreamProvider> ();
 		static Dictionary<string, IStreamProvider> styleLookup      = new Dictionary<string, IStreamProvider> ();
-		static Dictionary<string, string> isLoadedFromFile = new Dictionary<string, string> ();
-		
+
 		public static string[] Styles {
 			get {
 				List<string> result = new List<string> ();
@@ -60,14 +59,6 @@ public static class SyntaxModeService
 			}
 		}
 		
-		public static string GetFileNameForStyle (ColorScheme style)
-		{
-			string result;
-			if (!isLoadedFromFile.TryGetValue (style.Name, out result))
-				return null;
-			return result;
-		}
-		
 		public static void InstallSyntaxMode (string mimeType, ISyntaxModeProvider modeProvider)
 		{
 			if (syntaxModeLookup.ContainsKey (mimeType))
@@ -107,6 +98,7 @@ static void LoadStyle (string name)
 			if (!styleLookup.ContainsKey (name))
 				throw new System.ArgumentException ("Style " + name + " not found", "name");
 			var provider = styleLookup [name];
+			styleLookup.Remove (name); 
 			var stream = provider.Open ();
 			try {
 				if (provider is UrlStreamProvider) {
@@ -116,6 +108,7 @@ static void LoadStyle (string name)
 					} else {
 						styles [name] = ColorScheme.LoadFrom (stream);
 					}
+					styles [name].FileName = usp.Url;
 				} else {
 					styles [name] = ColorScheme.LoadFrom (stream);
 				}
@@ -196,10 +189,15 @@ public static bool ValidateAllSyntaxModes ()
 		
 		public static void Remove (ColorScheme style)
 		{
-			if (styles.ContainsKey (style.Name))
-				styles.Remove (style.Name);
 			if (styleLookup.ContainsKey (style.Name))
 				styleLookup.Remove (style.Name);
+
+			foreach (var kv in styles) {
+				if (kv.Value == style) {
+					styles.Remove (kv.Key); 
+					return;
+				}
+			}
 		}
 		
 		public static void Remove (SyntaxMode mode)
@@ -427,7 +425,6 @@ public static void LoadStylesAndModes (string path)
 						string styleName = ScanStyle (stream);
 						if (!string.IsNullOrEmpty (styleName)) {
 							styleLookup [styleName] = new UrlStreamProvider (file);
-							isLoadedFromFile [styleName] = file;
 						} else {
 							Console.WriteLine ("Invalid .json syntax sheme file : " + file);
 						}
@@ -436,7 +433,6 @@ public static void LoadStylesAndModes (string path)
 					using (var stream = File.OpenRead (file)) {
 						string styleName = Path.GetFileNameWithoutExtension (file);
 						styleLookup [styleName] = new UrlStreamProvider (file);
-						isLoadedFromFile [styleName] = file;
 					}
 				}
 			}
@@ -500,9 +496,8 @@ public static void RemoveSyntaxMode (IStreamProvider provider)
 			}
 		}
 		
-		public static void AddStyle (string fileName, ColorScheme style)
+		public static void AddStyle (ColorScheme style)
 		{
-			isLoadedFromFile [style.Name] = fileName;
 			styles [style.Name] = style;
 		}
 
_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.