- Timestamp:
- 11/19/15 11:29:17 (8 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13024,13080,13138,13218
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs
r12009 r13277 21 21 22 22 using System; 23 using System.Drawing;24 using System.Threading;25 23 using System.Windows.Forms; 26 24 using HeuristicLab.Common; 27 using HeuristicLab.Common.Resources;28 25 using HeuristicLab.MainForm; 29 26 … … 32 29 [View("C# Script View")] 33 30 [Content(typeof(CSharpScript), true)] 34 public partial class CSharpScriptView : ScriptView { 35 private const string ScriptExecutionStartedMessage = "Script execution started"; 36 private const string ScriptExecutionCanceledMessage = "Script execution canceled"; 37 private const string ScriptExecutionSuccessfulMessage = "Script execution successful"; 38 private const string ScriptExecutionFailedMessage = "Script execution failed"; 39 40 protected bool Running { get; set; } 31 public partial class CSharpScriptView : ExecutableScriptView { 41 32 42 33 public new CSharpScript Content { … … 51 42 protected override void RegisterContentEvents() { 52 43 base.RegisterContentEvents(); 53 Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;54 Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;55 44 Content.ConsoleOutputChanged += ContentOnConsoleOutputChanged; 56 45 } 57 46 58 47 protected override void DeregisterContentEvents() { 59 Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;60 Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;61 48 Content.ConsoleOutputChanged -= ContentOnConsoleOutputChanged; 62 49 base.DeregisterContentEvents(); … … 64 51 65 52 #region Content event handlers 66 protected virtual void ContentOnScriptExecutionStarted(object sender, EventArgs e) {67 if (InvokeRequired)68 Invoke((Action<object, EventArgs>)ContentOnScriptExecutionStarted, sender, e);69 else {70 Locked = true;71 ReadOnly = true;72 startStopButton.Image = VSImageLibrary.Stop;73 toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)");74 UpdateInfoTextLabel(ScriptExecutionStartedMessage, SystemColors.ControlText);75 infoTabControl.SelectedTab = outputTabPage;76 }77 }78 protected virtual void ContentOnScriptExecutionFinished(object sender, EventArgs<Exception> e) {79 if (InvokeRequired)80 Invoke((Action<object, EventArgs<Exception>>)ContentOnScriptExecutionFinished, sender, e);81 else {82 Locked = false;83 ReadOnly = false;84 startStopButton.Image = VSImageLibrary.Play;85 toolTip.SetToolTip(startStopButton, "Run (F5)");86 87 var ex = e.Value;88 if (ex == null) {89 UpdateInfoTextLabel(ScriptExecutionSuccessfulMessage, Color.DarkGreen);90 } else if (ex is ThreadAbortException) {91 // the execution was canceled by the user92 UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);93 } else {94 UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);95 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);96 }97 98 Running = false;99 }100 }101 53 protected virtual void ContentOnConsoleOutputChanged(object sender, EventArgs<string> e) { 102 54 if (InvokeRequired) … … 116 68 } 117 69 } 118 119 protected override void SetEnabledStateOfControls() {120 base.SetEnabledStateOfControls();121 startStopButton.Enabled = Content != null && (!Locked || Running);122 }123 124 protected virtual void StartStopButtonOnClick(object sender, EventArgs e) {125 if (Running) {126 Content.Kill();127 } else128 if (Compile()) {129 outputTextBox.Clear();130 Running = true;131 Content.ExecuteAsync();132 }133 }134 135 #region global HotKeys136 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {137 switch (keyData) {138 case Keys.F5:139 if (Content != null && !Locked && !Running) {140 if (Compile()) {141 outputTextBox.Clear();142 Content.ExecuteAsync();143 Running = true;144 }145 }146 return true;147 case Keys.F5 | Keys.Shift:148 if (Running) Content.Kill();149 return true;150 case Keys.F6:151 if (!Running) base.ProcessCmdKey(ref msg, keyData);152 return true;153 }154 return base.ProcessCmdKey(ref msg, keyData);155 }156 #endregion157 70 } 158 71 }
Note: See TracChangeset
for help on using the changeset viewer.