diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-15 13:45:37 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-15 13:45:37 +0300 |
| commit | 719749fc4475cecc2986df9484be63720bacf6b9 (patch) | |
| tree | e6bd1e82a67ba5a9dd08b141cc73b68214fb6dd6 | |
| parent | 9dab94b61087d870dd549cd652c5b9380e5e994c (diff) | |
| download | Tango-719749fc4475cecc2986df9484be63720bacf6b9.tar.gz Tango-719749fc4475cecc2986df9484be63720bacf6b9.zip | |
Diagnostics
5 files changed, 162 insertions, 23 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Project/DiagnosticsProjectTab.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Project/DiagnosticsProjectTab.cs index d50a6aa0d..6fd4519aa 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Project/DiagnosticsProjectTab.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Project/DiagnosticsProjectTab.cs @@ -23,5 +23,39 @@ namespace Tango.FSE.Diagnostics.Project Rows = new List<DiagnosticsProjectTabRowDefinition>(); Widgets = new ObservableCollection<DiagnosticsWidget>(); } + + public static DiagnosticsProjectTab CreateNew(String name, int columns, int rows) + { + var tab = new DiagnosticsProjectTab(); + tab.Name = name; + + for (int i = 0; i < columns; i++) + { + tab.Columns.Add(CreateColumn()); + } + + for (int i = 0; i < rows; i++) + { + tab.Rows.Add(CreateRow()); + } + + return tab; + } + + private static DiagnosticsProjectTabColumnDefinition CreateColumn() + { + return new DiagnosticsProjectTabColumnDefinition() + { + Width = new GridLength(1, GridUnitType.Star) + }; + } + + private static DiagnosticsProjectTabRowDefinition CreateRow() + { + return new DiagnosticsProjectTabRowDefinition() + { + Height = new GridLength(1, GridUnitType.Star) + }; + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/ViewModels/DiagnosticsViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/ViewModels/DiagnosticsViewVM.cs index d73c96b7f..7345218c0 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/ViewModels/DiagnosticsViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/ViewModels/DiagnosticsViewVM.cs @@ -19,7 +19,8 @@ namespace Tango.FSE.Diagnostics.ViewModels public class DiagnosticsViewVM : FSEViewModel { private bool _isLoaded; - private string _diagnosticsProjectFile; + private string _factoryPojectFile; + private string _customProjectFile; private FileSystemWatcher _diagnosticsProjectFileWatcher; private bool _isLoadingProject; @@ -69,7 +70,6 @@ namespace Tango.FSE.Diagnostics.ViewModels } } - public RelayCommand ExportProjectCommand { get; set; }//Need to remove! public RelayCommand NewProjectCommand { get; set; } public RelayCommand OpenProjectCommand { get; set; } public RelayCommand SaveProjectCommand { get; set; } @@ -78,13 +78,41 @@ namespace Tango.FSE.Diagnostics.ViewModels public RelayCommand CopySelectedWidgetsCommand { get; set; } public RelayCommand PasteWidgetsCommand { get; set; } public RelayCommand DeleteSelectedWidgetsCommand { get; set; } + public RelayCommand AddNewTabCommand { get; set; } + public RelayCommand<DiagnosticsTabViewVM> RemoveTabCommand { get; set; } public DiagnosticsViewVM() { Tabs = new ObservableCollection<DiagnosticsTabViewVM>(); Project = new DiagnosticsProject(); - ExportProjectCommand = new RelayCommand(ExportProject); + OpenProjectCommand = new RelayCommand(OpenProject, () => EditMode); + SaveProjectCommand = new RelayCommand(SaveProject, () => EditMode); + SaveAsProjectCommand = new RelayCommand(SaveAsProject, () => EditMode); + NewProjectCommand = new RelayCommand(CreateNewProject, () => EditMode); + AddNewTabCommand = new RelayCommand(AddNewTab, () => EditMode); + RemoveTabCommand = new RelayCommand<DiagnosticsTabViewVM>(RemoveTab, () => + { + return EditMode; + }); + } + + private async void OpenProject() + { + var result = await StorageProvider.OpenFile("Open diagnostics project", "Diagnostics Projects|*.json"); + + if (result.Confirmed) + { + try + { + await LoadProject(result.SelectedItem, true); + _customProjectFile = result.SelectedItem; + } + catch (Exception ex) + { + await NotificationProvider.ShowError($"Error opening diagnostics project.\n{ex.FlattenMessage()}"); + } + } } public override void OnApplicationStarted() @@ -129,19 +157,24 @@ namespace Tango.FSE.Diagnostics.ViewModels if (!_isLoaded) { - _diagnosticsProjectFile = Path.Combine(ApplicationManager.StartPath, "diagnostics.json"); + _factoryPojectFile = Path.Combine(ApplicationManager.StartPath, "diagnostics.json"); await LoadProject(); } } - private async Task LoadProject() + private Task LoadProject() + { + return LoadProject(_factoryPojectFile); + } + + private async Task LoadProject(String filePath, bool throwException = false) { try { IsLoadingProject = true; _isLoaded = false; - Project = DiagnosticsProject.FromFile(_diagnosticsProjectFile); + Project = DiagnosticsProject.FromFile(filePath); await Services.TechComponentsService.Preload(); @@ -178,7 +211,10 @@ namespace Tango.FSE.Diagnostics.ViewModels catch (Exception ex) { NotificationProvider.PushErrorReportingSnackbar(ex, "Diagnostics Module Error", "Error initializing diagnostics module."); - return; + if (throwException) + { + throw ex; + } } finally { @@ -205,26 +241,80 @@ namespace Tango.FSE.Diagnostics.ViewModels } } - private async void ExportProject() + private async void SaveAsProject() { - var result = await StorageProvider.SaveFile("Export diagnostics project", "Diagnostics Projects|*.json", "diagnostics.json", ".json"); + var result = await StorageProvider.SaveFile("Save diagnostics project", "Diagnostics Projects|*.json", "diagnostics.json", ".json"); if (result.Confirmed) { - try - { - Project.ToFile(result.SelectedItem); - SaveUserSettings(); - await NotificationProvider.ShowSuccess("Diagnostics project exported successfully."); - } - catch (Exception ex) + SaveProject(result.SelectedItem); + } + } + + private void SaveProject() + { + if (_customProjectFile != null) + { + SaveProject(_customProjectFile); + } + else + { + SaveAsProject(); + } + } + + private void SaveProject(String filePath, bool throwException = false) + { + try + { + Project.ToFile(filePath); + SaveUserSettings(); + _customProjectFile = filePath; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error saving diagnostics project."); + NotificationProvider.ShowError($"Error saving diagnostics project.\n{ex.FlattenMessage()}"); + + if (throwException) { - LogManager.Log(ex, "Error exporting diagnostics project."); - await NotificationProvider.ShowError($"Error exporting diagnostics project\n{ex.FlattenMessage()}"); + throw ex; } } } + private async void CreateNewProject() + { + if (!await NotificationProvider.ShowWarningQuestion("Are you sure you want to create a new project?")) return; + + Project = new DiagnosticsProject(); + Project.Tabs.Add(DiagnosticsProjectTab.CreateNew("untitled", 12, 12)); + + Tabs = new ObservableCollection<DiagnosticsTabViewVM>(); + foreach (var tab in Project.Tabs) + { + Tabs.Add(new DiagnosticsTabViewVM() { Tab = tab }); + } + + SelectedTab = Tabs.FirstOrDefault(); + } + + private void AddNewTab() + { + var tab = DiagnosticsProjectTab.CreateNew("untitled", 12, 12); + var tabVM = new DiagnosticsTabViewVM() + { + Tab = tab + }; + + Project.Tabs.Add(tab); + Tabs.Add(tabVM); + + tabVM.ShowGridLines = ShowGridLines; + tabVM.EditMode = EditMode; + SelectedTab = tabVM; + } + public override void OnApplicationShuttingDown() { base.OnApplicationShuttingDown(); @@ -234,6 +324,8 @@ namespace Tango.FSE.Diagnostics.ViewModels private void SaveUserSettings() { + if (EditMode) return; + try { foreach (var widget in Project.FlattenWidgets()) @@ -266,6 +358,16 @@ namespace Tango.FSE.Diagnostics.ViewModels private void OnEditModeChanged() { Tabs.ToList().ForEach(x => x.EditMode = EditMode); + InvalidateRelayCommands(); + } + + private async void RemoveTab(DiagnosticsTabViewVM tabVM) + { + if (await NotificationProvider.ShowWarningQuestion("Are you sure you want to remove this tab?")) + { + Tabs.Remove(tabVM); + Project.Tabs.Remove(tabVM.Tab); + } } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsTabView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsTabView.xaml index 4e2315bc1..cf7c25e14 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsTabView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsTabView.xaml @@ -22,7 +22,7 @@ </UserControl.Resources> <Grid> - <ListBox HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemsSource="{Binding Tab.Widgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" Style="{StaticResource FSE_BlankListBox}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> + <ListBox SelectionMode="Extended" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemsSource="{Binding Tab.Widgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" Style="{StaticResource FSE_BlankListBox}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <controls:DiagnosticsGrid IsItemsHost="True" ShowGridLines="{Binding ShowGridLines}" Columns="{Binding Tab.Columns}" Rows="{Binding Tab.Rows}"/> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsView.xaml index 60174692d..50ae9071b 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Views/DiagnosticsView.xaml @@ -10,7 +10,7 @@ xmlns:material="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.FSE.Diagnostics.Views" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:DiagnosticsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.DiagnosticsViewVM}" Background="{StaticResource FSE_PrimaryBackgroundBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> + d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:DiagnosticsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.DiagnosticsViewVM}" Background="{StaticResource FSE_PrimaryBackgroundBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}" x:Name="control"> <UserControl.InputBindings> <KeyBinding Modifiers="Ctrl" Key="S" Command="{Binding SaveProjectCommand}" /> <KeyBinding Modifiers="Ctrl+Shift" Key="S" Command="{Binding SaveAsProjectCommand}" /> @@ -96,10 +96,11 @@ <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Rectangle Grid.Column="0" VerticalAlignment="Bottom" StrokeThickness="2" Stroke="{StaticResource FSE_PrimaryAccentDarkBrush}" /> - <ListBox x:Name="listTabs" Grid.Column="1" DisplayMemberPath="Tag" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}" SelectedIndex="0"> + <ListBox x:Name="listTabs" FocusVisualStyle="{x:Null}" Grid.Column="1" DisplayMemberPath="Tag" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}" SelectedIndex="0"> <ListBox.Style> <Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}"> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter> @@ -145,6 +146,7 @@ </Grid> </Viewbox> <ContentPresenter Content="{Binding Tab.Name}" TextElement.Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" /> + <controls:IconButton Visibility="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.EditMode,Converter={StaticResource BooleanToVisibilityConverter}}" Cursor="Hand" Margin="0 0 20 0" Foreground="{StaticResource FSE_PrimaryForegroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Right" Icon="Close" Width="20" Height="20" Padding="0" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RemoveTabCommand}" CommandParameter="{Binding}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> @@ -171,7 +173,8 @@ </Style> </ListBox.Style> </ListBox> - <Rectangle Grid.Column="2" VerticalAlignment="Bottom" StrokeThickness="2" Stroke="{StaticResource FSE_PrimaryAccentDarkBrush}" /> + <controls:IconButton Cursor="Hand" Command="{Binding AddNewTabCommand}" Visibility="{Binding EditMode,Converter={StaticResource BooleanToVisibilityConverter}}" Grid.Column="2" Width="24" Height="24" Padding="0" Margin="10 0 0 0" Icon="Plus" Foreground="{StaticResource FSE_PrimaryAccentBrush}" /> + <Rectangle Margin="-50 0 0 0" Grid.Column="3" VerticalAlignment="Bottom" StrokeThickness="2" Stroke="{StaticResource FSE_PrimaryAccentDarkBrush}" /> </Grid> <Grid x:Name="grid"> diff --git a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs index 63a75480c..f09a82ae9 100644 --- a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs +++ b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs @@ -82,7 +82,7 @@ namespace Tango.Core { InvokeUI(() => { - foreach (var prop in this.GetType().GetProperties().Where(x => x.PropertyType == typeof(RelayCommand))) + foreach (var prop in this.GetType().GetProperties().Where(x => typeof(RelayCommand).IsAssignableFrom(x.PropertyType))) { var value = prop.GetValue(this) as RelayCommand; |
