diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-25 09:21:33 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-25 09:21:33 +0300 |
| commit | 4571fffeccd4b037553fdeb0ddaff8005de67f23 (patch) | |
| tree | 024e677241361972c3907a5b167c4564ea512161 /Software/Visual_Studio | |
| parent | 9d0f379104fa1e4d064e43a0b969dff5b206a90a (diff) | |
| download | Tango-4571fffeccd4b037553fdeb0ddaff8005de67f23.tar.gz Tango-4571fffeccd4b037553fdeb0ddaff8005de67f23.zip | |
Move/Scale widgets.
Diffstat (limited to 'Software/Visual_Studio')
5 files changed, 153 insertions, 18 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Controls/WidgetsListBox.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Controls/WidgetsListBox.cs new file mode 100644 index 000000000..cbf19ca7c --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Controls/WidgetsListBox.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Input; + +namespace Tango.FSE.Diagnostics.Controls +{ + public class WidgetsListBox : ListBox + { + protected override void OnKeyDown(KeyEventArgs e) + { + if (e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right) + { + e.Handled = false; + return; + } + + base.OnKeyDown(e); + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Tango.FSE.Diagnostics.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Tango.FSE.Diagnostics.csproj index a777c98bf..18161cc21 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Tango.FSE.Diagnostics.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Tango.FSE.Diagnostics.csproj @@ -94,6 +94,7 @@ <DependentUpon>DiagnosticsGridLinesEditor.xaml</DependentUpon> </Compile> <Compile Include="Controls\DiagnosticsSelectionGrid.cs" /> + <Compile Include="Controls\WidgetsListBox.cs" /> <Compile Include="Converters\DecimalPlacesToStringFormatConverter.cs" /> <Compile Include="Converters\DiagnosticsWidgetToSettingsViewConverter.cs" /> <Compile Include="Converters\DiagnosticsWidgetToViewConverter.cs" /> 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 8af6d3f2a..3c446c270 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 @@ -8,6 +8,8 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.Commands; @@ -137,6 +139,16 @@ namespace Tango.FSE.Diagnostics.ViewModels public RelayCommand DeselectWidgetsCommand { get; set; } public RelayCommand ResetGridCommand { get; set; } + public RelayCommand MoveSelectedWidgetsRightCommand { get; set; } + public RelayCommand MoveSelectedWidgetsLeftCommand { get; set; } + public RelayCommand MoveSelectedWidgetsDownCommand { get; set; } + public RelayCommand MoveSelectedWidgetsUpCommand { get; set; } + + public RelayCommand ScaleSelectedWidgetsRightCommand { get; set; } + public RelayCommand ScaleSelectedWidgetsLeftCommand { get; set; } + public RelayCommand ScaleSelectedWidgetsDownCommand { get; set; } + public RelayCommand ScaleSelectedWidgetsUpCommand { get; set; } + #endregion #region Constructors @@ -165,6 +177,16 @@ namespace Tango.FSE.Diagnostics.ViewModels DeleteSelectedWidgetsCommand = new RelayCommand(DeleteSelectedWidgets, () => EditMode && SelectedTab != null && SelectedTab.Tab.Widgets.Any(x => x.IsSelected)); CutSelectedWidgetsCommand = new RelayCommand(CutSelectedWidgets, () => EditMode && SelectedTab != null && SelectedTab.Tab.Widgets.Any(x => x.IsSelected)); + MoveSelectedWidgetsRightCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Right), () => EditMode); + MoveSelectedWidgetsLeftCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Left), () => EditMode); + MoveSelectedWidgetsUpCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Top), () => EditMode); + MoveSelectedWidgetsDownCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Bottom), () => EditMode); + + ScaleSelectedWidgetsRightCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Right), () => EditMode); + ScaleSelectedWidgetsLeftCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Left), () => EditMode); + ScaleSelectedWidgetsUpCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Top), () => EditMode); + ScaleSelectedWidgetsDownCommand = new RelayCommand(() => MoveSelectedWidgets(Dock.Bottom), () => EditMode); + InitAvailableWidgetTypes(); } @@ -245,6 +267,7 @@ namespace Tango.FSE.Diagnostics.ViewModels private async Task AddWidget(DiagnosticsTabViewVM tab, DiagnosticsWidget widget) { widget.IsVisible = tab.IsVisible; + widget.EditMode = EditMode; await widget.Init(); tab.Tab.Widgets.Add(widget); } @@ -326,6 +349,51 @@ namespace Tango.FSE.Diagnostics.ViewModels DeleteSelectedWidgets(); } + private void MoveSelectedWidgets(Dock direction) + { + if (SelectedTab != null) + { + var selectedWidgets = SelectedTab.Tab.Widgets.Where(x => x.IsSelected).ToList(); + + if (Keyboard.IsKeyDown(Key.LeftCtrl)) + { + switch (direction) + { + case Dock.Right: + selectedWidgets.ForEach(x => x.ColumnSpan += 1); + break; + case Dock.Left: + selectedWidgets.ForEach(x => x.ColumnSpan -= 1); + break; + case Dock.Top: + selectedWidgets.ForEach(x => x.RowSpan -= 1); + break; + case Dock.Bottom: + selectedWidgets.ForEach(x => x.RowSpan += 1); + break; + } + } + else + { + switch (direction) + { + case Dock.Right: + selectedWidgets.ForEach(x => x.Column += 1); + break; + case Dock.Left: + selectedWidgets.ForEach(x => x.Column -= 1); + break; + case Dock.Top: + selectedWidgets.ForEach(x => x.Row -= 1); + break; + case Dock.Bottom: + selectedWidgets.ForEach(x => x.Row += 1); + break; + } + } + } + } + #endregion #region Override Methods @@ -475,6 +543,8 @@ namespace Tango.FSE.Diagnostics.ViewModels SelectedTab = Tabs.FirstOrDefault(); + EditMode = EditMode; + _isLoaded = true; } catch (Exception ex) @@ -520,6 +590,10 @@ namespace Tango.FSE.Diagnostics.ViewModels Project.ToFile(filePath); SaveUserSettings(); _customProjectFile = filePath; + NotificationProvider.PushSnackbarItem(MessageType.Success, "Diagnostics Project Saved", true, "Diagnostics project saved to successfully saved.", TimeSpan.FromSeconds(3), null, () => + { + StorageProvider.ShowInExplorer(filePath); + }); } catch (Exception ex) { @@ -609,7 +683,7 @@ namespace Tango.FSE.Diagnostics.ViewModels private void OnSelectedTabChanged() { - + } private void AddNewTab() @@ -685,12 +759,15 @@ namespace Tango.FSE.Diagnostics.ViewModels private void CopySelectedWidgets() { - _copiedWidget.Clear(); - var selectedWidgets = SelectedTab.Tab.Widgets.Where(x => x.IsSelected).ToList(); - _copiedWidget.AddRange(selectedWidgets.Select(x => x.Clone())); - InvalidateRelayCommands(); + if (SelectedTab != null) + { + _copiedWidget.Clear(); + var selectedWidgets = SelectedTab.Tab.Widgets.Where(x => x.IsSelected).ToList(); + _copiedWidget.AddRange(selectedWidgets.Select(x => x.Clone())); + InvalidateRelayCommands(); - NotificationProvider.PushSnackbarItem(MessageType.Info, "Diagnostics Widgets Copied", true, $"{_copiedWidget.Count} diagnostics widgets copied.", TimeSpan.FromSeconds(1.5)); + NotificationProvider.PushSnackbarItem(MessageType.Info, "Diagnostics Widgets Copied", true, $"{_copiedWidget.Count} diagnostics widgets copied.", TimeSpan.FromSeconds(1.5)); + } } private void StartPasteWidgets() 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 ffd8ee983..966dc7c86 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,13 +22,13 @@ </UserControl.Resources> <Grid> - <ListBox FocusVisualStyle="{x:Null}" SelectionMode="Extended" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemsSource="{Binding Tab.Widgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" Style="{StaticResource FSE_BlankListBox}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> - <ListBox.ItemsPanel> + <controls:WidgetsListBox FocusVisualStyle="{x:Null}" SelectionMode="Extended" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemsSource="{Binding Tab.Widgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" Style="{StaticResource FSE_BlankListBox}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> + <controls:WidgetsListBox.ItemsPanel> <ItemsPanelTemplate> <controls:DiagnosticsGrid IsItemsHost="True" Columns="{Binding Tab.Columns}" Rows="{Binding Tab.Rows}"/> </ItemsPanelTemplate> - </ListBox.ItemsPanel> - <ListBox.ItemContainerStyle> + </controls:WidgetsListBox.ItemsPanel> + <controls:WidgetsListBox.ItemContainerStyle> <Style TargetType="ListBoxItem" BasedOn="{StaticResource FSE_BlankListBoxItem}"> <Setter Property="Grid.Column" Value="{Binding Column}"></Setter> <Setter Property="Grid.Row" Value="{Binding Row}"></Setter> @@ -37,25 +37,50 @@ <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}"></Setter> <Setter Property="Margin" Value="5"></Setter> </Style> - </ListBox.ItemContainerStyle> + </controls:WidgetsListBox.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <DockPanel x:Name="dockPanel"> - <Border Background="#292929" Padding="5" CornerRadius="5" DockPanel.Dock="{Binding ComponentNameAlignment}" Visibility="{Binding DisplayComponentName,Converter={StaticResource BooleanToVisibilityConverter}}"> + <Canvas DockPanel.Dock="Bottom" Height="25"> + <Canvas.Style> + <Style TargetType="Canvas"> + <Setter Property="Margin" Value="0 0 0 0"></Setter> + <Setter Property="Visibility" Value="Collapsed"></Setter> + <Style.Triggers> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding DisplayComponentName}" Value="True" /> + <Condition Binding="{Binding ComponentNameAlignment}" Value="Bottom" /> + </MultiDataTrigger.Conditions> + <Setter Property="Margin" Value="0 5 0 0"></Setter> + <Setter Property="Visibility" Value="Visible"></Setter> + </MultiDataTrigger> + </Style.Triggers> + </Style> + </Canvas.Style> + <Border Width="{Binding ElementName=dockPanel,Path=ActualWidth}" CornerRadius="5" Background="#292929" Padding="5"> + <TextBlock HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding DisplayName}"/> + </Border> + </Canvas> + <Border Background="#292929" Padding="5" CornerRadius="5" DockPanel.Dock="Top"> <Border.Style> <Style TargetType="Border"> - <Setter Property="Margin" Value="0 0 0 5"></Setter> + <Setter Property="Margin" Value="0 0 0 0"></Setter> <Setter Property="Visibility" Value="Collapsed"></Setter> <Style.Triggers> - <DataTrigger Binding="{Binding ComponentNameAlignment}" Value="Bottom"> - <Setter Property="Margin" Value="0 5 0 0"></Setter> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding DisplayComponentName}" Value="True" /> + <Condition Binding="{Binding ComponentNameAlignment}" Value="Top" /> + </MultiDataTrigger.Conditions> + <Setter Property="Margin" Value="0 0 0 5"></Setter> <Setter Property="Visibility" Value="Visible"></Setter> - </DataTrigger> + </MultiDataTrigger> </Style.Triggers> </Style> </Border.Style> - <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DisplayName}"/> + <TextBlock HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="NoWrap" VerticalAlignment="Center" Text="{Binding DisplayName}"/> </Border> <Grid x:Name="parentGrid"> <Grid x:Name="widgetGrid" Background="Transparent" HorizontalAlignment="Center" VerticalAlignment="Center"> @@ -133,7 +158,7 @@ </Grid> </DataTemplate> </ItemsControl.ItemTemplate> - </ListBox> + </controls:WidgetsListBox> <Grid Margin="0 10 0 0" HorizontalAlignment="Right" Width="300"> <Grid.Style> 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 e2299a211..d039ac1f6 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 @@ -24,6 +24,14 @@ <KeyBinding Modifiers="Ctrl" Key="V" Command="{Binding PasteWidgetsCommand}" /> <KeyBinding Key="Delete" Command="{Binding DeleteSelectedWidgetsCommand}" /> <KeyBinding Key="Esc" Command="{Binding AbortCreationCommand}" /> + <KeyBinding Key="Up" Command="{Binding MoveSelectedWidgetsUpCommand}" /> + <KeyBinding Key="Down" Command="{Binding MoveSelectedWidgetsDownCommand}" /> + <KeyBinding Key="Right" Command="{Binding MoveSelectedWidgetsRightCommand}" /> + <KeyBinding Key="Left" Command="{Binding MoveSelectedWidgetsLeftCommand}" /> + <KeyBinding Key="Up" Modifiers="Ctrl" Command="{Binding ScaleSelectedWidgetsUpCommand}" /> + <KeyBinding Key="Down" Modifiers="Ctrl" Command="{Binding ScaleSelectedWidgetsDownCommand}" /> + <KeyBinding Key="Right" Modifiers="Ctrl" Command="{Binding ScaleSelectedWidgetsRightCommand}" /> + <KeyBinding Key="Left" Modifiers="Ctrl" Command="{Binding ScaleSelectedWidgetsLeftCommand}" /> </UserControl.InputBindings> <DockPanel> <Grid DockPanel.Dock="Top" IsEnabled="{Binding NotInCreationOrPasteMode}" Visibility="{Binding EditMode,Converter={StaticResource BooleanToVisibilityConverter}}"> |
