Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5042 for trunk/sources


Ignore:
Timestamp:
12/06/10 18:17:09 (14 years ago)
Author:
epitzer
Message:

Add breakpoint to ProgrammableOperator (#1322)

this patch also adds a shortcut (F6) to recompile, makes minor GUI improvements and gets rid of resource files

Location:
trunk/sources/HeuristicLab.Operators.Programmable/3.3
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/HeuristicLab.Operators.Programmable-3.3.csproj

    r4828 r5042  
    191191  </ItemGroup>
    192192  <ItemGroup>
    193     <EmbeddedResource Include="ProgrammableOperatorView.resx">
    194       <DependentUpon>ProgrammableOperatorView.cs</DependentUpon>
    195       <SubType>Designer</SubType>
    196     </EmbeddedResource>
    197193    <EmbeddedResource Include="Properties\Resources.resx">
    198194      <Generator>ResXFileCodeGenerator</Generator>
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperator.cs

    r5011 r5042  
    3131using HeuristicLab.Collections;
    3232using HeuristicLab.Common;
     33using HeuristicLab.Common.Resources;
    3334using HeuristicLab.Core;
    3435using HeuristicLab.Persistence.Auxiliary;
     
    5051      get { return base.Parameters; }
    5152    }
     53
     54    public override System.Drawing.Image ItemImage { get { return VS2008ImageLibrary.Script; } }
    5255
    5356    private MethodInfo executeMethod;
     
    342345      var results = DoCompile();
    343346      executeMethod = null;
     347      CompileErrors = results.Errors;
    344348      if (results.Errors.HasErrors) {
    345         CompileErrors = results.Errors;
    346349        StringBuilder sb = new StringBuilder();
    347350        foreach (CompilerError error in results.Errors) {
     
    355358          sb.ToString()));
    356359      } else {
    357         CompileErrors = null;
    358360        Assembly assembly = results.CompiledAssembly;
    359361        Type[] types = assembly.GetTypes();
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.Designer.cs

    r4477 r5042  
    5959      this.tabPage1 = new System.Windows.Forms.TabPage();
    6060      this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     61      this.breakpointCheckBox = new System.Windows.Forms.CheckBox();
     62      this.breakpointLabel = new System.Windows.Forms.Label();
     63      this.compilationLabel = new System.Windows.Forms.Label();
    6164      tabPage2 = new System.Windows.Forms.TabPage();
    6265      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     
    9093      tabPage2.Name = "tabPage2";
    9194      tabPage2.Padding = new System.Windows.Forms.Padding(3);
    92       tabPage2.Size = new System.Drawing.Size(977, 619);
     95      tabPage2.Size = new System.Drawing.Size(977, 596);
    9396      tabPage2.TabIndex = 1;
    9497      tabPage2.Text = "Code";
     
    103106      // splitContainer1.Panel1
    104107      //
     108      this.splitContainer1.Panel1.Controls.Add(this.compilationLabel);
    105109      this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
    106110      this.splitContainer1.Panel1.Controls.Add(this.showCodeButton);
     
    110114      //
    111115      this.splitContainer1.Panel2.Controls.Add(this.codeEditor);
    112       this.splitContainer1.Size = new System.Drawing.Size(971, 613);
     116      this.splitContainer1.Size = new System.Drawing.Size(971, 590);
    113117      this.splitContainer1.SplitterDistance = 244;
    114118      this.splitContainer1.TabIndex = 0;
     
    116120      // splitContainer2
    117121      //
    118       this.splitContainer2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    119                   | System.Windows.Forms.AnchorStyles.Left)
    120                   | System.Windows.Forms.AnchorStyles.Right)));
     122      this.splitContainer2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     123            | System.Windows.Forms.AnchorStyles.Left)
     124            | System.Windows.Forms.AnchorStyles.Right)));
    121125      this.splitContainer2.Location = new System.Drawing.Point(0, 33);
    122126      this.splitContainer2.Name = "splitContainer2";
     
    130134      //
    131135      this.splitContainer2.Panel2.Controls.Add(this.namespacesBox);
    132       this.splitContainer2.Size = new System.Drawing.Size(242, 583);
    133       this.splitContainer2.SplitterDistance = 290;
     136      this.splitContainer2.Size = new System.Drawing.Size(242, 560);
     137      this.splitContainer2.SplitterDistance = 278;
    134138      this.splitContainer2.TabIndex = 2;
    135139      //
     
    140144      this.assembliesBox.Location = new System.Drawing.Point(0, 0);
    141145      this.assembliesBox.Name = "assembliesBox";
    142       this.assembliesBox.Size = new System.Drawing.Size(242, 290);
     146      this.assembliesBox.Size = new System.Drawing.Size(242, 278);
    143147      this.assembliesBox.TabIndex = 1;
    144148      this.assembliesBox.TabStop = false;
     
    151155      this.assembliesTreeView.Location = new System.Drawing.Point(3, 16);
    152156      this.assembliesTreeView.Name = "assembliesTreeView";
    153       this.assembliesTreeView.Size = new System.Drawing.Size(236, 271);
     157      this.assembliesTreeView.Size = new System.Drawing.Size(236, 259);
    154158      this.assembliesTreeView.TabIndex = 0;
    155159      this.assembliesTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.assembliesTreeView_AfterCheck);
     
    161165      this.namespacesBox.Location = new System.Drawing.Point(0, 0);
    162166      this.namespacesBox.Name = "namespacesBox";
    163       this.namespacesBox.Size = new System.Drawing.Size(242, 289);
     167      this.namespacesBox.Size = new System.Drawing.Size(242, 278);
    164168      this.namespacesBox.TabIndex = 1;
    165169      this.namespacesBox.TabStop = false;
     
    173177      this.namespacesTreeView.Name = "namespacesTreeView";
    174178      this.namespacesTreeView.PathSeparator = ".";
    175       this.namespacesTreeView.Size = new System.Drawing.Size(236, 270);
     179      this.namespacesTreeView.Size = new System.Drawing.Size(236, 259);
    176180      this.namespacesTreeView.TabIndex = 0;
    177181      this.namespacesTreeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.namespacesTreeView_AfterCheck);
     
    179183      // showCodeButton
    180184      //
    181       this.showCodeButton.Image = ((System.Drawing.Image)(resources.GetObject("showCodeButton.Image")));
     185      this.showCodeButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.PrintPreview;
    182186      this.showCodeButton.Location = new System.Drawing.Point(33, 3);
    183187      this.showCodeButton.Name = "showCodeButton";
     
    191195      // compileButton
    192196      //
    193       this.compileButton.Image = ((System.Drawing.Image)(resources.GetObject("compileButton.Image")));
     197      this.compileButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Script;
    194198      this.compileButton.Location = new System.Drawing.Point(3, 3);
    195199      this.compileButton.Name = "compileButton";
     
    207211      this.codeEditor.Name = "codeEditor";
    208212      this.codeEditor.Prefix = "";
    209       this.codeEditor.Size = new System.Drawing.Size(723, 613);
     213      this.codeEditor.Size = new System.Drawing.Size(723, 590);
    210214      this.codeEditor.Suffix = "";
    211215      this.codeEditor.TabIndex = 0;
     
    215219      // tabControl1
    216220      //
    217       this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    218                   | System.Windows.Forms.AnchorStyles.Left)
    219                   | System.Windows.Forms.AnchorStyles.Right)));
     221      this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     222            | System.Windows.Forms.AnchorStyles.Left)
     223            | System.Windows.Forms.AnchorStyles.Right)));
    220224      this.tabControl1.Controls.Add(this.tabPage1);
    221225      this.tabControl1.Controls.Add(tabPage2);
    222       this.tabControl1.Location = new System.Drawing.Point(0, 52);
     226      this.tabControl1.Location = new System.Drawing.Point(0, 75);
    223227      this.tabControl1.Name = "tabControl1";
    224228      this.tabControl1.SelectedIndex = 0;
    225       this.tabControl1.Size = new System.Drawing.Size(985, 645);
     229      this.tabControl1.Size = new System.Drawing.Size(985, 622);
    226230      this.tabControl1.TabIndex = 7;
    227231      //
     
    232236      this.tabPage1.Name = "tabPage1";
    233237      this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
    234       this.tabPage1.Size = new System.Drawing.Size(977, 619);
     238      this.tabPage1.Size = new System.Drawing.Size(977, 596);
    235239      this.tabPage1.TabIndex = 0;
    236240      this.tabPage1.Text = "Parameters";
     
    245249      this.parameterCollectionView.Name = "parameterCollectionView";
    246250      this.parameterCollectionView.ReadOnly = false;
    247       this.parameterCollectionView.Size = new System.Drawing.Size(971, 613);
     251      this.parameterCollectionView.Size = new System.Drawing.Size(971, 590);
    248252      this.parameterCollectionView.TabIndex = 0;
     253      //
     254      // breakpointCheckBox
     255      //
     256      this.breakpointCheckBox.AutoSize = true;
     257      this.breakpointCheckBox.Location = new System.Drawing.Point(72, 52);
     258      this.breakpointCheckBox.Name = "breakpointCheckBox";
     259      this.breakpointCheckBox.Size = new System.Drawing.Size(15, 14);
     260      this.breakpointCheckBox.TabIndex = 8;
     261      this.breakpointCheckBox.UseVisualStyleBackColor = true;
     262      this.breakpointCheckBox.CheckedChanged += new System.EventHandler(this.breakpointCheckBox_CheckedChanged);
     263      //
     264      // breakpointLabel
     265      //
     266      this.breakpointLabel.AutoSize = true;
     267      this.breakpointLabel.Location = new System.Drawing.Point(3, 52);
     268      this.breakpointLabel.Name = "breakpointLabel";
     269      this.breakpointLabel.Size = new System.Drawing.Size(61, 13);
     270      this.breakpointLabel.TabIndex = 9;
     271      this.breakpointLabel.Text = "Breakpoint:";
     272      //
     273      // compilationLabel
     274      //
     275      this.compilationLabel.AutoSize = true;
     276      this.compilationLabel.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
     277      this.compilationLabel.Location = new System.Drawing.Point(63, 9);
     278      this.compilationLabel.Name = "compilationLabel";
     279      this.compilationLabel.Size = new System.Drawing.Size(67, 13);
     280      this.compilationLabel.TabIndex = 3;
     281      this.compilationLabel.Text = "not compiled";
    249282      //
    250283      // ProgrammableOperatorView
     
    253286      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    254287      this.Controls.Add(this.tabControl1);
     288      this.Controls.Add(this.breakpointCheckBox);
     289      this.Controls.Add(this.breakpointLabel);
    255290      this.Name = "ProgrammableOperatorView";
    256291      this.Size = new System.Drawing.Size(985, 697);
     292      this.Controls.SetChildIndex(this.breakpointLabel, 0);
     293      this.Controls.SetChildIndex(this.breakpointCheckBox, 0);
    257294      this.Controls.SetChildIndex(this.tabControl1, 0);
    258295      this.Controls.SetChildIndex(this.nameTextBox, 0);
     
    263300      tabPage2.ResumeLayout(false);
    264301      this.splitContainer1.Panel1.ResumeLayout(false);
     302      this.splitContainer1.Panel1.PerformLayout();
    265303      this.splitContainer1.Panel2.ResumeLayout(false);
    266304      this.splitContainer1.ResumeLayout(false);
     
    291329    private System.Windows.Forms.GroupBox assembliesBox;
    292330    private System.Windows.Forms.GroupBox namespacesBox;
     331    private System.Windows.Forms.CheckBox breakpointCheckBox;
     332    private System.Windows.Forms.Label compilationLabel;
     333    private System.Windows.Forms.Label breakpointLabel;
    293334  }
    294335}
  • trunk/sources/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperatorView.cs

    r4838 r5042  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Reflection;
     
    3334
    3435namespace HeuristicLab.Operators.Programmable {
     36
    3537  [View("ProgrammableOperator View")]
    3638  [Content(typeof(ProgrammableOperator), true)]
     
    5557      ProgrammableOperator.CodeChanged += ProgrammableOperator_CodeChanged;
    5658      ProgrammableOperator.SignatureChanged += ProgrammableOperator_SignatureChanged;
     59      ProgrammableOperator.BreakpointChanged += ProgrammableOperator_BreakpointChanged;
    5760    }
    5861
     
    6063      ProgrammableOperator.CodeChanged -= ProgrammableOperator_CodeChanged;
    6164      ProgrammableOperator.SignatureChanged -= ProgrammableOperator_SignatureChanged;
     65      ProgrammableOperator.BreakpointChanged -= ProgrammableOperator_BreakpointChanged;
    6266      base.DeregisterContentEvents();
    6367    }
     68
     69    #region Content event handlers
     70    void ProgrammableOperator_BreakpointChanged(object sender, EventArgs e) {
     71      breakpointCheckBox.Checked = ProgrammableOperator.Breakpoint;
     72    }
     73    private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
     74      codeEditor.Text = ProgrammableOperator.Code;
     75    }
     76    private void ProgrammableOperator_SignatureChanged(object sender, EventArgs args) {
     77      codeEditor.Prefix = GetGeneratedPrefix();
     78    }
     79    #endregion
    6480
    6581    protected override void OnContentChanged() {
     
    86102          ProgrammableOperator.CompilationUnitCode.Length > 0;
    87103        parameterCollectionView.Content = ProgrammableOperator.Parameters;
     104        if (ProgrammableOperator.CompileErrors == null) {
     105          compilationLabel.ForeColor = SystemColors.ControlDarkDark;
     106          compilationLabel.Text = "not compiled";
     107        } else if (ProgrammableOperator.CompileErrors.HasErrors) {
     108          compilationLabel.ForeColor = Color.DarkRed;
     109          compilationLabel.Text = "compilation failed";
     110        } else {
     111          compilationLabel.ForeColor = Color.DarkGreen;
     112          compilationLabel.Text = "compilation successful";
     113        }
     114
    88115      }
    89116    }
     
    96123      compileButton.Enabled = Content != null && !ReadOnly;
    97124      codeEditor.Enabled = Content != null && !ReadOnly;
    98     }
    99 
    100 
    101     private string GetGeneratedPrefix() {
    102       StringBuilder prefix = new StringBuilder();
    103       foreach (var ns in ProgrammableOperator.GetSelectedAndValidNamespaces()) {
    104         prefix.Append("using ").Append(ns).AppendLine(";");
    105       }
    106       prefix.AppendLine();
    107       prefix.Append("public class ").Append(ProgrammableOperator.CompiledTypeName).AppendLine(" {");
    108       prefix.Append("  ").Append(ProgrammableOperator.Signature).AppendLine(" {");
    109       return prefix.ToString();
    110     }
    111 
     125      showCodeButton.Enabled = Content != null && !string.IsNullOrEmpty(ProgrammableOperator.CompilationUnitCode) && !ReadOnly;
     126    }
     127
     128    #region Child Control event handlers
     129    private void compileButton_Click(object sender, EventArgs e) {
     130      Recompile();
     131    }
     132    private void breakpointCheckBox_CheckedChanged(object sender, EventArgs e) {
     133      if (ProgrammableOperator != null) ProgrammableOperator.Breakpoint = breakpointCheckBox.Checked;
     134    }
     135    private void showCodeButton_Click(object sender, EventArgs e) {
     136      new CodeViewer(ProgrammableOperator.CompilationUnitCode).ShowDialog(this);
     137    }
    112138    private void codeEditor_Validated(object sender, EventArgs e) {
    113139      ProgrammableOperator.Code = codeEditor.UserCode;
    114140    }
    115 
    116     private void Recompile() {
    117       this.Enabled = false;
    118       try {
    119         ProgrammableOperator.Compile();
    120         MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
    121       } catch (Exception ex) {
    122         ErrorHandling.ShowErrorDialog(this, ex);
    123       }
    124       OnContentChanged();
    125       this.Enabled = true;
    126     }
    127 
    128     private void compileButton_Click(object sender, EventArgs e) {
    129       Recompile();
    130     }
    131 
    132     #region ProgrammableOperator Events
    133     private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
    134       codeEditor.Text = ProgrammableOperator.Code;
    135     }
    136     private void ProgrammableOperator_SignatureChanged(object sender, EventArgs args) {
    137       codeEditor.Prefix = GetGeneratedPrefix();
    138     }
    139     #endregion
    140 
    141141    private void assembliesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
    142142      if (initializing)
     
    158158      InitializeNamespacesList();
    159159      codeEditor.Prefix = GetGeneratedPrefix();
     160    }
     161    private void namespacesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
     162      if (initializing)
     163        return;
     164      if (e.Node.Checked) {
     165        ProgrammableOperator.SelectNamespace(e.Node.FullPath);
     166      } else {
     167        ProgrammableOperator.UnselectNamespace(e.Node.FullPath);
     168      }
     169      codeEditor.Prefix = GetGeneratedPrefix();
     170    }
     171    #endregion
     172
     173    #region global HotKeys
     174    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
     175      if (keyData == Keys.F6) {
     176        Control activeControl = ActiveControl;
     177        compileButton.Focus();
     178        Recompile();
     179        if (activeControl != null)
     180          activeControl.Focus();
     181        return true;
     182      }
     183      return base.ProcessCmdKey(ref msg, keyData);
     184    }
     185    #endregion
     186
     187    #region Auxiliary functions
     188
     189    private string GetGeneratedPrefix() {
     190      StringBuilder prefix = new StringBuilder();
     191      foreach (var ns in ProgrammableOperator.GetSelectedAndValidNamespaces()) {
     192        prefix.Append("using ").Append(ns).AppendLine(";");
     193      }
     194      prefix.AppendLine();
     195      prefix.Append("public class ").Append(ProgrammableOperator.CompiledTypeName).AppendLine(" {");
     196      prefix.Append("  ").Append(ProgrammableOperator.Signature).AppendLine(" {");
     197      return prefix.ToString();
     198    }
     199
     200    private void Recompile() {
     201      this.Enabled = false;
     202      try {
     203        ProgrammableOperator.Compile();
     204      } catch (Exception ex) {
     205        ErrorHandling.ShowErrorDialog(this, ex);
     206      }
     207      OnContentChanged();
     208      this.Enabled = true;
    160209    }
    161210
     
    265314    }
    266315
    267     private void namespacesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
    268       if (initializing)
    269         return;
    270       if (e.Node.Checked) {
    271         ProgrammableOperator.SelectNamespace(e.Node.FullPath);
    272       } else {
    273         ProgrammableOperator.UnselectNamespace(e.Node.FullPath);
    274       }
    275       codeEditor.Prefix = GetGeneratedPrefix();
    276     }
    277 
    278     private void showCodeButton_Click(object sender, EventArgs e) {
    279       new CodeViewer(ProgrammableOperator.CompilationUnitCode).ShowDialog(this);
    280     }
     316    #endregion
    281317  }
    282318}
Note: See TracChangeset for help on using the changeset viewer.