diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-23 12:27:01 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-23 12:27:01 +0300 |
| commit | a440c6477a12a263969a507c2178981642ffb457 (patch) | |
| tree | 7219ddba387349693826d9812926b0abe51d59e7 | |
| parent | 27e290d2f7efc93297420a68073d7b66430ada96 (diff) | |
| download | Tango-a440c6477a12a263969a507c2178981642ffb457.tar.gz Tango-a440c6477a12a263969a507c2178981642ffb457.zip | |
Stubs module format code.
8 files changed, 77 insertions, 24 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs index 604d54571..bba69bac1 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs @@ -3,11 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.FSE.Common; namespace Tango.FSE.Stubs.Contracts { - public interface ITestDesignerView + public interface ITestDesignerView : IFSEView { - + void FormatCode(); } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs index 1afc0478a..e1fc8c539 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -12,6 +12,7 @@ using Tango.Core; using Tango.Core.Commands; using Tango.Core.ExtensionMethods; using Tango.FSE.Common; +using Tango.FSE.Stubs.Contracts; using Tango.FSE.Stubs.Dialogs; using Tango.Integration.Operation; using Tango.Scripting.Basic; @@ -22,7 +23,7 @@ using Tango.Transport; namespace Tango.FSE.Stubs.ViewModels { - public class TestDesignerViewVM : FSEViewModel, ITestLogger + public class TestDesignerViewVM : FSEViewModel<ITestDesignerView>, ITestLogger { public enum ToolWindows { @@ -124,6 +125,7 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand<ReferenceAssembly> RemoveReferenceAssemblyCommand { get; set; } public RelayCommand AddProjectInputCommand { get; set; } public RelayCommand<TestInput> RemoveProjectInputCommand { get; set; } + public RelayCommand FormatCodeCommand { get; set; } #endregion @@ -153,6 +155,7 @@ namespace Tango.FSE.Stubs.ViewModels RemoveReferenceAssemblyCommand = new RelayCommand<ReferenceAssembly>(RemoveReferenceAssembly); AddProjectInputCommand = new RelayCommand(AddProjectInput); RemoveProjectInputCommand = new RelayCommand<TestInput>(RemoveProjectInput); + FormatCodeCommand = new RelayCommand(FormatCode); _compileTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); _compileTimer.Interval = TimeSpan.FromSeconds(2); @@ -162,6 +165,11 @@ namespace Tango.FSE.Stubs.ViewModels CreateNewProject(); } + private void FormatCode() + { + View.FormatCode(); + } + #endregion #region Script Editor Symbols Loading Handlers diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml index 715960932..4d31b9083 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml @@ -28,7 +28,7 @@ <DockPanel> <Menu IsMainMenu="True" DockPanel.Dock="Top"> <MenuItem Header="_File"> - <MenuItem Header="_New" Command="{Binding NewProjectCommand}"> + <MenuItem Header="_New" MinWidth="250" Command="{Binding NewProjectCommand}"> <MenuItem.Icon> <material:PackIcon Kind="FileDocument" /> </MenuItem.Icon> @@ -40,7 +40,7 @@ </MenuItem> </MenuItem> <MenuItem Header="_Edit"> - <MenuItem Header="_Undo" Command="Undo"> + <MenuItem MinWidth="250" Header="_Undo" Command="Undo"> <MenuItem.Icon> <material:PackIcon Kind="Undo" /> </MenuItem.Icon> @@ -66,9 +66,15 @@ <material:PackIcon Kind="ContentPaste" /> </MenuItem.Icon> </MenuItem> + <Separator/> + <MenuItem Header="_Format Code" InputGestureText="Ctrl+K+D" Command="{Binding FormatCodeCommand}"> + <MenuItem.Icon> + <material:PackIcon Kind="FormatColumns" /> + </MenuItem.Icon> + </MenuItem> </MenuItem> <MenuItem Header="Debug"> - <MenuItem Header="_Build" Command="{Binding CompileProjectCommand}" InputGestureText="F6" IsEnabled="{Binding ProjectRunner.CanCompile}"> + <MenuItem Header="_Build" MinWidth="250" Command="{Binding CompileProjectCommand}" InputGestureText="F6" IsEnabled="{Binding ProjectRunner.CanCompile}"> <MenuItem.Icon> <material:PackIcon Kind="PackageDown" /> </MenuItem.Icon> @@ -115,13 +121,13 @@ <Button Width="120" ToolTip="Run (F5)" ToolBar.OverflowMode="AsNeeded" Command="{Binding RunProjectCommand}" Visibility="{Binding ProjectRunner.IsRunning,Converter={StaticResource BooleanToVisibilityInverseConverter}}" IsEnabled="{Binding ProjectRunner.CanRun}"> <DockPanel> <material:PackIcon Kind="Play" Foreground="{StaticResource FSE_GreenBrush}" /> - <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Start</TextBlock> + <TextBlock Margin="10 2 0 0" VerticalAlignment="Center">Start</TextBlock> </DockPanel> </Button> <Button Width="120" ToolTip="Stop" ToolBar.OverflowMode="AsNeeded" Command="{Binding StopProjectCommand}" Visibility="{Binding ProjectRunner.IsRunning,Converter={StaticResource BooleanToVisibilityConverter}}"> <DockPanel> <material:PackIcon Kind="Stop" Foreground="{StaticResource FSE_RedBrush}" /> - <TextBlock Margin="5 0 0 0" VerticalAlignment="Center">Stop</TextBlock> + <TextBlock Margin="10 2 0 0" VerticalAlignment="Center">Stop</TextBlock> </DockPanel> </Button> </ToolBar> @@ -148,14 +154,14 @@ <Grid.ColumnDefinitions> <ColumnDefinition Width="499*"/> <ColumnDefinition Width="5"/> - <ColumnDefinition Width="134*"/> + <ColumnDefinition MaxWidth="500" MinWidth="250" Width="134*"/> </Grid.ColumnDefinitions> <Grid> <Grid.RowDefinitions> - <RowDefinition Height="491*"/> + <RowDefinition MinHeight="35" Height="491*"/> <RowDefinition Height="5"/> - <RowDefinition Height="174*"/> + <RowDefinition MinHeight="30" Height="174*"/> </Grid.RowDefinitions> <Grid> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs index ab9289ddb..5bd798cc0 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs @@ -12,21 +12,24 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.FSE.Stubs.Contracts; using Tango.FSE.Stubs.ViewModels; using Tango.Scripting.Basic; +using Tango.Scripting.Editors; namespace Tango.FSE.Stubs.Views { /// <summary> /// Interaction logic for TestDesignerView.xaml /// </summary> - public partial class TestDesignerView : UserControl + public partial class TestDesignerView : UserControl, ITestDesignerView { private TestDesignerViewVM _vm; public TestDesignerView() { InitializeComponent(); + this.Register<ITestDesignerView>(); Loaded += (_, __) => _vm = DataContext as TestDesignerViewVM; } @@ -34,5 +37,15 @@ namespace Tango.FSE.Stubs.Views { _vm.OpenScript((sender as FrameworkElement).DataContext as Script); } + + public void FormatCode() + { + var editor = tabControl.FindVisualChildren<ScriptEditor>().FirstOrDefault(x => x.IsVisible); + + if (editor != null) + { + editor.FormatCode(); + } + } } } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs new file mode 100644 index 000000000..7707100ad --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.FSE.Common; + +public static class IFSEViewExtensions +{ + public static void Register<T>(this T view) where T : class, IFSEView + { + TangoIOC.Default.Register<T>(view); + } +} + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj index 47bc2c36f..f79bfba03 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Tango.FSE.Common.csproj @@ -125,6 +125,7 @@ <Compile Include="Dialogs\FirmwareLogItemViewVM.cs" /> <Compile Include="EventTriggerActions\SetterAction.cs" /> <Compile Include="ExtensionMethods\IExternalBridgeClientExtensions.cs" /> + <Compile Include="ExtensionMethods\IFSEViewExtensions.cs" /> <Compile Include="ExtensionMethods\ViewModelExtensionMethods.cs" /> <Compile Include="FileSystem\FileSystemHandler.cs" /> <Compile Include="FileSystem\FileSystemHandlerStatus.cs" /> diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs index 446e5b529..776c21e53 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs @@ -60,18 +60,6 @@ namespace Tango.Scripting.Basic Scripts.CollectionChanged += (x, e) => { RaisePropertyChanged(nameof(AdditionalScripts)); }; } - public static TProject New<TProject, TContext>(String name) where TProject : Project<TContext> where TContext : IContext - { - TProject p = Activator.CreateInstance<TProject>(); - - p.Name = name; - - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(String))); - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Enumerable))); - p.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Form))); - return p; - } - public Task<CompilationResult> Compile() { return Task.Factory.StartNew<CompilationResult>(() => diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index 02615e0d2..42103a1b1 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -2102,5 +2102,25 @@ namespace Tango.Scripting.Editors } #endregion + + #region Public Methods + + public void FormatCode() + { + try + { + int index = CaretOffset; + Document.BeginUpdate(); + IndentCode(); + Document.EndUpdate(); + CaretOffset = index; + } + catch + { + Debug.WriteLine("Error formatting code."); + } + } + + #endregion } } |
