4
using System.Collections;
5
using System.Collections.Generic;
11
using MonoDevelop.Components;
13
using MonoDevelop.Core;
14
using MonoDevelop.Core.Gui.Dialogs;
16
using MonoDevelop.Ide.Gui.Content;
18
namespace MonoDevelop.SourceEditor.Gui.OptionPanels
20
class SyntaxHighlightingPanel : AbstractOptionPanel
22
SyntaxHighlightingPanelWidget widget;
24
public override void LoadPanelContents()
26
Add (widget = new SyntaxHighlightingPanelWidget ());
29
public override bool StorePanelContents()
35
class SyntaxHighlightingPanelWidget : GladeWidgetExtract
37
[Glade.Widget] CheckButton enableSyntaxHighlighting;
38
[Glade.Widget] ComboBox sourceLanguages;
39
[Glade.Widget] Gtk.TreeView stylesTreeView;
40
[Glade.Widget] ToggleButton boldToggle;
41
[Glade.Widget] ToggleButton italicToggle;
42
[Glade.Widget] ToggleButton underlineToggle;
43
[Glade.Widget] ToggleButton strikeToggle;
44
[Glade.Widget] ColorButton fgColorButton;
45
[Glade.Widget] ColorButton bgColorButton;
46
[Glade.Widget] Button restoreDefaultButton;
47
[Glade.Widget] VBox childrenVBox;
48
[Glade.Widget] CheckButton checkColor;
49
[Glade.Widget] CheckButton checkBackground;
51
SourceViewService svs = (SourceViewService) ServiceManager.GetService (typeof (SourceViewService));
52
SourceLanguage currentLanguage;
53
SourceTagStyle currentStyle;
56
Dictionary<SourceLanguage,Dictionary<string,SourceTagStyle>> changes = new Dictionary<SourceLanguage,Dictionary<string,SourceTagStyle>> ();
58
public SyntaxHighlightingPanelWidget () : base ("EditorBindings.glade", "SyntaxHighlightingPanel")
60
enableSyntaxHighlighting.Active = TextEditorProperties.SyntaxHighlight;
62
// add available sourceLanguages
63
ListStore store = new ListStore (typeof (string));
64
foreach (SourceLanguage sl in svs.AvailableLanguages)
65
store.AppendValues (sl.Name);
66
store.SetSortColumnId (0, SortType.Ascending);
67
sourceLanguages.Model = store;
69
CellRendererText cr = new CellRendererText ();
70
sourceLanguages.PackStart (cr, true);
71
sourceLanguages.AddAttribute (cr, "text", 0);
72
sourceLanguages.Active = 0;
74
stylesTreeView.AppendColumn ("styles", new CellRendererText (), "text", 0);
75
stylesTreeView.Selection.Changed += new EventHandler (OnStyleChanged);
80
TextEditorProperties.SyntaxHighlight = enableSyntaxHighlighting.Active;
81
foreach (KeyValuePair<SourceLanguage,Dictionary<string,SourceTagStyle>> lang in changes) {
82
foreach (KeyValuePair<string,SourceTagStyle> style in lang.Value) {
83
lang.Key.SetTagStyle (style.Key, style.Value);
88
void SetCurrentLanguage (string name)
90
currentLanguage = svs.FindLanguage (name);
94
void SetSourceTagStyle ()
96
SourceTagStyle sts = currentStyle;
97
boldToggle.Active = sts.Bold;
98
italicToggle.Active = sts.Italic;
99
underlineToggle.Active = sts.Underline;
100
strikeToggle.Active = sts.Strikethrough;
101
fgColorButton.Color = sts.Foreground;
102
bgColorButton.Color = sts.Background;
103
checkColor.Active = (sts.Mask & 2) != 0;
104
checkBackground.Active = (sts.Mask & 1) != 0;
105
fgColorButton.Sensitive = checkColor.Active;
106
bgColorButton.Sensitive = checkBackground.Active;
107
restoreDefaultButton.Sensitive = !sts.IsDefault;
110
void SetTreeValues ()
113
ListStore store = new ListStore (typeof (string), typeof (string));
114
foreach (SourceTag t in currentLanguage.Tags)
115
store.AppendValues (t.Name, t.Id);
116
stylesTreeView.Model = store;
119
store.GetIterFirst (out first);
120
stylesTreeView.Selection.SelectIter (first);
123
protected void OnButtonToggled (object sender, EventArgs a)
125
SourceTagStyle sts = currentStyle;
126
sts.Bold = boldToggle.Active;
127
sts.Italic = italicToggle.Active;
128
sts.Underline = underlineToggle.Active;
129
sts.Strikethrough = strikeToggle.Active;
130
sts.IsDefault = false;
131
SetTagStyle (currentLanguage, styleid, sts);
132
restoreDefaultButton.Sensitive = true;
135
protected void OnColorSet (object sender, EventArgs a)
137
SourceTagStyle sts = currentStyle;
138
sts.Foreground = fgColorButton.Color;
139
sts.Background = bgColorButton.Color;
140
sts.Mask = checkColor.Active ? 2u : 0u;
141
sts.Mask += checkBackground.Active ? 1u : 0u;
142
fgColorButton.Sensitive = checkColor.Active;
143
bgColorButton.Sensitive = checkBackground.Active;
144
sts.IsDefault = false;
145
SetTagStyle (currentLanguage, styleid, sts);
146
restoreDefaultButton.Sensitive = true;
149
protected void OnHighlightingToggled (object sender, EventArgs a)
151
CheckButton cb = sender as CheckButton;
152
childrenVBox.Sensitive = cb.Active;
155
protected void OnLanguageSelected (object sender, EventArgs a)
158
if (sourceLanguages.GetActiveIter (out iter)) {
159
SetCurrentLanguage ((string) sourceLanguages.Model.GetValue (iter, 0));
163
protected void OnRestoreClicked (object sender, EventArgs a)
165
currentLanguage = svs.RestoreDefaults (currentLanguage);
166
OnStyleChanged (stylesTreeView.Selection, EventArgs.Empty);
169
private void OnStyleChanged (object sender, EventArgs a)
173
TreeSelection selection = sender as TreeSelection;
175
if (selection.GetSelected (out model, out iter)) {
176
styleid = (string) model.GetValue (iter, 1);
177
currentStyle = GetTagStyle (currentLanguage, styleid);
178
SetSourceTagStyle ();
182
SourceTagStyle GetTagStyle (SourceLanguage lang, string id)
184
Dictionary<string,SourceTagStyle> styles;
185
if (changes.TryGetValue (lang, out styles)) {
186
SourceTagStyle style;
187
if (styles.TryGetValue (id, out style))
190
return currentLanguage.GetTagStyle (styleid);
193
void SetTagStyle (SourceLanguage lang, string id, SourceTagStyle style)
195
Dictionary<string,SourceTagStyle> styles;
196
if (!changes.TryGetValue (lang, out styles)) {
197
styles = new Dictionary<string,SourceTagStyle> ();
198
changes [lang] = styles;