Changeset 11907 for stable/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
- Timestamp:
- 02/05/15 10:51:29 (9 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r11170 r11907 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 43 public override bool ReadOnly { 44 get { return codeEditor.ReadOnly || base.ReadOnly; } 45 set { base.ReadOnly = codeEditor.ReadOnly = value; } 46 } 47 48 public override bool Locked { 49 get { return codeEditor.ReadOnly || base.Locked; } 50 set { base.Locked = codeEditor.ReadOnly = value; } 51 } 52 #endregion 41 53 42 54 public ScriptView() { … … 47 59 protected override void RegisterContentEvents() { 48 60 base.RegisterContentEvents(); 49 Content.CodeChanged += Content OnCodeChanged;61 Content.CodeChanged += Content_CodeChanged; 50 62 } 51 63 52 64 protected override void DeregisterContentEvents() { 53 Content.CodeChanged -= Content OnCodeChanged;65 Content.CodeChanged -= Content_CodeChanged; 54 66 base.DeregisterContentEvents(); 55 67 } 56 68 57 protected virtual void ContentOnCodeChanged(object sender, EventArgs e) { 58 codeEditor.UserCode = Content.Code; 59 } 60 69 #region Overrides 61 70 protected override void OnContentChanged() { 62 71 base.OnContentChanged(); … … 64 73 codeEditor.UserCode = string.Empty; 65 74 } else { 66 codeEditor.UserCode = Content.Code; 75 if (codeEditor.UserCode != Content.Code) 76 codeEditor.UserCode = Content.Code; 67 77 foreach (var asm in Content.GetAssemblies()) 68 78 codeEditor.AddAssembly(asm); … … 83 93 base.SetEnabledStateOfControls(); 84 94 compileButton.Enabled = Content != null && !Locked && !ReadOnly; 85 codeEditor.Enabled = Content != null && !Locked && !ReadOnly;95 codeEditor.Enabled = Content != null; 86 96 } 87 97 88 protected virtual void CompileButtonOnClick(object sender, EventArgs e) {89 Compile();90 }91 92 protected virtual void CodeEditorOnTextEditorTextChanged(object sender, EventArgs e) {93 if (Content == null) return;94 Content.Code = codeEditor.UserCode;95 }96 98 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { 97 99 switch (keyData) { … … 103 105 return base.ProcessCmdKey(ref msg, keyData); 104 106 } 107 #endregion 105 108 106 109 public virtual bool Compile() { … … 113 116 outputTextBox.AppendText("Compilation succeeded."); 114 117 return true; 115 } catch {118 } catch (InvalidOperationException) { 116 119 if (Content.CompileErrors.HasErrors) { 117 120 outputTextBox.AppendText("Compilation failed."); … … 127 130 ReadOnly = false; 128 131 Locked = false; 132 codeEditor.Focus(); 129 133 OnContentChanged(); 130 134 } 131 135 } 132 136 137 #region Helpers 133 138 protected virtual void ShowCompilationResults() { 134 139 if (Content.CompileErrors.Count == 0) return; 135 var msgs = Content.CompileErrors.OfType<CompilerError>() 140 141 var messages = Content.CompileErrors.OfType<CompilerError>() 136 142 .OrderBy(x => x.IsWarning) 137 143 .ThenBy(x => x.Line) 138 144 .ThenBy(x => x.Column); 139 foreach (var m in msgs) { 140 var item = new ListViewItem(); 145 146 foreach (var m in messages) { 147 var item = new ListViewItem { Tag = m }; 141 148 item.SubItems.AddRange(new[] { 142 149 m.IsWarning ? "Warning" : "Error", … … 149 156 errorListView.Items.Add(item); 150 157 } 158 159 codeEditor.ShowCompileErrors(Content.CompileErrors, ".cs"); 160 151 161 AdjustErrorListViewColumnSizes(); 152 162 } … … 157 167 ch.Width = -2; 158 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 159 198 } 160 199 }
Note: See TracChangeset
for help on using the changeset viewer.