diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs')
-rw-r--r-- | main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs index 621ced902e..013f184cb4 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs @@ -38,14 +38,24 @@ namespace MonoDevelop.SourceEditor.OptionPanels public partial class HighlightingPanel : Gtk.Bin, IOptionsPanel { string schemeName; + ListStore styleStore = new ListStore (typeof (string), typeof (Mono.TextEditor.Highlighting.ColorScheme), typeof(bool)); + Lazy<Gdk.Pixbuf> errorPixbuf = new Lazy<Gdk.Pixbuf> (() => ImageService.GetIcon (Stock.DialogError, IconSize.Menu).ToPixbuf ()); - - ListStore styleStore = new ListStore (typeof (string), typeof (Mono.TextEditor.Highlighting.ColorScheme)); - public HighlightingPanel () { this.Build (); - styleTreeview.AppendColumn ("", new CellRendererText (), "markup", 0); + var col = new TreeViewColumn (); + var crpixbuf = new CellRendererPixbuf (); + col.PackStart (crpixbuf, false); + col.SetCellDataFunc (crpixbuf, (TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) => { + var isError = (bool)styleStore.GetValue (iter, 2); + crpixbuf.Visible = isError; + crpixbuf.Pixbuf = isError ? errorPixbuf.Value : null; + }); + var crtext = new CellRendererText (); + col.PackEnd (crtext, true); + col.SetAttributes (crtext, "markup", 0); + styleTreeview.AppendColumn (col); styleTreeview.Model = styleStore; // ensure that custom styles are loaded. new SourceEditorDisplayBinding (); @@ -101,7 +111,11 @@ namespace MonoDevelop.SourceEditor.OptionPanels var sheme = (Mono.TextEditor.Highlighting.ColorScheme)styleStore.GetValue (iter, 1); if (sheme == null) return; - + var isError = (bool)styleStore.GetValue (iter, 2); + if (isError) { + this.removeButton.Sensitive = true; + return; + } DefaultSourceEditorOptions.Instance.ColorScheme = sheme.Name; this.buttonExport.Sensitive = true; string fileName = sheme.FileName; @@ -118,19 +132,24 @@ namespace MonoDevelop.SourceEditor.OptionPanels using (var editor = new ColorShemeEditor (this)) { var colorScheme = (Mono.TextEditor.Highlighting.ColorScheme)this.styleStore.GetValue (selectedIter, 1); editor.SetSheme (colorScheme); - MessageService.ShowCustomDialog (editor, dialog); + MessageService. ShowCustomDialog (editor, dialog); } } } - Mono.TextEditor.Highlighting.ColorScheme LoadStyle (string styleName, bool showException = true) + Mono.TextEditor.Highlighting.ColorScheme LoadStyle (string styleName, out bool error) { try { + error = false; return Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle (styleName); } catch (Exception e) { - if (showException) - MessageService.ShowError ("Error while importing color style " + styleName, (e.InnerException ?? e).Message); - return Mono.TextEditor.Highlighting.SyntaxModeService.DefaultColorStyle; + LoggingService.LogError ("Error while loading color style " + styleName, e); + error = true; + var style = Mono.TextEditor.Highlighting.SyntaxModeService.DefaultColorStyle.Clone (); + style.Name = styleName; + style.Description = GettextCatalog.GetString ("Loading error:" + e.Message); + style.FileName = Mono.TextEditor.Highlighting.SyntaxModeService.GetFileName (styleName); + return style; } } @@ -138,11 +157,12 @@ namespace MonoDevelop.SourceEditor.OptionPanels internal void ShowStyles () { styleStore.Clear (); - TreeIter selectedIter = styleStore.AppendValues (GetMarkup (GettextCatalog.GetString ("Default"), GettextCatalog.GetString ("The default color scheme.")), LoadStyle ("Default")); + bool error; + TreeIter selectedIter = styleStore.AppendValues (GetMarkup (GettextCatalog.GetString ("Default"), GettextCatalog.GetString ("The default color scheme.")), LoadStyle ("Default", out error)); foreach (string styleName in Mono.TextEditor.Highlighting.SyntaxModeService.Styles) { if (styleName == "Default") continue; - var style = LoadStyle (styleName); + var style = LoadStyle (styleName, out error); string name = style.Name ?? ""; string description = style.Description ?? ""; // translate only build-in sheme names @@ -154,7 +174,7 @@ namespace MonoDevelop.SourceEditor.OptionPanels } catch { } } - TreeIter iter = styleStore.AppendValues (GetMarkup (name, description), style); + TreeIter iter = styleStore.AppendValues (GetMarkup (name, description), style, error); if (style.Name == DefaultSourceEditorOptions.Instance.ColorScheme) selectedIter = iter; } @@ -179,7 +199,7 @@ namespace MonoDevelop.SourceEditor.OptionPanels void HandleButtonExportClicked (object sender, EventArgs e) { - var dialog = new SelectFileDialog (GettextCatalog.GetString ("Highlighting Scheme"), Gtk.FileChooserAction.Save) { + var dialog = new SelectFileDialog (GettextCatalog.GetString ("Highlighting Scheme"), MonoDevelop.Components.FileChooserAction.Save) { TransientFor = this.Toplevel as Gtk.Window, }; dialog.AddFilter (GettextCatalog.GetString ("Color schemes"), "*.json"); @@ -198,7 +218,7 @@ namespace MonoDevelop.SourceEditor.OptionPanels void AddColorScheme (object sender, EventArgs args) { - var dialog = new SelectFileDialog (GettextCatalog.GetString ("Highlighting Scheme"), Gtk.FileChooserAction.Open) { + var dialog = new SelectFileDialog (GettextCatalog.GetString ("Highlighting Scheme"), MonoDevelop.Components.FileChooserAction.Open) { TransientFor = this.Toplevel as Gtk.Window, }; dialog.AddFilter (GettextCatalog.GetString ("Color schemes"), "*.json"); |