- Timestamp:
- 12/04/14 17:14:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r11480 r11657 35 35 [Content(typeof(Script), true)] 36 36 public partial class ScriptView : NamedItemView { 37 #region Properties 37 38 public new Script Content { 38 39 get { return (Script)base.Content; } 39 40 set { base.Content = value; } 40 }41 42 public ScriptView() {43 InitializeComponent();44 errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error });45 41 } 46 42 … … 54 50 set { base.Locked = codeEditor.ReadOnly = value; } 55 51 } 52 #endregion 53 54 public ScriptView() { 55 InitializeComponent(); 56 errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error }); 57 } 56 58 57 59 protected override void RegisterContentEvents() { 58 60 base.RegisterContentEvents(); 59 Content.CodeChanged += Content OnCodeChanged;61 Content.CodeChanged += Content_CodeChanged; 60 62 } 61 63 62 64 protected override void DeregisterContentEvents() { 63 Content.CodeChanged -= Content OnCodeChanged;65 Content.CodeChanged -= Content_CodeChanged; 64 66 base.DeregisterContentEvents(); 65 67 } 66 68 67 protected virtual void ContentOnCodeChanged(object sender, EventArgs e) { 68 codeEditor.UserCode = Content.Code; 69 } 70 69 #region Overrides 71 70 protected override void OnContentChanged() { 72 71 base.OnContentChanged(); … … 74 73 codeEditor.UserCode = string.Empty; 75 74 } else { 76 codeEditor.UserCode = Content.Code; 75 if (codeEditor.UserCode != Content.Code) 76 codeEditor.UserCode = Content.Code; 77 77 foreach (var asm in Content.GetAssemblies()) 78 78 codeEditor.AddAssembly(asm); … … 96 96 } 97 97 98 protected virtual void CompileButtonOnClick(object sender, EventArgs e) {99 Compile();100 }101 102 protected virtual void CodeEditorOnTextEditorTextChanged(object sender, EventArgs e) {103 if (Content == null) return;104 Content.Code = codeEditor.UserCode;105 }106 98 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { 107 99 switch (keyData) { … … 113 105 return base.ProcessCmdKey(ref msg, keyData); 114 106 } 107 #endregion 115 108 116 109 public virtual bool Compile() { … … 123 116 outputTextBox.AppendText("Compilation succeeded."); 124 117 return true; 125 } catch {118 } catch (InvalidOperationException) { 126 119 if (Content.CompileErrors.HasErrors) { 127 120 outputTextBox.AppendText("Compilation failed."); … … 137 130 ReadOnly = false; 138 131 Locked = false; 132 codeEditor.Focus(); 139 133 OnContentChanged(); 140 134 } 141 135 } 142 136 137 #region Helpers 143 138 protected virtual void ShowCompilationResults() { 144 139 if (Content.CompileErrors.Count == 0) return; 145 var msgs = Content.CompileErrors.OfType<CompilerError>() 140 141 var messages = Content.CompileErrors.OfType<CompilerError>() 146 142 .OrderBy(x => x.IsWarning) 147 143 .ThenBy(x => x.Line) 148 144 .ThenBy(x => x.Column); 149 foreach (var m in msgs) { 150 var item = new ListViewItem(); 145 146 foreach (var m in messages) { 147 var item = new ListViewItem { Tag = m }; 151 148 item.SubItems.AddRange(new[] { 152 149 m.IsWarning ? "Warning" : "Error", … … 159 156 errorListView.Items.Add(item); 160 157 } 158 159 codeEditor.ShowCompileErrors(Content.CompileErrors, ".cs"); 160 161 161 AdjustErrorListViewColumnSizes(); 162 162 } … … 167 167 ch.Width = -2; 168 168 } 169 #endregion 170 171 #region Event Handlers 172 private void Content_CodeChanged(object sender, EventArgs e) { 173 if (InvokeRequired) 174 Invoke(new EventHandler(Content_CodeChanged), sender, e); 175 else { 176 codeEditor.UserCode = Content.Code; 177 } 178 } 179 180 private void compileButton_Click(object sender, EventArgs e) { 181 Compile(); 182 } 183 184 private void codeEditor_TextEditorTextChanged(object sender, EventArgs e) { 185 if (Content == null) return; 186 Content.Code = codeEditor.UserCode; 187 } 188 189 private void errorListView_MouseDoubleClick(object sender, MouseEventArgs e) { 190 if (e.Button == MouseButtons.Left) { 191 var item = errorListView.SelectedItems[0]; 192 var message = (CompilerError)item.Tag; 193 codeEditor.ScrollToPosition(message.Line, message.Column); 194 codeEditor.Focus(); 195 } 196 } 197 #endregion 169 198 } 170 199 }
Note: See TracChangeset
for help on using the changeset viewer.