Changeset 10891 for stable/HeuristicLab.HLScript.Views/3.3/ScriptView.cs
- Timestamp:
- 05/26/14 16:38:08 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/branches/HLScript (added) merged: 10331-10332,10358 /trunk/sources merged: 10359,10391,10401,10506
- Property svn:mergeinfo changed
-
stable/HeuristicLab.HLScript.Views/3.3
-
Property
svn:global-ignores
set to
bin
obj
Plugin.cs
-
Property
svn:global-ignores
set to
-
stable/HeuristicLab.HLScript.Views/3.3/ScriptView.cs
r10401 r10891 22 22 using System; 23 23 using System.CodeDom.Compiler; 24 using System.Collections.Generic;25 24 using System.Drawing; 25 using System.Globalization; 26 26 using System.Linq; 27 27 using System.Windows.Forms; … … 31 31 using HeuristicLab.MainForm; 32 32 33 namespace HeuristicLab. HLScript.Views {33 namespace HeuristicLab.Scripting.Views { 34 34 35 35 [View("Script View")] … … 45 45 public ScriptView() { 46 46 InitializeComponent(); 47 errorListView.SmallImageList.Images.AddRange(new Image[] { VSImageLibrary.Warning, VSImageLibrary.Error }); 48 AdjustErrorListViewColumnSizes(); 47 49 } 48 50 … … 68 70 } 69 71 private void Content_ScriptExecutionStarted(object sender, EventArgs e) { 70 Locked = true; 71 ReadOnly = true; 72 startStopButton.Image = VSImageLibrary.Stop; 73 } 74 private void Content_ScriptExecutionFinished(object sender, EventArgs e) { 75 Locked = false; 76 ReadOnly = false; 77 startStopButton.Image = VSImageLibrary.Play; 78 running = false; 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 infoTabControl.SelectedTab = outputTabPage; 79 } 80 } 81 private void Content_ScriptExecutionFinished(object sender, EventArgs<Exception> e) { 82 if (InvokeRequired) 83 Invoke((Action<object, EventArgs<Exception>>)Content_ScriptExecutionFinished, sender, e); 84 else { 85 Locked = false; 86 ReadOnly = false; 87 startStopButton.Image = VSImageLibrary.Play; 88 running = false; 89 var ex = e.Value; 90 if (ex != null) 91 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex); 92 } 79 93 } 80 94 private void Content_ConsoleOutputChanged(object sender, EventArgs<string> e) { 81 if (InvokeRequired) Invoke((Action<object, EventArgs<string>>)Content_ConsoleOutputChanged, sender, e); 95 if (InvokeRequired) 96 Invoke((Action<object, EventArgs<string>>)Content_ConsoleOutputChanged, sender, e); 82 97 else { 83 98 outputTextBox.AppendText(e.Value); … … 111 126 protected override void SetEnabledStateOfControls() { 112 127 base.SetEnabledStateOfControls(); 128 compileButton.Enabled = Content != null && !Locked && !ReadOnly; 113 129 startStopButton.Enabled = Content != null && (!Locked || running); 114 130 codeEditor.Enabled = Content != null && !Locked && !ReadOnly; … … 116 132 117 133 #region Child Control event handlers 134 private void compileButton_Click(object sender, EventArgs e) { 135 Compile(); 136 } 137 118 138 private void startStopButton_Click(object sender, EventArgs e) { 119 139 if (running) { … … 134 154 #region global HotKeys 135 155 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { 136 if (keyData == Keys.F5) { 137 if (Content == null || Locked) 138 return base.ProcessCmdKey(ref msg, keyData); 139 outputTextBox.Clear(); 140 bool result = Compile(); 141 if (result) { 142 outputTextBox.Clear(); 143 Content.Execute(); 144 running = true; 145 } 146 return true; 147 } else if (keyData == (Keys.F5 | Keys.Shift)) { 148 Content.Kill(); 156 switch (keyData) { 157 case Keys.F5: 158 if (Content != null && !Locked) { 159 if (Compile()) { 160 outputTextBox.Clear(); 161 Content.Execute(); 162 running = true; 163 } else 164 infoTabControl.SelectedTab = errorListTabPage; 165 } 166 break; 167 case Keys.F5 | Keys.Shift: 168 if (running) Content.Kill(); 169 break; 170 case Keys.F6: 171 if (!Compile() || Content.CompileErrors.HasWarnings) 172 infoTabControl.SelectedTab = errorListTabPage; 173 break; 149 174 } 150 175 return base.ProcessCmdKey(ref msg, keyData); … … 157 182 Locked = true; 158 183 errorListView.Items.Clear(); 159 outputTextBox.Clear(); 160 outputTextBox.AppendText("Compiling ... "); 184 outputTextBox.Text = "Compiling ... "; 161 185 try { 162 186 Content.Compile(); … … 165 189 } catch { 166 190 outputTextBox.AppendText("Compilation failed."); 167 ShowCompilationErrors();168 191 return false; 169 192 } finally { 170 OnContentChanged();193 ShowCompilationResults(); 171 194 ReadOnly = false; 172 195 Locked = false; 173 } 174 } 175 #endregion 176 177 private void ShowCompilationErrors() { 196 OnContentChanged(); 197 } 198 } 199 #endregion 200 201 private void ShowCompilationResults() { 178 202 if (Content.CompileErrors.Count == 0) return; 179 var warnings = new List<CompilerError>(); 180 var errors = new List<CompilerError>(); 181 foreach (CompilerError ce in Content.CompileErrors) { 182 if (ce.IsWarning) warnings.Add(ce); 183 else errors.Add(ce); 184 } 185 var msgs = warnings.OrderBy(x => x.Line) 186 .ThenBy(x => x.Column) 187 .Concat(errors.OrderBy(x => x.Line) 188 .ThenBy(x => x.Column)); 189 outputTextBox.AppendText(Environment.NewLine); 190 outputTextBox.AppendText("---"); 191 outputTextBox.AppendText(Environment.NewLine); 203 var msgs = Content.CompileErrors.OfType<CompilerError>() 204 .OrderBy(x => x.IsWarning) 205 .ThenBy(x => x.Line) 206 .ThenBy(x => x.Column); 192 207 foreach (var m in msgs) { 193 var item = new ListViewItem(new[] { 208 var item = new ListViewItem(); 209 item.SubItems.AddRange(new[] { 194 210 m.IsWarning ? "Warning" : "Error", 195 211 m.ErrorNumber, 196 m.Line.ToString( ),197 m.Column.ToString( ),212 m.Line.ToString(CultureInfo.InvariantCulture), 213 m.Column.ToString(CultureInfo.InvariantCulture), 198 214 m.ErrorText 199 215 }); 216 item.ImageIndex = m.IsWarning ? 0 : 1; 200 217 errorListView.Items.Add(item); 201 outputTextBox.AppendText(string.Format("{0} {1} ({2}:{3}): {4}", 202 item.SubItems[0].Text, 203 item.SubItems[1].Text, 204 item.SubItems[2].Text, 205 item.SubItems[3].Text, 206 item.SubItems[4].Text)); 207 outputTextBox.AppendText(Environment.NewLine); 208 } 218 } 219 AdjustErrorListViewColumnSizes(); 220 } 221 222 private void AdjustErrorListViewColumnSizes() { 223 foreach (ColumnHeader ch in errorListView.Columns) 224 // adjusts the column width to the width of the column 225 // header or the column content, whichever is greater 226 ch.Width = -2; 209 227 } 210 228 }
Note: See TracChangeset
for help on using the changeset viewer.