Changeset 16528


Ignore:
Timestamp:
01/10/19 14:16:21 (11 days ago)
Author:
jkarder
Message:

#2967: fixed ctrl+z removing all code and improved code handling in programmable operators

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.CodeEditor/3.4/CodeEditor.cs

    r15583 r16528  
    109109      get { return Doc.GetText(prefix.Length, Doc.TextLength - suffix.Length - prefix.Length); }
    110110      set {
    111         if (Doc.Text == value) return;
    112         Doc.Replace(prefix.Length, Doc.TextLength - suffix.Length - prefix.Length, value);
     111        var curLength = Doc.TextLength - suffix.Length - prefix.Length;
     112        var curUserCode = Doc.GetText(prefix.Length, curLength);
     113        if (curUserCode == value) return;
     114        Doc.Replace(prefix.Length, curLength, value);
    113115      }
    114116    }
     
    274276    #endregion
    275277
     278    public override void ClearEditHistory() {
     279      Doc.UndoStack.ClearAll();
     280    }
     281
    276282    public override void ScrollToPosition(int line, int column) {
    277283      var segment = GetSegmentAtLocation(line, column);
  • trunk/HeuristicLab.CodeEditor/3.4/CodeEditorBase.cs

    r15583 r16528  
    5757    public virtual void ScrollToPosition(int line, int column) { }
    5858
     59    public virtual void ClearEditHistory() { }
     60
    5961    public virtual void ShowCompileErrors(CompilerErrorCollection compileErrors) { }
    6062
  • trunk/HeuristicLab.Operators.Programmable.Views/3.3/ProgrammableOperatorView.cs

    r15583 r16528  
    8383      if (ProgrammableOperator == null) {
    8484        codeEditor.UserCode = string.Empty;
     85        codeEditor.ClearEditHistory();
    8586        assembliesTreeView.Nodes.Clear();
    8687        parameterCollectionView.Content = null;
     
    9192        if (codeEditor.UserCode == string.Empty)
    9293          codeEditor.UserCode = string.Format("    {0}", Environment.NewLine);
     94        codeEditor.ClearEditHistory();
    9395        InitializeAssemblyList();
    9496        InitializeNamespacesList();
     
    98100        showCodeButton.Enabled = !string.IsNullOrEmpty(ProgrammableOperator.CompilationUnitCode);
    99101        parameterCollectionView.Content = ProgrammableOperator.Parameters;
    100         if (ProgrammableOperator.CompileErrors == null) {
    101           compilationLabel.ForeColor = SystemColors.ControlDarkDark;
    102           compilationLabel.Text = "Not compiled";
    103         } else if (ProgrammableOperator.CompileErrors.HasErrors) {
    104           compilationLabel.ForeColor = Color.DarkRed;
    105           compilationLabel.Text = "Compilation failed";
    106         } else {
    107           compilationLabel.ForeColor = Color.DarkGreen;
    108           compilationLabel.Text = "Compilation successful";
    109         }
    110 
     102      }
     103      UpdateCompilationLabel();
     104    }
     105
     106    private void UpdateCompilationLabel() {
     107      if (ProgrammableOperator == null || ProgrammableOperator.CompileErrors == null) {
     108        compilationLabel.ForeColor = SystemColors.ControlDarkDark;
     109        compilationLabel.Text = "Not compiled";
     110      } else if (ProgrammableOperator.CompileErrors.HasErrors) {
     111        compilationLabel.ForeColor = Color.DarkRed;
     112        compilationLabel.Text = "Compilation failed";
     113      } else {
     114        compilationLabel.ForeColor = Color.DarkGreen;
     115        compilationLabel.Text = "Compilation successful";
    111116      }
    112117    }
     
    158163      }
    159164      InitializeNamespacesList();
    160       codeEditor.Prefix = GetGeneratedPrefix();
    161165    }
    162166    private void namespacesTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
     
    168172        ProgrammableOperator.UnselectNamespace(e.Node.FullPath);
    169173      }
    170       codeEditor.Prefix = GetGeneratedPrefix();
    171174    }
    172175    #endregion
     
    190193    private string GetGeneratedPrefix() {
    191194      StringBuilder prefix = new StringBuilder();
    192       foreach (var ns in ProgrammableOperator.GetSelectedAndValidNamespaces()) {
    193         prefix.Append("using ").Append(ns).AppendLine(";");
    194       }
    195       prefix.AppendLine();
    196195      prefix.Append("public class ").Append(ProgrammableOperator.CompiledTypeName).AppendLine(" {");
    197196      prefix.Append("  ").Append(ProgrammableOperator.Signature).AppendLine(" {");
     
    203202      try {
    204203        ProgrammableOperator.Compile();
    205       }
    206       catch (Exception ex) {
     204      } catch (Exception ex) {
    207205        ErrorHandling.ShowErrorDialog(this, ex);
    208206      }
    209       OnContentChanged();
    210207      this.Enabled = true;
     208      UpdateCompilationLabel();
     209      codeEditor.ShowCompileErrors(ProgrammableOperator.CompileErrors);
    211210    }
    212211
  • trunk/HeuristicLab.Operators.Programmable/3.3/ProgrammableOperator.cs

    r15583 r16528  
    129129    public void SelectNamespace(string ns) {
    130130      namespaces.Add(ns);
    131       OnSignatureChanged();
    132131    }
    133132
    134133    public void UnselectNamespace(string ns) {
    135134      namespaces.Remove(ns);
    136       OnSignatureChanged();
    137135    }
    138136
  • trunk/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r16430 r16528  
    8282      if (Content == null) {
    8383        codeEditor.UserCode = string.Empty;
     84        codeEditor.ClearEditHistory();
    8485      } else {
    8586        codeEditor.UserCode = Content.Code;
     87        codeEditor.ClearEditHistory();
    8688        codeEditor.AddAssembliesAsync(Content.GetAssemblies());
    8789        if (Content.CompileErrors == null) {
Note: See TracChangeset for help on using the changeset viewer.