Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10731 for trunk/sources


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

#2136:

  • Split Script into Script and CSharpScript
  • Split ScriptView into ScriptView and CSharpScriptView
Location:
trunk/sources
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj

    r10510 r10731  
    8686  <ItemGroup>
    8787    <None Include="Plugin.cs.frame" />
     88    <Compile Include="CSharpScriptView.cs">
     89      <SubType>UserControl</SubType>
     90    </Compile>
     91    <Compile Include="CSharpScriptView.Designer.cs">
     92      <DependentUpon>CSharpScriptView.cs</DependentUpon>
     93    </Compile>
    8894    <Compile Include="ScriptView.cs">
    8995      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs

    r10506 r10731  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
     48      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ScriptView));
    4849      this.compilationLabel = new System.Windows.Forms.Label();
    49       this.startStopButton = new System.Windows.Forms.Button();
     50      this.imageList = new System.Windows.Forms.ImageList(this.components);
     51      this.compileButton = new System.Windows.Forms.Button();
     52      this.infoTabControl = new System.Windows.Forms.TabControl();
     53      this.errorListTabPage = new System.Windows.Forms.TabPage();
    5054      this.errorListView = new System.Windows.Forms.ListView();
    5155      this.iconColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     
    5559      this.columnColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    5660      this.descriptionColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    57       this.imageList = new System.Windows.Forms.ImageList(this.components);
     61      this.outputTabPage = new System.Windows.Forms.TabPage();
     62      this.outputTextBox = new System.Windows.Forms.TextBox();
    5863      this.codeEditor = new HeuristicLab.CodeEditor.CodeEditor();
    5964      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    60       this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    61       this.infoTabControl = new System.Windows.Forms.TabControl();
    62       this.outputTabPage = new System.Windows.Forms.TabPage();
    63       this.outputTextBox = new System.Windows.Forms.TextBox();
    64       this.errorListTabPage = new System.Windows.Forms.TabPage();
    65       this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
    66       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    67       this.compileButton = new System.Windows.Forms.Button();
    6865      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     66      this.infoTabControl.SuspendLayout();
     67      this.errorListTabPage.SuspendLayout();
     68      this.outputTabPage.SuspendLayout();
    6969      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
    7070      this.splitContainer1.Panel1.SuspendLayout();
    7171      this.splitContainer1.Panel2.SuspendLayout();
    7272      this.splitContainer1.SuspendLayout();
    73       ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
    74       this.splitContainer2.Panel1.SuspendLayout();
    75       this.splitContainer2.Panel2.SuspendLayout();
    76       this.splitContainer2.SuspendLayout();
    77       this.infoTabControl.SuspendLayout();
    78       this.outputTabPage.SuspendLayout();
    79       this.errorListTabPage.SuspendLayout();
    8073      this.SuspendLayout();
    8174      //
     
    8477      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    8578      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    86       this.nameTextBox.Location = new System.Drawing.Point(60, 0);
    87       this.nameTextBox.Size = new System.Drawing.Size(750, 20);
     79      this.nameTextBox.Location = new System.Drawing.Point(69, 0);
     80      this.nameTextBox.Size = new System.Drawing.Size(741, 20);
    8881      //
    8982      // infoLabel
     
    10194      this.compilationLabel.Text = "Not compiled";
    10295      //
    103       // startStopButton
    104       //
    105       this.startStopButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Play;
    106       this.startStopButton.Location = new System.Drawing.Point(36, 26);
    107       this.startStopButton.Name = "startStopButton";
    108       this.startStopButton.Size = new System.Drawing.Size(24, 24);
    109       this.startStopButton.TabIndex = 1;
    110       this.startStopButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
    111       this.toolTip.SetToolTip(this.startStopButton, "Run (F5)");
    112       this.startStopButton.UseVisualStyleBackColor = true;
    113       this.startStopButton.Click += new System.EventHandler(this.startStopButton_Click);
     96      // imageList
     97      //
     98      this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
     99      this.imageList.ImageSize = new System.Drawing.Size(16, 16);
     100      this.imageList.TransparentColor = System.Drawing.Color.Transparent;
     101      //
     102      // compileButton
     103      //
     104      this.compileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Script;
     105      this.compileButton.Location = new System.Drawing.Point(6, 26);
     106      this.compileButton.Name = "compileButton";
     107      this.compileButton.Size = new System.Drawing.Size(24, 24);
     108      this.compileButton.TabIndex = 8;
     109      this.compileButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     110      this.toolTip.SetToolTip(this.compileButton, "Compile (F6)");
     111      this.compileButton.UseVisualStyleBackColor = true;
     112      this.compileButton.Click += new System.EventHandler(this.CompileButtonOnClick);
     113      //
     114      // infoTabControl
     115      //
     116      this.infoTabControl.Controls.Add(this.outputTabPage);
     117      this.infoTabControl.Controls.Add(this.errorListTabPage);
     118      this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
     119      this.infoTabControl.Location = new System.Drawing.Point(0, 0);
     120      this.infoTabControl.Name = "infoTabControl";
     121      this.infoTabControl.SelectedIndex = 0;
     122      this.infoTabControl.Size = new System.Drawing.Size(832, 112);
     123      this.infoTabControl.TabIndex = 1;
     124      //
     125      // errorListTabPage
     126      //
     127      this.errorListTabPage.Controls.Add(this.errorListView);
     128      this.errorListTabPage.Location = new System.Drawing.Point(4, 22);
     129      this.errorListTabPage.Name = "errorListTabPage";
     130      this.errorListTabPage.Padding = new System.Windows.Forms.Padding(3);
     131      this.errorListTabPage.Size = new System.Drawing.Size(824, 86);
     132      this.errorListTabPage.TabIndex = 0;
     133      this.errorListTabPage.Text = "Error List";
     134      this.errorListTabPage.UseVisualStyleBackColor = true;
    114135      //
    115136      // errorListView
     
    128149      this.errorListView.Location = new System.Drawing.Point(3, 3);
    129150      this.errorListView.Name = "errorListView";
    130       this.errorListView.Size = new System.Drawing.Size(623, 79);
     151      this.errorListView.Size = new System.Drawing.Size(818, 80);
    131152      this.errorListView.SmallImageList = this.imageList;
    132153      this.errorListView.TabIndex = 0;
     
    158179      this.descriptionColumnHeader.Text = "Description";
    159180      //
    160       // imageList
    161       //
    162       this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
    163       this.imageList.ImageSize = new System.Drawing.Size(16, 16);
    164       this.imageList.TransparentColor = System.Drawing.Color.Transparent;
    165       //
    166       // codeEditor
    167       //
    168       this.codeEditor.Dock = System.Windows.Forms.DockStyle.Fill;
    169       this.codeEditor.Location = new System.Drawing.Point(0, 0);
    170       this.codeEditor.Name = "codeEditor";
    171       this.codeEditor.Prefix = "";
    172       this.codeEditor.Size = new System.Drawing.Size(637, 428);
    173       this.codeEditor.Suffix = "";
    174       this.codeEditor.TabIndex = 0;
    175       this.codeEditor.UserCode = "";
    176       this.codeEditor.TextEditorTextChanged += new System.EventHandler(this.codeEditor_TextEditorTextChanged);
    177       //
    178       // splitContainer1
    179       //
    180       this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    181             | System.Windows.Forms.AnchorStyles.Left)
    182             | System.Windows.Forms.AnchorStyles.Right)));
    183       this.splitContainer1.Location = new System.Drawing.Point(3, 56);
    184       this.splitContainer1.Name = "splitContainer1";
    185       //
    186       // splitContainer1.Panel1
    187       //
    188       this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
    189       //
    190       // splitContainer1.Panel2
    191       //
    192       this.splitContainer1.Panel2.Controls.Add(this.variableStoreView);
    193       this.splitContainer1.Panel2.Controls.Add(this.viewHost);
    194       this.splitContainer1.Size = new System.Drawing.Size(829, 543);
    195       this.splitContainer1.SplitterDistance = 637;
    196       this.splitContainer1.TabIndex = 7;
    197       //
    198       // splitContainer2
    199       //
    200       this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
    201       this.splitContainer2.Location = new System.Drawing.Point(0, 0);
    202       this.splitContainer2.Name = "splitContainer2";
    203       this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
    204       //
    205       // splitContainer2.Panel1
    206       //
    207       this.splitContainer2.Panel1.Controls.Add(this.codeEditor);
    208       //
    209       // splitContainer2.Panel2
    210       //
    211       this.splitContainer2.Panel2.Controls.Add(this.infoTabControl);
    212       this.splitContainer2.Size = new System.Drawing.Size(637, 543);
    213       this.splitContainer2.SplitterDistance = 428;
    214       this.splitContainer2.TabIndex = 5;
    215       //
    216       // infoTabControl
    217       //
    218       this.infoTabControl.Controls.Add(this.outputTabPage);
    219       this.infoTabControl.Controls.Add(this.errorListTabPage);
    220       this.infoTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
    221       this.infoTabControl.Location = new System.Drawing.Point(0, 0);
    222       this.infoTabControl.Name = "infoTabControl";
    223       this.infoTabControl.SelectedIndex = 0;
    224       this.infoTabControl.Size = new System.Drawing.Size(637, 111);
    225       this.infoTabControl.TabIndex = 1;
    226       //
    227181      // outputTabPage
    228182      //
     
    231185      this.outputTabPage.Name = "outputTabPage";
    232186      this.outputTabPage.Padding = new System.Windows.Forms.Padding(3);
    233       this.outputTabPage.Size = new System.Drawing.Size(629, 85);
     187      this.outputTabPage.Size = new System.Drawing.Size(824, 86);
    234188      this.outputTabPage.TabIndex = 1;
    235189      this.outputTabPage.Text = "Output";
     
    245199      this.outputTextBox.ReadOnly = true;
    246200      this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
    247       this.outputTextBox.Size = new System.Drawing.Size(623, 79);
     201      this.outputTextBox.Size = new System.Drawing.Size(818, 80);
    248202      this.outputTextBox.TabIndex = 0;
    249203      this.outputTextBox.WordWrap = false;
    250204      //
    251       // errorListTabPage
    252       //
    253       this.errorListTabPage.Controls.Add(this.errorListView);
    254       this.errorListTabPage.Location = new System.Drawing.Point(4, 22);
    255       this.errorListTabPage.Name = "errorListTabPage";
    256       this.errorListTabPage.Padding = new System.Windows.Forms.Padding(3);
    257       this.errorListTabPage.Size = new System.Drawing.Size(629, 85);
    258       this.errorListTabPage.TabIndex = 0;
    259       this.errorListTabPage.Text = "Error List";
    260       this.errorListTabPage.UseVisualStyleBackColor = true;
    261       //
    262       // variableStoreView
    263       //
    264       this.variableStoreView.Caption = "ItemCollection View";
    265       this.variableStoreView.Content = null;
    266       this.variableStoreView.Dock = System.Windows.Forms.DockStyle.Fill;
    267       this.variableStoreView.Location = new System.Drawing.Point(0, 0);
    268       this.variableStoreView.Name = "variableStoreView";
    269       this.variableStoreView.ReadOnly = false;
    270       this.variableStoreView.Size = new System.Drawing.Size(188, 543);
    271       this.variableStoreView.TabIndex = 0;
    272       //
    273       // viewHost
    274       //
    275       this.viewHost.Caption = "View";
    276       this.viewHost.Content = null;
    277       this.viewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    278       this.viewHost.Enabled = false;
    279       this.viewHost.Location = new System.Drawing.Point(0, 0);
    280       this.viewHost.Name = "viewHost";
    281       this.viewHost.ReadOnly = false;
    282       this.viewHost.Size = new System.Drawing.Size(188, 543);
    283       this.viewHost.TabIndex = 0;
    284       this.viewHost.ViewsLabelVisible = true;
    285       this.viewHost.ViewType = null;
    286       //
    287       // compileButton
    288       //
    289       this.compileButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Script;
    290       this.compileButton.Location = new System.Drawing.Point(6, 26);
    291       this.compileButton.Name = "compileButton";
    292       this.compileButton.Size = new System.Drawing.Size(24, 24);
    293       this.compileButton.TabIndex = 8;
    294       this.compileButton.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
    295       this.toolTip.SetToolTip(this.compileButton, "Compile (F6)");
    296       this.compileButton.UseVisualStyleBackColor = true;
    297       this.compileButton.Click += new System.EventHandler(this.compileButton_Click);
     205      // codeEditor
     206      //
     207      this.codeEditor.Dock = System.Windows.Forms.DockStyle.Fill;
     208      this.codeEditor.Location = new System.Drawing.Point(0, 0);
     209      this.codeEditor.Name = "codeEditor";
     210      this.codeEditor.Prefix = "";
     211      this.codeEditor.Size = new System.Drawing.Size(832, 430);
     212      this.codeEditor.Suffix = "";
     213      this.codeEditor.TabIndex = 0;
     214      this.codeEditor.UserCode = "";
     215      this.codeEditor.TextEditorTextChanged += new System.EventHandler(this.CodeEditorOnTextEditorTextChanged);
     216      //
     217      // splitContainer1
     218      //
     219      this.splitContainer1.Location = new System.Drawing.Point(0, 56);
     220      this.splitContainer1.Name = "splitContainer1";
     221      this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
     222      //
     223      // splitContainer1.Panel1
     224      //
     225      this.splitContainer1.Panel1.Controls.Add(this.codeEditor);
     226      //
     227      // splitContainer1.Panel2
     228      //
     229      this.splitContainer1.Panel2.Controls.Add(this.infoTabControl);
     230      this.splitContainer1.Size = new System.Drawing.Size(832, 546);
     231      this.splitContainer1.SplitterDistance = 430;
     232      this.splitContainer1.TabIndex = 9;
    298233      //
    299234      // ScriptView
    300235      //
    301236      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     237      this.Controls.Add(this.splitContainer1);
    302238      this.Controls.Add(this.compileButton);
    303       this.Controls.Add(this.splitContainer1);
    304       this.Controls.Add(this.startStopButton);
    305239      this.Controls.Add(this.compilationLabel);
    306240      this.Name = "ScriptView";
    307241      this.Size = new System.Drawing.Size(835, 602);
    308242      this.Controls.SetChildIndex(this.compilationLabel, 0);
    309       this.Controls.SetChildIndex(this.startStopButton, 0);
     243      this.Controls.SetChildIndex(this.compileButton, 0);
    310244      this.Controls.SetChildIndex(this.splitContainer1, 0);
    311245      this.Controls.SetChildIndex(this.nameLabel, 0);
    312246      this.Controls.SetChildIndex(this.nameTextBox, 0);
    313247      this.Controls.SetChildIndex(this.infoLabel, 0);
    314       this.Controls.SetChildIndex(this.compileButton, 0);
    315248      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     249      this.infoTabControl.ResumeLayout(false);
     250      this.errorListTabPage.ResumeLayout(false);
     251      this.outputTabPage.ResumeLayout(false);
     252      this.outputTabPage.PerformLayout();
    316253      this.splitContainer1.Panel1.ResumeLayout(false);
    317254      this.splitContainer1.Panel2.ResumeLayout(false);
    318255      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    319256      this.splitContainer1.ResumeLayout(false);
    320       this.splitContainer2.Panel1.ResumeLayout(false);
    321       this.splitContainer2.Panel2.ResumeLayout(false);
    322       ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
    323       this.splitContainer2.ResumeLayout(false);
    324       this.infoTabControl.ResumeLayout(false);
    325       this.outputTabPage.ResumeLayout(false);
    326       this.outputTabPage.PerformLayout();
    327       this.errorListTabPage.ResumeLayout(false);
    328257      this.ResumeLayout(false);
    329258      this.PerformLayout();
     
    333262    #endregion
    334263
    335     private System.Windows.Forms.Label compilationLabel;
    336     private System.Windows.Forms.Button startStopButton;
    337     private System.Windows.Forms.ListView errorListView;
    338     private System.Windows.Forms.ColumnHeader descriptionColumnHeader;
    339     private System.Windows.Forms.ColumnHeader lineColumnHeader;
    340     private System.Windows.Forms.ColumnHeader columnColumnHeader;
    341     private CodeEditor.CodeEditor codeEditor;
    342     private System.Windows.Forms.SplitContainer splitContainer1;
    343     private System.Windows.Forms.SplitContainer splitContainer2;
    344     private MainForm.WindowsForms.ViewHost viewHost;
    345     private VariableStoreView variableStoreView;
    346     private System.Windows.Forms.ColumnHeader errorNumberColumnHeader;
    347     private System.Windows.Forms.ColumnHeader categoryColumnHeader;
    348     private System.Windows.Forms.TabControl infoTabControl;
    349     private System.Windows.Forms.TabPage errorListTabPage;
    350     private System.Windows.Forms.TabPage outputTabPage;
    351     private System.Windows.Forms.TextBox outputTextBox;
    352     private System.Windows.Forms.Button compileButton;
    353     private System.Windows.Forms.ColumnHeader iconColumnHeader;
    354     private System.Windows.Forms.ImageList imageList;
     264    protected System.Windows.Forms.Label compilationLabel;
     265    protected System.Windows.Forms.Button compileButton;
     266    protected System.Windows.Forms.ImageList imageList;
     267    protected System.Windows.Forms.TabControl infoTabControl;
     268    protected System.Windows.Forms.TabPage outputTabPage;
     269    protected System.Windows.Forms.TextBox outputTextBox;
     270    protected System.Windows.Forms.TabPage errorListTabPage;
     271    protected System.Windows.Forms.ListView errorListView;
     272    protected System.Windows.Forms.ColumnHeader iconColumnHeader;
     273    protected System.Windows.Forms.ColumnHeader categoryColumnHeader;
     274    protected System.Windows.Forms.ColumnHeader errorNumberColumnHeader;
     275    protected System.Windows.Forms.ColumnHeader lineColumnHeader;
     276    protected System.Windows.Forms.ColumnHeader columnColumnHeader;
     277    protected System.Windows.Forms.ColumnHeader descriptionColumnHeader;
     278    protected CodeEditor.CodeEditor codeEditor;
     279    protected System.Windows.Forms.SplitContainer splitContainer1;
    355280  }
    356281}
  • 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
  • trunk/sources/HeuristicLab.Scripting/3.3/HeuristicLab.Scripting-3.3.csproj

    r10566 r10731  
    8585  </ItemGroup>
    8686  <ItemGroup>
     87    <Compile Include="CSharpScript.cs" />
    8788    <Compile Include="Variables.cs" />
    8889    <Compile Include="VariableStore.cs" />
    8990    <None Include="Plugin.cs.frame" />
    9091    <Compile Include="Script.cs" />
    91     <Compile Include="UserScriptBase.cs" />
     92    <Compile Include="CSharpScriptBase.cs" />
    9293    <Compile Include="Plugin.cs" />
    9394    <Compile Include="Properties\AssemblyInfo.cs" />
  • trunk/sources/HeuristicLab.Scripting/3.3/Script.cs

    r10727 r10731  
    2929using System.Reflection;
    3030using System.Text;
    31 using System.Text.RegularExpressions;
    32 using System.Threading;
    3331using HeuristicLab.Common;
    3432using HeuristicLab.Common.Resources;
     
    3836
    3937namespace HeuristicLab.Scripting {
    40   [Item("C# Script", "An empty C# script.")]
    41   [Creatable("Scripts")]
    4238  [StorableClass]
    43   public sealed class Script : NamedItem, IStorableContent {
    44     #region Constants
    45     private const string ExecuteMethodName = "Execute";
    46     private const string CodeTemplate =
    47 @"// use 'vars' to access variables in the script's variable store (e.g. vars.x = 5)
    48 // use 'vars.Contains(string)' to check if a variable exists
    49 // use 'vars.Clear()' to remove all variables
    50 // use 'foreach (KeyValuePair<string, object> v in vars) { ... }' to iterate over all variables
    51 
    52 using System;
    53 using System.Linq;
    54 using System.Collections.Generic;
    55 using HeuristicLab.Common;
    56 using HeuristicLab.Core;
    57 using HeuristicLab.Data;
    58 
    59 public class UserScript : HeuristicLab.Scripting.UserScriptBase {
    60   public override void Main() {
    61     // type your code here
    62   }
    63 
    64   // implement further classes and methods
    65 
    66 }";
    67     #endregion
     39  public class Script : NamedItem {
     40    protected virtual string CodeTemplate {
     41      get { return string.Empty; }
     42    }
    6843
    6944    #region Fields & Properties
    70     private UserScriptBase compiledScript;
    71 
    72     public string Filename { get; set; }
    73 
    7445    public static new Image StaticItemImage {
    7546      get { return VSImageLibrary.Script; }
     
    7748
    7849    [Storable]
    79     private VariableStore variableStore;
    80     public VariableStore VariableStore {
    81       get { return variableStore; }
    82     }
    83 
    84     [Storable]
    8550    private string code;
    86     public string Code {
     51    public virtual string Code {
    8752      get { return code; }
    8853      set {
    8954        if (value == code) return;
    9055        code = value;
    91         compiledScript = null;
    9256        OnCodeChanged();
    9357      }
     
    9559
    9660    private string compilationUnitCode;
    97     public string CompilationUnitCode {
     61    public virtual string CompilationUnitCode {
    9862      get { return compilationUnitCode; }
    9963    }
    10064
    10165    private CompilerErrorCollection compileErrors;
    102     public CompilerErrorCollection CompileErrors {
     66    public virtual CompilerErrorCollection CompileErrors {
    10367      get { return compileErrors; }
    10468      private set {
     
    11175    #region Construction & Initialization
    11276    [StorableConstructor]
    113     private Script(bool deserializing) : base(deserializing) { }
    114     private Script(Script original, Cloner cloner)
     77    protected Script(bool deserializing) : base(deserializing) { }
     78    protected Script(Script original, Cloner cloner)
    11579      : base(original, cloner) {
    11680      code = original.code;
    117       variableStore = new VariableStore();
    11881      compilationUnitCode = original.compilationUnitCode;
    11982      if (original.compileErrors != null)
     
    12487      description = ItemDescription;
    12588      code = CodeTemplate;
    126       variableStore = new VariableStore();
    12789    }
    12890    public Script(string code)
     
    13698    #endregion
    13799
    138     private void RegisterScriptEvents() {
    139       if (compiledScript == null) return;
    140       compiledScript.ConsoleOutputChanged += compiledScript_ConsoleOutputChanged;
     100    #region Compilation
     101    protected virtual CSharpCodeProvider CodeProvider {
     102      get {
     103        return new CSharpCodeProvider(
     104          new Dictionary<string, string> {
     105                {"CompilerVersion", "v4.0"}, // support C# 4.0 syntax
     106              });
     107      }
    141108    }
    142109
    143     private void DeregisterScriptEvents() {
    144       if (compiledScript == null) return;
    145       compiledScript.ConsoleOutputChanged -= compiledScript_ConsoleOutputChanged;
    146     }
    147 
    148     #region Compilation
    149     private CSharpCodeProvider codeProvider =
    150       new CSharpCodeProvider(
    151         new Dictionary<string, string> {
    152           { "CompilerVersion", "v4.0" },  // support C# 4.0 syntax
    153         });
    154 
    155     private CompilerResults DoCompile() {
     110    protected virtual CompilerResults DoCompile() {
    156111      var parameters = new CompilerParameters {
    157112        GenerateExecutable = false,
     
    166121      var unit = CreateCompilationUnit();
    167122      var writer = new StringWriter();
    168       codeProvider.GenerateCodeFromCompileUnit(
     123      CodeProvider.GenerateCodeFromCompileUnit(
    169124        unit,
    170125        writer,
     
    174129        });
    175130      compilationUnitCode = writer.ToString();
    176       return codeProvider.CompileAssemblyFromDom(parameters, unit);
     131      return CodeProvider.CompileAssemblyFromDom(parameters, unit);
    177132    }
    178133
    179     public void Compile() {
     134    public virtual Assembly Compile() {
    180135      var results = DoCompile();
    181       compiledScript = null;
    182136      CompileErrors = results.Errors;
    183137      if (results.Errors.HasErrors) {
     
    188142            .AppendLine(error.ErrorText);
    189143        }
    190         throw new Exception(string.Format(
    191           "Compilation of \"{0}\" failed:{1}{2}",
    192           Name, Environment.NewLine,
    193           sb.ToString()));
     144        throw new Exception(string.Format("Compilation of \"{0}\" failed:{1}{2}",
     145          Name, Environment.NewLine, sb.ToString()));
    194146      } else {
    195         var assembly = results.CompiledAssembly;
    196         var types = assembly.GetTypes();
    197         DeregisterScriptEvents();
    198         compiledScript = (UserScriptBase)Activator.CreateInstance(types[0]);
    199         RegisterScriptEvents();
     147        return results.CompiledAssembly;
    200148      }
    201149    }
    202150
    203     public IEnumerable<Assembly> GetAssemblies() {
     151    public virtual IEnumerable<Assembly> GetAssemblies() {
    204152      var assemblies = new List<Assembly>();
    205153      foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
     
    217165    }
    218166
    219     private readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+");
    220     private readonly Regex SafeTypeNameRegex = new Regex("[_a-zA-Z][_a-zA-Z0-9]*");
    221 
    222     private CodeCompileUnit CreateCompilationUnit() {
     167    protected virtual CodeCompileUnit CreateCompilationUnit() {
    223168      var unit = new CodeSnippetCompileUnit(code);
    224169      return unit;
    225170    }
    226 
    227     public string CompiledTypeName {
    228       get {
    229         var sb = new StringBuilder();
    230         var strings = SafeTypeNameCharRegex.Matches(Name)
    231                                            .Cast<Match>()
    232                                            .Select(m => m.Value);
    233         foreach (string s in strings)
    234           sb.Append(s);
    235         return SafeTypeNameRegex.Match(sb.ToString()).Value;
    236       }
    237     }
    238171    #endregion
    239172
    240     private Thread scriptThread;
    241     public void Execute() {
    242       if (compiledScript == null) return;
    243       var executeMethod = typeof(UserScriptBase).GetMethod(ExecuteMethodName, BindingFlags.NonPublic | BindingFlags.Instance);
    244       if (executeMethod != null) {
    245         scriptThread = new Thread(() => {
    246           Exception ex = null;
    247           try {
    248             OnScriptExecutionStarted();
    249             executeMethod.Invoke(compiledScript, new[] { VariableStore });
    250           } catch (ThreadAbortException) {
    251             // the execution was cancelled by the user
    252           } catch (TargetInvocationException e) {
    253             ex = e.InnerException;
    254           } finally {
    255             OnScriptExecutionFinished(ex);
    256           }
    257         });
    258         scriptThread.Start();
    259       }
    260     }
    261 
    262     public void Kill() {
    263       if (scriptThread.IsAlive)
    264         scriptThread.Abort();
    265     }
    266 
    267     private void compiledScript_ConsoleOutputChanged(object sender, EventArgs<string> e) {
    268       OnConsoleOutputChanged(e.Value);
    269     }
    270 
    271173    public event EventHandler CodeChanged;
    272     private void OnCodeChanged() {
     174    protected virtual void OnCodeChanged() {
    273175      var handler = CodeChanged;
    274176      if (handler != null) handler(this, EventArgs.Empty);
     
    276178
    277179    public event EventHandler CompileErrorsChanged;
    278     private void OnCompileErrorsChanged() {
     180    protected virtual void OnCompileErrorsChanged() {
    279181      var handler = CompileErrorsChanged;
    280182      if (handler != null) handler(this, EventArgs.Empty);
    281183    }
    282 
    283     public event EventHandler ScriptExecutionStarted;
    284     private void OnScriptExecutionStarted() {
    285       var handler = ScriptExecutionStarted;
    286       if (handler != null) handler(this, EventArgs.Empty);
    287     }
    288 
    289     public event EventHandler<EventArgs<Exception>> ScriptExecutionFinished;
    290     private void OnScriptExecutionFinished(Exception e) {
    291       var handler = ScriptExecutionFinished;
    292       if (handler != null) handler(this, new EventArgs<Exception>(e));
    293     }
    294 
    295     public event EventHandler<EventArgs<string>> ConsoleOutputChanged;
    296     private void OnConsoleOutputChanged(string args) {
    297       var handler = ConsoleOutputChanged;
    298       if (handler != null) handler(this, new EventArgs<string>(args));
    299     }
    300184  }
    301185}
Note: See TracChangeset for help on using the changeset viewer.