Changeset 11975 for branches/ALPS/HeuristicLab.Scripting.Views/3.3
- Timestamp:
- 02/10/15 09:57:29 (10 years ago)
- Location:
- branches/ALPS
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS
- Property svn:mergeinfo changed
-
branches/ALPS/HeuristicLab.Scripting.Views/3.3/CSharpScriptView.cs
r11677 r11975 21 21 22 22 using System; 23 using System.Drawing; 24 using System.Threading; 23 25 using System.Windows.Forms; 24 26 using HeuristicLab.Common; … … 31 33 [Content(typeof(CSharpScript), true)] 32 34 public partial class CSharpScriptView : ScriptView { 35 private const string ScriptExecutionStartedMessage = "Script execution started"; 36 private const string ScriptExecutionCanceledMessage = "Script execution canceled"; 37 private const string ScriptExecutionSuccessfulMessage = "Script execution successful"; 38 private const string ScriptExecutionFailedMessage = "Script execution failed"; 39 33 40 protected bool Running { get; set; } 34 41 … … 65 72 startStopButton.Image = VSImageLibrary.Stop; 66 73 toolTip.SetToolTip(startStopButton, "Stop (Shift+F5)"); 74 UpdateInfoTextLabel(ScriptExecutionStartedMessage, SystemColors.ControlText); 67 75 infoTabControl.SelectedTab = outputTabPage; 68 76 } … … 76 84 startStopButton.Image = VSImageLibrary.Play; 77 85 toolTip.SetToolTip(startStopButton, "Run (F5)"); 86 87 var ex = e.Value; 88 if (ex == null) { 89 UpdateInfoTextLabel(ScriptExecutionSuccessfulMessage, Color.DarkGreen); 90 } else if (ex is ThreadAbortException) { 91 // the execution was canceled by the user 92 UpdateInfoTextLabel(ScriptExecutionCanceledMessage, Color.DarkOrange); 93 } else { 94 UpdateInfoTextLabel(ScriptExecutionFailedMessage, Color.DarkRed); 95 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex); 96 } 97 78 98 Running = false; 79 var ex = e.Value;80 if (ex != null)81 PluginInfrastructure.ErrorHandling.ShowErrorDialog(this, ex);82 99 } 83 100 } … … 111 128 if (Compile()) { 112 129 outputTextBox.Clear(); 113 Content.Execute();114 130 Running = true; 131 Content.ExecuteAsync(); 115 132 } 116 133 } … … 123 140 if (Compile()) { 124 141 outputTextBox.Clear(); 125 Content.Execute ();142 Content.ExecuteAsync(); 126 143 Running = true; 127 144 } -
branches/ALPS/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj
r11677 r11975 118 118 </ItemGroup> 119 119 <ItemGroup> 120 <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.3\HeuristicLab.CodeEditor-3.3.csproj"> 121 <Project>{489cfe09-fdf7-4c89-bab5-bd09cadd61ad}</Project> 122 <Name>HeuristicLab.CodeEditor-3.3</Name> 123 <Private>False</Private> 120 <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.4\HeuristicLab.CodeEditor-3.4.csproj"> 121 <Project>{c38691ae-ecb4-489a-a05d-b035554e0168}</Project> 122 <Name>HeuristicLab.CodeEditor-3.4</Name> 124 123 </ProjectReference> 125 124 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> -
branches/ALPS/HeuristicLab.Scripting.Views/3.3/Plugin.cs.frame
r11174 r11975 25 25 [Plugin("HeuristicLab.Scripting.Views", "3.3.10.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Scripting.Views-3.3.dll", PluginFileType.Assembly)] 27 [PluginDependency("HeuristicLab.CodeEditor", "3. 3")]27 [PluginDependency("HeuristicLab.CodeEditor", "3.4")] 28 28 [PluginDependency("HeuristicLab.Collections", "3.3")] 29 29 [PluginDependency("HeuristicLab.Common", "3.3")] -
branches/ALPS/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs
r11677 r11975 19 19 */ 20 20 #endregion 21 22 using System.Collections.Generic; 23 using System.Reflection; 24 using HeuristicLab.Common; 21 25 22 26 namespace HeuristicLab.Scripting.Views { … … 46 50 private void InitializeComponent() { 47 51 this.components = new System.ComponentModel.Container(); 48 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ScriptView)); 49 this.compilationLabel = new System.Windows.Forms.Label(); 52 this.infoTextLabel = new System.Windows.Forms.Label(); 50 53 this.imageList = new System.Windows.Forms.ImageList(this.components); 51 54 this.compileButton = new System.Windows.Forms.Button(); … … 84 87 this.infoLabel.Location = new System.Drawing.Point(816, 4); 85 88 // 86 // compilationLabel87 // 88 this. compilationLabel.AutoSize = true;89 this. compilationLabel.ForeColor = System.Drawing.SystemColors.ControlDarkDark;90 this. compilationLabel.Location = new System.Drawing.Point(66, 32);91 this. compilationLabel.Name = "compilationLabel";92 this. compilationLabel.Size = new System.Drawing.Size(69, 13);93 this. compilationLabel.TabIndex = 3;94 this. compilationLabel.Text = "Not compiled";89 // infoTextLabel 90 // 91 this.infoTextLabel.AutoSize = true; 92 this.infoTextLabel.ForeColor = System.Drawing.SystemColors.ControlDarkDark; 93 this.infoTextLabel.Location = new System.Drawing.Point(66, 32); 94 this.infoTextLabel.Name = "infoTextLabel"; 95 this.infoTextLabel.Size = new System.Drawing.Size(69, 13); 96 this.infoTextLabel.TabIndex = 3; 97 this.infoTextLabel.Text = "Not compiled"; 95 98 // 96 99 // imageList … … 215 218 this.codeEditor.UserCode = ""; 216 219 this.codeEditor.TextEditorTextChanged += new System.EventHandler(this.codeEditor_TextEditorTextChanged); 220 this.codeEditor.AssembliesLoading += new System.EventHandler<HeuristicLab.Common.EventArgs<System.Collections.Generic.IEnumerable<System.Reflection.Assembly>>>(this.codeEditor_AssembliesLoading); 221 this.codeEditor.AssembliesLoaded += new System.EventHandler<HeuristicLab.Common.EventArgs<System.Collections.Generic.IEnumerable<System.Reflection.Assembly>>>(this.codeEditor_AssembliesLoaded); 222 this.codeEditor.AssembliesUnloading += new System.EventHandler<HeuristicLab.Common.EventArgs<System.Collections.Generic.IEnumerable<System.Reflection.Assembly>>>(this.codeEditor_AssembliesUnloading); 223 this.codeEditor.AssembliesUnloaded += new System.EventHandler<HeuristicLab.Common.EventArgs<System.Collections.Generic.IEnumerable<System.Reflection.Assembly>>>(this.codeEditor_AssembliesUnloaded); 217 224 // 218 225 // splitContainer1 … … 241 248 this.Controls.Add(this.splitContainer1); 242 249 this.Controls.Add(this.compileButton); 243 this.Controls.Add(this. compilationLabel);250 this.Controls.Add(this.infoTextLabel); 244 251 this.Name = "ScriptView"; 245 252 this.Size = new System.Drawing.Size(835, 602); 246 this.Controls.SetChildIndex(this. compilationLabel, 0);253 this.Controls.SetChildIndex(this.infoTextLabel, 0); 247 254 this.Controls.SetChildIndex(this.compileButton, 0); 248 255 this.Controls.SetChildIndex(this.splitContainer1, 0); … … 266 273 #endregion 267 274 268 protected System.Windows.Forms.Label compilationLabel;275 protected System.Windows.Forms.Label infoTextLabel; 269 276 protected System.Windows.Forms.Button compileButton; 270 277 protected System.Windows.Forms.ImageList imageList; -
branches/ALPS/HeuristicLab.Scripting.Views/3.3/ScriptView.cs
r11677 r11975 22 22 using System; 23 23 using System.CodeDom.Compiler; 24 using System.Collections.Generic; 24 25 using System.Drawing; 25 26 using System.Globalization; 26 27 using System.Linq; 28 using System.Reflection; 27 29 using System.Windows.Forms; 30 using HeuristicLab.Common; 28 31 using HeuristicLab.Common.Resources; 29 32 using HeuristicLab.Core.Views; … … 35 38 [Content(typeof(Script), true)] 36 39 public partial class ScriptView : NamedItemView { 40 private const string NotCompiledMessage = "Not compiled"; 41 private const string CompilationSucceededMessage = "Compilation succeeded"; 42 private const string CompilationFailedMessage = "Compilation failed"; 43 private const string AssembliesLoadingMessage = "Loading Assemblies"; 44 private const string AssembliesUnloadingMessage = "Unloading Assemblies"; 45 private const int SilentAssemblyLoadingOperationLimit = 10; 46 37 47 #region Properties 38 48 public new Script Content { … … 73 83 codeEditor.UserCode = string.Empty; 74 84 } else { 75 if (codeEditor.UserCode != Content.Code) 76 codeEditor.UserCode = Content.Code; 77 foreach (var asm in Content.GetAssemblies()) 78 codeEditor.AddAssembly(asm); 85 codeEditor.UserCode = Content.Code; 86 codeEditor.AddAssembliesAsync(Content.GetAssemblies()); 79 87 if (Content.CompileErrors == null) { 80 compilationLabel.ForeColor = SystemColors.ControlDarkDark; 81 compilationLabel.Text = "Not compiled"; 82 } else if (Content.CompileErrors.HasErrors) { 83 compilationLabel.ForeColor = Color.DarkRed; 84 compilationLabel.Text = "Compilation failed"; 85 } else { 86 compilationLabel.ForeColor = Color.DarkGreen; 87 compilationLabel.Text = "Compilation successful"; 88 UpdateInfoTextLabel(NotCompiledMessage, SystemColors.ControlText); 88 89 } 89 90 } … … 114 115 try { 115 116 Content.Compile(); 116 outputTextBox.AppendText("Compilation succeeded."); 117 outputTextBox.AppendText(CompilationSucceededMessage); 118 UpdateInfoTextLabel(CompilationSucceededMessage, Color.DarkGreen); 117 119 return true; 118 } catch ( InvalidOperationException) {120 } catch (CompilationException) { 119 121 if (Content.CompileErrors.HasErrors) { 120 outputTextBox.AppendText("Compilation failed."); 122 outputTextBox.AppendText(CompilationFailedMessage); 123 UpdateInfoTextLabel(CompilationFailedMessage, Color.DarkRed); 121 124 return false; 122 125 } else { 123 outputTextBox.AppendText("Compilation succeeded."); 126 outputTextBox.AppendText(CompilationSucceededMessage); 127 UpdateInfoTextLabel(CompilationSucceededMessage, Color.DarkGreen); 124 128 return true; 125 129 } … … 131 135 Locked = false; 132 136 codeEditor.Focus(); 133 OnContentChanged();134 137 } 135 138 } … … 137 140 #region Helpers 138 141 protected virtual void ShowCompilationResults() { 139 if (Content.CompileErrors.Count == 0) return;140 141 142 var messages = Content.CompileErrors.OfType<CompilerError>() 142 143 .OrderBy(x => x.IsWarning) … … 157 158 } 158 159 159 codeEditor.ShowCompileErrors(Content.CompileErrors , ".cs");160 codeEditor.ShowCompileErrors(Content.CompileErrors); 160 161 161 162 AdjustErrorListViewColumnSizes(); 163 } 164 165 protected virtual void UpdateInfoTextLabel(string message, Color color) { 166 infoTextLabel.Text = message; 167 infoTextLabel.ForeColor = color; 162 168 } 163 169 … … 167 173 ch.Width = -2; 168 174 } 175 176 #region ProgressView 177 private bool progressViewCreated; 178 179 private void AddProgressView(string progressMessage) { 180 var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>(); 181 mainForm.AddOperationProgressToView(this, progressMessage); 182 progressViewCreated = true; 183 } 184 185 private void RemoveProgressView() { 186 if (!progressViewCreated) return; 187 var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>(); 188 mainForm.RemoveOperationProgressFromView(this); 189 progressViewCreated = false; 190 } 191 #endregion 169 192 #endregion 170 193 171 194 #region Event Handlers 172 private void Content_CodeChanged(object sender, EventArgs e) { 173 if (InvokeRequired) 174 Invoke(new EventHandler(Content_CodeChanged), sender, e); 195 protected virtual void Content_CodeChanged(object sender, EventArgs e) { 196 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_CodeChanged, sender, e); 175 197 else { 176 198 codeEditor.UserCode = Content.Code; … … 196 218 } 197 219 #endregion 220 221 private void codeEditor_AssembliesLoading(object sender, EventArgs<IEnumerable<Assembly>> e) { 222 if (InvokeRequired) Invoke((Action<object, EventArgs<IEnumerable<Assembly>>>)codeEditor_AssembliesLoading, sender, e); 223 else { 224 int nrOfAssemblies = e.Value.Count(); 225 if (nrOfAssemblies > SilentAssemblyLoadingOperationLimit) 226 AddProgressView(AssembliesLoadingMessage); 227 } 228 } 229 230 private void codeEditor_AssembliesLoaded(object sender, EventArgs<IEnumerable<Assembly>> e) { 231 if (InvokeRequired) Invoke((Action<object, EventArgs<IEnumerable<Assembly>>>)codeEditor_AssembliesLoaded, sender, e); 232 else { 233 RemoveProgressView(); 234 } 235 } 236 237 private void codeEditor_AssembliesUnloading(object sender, EventArgs<IEnumerable<Assembly>> e) { 238 if (InvokeRequired) Invoke((Action<object, EventArgs<IEnumerable<Assembly>>>)codeEditor_AssembliesUnloading, sender, e); 239 else { 240 int nrOfAssemblies = e.Value.Count(); 241 if (nrOfAssemblies > SilentAssemblyLoadingOperationLimit) 242 AddProgressView(AssembliesUnloadingMessage); 243 } 244 } 245 246 private void codeEditor_AssembliesUnloaded(object sender, EventArgs<IEnumerable<Assembly>> e) { 247 if (InvokeRequired) Invoke((Action<object, EventArgs<IEnumerable<Assembly>>>)codeEditor_AssembliesUnloaded, sender, e); 248 else { 249 RemoveProgressView(); 250 } 251 } 198 252 } 199 253 } -
branches/ALPS/HeuristicLab.Scripting.Views/3.3/VariableStoreView.cs
r11480 r11975 47 47 #endregion 48 48 49 private readonly Regex SafeVariableNameRegex = new Regex("^[@]?[_a-zA-Z][_a-zA-Z0-9]*$"); 50 private const string DefaultVariableName = "enter_name"; 49 51 protected readonly Dictionary<string, ListViewItem> itemListViewItemMapping; 50 52 protected readonly Dictionary<Type, bool> serializableLookup; … … 117 119 sortDescendingButton.Enabled = false; 118 120 removeButton.Enabled = false; 119 variableListView. Enabled= false;121 variableListView.LabelEdit = false; 120 122 } else { 121 123 bool enabled = !Locked && !ReadOnly; … … 124 126 sortDescendingButton.Enabled = variableListView.Items.Count > 1; 125 127 removeButton.Enabled = enabled && variableListView.SelectedItems.Count > 0; 126 variableListView.Enabled = enabled;127 128 variableListView.LabelEdit = enabled; 128 129 } … … 242 243 } 243 244 protected virtual void variableListView_DragEnter(object sender, DragEventArgs e) { 244 validDragOperation = !Locked && !ReadOnly && e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) != null; 245 validDragOperation = !Locked && !ReadOnly; 246 247 object item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 248 if (item is KeyValuePair<string, object>) { 249 var variable = (KeyValuePair<string, object>)item; 250 validDragOperation &= variable.Value is IDeepCloneable; 251 } else { 252 validDragOperation &= item is IDeepCloneable; 253 } 245 254 } 246 255 protected virtual void variableListView_DragOver(object sender, DragEventArgs e) { 247 256 e.Effect = DragDropEffects.None; 248 257 if (validDragOperation) { 249 if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 258 if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) 259 e.Effect = DragDropEffects.Copy; 250 260 } 251 261 } … … 270 280 271 281 var cloneable = item as IDeepCloneable; 272 if (cloneable != null) item = cloneable.Clone(); 273 274 Content.Add(variableName, item); 282 if (cloneable == null) return; 283 284 var clonedItem = cloneable.Clone(); 285 Content.Add(variableName, clonedItem); 275 286 276 287 var listViewItem = variableListView.FindItemWithText(variableName); … … 278 289 if (editLabel) listViewItem.BeginEdit(); 279 290 } 280 281 private readonly Regex SafeVariableNameRegex = new Regex("^[@]?[_a-zA-Z][_a-zA-Z0-9]*$");282 private const string DefaultVariableName = "enter_name";283 291 284 292 private void variableListView_AfterLabelEdit(object sender, LabelEditEventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.