diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console')
3 files changed, 243 insertions, 14 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml index 3a30eda57..22338fea7 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml @@ -8,6 +8,7 @@ xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:views="clr-namespace:Tango.MachineStudio.UI.Views" + xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:sharedControls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:console="clr-namespace:Tango.MachineStudio.UI.Console" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Console" @@ -29,7 +30,105 @@ </Window.Resources> <Grid> - <DockPanel> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="742*"/> + </Grid.RowDefinitions> + + <Menu IsMainMenu="True" BorderThickness="0"> + <MenuItem Header="File"> + <MenuItem Header="New" Command="{Binding NewCommand}"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="FileOutline" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="Open" MinWidth="150" Command="{Binding OpenCommand}"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="FolderOutline" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="Save" Command="{Binding SaveCommand}"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Save" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="Save as" Command="{Binding SaveAsCommand}"> + <MenuItem.Icon> + <Grid> + <fa:ImageAwesome Icon="Save" Width="10" Foreground="Gainsboro" Margin="2" /> + <fa:ImageAwesome Icon="Save" Width="10" Foreground="Gainsboro" Margin="2 -5 -5 2" /> + </Grid> + </MenuItem.Icon> + </MenuItem> + </MenuItem> + <MenuItem Header="Edit"> + <MenuItem Header="Cut" MinWidth="150" Command="Cut"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Cut" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="Copy" Command="Copy"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Copy" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="Paste" Command="Paste"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Paste" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="Undo" Command="Undo"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Undo" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="Redo" Command="Redo"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Repeat" Width="12" Foreground="Gainsboro" Margin="2" /> + </MenuItem.Icon> + </MenuItem> + </MenuItem> + <MenuItem Header="Debug"> + <MenuItem Header="Run (F5)" MinWidth="150" Command="{Binding RunCommand}" > + <MenuItem.Icon> + <fa:ImageAwesome Icon="Play" Width="12" Margin="2"> + <fa:ImageAwesome.Style> + <Style TargetType="fa:ImageAwesome"> + <Setter Property="Foreground" Value="#8DD28A"></Setter> + <Style.Triggers> + <Trigger Property="IsEnabled" Value="False"> + <Setter Property="Foreground" Value="Gray"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </fa:ImageAwesome.Style> + </fa:ImageAwesome> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="Stop" Command="{Binding StopCommand}" IsEnabled="False"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Stop" Width="12" Margin="2"> + <fa:ImageAwesome.Style> + <Style TargetType="fa:ImageAwesome"> + <Setter Property="Foreground" Value="#F38B76"></Setter> + <Style.Triggers> + <Trigger Property="IsEnabled" Value="False"> + <Setter Property="Foreground" Value="Gray"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </fa:ImageAwesome.Style> + </fa:ImageAwesome> + </MenuItem.Icon> + </MenuItem> + </MenuItem> + </Menu> + + <DockPanel Grid.Row="1"> <materialDesign:ColorZone Background="#2E2E2E" Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2" Mode="PrimaryMid" DockPanel.Dock="Top"> <DockPanel> @@ -57,12 +156,23 @@ <RowDefinition Height="200*"/> </Grid.RowDefinitions> - <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" RunCommand="{Binding RunCommand}" StopCommand="{Binding StopCommand}" HighlightTypes="{Binding HighlightTypes}" IntellisenseTypes="{Binding IntellisenseTypes}"></controls:ScriptEditorControl> + <controls:ScriptEditorControl BorderThickness="0 1 0 0" BorderBrush="#616161" Text="{Binding Code,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" RunCommand="{Binding RunCommand}" StopCommand="{Binding StopCommand}" HighlightTypes="{Binding HighlightTypes}" IntellisenseTypes="{Binding IntellisenseTypes}"></controls:ScriptEditorControl> <GridSplitter Grid.Row="1" Background="#101010" Foreground="#202020" BorderBrush="#202020" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" /> - - <TextBox x:Name="txtLog" Text="{Binding Log}" FontFamily="Lucida Console" Background="Black" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro" Grid.Row="2"></TextBox> + + <Grid Grid.Row="2" Background="#1B1B1B"> + <Grid.RowDefinitions> + <RowDefinition Height="20"/> + <RowDefinition Height="57*"/> + </Grid.RowDefinitions> + + <Border BorderThickness="0 0 0 1" BorderBrush="#595959"> + <TextBlock Margin="2" HorizontalAlignment="Center">LOG</TextBlock> + </Border> + + <TextBox x:Name="txtLog" TextChanged="TextBox_TextChanged" FontFamily="Lucida Console" Background="#202020" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro" Grid.Row="2"></TextBox> + </Grid> </Grid> </Grid> </Grid> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs index e22582a46..de2c728b0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs @@ -26,10 +26,18 @@ namespace Tango.MachineStudio.UI.Console { InitializeComponent(); - this.Loaded += (_, __) => + this.Loaded += (_, __) => { _vm = this.DataContext as ConsoleWindowVM; + _vm.SetLogTextBox(txtLog); }; } + + //Auto scroll to bottom of response log each time it is changed. + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + txtLog.SelectionStart = txtLog.Text.Length; + txtLog.ScrollToEnd(); + } } } 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; } } } |
