Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/15 11:29:17 (8 years ago)
Author:
mkommend
Message:

#2298: Merged r13024, r13080, r13138, and r13218 into stable.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs

    r12009 r13277  
    2121
    2222using System;
    23 using System.Drawing;
    24 using System.Threading;
    2523using System.Windows.Forms;
    2624using HeuristicLab.Common;
    27 using HeuristicLab.Common.Resources;
    2825using HeuristicLab.MainForm;
    2926
     
    3229  [View("C# Script View")]
    3330  [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 {
    4132
    4233    public new CSharpScript Content {
     
    5142    protected override void RegisterContentEvents() {
    5243      base.RegisterContentEvents();
    53       Content.ScriptExecutionStarted += ContentOnScriptExecutionStarted;
    54       Content.ScriptExecutionFinished += ContentOnScriptExecutionFinished;
    5544      Content.ConsoleOutputChanged += ContentOnConsoleOutputChanged;
    5645    }
    5746
    5847    protected override void DeregisterContentEvents() {
    59       Content.ScriptExecutionStarted -= ContentOnScriptExecutionStarted;
    60       Content.ScriptExecutionFinished -= ContentOnScriptExecutionFinished;
    6148      Content.ConsoleOutputChanged -= ContentOnConsoleOutputChanged;
    6249      base.DeregisterContentEvents();
     
    6451
    6552    #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 user
    92           UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange);
    93         } else {
    94           UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed);
    95           PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);
    96         }
    97 
    98         Running = false;
    99       }
    100     }
    10153    protected virtual void ContentOnConsoleOutputChanged(object sender, EventArgs<string> e) {
    10254      if (InvokeRequired)
     
    11668      }
    11769    }
    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       } else
    128         if (Compile()) {
    129           outputTextBox.Clear();
    130           Running = true;
    131           Content.ExecuteAsync();
    132         }
    133     }
    134 
    135     #region global HotKeys
    136     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     #endregion
    15770  }
    15871}
Note: See TracChangeset for help on using the changeset viewer.