- Timestamp:
- 04/08/14 23:28:40 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r10727 r10731 26 26 using System.Linq; 27 27 using System.Windows.Forms; 28 using HeuristicLab.Common;29 28 using HeuristicLab.Common.Resources; 30 29 using HeuristicLab.Core.Views; … … 36 35 [Content(typeof(Script), true)] 37 36 public partial class ScriptView : NamedItemView { 38 private bool running;39 40 37 public new Script Content { 41 38 get { return (Script)base.Content; } 42 set { base.Content = (Script)value; }39 set { base.Content = value; } 43 40 } 44 41 … … 46 43 InitializeComponent(); 47 44 errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error }); 48 AdjustErrorListViewColumnSizes();49 45 } 50 46 51 47 protected override void RegisterContentEvents() { 52 48 base.RegisterContentEvents(); 53 Content.CodeChanged += Content_CodeChanged; 54 Content.ScriptExecutionStarted += Content_ScriptExecutionStarted; 55 Content.ScriptExecutionFinished += Content_ScriptExecutionFinished; 56 Content.ConsoleOutputChanged += Content_ConsoleOutputChanged; 49 Content.CodeChanged += ContentOnCodeChanged; 57 50 } 58 51 59 52 protected override void DeregisterContentEvents() { 60 Content.CodeChanged -= Content_CodeChanged; 61 Content.ScriptExecutionStarted -= Content_ScriptExecutionStarted; 62 Content.ScriptExecutionFinished -= Content_ScriptExecutionFinished; 63 Content.ConsoleOutputChanged -= Content_ConsoleOutputChanged; 53 Content.CodeChanged -= ContentOnCodeChanged; 64 54 base.DeregisterContentEvents(); 65 55 } 66 56 67 #region Content event handlers 68 private void Content_CodeChanged(object sender, EventArgs e) { 57 protected virtual void ContentOnCodeChanged(object sender, EventArgs e) { 69 58 codeEditor.UserCode = Content.Code; 70 59 } 71 private void Content_ScriptExecutionStarted(object sender, EventArgs e) {72 if (InvokeRequired)73 Invoke((Action<object, EventArgs>)Content_ScriptExecutionStarted, sender, e);74 else {75 Locked = true;76 ReadOnly = true;77 startStopButton.Image = VSImageLibrary.Stop;78 toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)");79 infoTabControl.SelectedTab = outputTabPage;80 }81 }82 private void Content_ScriptExecutionFinished(object sender, EventArgs<Exception> e) {83 if (InvokeRequired)84 Invoke((Action<object, EventArgs<Exception>>)Content_ScriptExecutionFinished, sender, e);85 else {86 Locked = false;87 ReadOnly = false;88 startStopButton.Image = VSImageLibrary.Play;89 toolTip.SetToolTip(startStopButton, "Run (F5)");90 running = false;91 var ex = e.Value;92 if (ex != null)93 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);94 }95 }96 private void Content_ConsoleOutputChanged(object sender, EventArgs<string> e) {97 if (InvokeRequired)98 Invoke((Action<object, EventArgs<string>>)Content_ConsoleOutputChanged, sender, e);99 else {100 outputTextBox.AppendText(e.Value);101 }102 }103 #endregion104 60 105 61 protected override void OnContentChanged() { … … 107 63 if (Content == null) { 108 64 codeEditor.UserCode = string.Empty; 109 variableStoreView.Content = null;110 65 } else { 111 66 codeEditor.UserCode = Content.Code; 112 67 foreach (var asm in Content.GetAssemblies()) 113 68 codeEditor.AddAssembly(asm); 114 variableStoreView.Content = Content.VariableStore;115 69 if (Content.CompileErrors == null) { 116 70 compilationLabel.ForeColor = SystemColors.ControlDarkDark; … … 129 83 base.SetEnabledStateOfControls(); 130 84 compileButton.Enabled = Content != null && !Locked && !ReadOnly; 131 startStopButton.Enabled = Content != null && (!Locked || running);132 85 codeEditor.Enabled = Content != null && !Locked && !ReadOnly; 133 86 } 134 87 135 #region Child Control event handlers 136 private void compileButton_Click(object sender, EventArgs e) { 88 protected virtual void CompileButtonOnClick(object sender, EventArgs e) { 137 89 Compile(); 138 90 } 139 91 140 private void startStopButton_Click(object sender, EventArgs e) { 141 if (running) { 142 Content.Kill(); 143 } else 144 if (Compile()) { 145 outputTextBox.Clear(); 146 Content.Execute(); 147 running = true; 148 } 149 } 150 151 private void codeEditor_TextEditorTextChanged(object sender, EventArgs e) { 92 protected virtual void CodeEditorOnTextEditorTextChanged(object sender, EventArgs e) { 152 93 Content.Code = codeEditor.UserCode; 153 94 } 154 #endregion155 156 #region global HotKeys157 95 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { 158 96 switch (keyData) { 159 case Keys.F5:160 if (Content != null && !Locked && !running) {161 if (Compile()) {162 outputTextBox.Clear();163 Content.Execute();164 running = true;165 }166 }167 break;168 case Keys.F5 | Keys.Shift:169 if (running) Content.Kill();170 break;171 97 case Keys.F6: 172 if (!running) Compile(); 173 break; 98 if (Content != null && !Locked) 99 Compile(); 100 return true; 174 101 } 175 102 return base.ProcessCmdKey(ref msg, keyData); 176 103 } 177 #endregion178 104 179 #region Auxiliary functions 180 private bool Compile() { 105 public virtual bool Compile() { 181 106 ReadOnly = true; 182 107 Locked = true; … … 199 124 } 200 125 } 201 #endregion202 126 203 pr ivatevoid ShowCompilationResults() {127 protected virtual void ShowCompilationResults() { 204 128 if (Content.CompileErrors.Count == 0) return; 205 129 var msgs = Content.CompileErrors.OfType<CompilerError>() … … 222 146 } 223 147 224 pr ivatevoid AdjustErrorListViewColumnSizes() {148 protected virtual void AdjustErrorListViewColumnSizes() { 225 149 foreach (ColumnHeader ch in errorListView.Columns) 226 150 // adjusts the column width to the width of the column
Note: See TracChangeset
for help on using the changeset viewer.