diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs | 129 |
1 files changed, 120 insertions, 9 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs index 9c1192f06..a3a0a734e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs @@ -1,10 +1,13 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Controls; using System.Windows.Threading; using Tango.Core.Commands; using Tango.Core.Helpers; @@ -19,6 +22,8 @@ namespace Tango.MachineStudio.UI.Console { private IStudioModuleLoader _moduleLoader; private INotificationProvider _notificatrion; + private TextBox _txtLog; + private String _currentFile; /// <summary> @@ -26,28 +31,36 @@ namespace Tango.MachineStudio.UI.Console /// </summary> public ObservableCollection<KeyValuePair<String, Type>> HighlightTypes { get; set; } + internal void SetLogTextBox(TextBox txtLog) + { + _txtLog = txtLog; + } + /// <summary> /// Gets or sets the intellisense types. /// </summary> public ObservableCollection<KeyValuePair<String, Type>> IntellisenseTypes { get; set; } private String _code; - + /// <summary> + /// Gets or sets the code. + /// </summary> public String Code { get { return _code; } set { _code = value; RaisePropertyChangedAuto(); } } - private String _log; - - public String Log + private bool _isRunning; + /// <summary> + /// Gets or sets a value indicating whether a stub is currently running. + /// </summary> + public bool IsRunning { - get { return _log; } - set { _log = value; RaisePropertyChangedAuto(); } + get { return _isRunning; } + set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); } } - /// <summary> /// Gets or sets the run command. /// </summary> @@ -63,6 +76,26 @@ namespace Tango.MachineStudio.UI.Console /// </summary> public RelayCommand ClearCommand { get; set; } + /// <summary> + /// Gets or sets the new command. + /// </summary> + public RelayCommand NewCommand { get; set; } + + /// <summary> + /// Gets or sets the open command. + /// </summary> + public RelayCommand OpenCommand { get; set; } + + /// <summary> + /// Gets or sets the save command. + /// </summary> + public RelayCommand SaveCommand { get; set; } + + /// <summary> + /// Gets or sets the save as command. + /// </summary> + public RelayCommand SaveAsCommand { get; set; } + public ConsoleWindowVM(IStudioModuleLoader moduleLoader, INotificationProvider notification) { _moduleLoader = moduleLoader; @@ -117,6 +150,12 @@ namespace Tango.MachineStudio.UI.Console } Code = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.Console.CodeTemplate.cs"); + + NewCommand = new RelayCommand(CreateNew); + OpenCommand = new RelayCommand(OpenFile); + SaveCommand = new RelayCommand(SaveFile); + SaveAsCommand = new RelayCommand(SaveAsFile); + ClearCommand = new RelayCommand(ClearLog); } private void Stop() @@ -127,6 +166,7 @@ namespace Tango.MachineStudio.UI.Console private async void Run() { ScriptEngine engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine))); + engine.Stop(); engine.ReferencedAssemblies.Add(this.GetType()); engine.ReferencedAssemblies.Add(typeof(INotificationProvider)); @@ -140,7 +180,78 @@ namespace Tango.MachineStudio.UI.Console private void WriteLine(String text) { - Log += text + Environment.NewLine; + InvokeUI(() => + { + _txtLog.AppendText(text); + }); + } + + /// <summary> + /// Clears the log. + /// </summary> + private void ClearLog() + { + _txtLog.Clear(); + } + + /// <summary> + /// Saves the selected script file. + /// </summary> + private void SaveFile() + { + if (_currentFile == null) + { + SaveAsFile(); + } + else + { + File.WriteAllText(_currentFile, Code); + } + } + + /// <summary> + /// Saves the selected script file. + /// </summary> + private void SaveAsFile() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Filter = "C# Script Files|*.cs"; + dlg.DefaultExt = ".cs"; + if (dlg.ShowDialog().Value) + { + File.WriteAllText(dlg.FileName, Code); + _currentFile = dlg.FileName; + } + } + + /// <summary> + /// Opens a script from HD. + /// </summary> + private void OpenFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Filter = "C# Script Files|*.cs"; + if (dlg.ShowDialog().Value) + { + OpenFile(dlg.FileName); + } + } + + /// <summary> + /// Opens the file. + /// </summary> + /// <param name="file">The file.</param> + private void OpenFile(String file) + { + Code = File.ReadAllText(file); + _currentFile = file; + } + + private void CreateNew() + { + _txtLog.Clear(); + _currentFile = null; + Code = String.Empty; } } } |
