diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-08 00:54:27 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-08 00:54:27 +0200 |
| commit | db4db5d05b42cbc795b3a38bba3e6c87f30d583f (patch) | |
| tree | 6eb253e1bb8d267ffdf41b2e1ff14febfd4f62a9 /Software/Visual_Studio | |
| parent | b457125866deb830b379cf3873e5cda3975b077a (diff) | |
| download | Tango-db4db5d05b42cbc795b3a38bba3e6c87f30d583f.tar.gz Tango-db4db5d05b42cbc795b3a38bba3e6c87f30d583f.zip | |
Stubs scripting improvements.
Diffstat (limited to 'Software/Visual_Studio')
9 files changed, 163 insertions, 50 deletions
diff --git a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd index b830b4a43..4555a2e58 100644 --- a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd +++ b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Highlighting/Resources/CSharp-Mode.xshd @@ -114,11 +114,6 @@ </Rule> <Keywords color="CustomTypes"> - <Word>MediaManager</Word> - <Word>Preset</Word> - <Word>CanvasItem</Word> - <Word>CanvasScriptItem</Word> - <Word>MainWindow</Word> <Word>String</Word> <Word>int</Word> <Word>Thread</Word> @@ -128,17 +123,7 @@ <Word>BitmapSource</Word> <Word>TimeSpan</Word> <Word>Dispatcher</Word> - - <Word>CanvasExecuteItem</Word> - <Word>CanvasFolderItem</Word> - <Word>CanvasImageItem</Word> - <Word>CanvasLabelItem</Word> - <Word>CanvasPowerPointItem</Word> - <Word>CanvasPreviewItem</Word> - <Word>CanvasProgressItem</Word> - <Word>CanvasRTSPItem</Word> - <Word>CanvasStaticImageItem</Word> - <Word>CanvasVideoItem</Word> + <Word>StubManager</Word> </Keywords> <Keywords color="ThisOrBaseReference"> diff --git a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Rendering/GlobalTextRunProperties.cs b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Rendering/GlobalTextRunProperties.cs index e9f9b6a33..9f00e1a40 100644 --- a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Rendering/GlobalTextRunProperties.cs +++ b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/Rendering/GlobalTextRunProperties.cs @@ -13,16 +13,18 @@ namespace ICSharpCode.AvalonEdit.Rendering internal Typeface typeface; internal double fontRenderingEmSize; internal Brush foregroundBrush; - internal Brush backgroundBrush; - internal System.Globalization.CultureInfo cultureInfo; + private Brush backgroundBrush1; + internal System.Globalization.CultureInfo cultureInfo; public override Typeface Typeface { get { return typeface; } } public override double FontRenderingEmSize { get { return fontRenderingEmSize; } } public override double FontHintingEmSize { get { return fontRenderingEmSize; } } public override TextDecorationCollection TextDecorations { get { return null; } } public override Brush ForegroundBrush { get { return foregroundBrush; } } - public override Brush BackgroundBrush { get { return backgroundBrush; } } + public override Brush BackgroundBrush { get { return BackgroundBrush1; } } public override System.Globalization.CultureInfo CultureInfo { get { return cultureInfo; } } public override TextEffectCollection TextEffects { get { return null; } } - } + + internal Brush BackgroundBrush1 { get => backgroundBrush1; set => backgroundBrush1 = value; } + } } diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml index 1329bedc5..e7f3308b8 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml @@ -5,10 +5,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="600" Background="#151515"> + <UserControl.InputBindings> + <KeyBinding Key="F5" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=RunCommand}" /> + </UserControl.InputBindings> + <Grid> <Grid> <Grid.RowDefinitions> @@ -39,7 +42,7 @@ <fa:ImageAwesome Icon="Paste" Foreground="LightGray"></fa:ImageAwesome> </Button> <Rectangle Margin="20 7 10 5" HorizontalAlignment="Center" VerticalAlignment="Stretch" Stroke="#3E3E3E" StrokeThickness="2"></Rectangle> - <Button Cursor="Hand" Margin="10 0 0 0" ToolTip="Run" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=RunCommand}" Style="{DynamicResource MetroCircleButtonStyle}" Width="16" Height="16"> + <Button Cursor="Hand" Margin="10 0 0 0" ToolTip="Run (F5)" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=RunCommand}" Style="{DynamicResource MetroCircleButtonStyle}" Width="16" Height="16"> <fa:ImageAwesome Icon="Play" Foreground="#39B839"></fa:ImageAwesome> </Button> <Button Cursor="Hand" Margin="15 0 0 0" IsEnabled="False" ToolTip="Stop" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=StopCommand}" Style="{DynamicResource MetroCircleButtonStyle}" Width="14" Height="14"> diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs index d3adf4d78..0551de699 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs @@ -78,11 +78,9 @@ namespace Tango.SharedUI.Controls public partial class ScriptEditorControl : UserControl { private CompletionWindow completionWindow; - private bool textChanged; + public ScriptEditorControl() { - HighlightTypes = new ObservableCollection<Type>(); - InitializeComponent(); textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(); @@ -120,9 +118,12 @@ namespace Tango.SharedUI.Controls types.Add(new KeyValuePair<string, Type>("String", typeof(String))); types.Add(new KeyValuePair<string, Type>("string", typeof(String))); - foreach (var t in HighlightTypes) + if (HighlightTypes != null) { - types.Add(new KeyValuePair<string, Type>(t.Name, t)); + foreach (var t in HighlightTypes) + { + types.Add(new KeyValuePair<string, Type>(t.Key, t.Value)); + } } var type = types.SingleOrDefault(x => x.Key == keyword); @@ -213,22 +214,21 @@ namespace Tango.SharedUI.Controls private void OnTextChanged() { - if (!textChanged) + if (textEditor.Text != Text) { textEditor.Text = Text; - textChanged = true; } } - public ObservableCollection<Type> HighlightTypes + public ObservableCollection<KeyValuePair<string, Type>> HighlightTypes { - get { return (ObservableCollection<Type>)GetValue(HighlightTypesProperty); } + get { return (ObservableCollection<KeyValuePair<string, Type>>)GetValue(HighlightTypesProperty); } set { SetValue(HighlightTypesProperty, value); } } public static readonly DependencyProperty HighlightTypesProperty = - DependencyProperty.Register("HighlightTypes", typeof(ObservableCollection<Type>), typeof(ScriptEditorControl), new PropertyMetadata(null)); + DependencyProperty.Register("HighlightTypes", typeof(ObservableCollection<KeyValuePair<string, Type>>), typeof(ScriptEditorControl), new PropertyMetadata(null)); diff --git a/Software/Visual_Studio/Tango.SharedUI/Helpers/ResourceHelper.cs b/Software/Visual_Studio/Tango.SharedUI/Helpers/ResourceHelper.cs index 80fa0ac3d..80b2b51a5 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Helpers/ResourceHelper.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Helpers/ResourceHelper.cs @@ -16,7 +16,7 @@ namespace Tango.SharedUI public static BitmapSource GetImageFromResources(String imagePath) { - return new BitmapImage(new Uri(String.Format("pack://application:,,,/{0};component/{1}", System.Reflection.Assembly.GetEntryAssembly(), imagePath), UriKind.Absolute)); + return new BitmapImage(new Uri(String.Format("pack://application:,,,/{0};component/{1}", typeof(ResourceHelper).Assembly, imagePath), UriKind.Absolute)); } } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs index 9895e6993..68ff84013 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs @@ -71,7 +71,7 @@ namespace Tango.Stubs.CLI } else { - prop.SetValue(request, args[argIndex++]); + prop.SetValue(request, arg); } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs index 8bfb0db7c..944decb9d 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs @@ -19,6 +19,7 @@ namespace Tango.Stubs.UI public event EventHandler<Exception> Failed; public event EventHandler<String> Completed; + public event EventHandler<String> Executed; public StubManager(UsbTransportAdapter adapter) { @@ -40,6 +41,8 @@ namespace Tango.Stubs.UI OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + ".")); } + Executed?.Invoke(this, stubType.Name); + try { MessageContainer container = new MessageContainer(); @@ -65,7 +68,7 @@ namespace Tango.Stubs.UI } else { - prop.SetValue(request, args[argIndex++]); + prop.SetValue(request, arg); } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs index 5939dfd95..bb0632e56 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs @@ -16,7 +16,7 @@ namespace Tango.Stubs.UI.ViewModels private UsbTransportAdapter _adapter; public ObservableCollection<CodeTabVM> CodeTabs { get; set; } - public ObservableCollection<Type> HighlightTypes { get; set; } + public ObservableCollection<KeyValuePair<String, Type>> HighlightTypes { get; set; } private String _log; @@ -26,7 +26,6 @@ namespace Tango.Stubs.UI.ViewModels set { _log = value; RaisePropertyChanged(nameof(Log)); } } - private CodeTabVM _selectedCodeTab; public CodeTabVM SelectedCodeTab @@ -35,10 +34,47 @@ namespace Tango.Stubs.UI.ViewModels set { _selectedCodeTab = value; RaisePropertyChanged(nameof(SelectedCodeTab)); } } + private bool _isConnected; + + public bool IsConnected + { + get { return _isConnected; } + set { _isConnected = value; RaisePropertyChanged(nameof(IsConnected)); } + } + + private List<String> _ports; + /// <summary> + /// Gets or sets the ports. + /// </summary> + public List<String> Ports + { + get { return _ports; } + set { _ports = value; RaisePropertyChanged(nameof(Ports)); } + } + + private String _selectedPort; + /// <summary> + /// Gets or sets the selected port. + /// </summary> + public String SelectedPort + { + get { return _selectedPort; } + set { _selectedPort = value; RaisePropertyChanged(nameof(SelectedPort)); } + } + + private String _status; + + public String Status + { + get { return _status; } + set { _status = value; RaisePropertyChanged(nameof(Status)); } + } + public RelayCommand NewCommand { get; set; } public RelayCommand<CodeTabVM> CloseTabCommand { get; set; } public RelayCommand RunCommand { get; set; } + public RelayCommand ToggleConnectionCommand { get; set; } public MainViewVM() { @@ -47,11 +83,42 @@ namespace Tango.Stubs.UI.ViewModels CloseTabCommand = new RelayCommand<CodeTabVM>(OnTabClosing); RunCommand = new RelayCommand(OnTabRun); - HighlightTypes = new ObservableCollection<Type>(); - HighlightTypes.Add(typeof(StubManager)); + HighlightTypes = new ObservableCollection<KeyValuePair<string, Type>>(); + HighlightTypes.Add(new KeyValuePair<string, Type>("stubManager", typeof(StubManager))); + + ToggleConnectionCommand = new RelayCommand(ToggleConnection); - _adapter = new UsbTransportAdapter("COM2"); - _adapter.Connect().Wait(); + Ports = new List<string>() + { + "COM1", + "COM2", + "COM3", + "COM4", + "COM5", + "COM6", + "COM7", + "COM8", + "COM9", + }; + + SelectedPort = Ports.First(); + + Status = "Read"; + } + + private void ToggleConnection() + { + if (!IsConnected) + { + _adapter = new UsbTransportAdapter(SelectedPort); + _adapter.Connect().Wait(); + IsConnected = true; + } + else + { + _adapter.Disconnect().Wait(); + IsConnected = false; + } } private void OnCreateNewTab() @@ -68,34 +135,40 @@ namespace Tango.Stubs.UI.ViewModels StubManager manager = new StubManager(_adapter); manager.Completed += Manager_Completed; manager.Failed += Manager_Failed; + manager.Executed += Manager_Executed; ScriptEngine engine = new ScriptEngine(new StubOnExecuteParameters(manager)); engine.ReferencedAssemblies.Add(this.GetType()); await engine.Run(SelectedCodeTab.Code); } - catch (Exception ex) + catch { throw; } } + private void Manager_Executed(object sender, string e) + { + Status = "Executing " + e + "..."; + } + private void Manager_Failed(object sender, Exception e) { Log += e.Message + Environment.NewLine; + Status = "Failed!"; } private void Manager_Completed(object sender, string response) { Log += "Response Received:" + Environment.NewLine; Log += response + Environment.NewLine; + Status = "Completed"; } private void OnTabClosing(CodeTabVM codeTab) { CodeTabs.Remove(codeTab); } - - } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml index 9f1c15947..1657908db 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml @@ -34,7 +34,7 @@ <Setter.Value> <DataTemplate> <Grid Background="#181818"> - <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay}" RunCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RunCommand}" /> + <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay}" HighlightTypes="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.HighlightTypes}" RunCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RunCommand}" /> </Grid> </DataTemplate> </Setter.Value> @@ -52,14 +52,14 @@ <MenuItem Header="File"> <MenuItem Header="New" Command="{Binding NewCommand}"></MenuItem> <Separator/> - <MenuItem Header="Open" MinWidth="150"></MenuItem> + <MenuItem Header="Open" MinWidth="150" Command="{Binding OpenCommand}"></MenuItem> <Separator/> - <MenuItem Header="Save"></MenuItem> - <MenuItem Header="Save as"></MenuItem> + <MenuItem Header="Save" Command="{Binding SaveCommand}"></MenuItem> + <MenuItem Header="Save as" Command="{Binding SaveAsCommand}"></MenuItem> <Separator/> <MenuItem Header="Exit"></MenuItem> </MenuItem> - <MenuItem Header="Edit"> + <!--<MenuItem Header="Edit"> <MenuItem Header="Cut" MinWidth="150"></MenuItem> <Separator/> <MenuItem Header="Copy"></MenuItem> @@ -67,7 +67,7 @@ <Separator/> <MenuItem Header="Undo"></MenuItem> <MenuItem Header="Redo"></MenuItem> - </MenuItem> + </MenuItem>--> </Menu> </Grid> @@ -88,6 +88,46 @@ </TabControl> </Grid> + <Grid Grid.Column="1" Grid.RowSpan="3"> + <DockPanel Margin="5"> + <StackPanel VerticalAlignment="Top" DockPanel.Dock="Top"> + <TextBlock>Connection</TextBlock> + <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Ports}" Height="35" SelectedItem="{Binding SelectedPort}"></ComboBox> + </StackPanel> + + <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom"> + <Button Margin="0 0 0 22" Height="50" MinWidth="100" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding ToggleConnectionCommand}"> + <Button.Style> + <Style TargetType="Button" BasedOn="{StaticResource AccentedSquareButtonStyle}"> + <Style.Triggers> + <DataTrigger Binding="{Binding IsConnected}" Value="False"> + <Setter Property="Content"> + <Setter.Value> + <StackPanel Orientation="Horizontal"> + <fa:ImageAwesome Icon="Link" Width="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CONNECT</TextBlock> + </StackPanel> + </Setter.Value> + </Setter> + </DataTrigger> + <DataTrigger Binding="{Binding IsConnected}" Value="True"> + <Setter Property="Content"> + <Setter.Value> + <StackPanel Orientation="Horizontal"> + <fa:ImageAwesome Icon="Unlink" Width="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">DISCONNECT</TextBlock> + </StackPanel> + </Setter.Value> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Button.Style> + </Button> + </StackPanel> + </DockPanel> + </Grid> + <GridSplitter Margin="5 0 5 0" Grid.Row="1" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center"> <GridSplitter.Background> <LinearGradientBrush> @@ -105,7 +145,14 @@ </Grid.RowDefinitions> <TextBlock Foreground="Gainsboro" VerticalAlignment="Center" Margin="5 0 0 0">Response</TextBlock> <Grid Background="Black" Grid.Row="1"> + <Grid.RowDefinitions> + <RowDefinition Height="169*"/> + <RowDefinition Height="25"/> + </Grid.RowDefinitions> <TextBox x:Name="txtLog" TextChanged="TextBox_TextChanged" Background="Transparent" Text="{Binding Log}" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro"></TextBox> + <StatusBar Grid.Row="1" Background="#CD5805"> + <TextBlock Text="{Binding Status}"></TextBlock> + </StatusBar> </Grid> </Grid> </Grid> |
