Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/04/14 17:14:01 (10 years ago)
Author:
jkarder
Message:

#2262: applied some of the changes suggested by swagner in comment:17:ticket:2262

  • added highlighting of current line
  • added error markers and bookmarks
  • fixed <Ctrl> + <Backspace> bug
  • minor code changes
File:
1 edited

Legend:

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

    r11480 r11657  
    3535  [Content(typeof(Script), true)]
    3636  public partial class ScriptView : NamedItemView {
     37    #region Properties
    3738    public new Script Content {
    3839      get { return (Script)base.Content; }
    3940      set { base.Content = value; }
    40     }
    41 
    42     public ScriptView() {
    43       InitializeComponent();
    44       errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error });
    4541    }
    4642
     
    5450      set { base.Locked = codeEditor.ReadOnly = value; }
    5551    }
     52    #endregion
     53
     54    public ScriptView() {
     55      InitializeComponent();
     56      errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error });
     57    }
    5658
    5759    protected override void RegisterContentEvents() {
    5860      base.RegisterContentEvents();
    59       Content.CodeChanged += ContentOnCodeChanged;
     61      Content.CodeChanged += Content_CodeChanged;
    6062    }
    6163
    6264    protected override void DeregisterContentEvents() {
    63       Content.CodeChanged -= ContentOnCodeChanged;
     65      Content.CodeChanged -= Content_CodeChanged;
    6466      base.DeregisterContentEvents();
    6567    }
    6668
    67     protected virtual void ContentOnCodeChanged(object sender, EventArgs e) {
    68       codeEditor.UserCode = Content.Code;
    69     }
    70 
     69    #region Overrides
    7170    protected override void OnContentChanged() {
    7271      base.OnContentChanged();
     
    7473        codeEditor.UserCode = string.Empty;
    7574      } else {
    76         codeEditor.UserCode = Content.Code;
     75        if (codeEditor.UserCode != Content.Code)
     76          codeEditor.UserCode = Content.Code;
    7777        foreach (var asm in Content.GetAssemblies())
    7878          codeEditor.AddAssembly(asm);
     
    9696    }
    9797
    98     protected virtual void CompileButtonOnClick(object sender, EventArgs e) {
    99       Compile();
    100     }
    101 
    102     protected virtual void CodeEditorOnTextEditorTextChanged(object sender, EventArgs e) {
    103       if (Content == null) return;
    104       Content.Code = codeEditor.UserCode;
    105     }
    10698    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
    10799      switch (keyData) {
     
    113105      return base.ProcessCmdKey(ref msg, keyData);
    114106    }
     107    #endregion
    115108
    116109    public virtual bool Compile() {
     
    123116        outputTextBox.AppendText("Compilation succeeded.");
    124117        return true;
    125       } catch {
     118      } catch (InvalidOperationException) {
    126119        if (Content.CompileErrors.HasErrors) {
    127120          outputTextBox.AppendText("Compilation failed.");
     
    137130        ReadOnly = false;
    138131        Locked = false;
     132        codeEditor.Focus();
    139133        OnContentChanged();
    140134      }
    141135    }
    142136
     137    #region Helpers
    143138    protected virtual void ShowCompilationResults() {
    144139      if (Content.CompileErrors.Count == 0) return;
    145       var msgs = Content.CompileErrors.OfType<CompilerError>()
     140
     141      var messages = Content.CompileErrors.OfType<CompilerError>()
    146142                                      .OrderBy(x => x.IsWarning)
    147143                                      .ThenBy(x => x.Line)
    148144                                      .ThenBy(x => x.Column);
    149       foreach (var m in msgs) {
    150         var item = new ListViewItem();
     145
     146      foreach (var m in messages) {
     147        var item = new ListViewItem { Tag = m };
    151148        item.SubItems.AddRange(new[] {
    152149          m.IsWarning ? "Warning" : "Error",
     
    159156        errorListView.Items.Add(item);
    160157      }
     158
     159      codeEditor.ShowCompileErrors(Content.CompileErrors, ".cs");
     160
    161161      AdjustErrorListViewColumnSizes();
    162162    }
     
    167167        ch.Width = -2;
    168168    }
     169    #endregion
     170
     171    #region Event Handlers
     172    private void Content_CodeChanged(object sender, EventArgs e) {
     173      if (InvokeRequired)
     174        Invoke(new EventHandler(Content_CodeChanged), sender, e);
     175      else {
     176        codeEditor.UserCode = Content.Code;
     177      }
     178    }
     179
     180    private void compileButton_Click(object sender, EventArgs e) {
     181      Compile();
     182    }
     183
     184    private void codeEditor_TextEditorTextChanged(object sender, EventArgs e) {
     185      if (Content == null) return;
     186      Content.Code = codeEditor.UserCode;
     187    }
     188
     189    private void errorListView_MouseDoubleClick(object sender, MouseEventArgs e) {
     190      if (e.Button == MouseButtons.Left) {
     191        var item = errorListView.SelectedItems[0];
     192        var message = (CompilerError)item.Tag;
     193        codeEditor.ScrollToPosition(message.Line, message.Column);
     194        codeEditor.Focus();
     195      }
     196    }
     197    #endregion
    169198  }
    170199}
Note: See TracChangeset for help on using the changeset viewer.