Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/08/14 23:28:40 (9 years ago)
Author:
abeham
Message:

#2136:

  • Split Script into Script and CSharpScript
  • Split ScriptView into ScriptView and CSharpScriptView
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r10727 r10731  
    2626using System.Linq;
    2727using System.Windows.Forms;
    28 using HeuristicLab.Common;
    2928using HeuristicLab.Common.Resources;
    3029using HeuristicLab.Core.Views;
     
    3635  [Content(typeof(Script), true)]
    3736  public partial class ScriptView : NamedItemView {
    38     private bool running;
    39 
    4037    public new Script Content {
    4138      get { return (Script)base.Content; }
    42       set { base.Content = (Script)value; }
     39      set { base.Content = value; }
    4340    }
    4441
     
    4643      InitializeComponent();
    4744      errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error });
    48       AdjustErrorListViewColumnSizes();
    4945    }
    5046
    5147    protected override void RegisterContentEvents() {
    5248      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;
    5750    }
    5851
    5952    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;
    6454      base.DeregisterContentEvents();
    6555    }
    6656
    67     #region Content event handlers
    68     private void Content_CodeChanged(object sender, EventArgs e) {
     57    protected virtual void ContentOnCodeChanged(object sender, EventArgs e) {
    6958      codeEditor.UserCode = Content.Code;
    7059    }
    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     #endregion
    10460
    10561    protected override void OnContentChanged() {
     
    10763      if (Content == null) {
    10864        codeEditor.UserCode = string.Empty;
    109         variableStoreView.Content = null;
    11065      } else {
    11166        codeEditor.UserCode = Content.Code;
    11267        foreach (var asm in Content.GetAssemblies())
    11368          codeEditor.AddAssembly(asm);
    114         variableStoreView.Content = Content.VariableStore;
    11569        if (Content.CompileErrors == null) {
    11670          compilationLabel.ForeColor = SystemColors.ControlDarkDark;
     
    12983      base.SetEnabledStateOfControls();
    13084      compileButton.Enabled = Content != null && !Locked && !ReadOnly;
    131       startStopButton.Enabled = Content != null && (!Locked || running);
    13285      codeEditor.Enabled = Content != null && !Locked && !ReadOnly;
    13386    }
    13487
    135     #region Child Control event handlers
    136     private void compileButton_Click(object sender, EventArgs e) {
     88    protected virtual void CompileButtonOnClick(object sender, EventArgs e) {
    13789      Compile();
    13890    }
    13991
    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) {
    15293      Content.Code = codeEditor.UserCode;
    15394    }
    154     #endregion
    155 
    156     #region global HotKeys
    15795    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    15896      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;
    17197        case Keys.F6:
    172           if (!running) Compile();
    173           break;
     98          if (Content != null && !Locked)
     99            Compile();
     100          return true;
    174101      }
    175102      return base.ProcessCmdKey(ref msg, keyData);
    176103    }
    177     #endregion
    178104
    179     #region Auxiliary functions
    180     private bool Compile() {
     105    public virtual bool Compile() {
    181106      ReadOnly = true;
    182107      Locked = true;
     
    199124      }
    200125    }
    201     #endregion
    202126
    203     private void ShowCompilationResults() {
     127    protected virtual void ShowCompilationResults() {
    204128      if (Content.CompileErrors.Count == 0) return;
    205129      var msgs = Content.CompileErrors.OfType<CompilerError>()
     
    222146    }
    223147
    224     private void AdjustErrorListViewColumnSizes() {
     148    protected virtual void AdjustErrorListViewColumnSizes() {
    225149      foreach (ColumnHeader ch in errorListView.Columns)
    226150        // adjusts the column width to the width of the column
Note: See TracChangeset for help on using the changeset viewer.