From 27e290d2f7efc93297420a68073d7b66430ada96 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 10:43:59 +0300 Subject: CodeFormatter and auto assembly redirects for FSE finally works. --- .../Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs | 4 +++- .../Tango.Scripting.Editors/Tango.Scripting.Editors.csproj | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index d1ea9de43..02615e0d2 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -36,6 +36,7 @@ using Tango.Scripting.Editors.Highlighting.Xshd; using Tango.Scripting.Editors.Intellisense; using Tango.Scripting.Editors.Popups; using Tango.Scripting.Editors.Rendering; +using Tango.Scripting.Formatting; using Tango.Scripting.Parsing; namespace Tango.Scripting.Editors @@ -1681,7 +1682,8 @@ namespace Tango.Scripting.Editors private void IndentCode() { - Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); + Text = CodeFormatter.Format(Text); + //Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); //Text = _parser.IndentCSharpCode(Text); } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj index cabacbc28..5f9548262 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj @@ -590,6 +590,10 @@ {5812E1C6-ABAA-4066-94AC-971C27B4F46A} Tango.Scripting.Core + + {8d8f06ed-7f75-4933-b0c5-829b0ff654d0} + Tango.Scripting.Formatting + {1e938fd2-c669-4738-98c9-77f96ce4d451} Tango.Scripting @@ -642,7 +646,7 @@ - + \ No newline at end of file -- cgit v1.3.1 From a440c6477a12a263969a507c2178981642ffb457 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 12:27:01 +0300 Subject: Stubs module format code. --- .../Tango.FSE.Stubs/Contracts/ITestDesignerView.cs | 5 +++-- .../ViewModels/TestDesignerViewVM.cs | 10 +++++++++- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 22 ++++++++++++++-------- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs | 15 ++++++++++++++- .../ExtensionMethods/IFSEViewExtensions.cs | 16 ++++++++++++++++ .../FSE/Tango.FSE.Common/Tango.FSE.Common.csproj | 1 + .../Scripting/Tango.Scripting.Basic/Project.cs | 12 ------------ .../Tango.Scripting.Editors/ScriptEditor.cs | 20 ++++++++++++++++++++ 8 files changed, 77 insertions(+), 24 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/IFSEViewExtensions.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors') 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, ITestLogger { public enum ToolWindows { @@ -124,6 +125,7 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand RemoveReferenceAssemblyCommand { get; set; } public RelayCommand AddProjectInputCommand { get; set; } public RelayCommand RemoveProjectInputCommand { get; set; } + public RelayCommand FormatCodeCommand { get; set; } #endregion @@ -153,6 +155,7 @@ namespace Tango.FSE.Stubs.ViewModels RemoveReferenceAssemblyCommand = new RelayCommand(RemoveReferenceAssembly); AddProjectInputCommand = new RelayCommand(AddProjectInput); RemoveProjectInputCommand = new RelayCommand(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 @@ - + @@ -40,7 +40,7 @@ - + @@ -66,9 +66,15 @@ + + + + + + - + @@ -115,13 +121,13 @@ @@ -148,14 +154,14 @@ - + - + - + 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 { /// /// Interaction logic for TestDesignerView.xaml /// - public partial class TestDesignerView : UserControl + public partial class TestDesignerView : UserControl, ITestDesignerView { private TestDesignerViewVM _vm; public TestDesignerView() { InitializeComponent(); + this.Register(); 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().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(this T view) where T : class, IFSEView + { + TangoIOC.Default.Register(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 @@ + 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(String name) where TProject : Project where TContext : IContext - { - TProject p = Activator.CreateInstance(); - - 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 Compile() { return Task.Factory.StartNew(() => 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 } } -- cgit v1.3.1 From 4c0712fb9ac9ea65b0c66c16639f847307c84f98 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 23 Apr 2020 17:55:12 +0300 Subject: Improvements on test designer. --- .../Tango.FSE.Stubs/Contracts/ITestDesignerView.cs | 1 + .../Dialogs/AddReferenceAssemblyViewVM.cs | 55 +++-- .../FSE/Modules/Tango.FSE.Stubs/TestProject.cs | 22 ++ .../ViewModels/TestDesignerViewVM.cs | 240 ++++++++++++++++++++- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 226 ++++++++++++------- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs | 16 +- .../FSE/Tango.FSE.Common/Resources/Converters.xaml | 1 + .../Tango.Scripting.Basic/CompilationError.cs | 1 + .../Scripting/Tango.Scripting.Basic/Project.cs | 3 + .../Scripting/Tango.Scripting.Basic/Script.cs | 27 ++- .../Tango.Scripting.Editors/ScriptEditor.cs | 5 + 11 files changed, 486 insertions(+), 111 deletions(-) (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors') 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 bba69bac1..ea87a4f19 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 @@ -10,5 +10,6 @@ namespace Tango.FSE.Stubs.Contracts public interface ITestDesignerView : IFSEView { void FormatCode(); + void HighlightCode(int position, int length); } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs index aa32f6a03..cee06ed91 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs @@ -17,6 +17,8 @@ namespace Tango.FSE.Stubs.Dialogs { public class AddReferenceAssemblyViewVM : FSEDialogViewVM { + private List _existing; + [TangoInject] private IFSEApplicationManager ApplicationManager { get; set; } @@ -24,42 +26,53 @@ namespace Tango.FSE.Stubs.Dialogs public AddReferenceAssemblyViewVM(List existing) { + _existing = existing; OKText = "DONE"; - TangoIOC.Default.Inject(this); + } - List source = new List(); - - var startPath = ApplicationManager.StartPath; + public override void OnShow() + { + base.OnShow(); - foreach (var file in Directory.GetFiles(startPath, "*.dll")) + Task.Factory.StartNew(() => { - if (Path.GetFileName(file).StartsWith("Tango")) + System.Threading.Thread.Sleep(200); + List source = new List(); + + var startPath = ApplicationManager.StartPath; + + foreach (var file in Directory.GetFiles(startPath, "*.dll")) { - source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + if (Path.GetFileName(file).StartsWith("Tango")) + { + source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + } } - } - String dotNetPath = AssemblyHelper.GetAssemblyTargetFrameworkFolder(Assembly.GetExecutingAssembly()); + String dotNetPath = AssemblyHelper.GetAssemblyTargetFrameworkFolder(Assembly.GetExecutingAssembly()); - foreach (var file in Directory.GetFiles(dotNetPath, "*.dll")) - { - source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); - } + foreach (var file in Directory.GetFiles(dotNetPath, "*.dll")) + { + source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + } - source = source.DistinctBy(x => x.Name).ToList(); + source = source.DistinctBy(x => x.Name).ToList(); - List existingReferences = new List(); + List existingReferences = new List(); - foreach (var asm in source) - { - if (existing.Exists(x => x.Name == asm.Name)) + foreach (var asm in source) { - existingReferences.Add(asm); + if (_existing.Exists(x => x.Name == asm.Name)) + { + existingReferences.Add(asm); + } } - } - ReferenceAssemblies = new SelectedObjectCollection(source.ToObservableCollection(), existingReferences.ToObservableCollection()); + ReferenceAssemblies = new SelectedObjectCollection(source.ToObservableCollection(), existingReferences.ToObservableCollection()); + + RaisePropertyChanged(nameof(ReferenceAssemblies)); + }); } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs index 1600c9752..0bb4783dd 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs @@ -1,4 +1,5 @@ using Google.Protobuf; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -14,8 +15,19 @@ namespace Tango.FSE.Stubs { public class TestProject : Project { + private static JsonSerializerSettings _jsonSettings; + public ObservableCollection Inputs { get; set; } + static TestProject() + { + _jsonSettings = new JsonSerializerSettings() + { + TypeNameHandling = TypeNameHandling.Auto, + PreserveReferencesHandling = PreserveReferencesHandling.All, + }; + } + public TestProject() : base() { Inputs = new ObservableCollection(); @@ -41,5 +53,15 @@ namespace Tango.FSE.Stubs return project; } + + public String ToJson() + { + return JsonConvert.SerializeObject(this, _jsonSettings); + } + + public static TestProject FromJson(String json) + { + return JsonConvert.DeserializeObject(json, _jsonSettings); + } } } 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 e1fc8c539..1550da2ed 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 @@ -1,7 +1,9 @@ using Google.Protobuf; +using MaterialDesignThemes.Wpf; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -35,6 +37,10 @@ namespace Tango.FSE.Stubs.ViewModels } private DispatcherTimer _compileTimer; + private String _projectFile; + private String PROJECT_FILE_EXTENSION = ".tproj"; + private String PROJECT_DIALOG_FILTER = $"Test Project Files|*.tproj"; + private bool _isProjectChanged; #region Properties @@ -126,6 +132,14 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand AddProjectInputCommand { get; set; } public RelayCommand RemoveProjectInputCommand { get; set; } public RelayCommand FormatCodeCommand { get; set; } + public RelayCommand HighlightErrorCommand { get; set; } + public RelayCommand NewProjectCommand { get; set; } + public RelayCommand SaveProjectCommand { get; set; } + public RelayCommand SaveAsProjectCommand { get; set; } + public RelayCommand OpenProjectCommand { get; set; } + public RelayCommand AddLibraryCommand { get; set; } + public RelayCommand