diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-09-26 14:35:47 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-09-26 14:35:47 +0300 |
| commit | dee664eaeaf48edfa2ad2f90d6384d727dc35432 (patch) | |
| tree | 12e4d9f3896812aa1358cb3d2587910447bcd53f /Software/Visual_Studio/MachineStudio/Modules | |
| parent | b55886b8a240f597cdac1232764da0e08528fb22 (diff) | |
| download | Tango-dee664eaeaf48edfa2ad2f90d6384d727dc35432.tar.gz Tango-dee664eaeaf48edfa2ad2f90d6384d727dc35432.zip | |
Implemented Tech board tabs and project!!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
6 files changed, 235 insertions, 83 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs index 0837fde53..2e7ba6cf7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Project/MachineTechViewProject.cs @@ -10,10 +10,17 @@ namespace Tango.MachineStudio.Technician.Project { public class MachineTechViewProject { + +#warning This is legacy and should be removed + public List<TechItem> Items { get; set; } + public List<MachineTechViewProjectTab> Tabs { get; set; } + public int SelectedTabIndex { get; set; } + public MachineTechViewProject() { + Items = new List<TechItem>(); Tabs = new List<MachineTechViewProjectTab>(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 4df317c6a..38868a649 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -264,9 +264,6 @@ <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\MachineTechTabVM.cs" /> <Compile Include="ViewModels\MachineTechViewVM.cs" /> - <Compile Include="Views\MachineTechTabView.xaml.cs"> - <DependentUpon>MachineTechTabView.xaml</DependentUpon> - </Compile> <Compile Include="Views\MachineTechView.xaml.cs"> <DependentUpon>MachineTechView.xaml</DependentUpon> </Compile> @@ -442,10 +439,6 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Views\MachineTechTabView.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> <Page Include="Views\MachineTechView.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -667,7 +660,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 85a431594..738e871c9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -33,6 +33,7 @@ using Tango.MachineStudio.Common; using Tango.Core.Commands; using Tango.MachineStudio.Technician.Helpers; using Tango.MachineStudio.Technician.Models; +using Tango.Logging; namespace Tango.MachineStudio.Technician.ViewModels { @@ -88,7 +89,10 @@ namespace Tango.MachineStudio.Technician.ViewModels tab.IsSelected = false; } - _selectedTab.IsSelected = true; + if (_selectedTab != null) + { + _selectedTab.IsSelected = true; + } } } @@ -231,8 +235,30 @@ namespace Tango.MachineStudio.Technician.ViewModels /// </summary> public RelayCommand ResetHardwareConfigurationCommand { get; set; } + /// <summary> + /// Gets or sets the update graphs duration command. + /// </summary> public RelayCommand UpdateGraphsDurationCommand { get; set; } + /// <summary> + /// Gets or sets the add tab command. + /// </summary> + public RelayCommand AddTabCommand { get; set; } + + /// <summary> + /// Gets or sets the remove tab command. + /// </summary> + public RelayCommand<MachineTechTabVM> RemoveTabCommand { get; set; } + + /// <summary> + /// Gets or sets the new project command. + /// </summary> + public RelayCommand NewProjectCommand { get; set; } + + /// <summary> + /// Gets or sets the rename tab command. + /// </summary> + public RelayCommand RenameTabCommand { get; set; } #endregion #region Constructors @@ -245,7 +271,7 @@ namespace Tango.MachineStudio.Technician.ViewModels public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IEventLogger eventLogger) { Tabs = new ObservableCollection<MachineTechTabVM>(); - Tabs.Add(new MachineTechTabVM() { IsSelected = true }); + Tabs.Add(new MachineTechTabVM() { IsSelected = true, Name = "Untitled" }); SelectedTab = Tabs.First(); _settings = SettingsManager.Default.GetOrCreate<TechnicianModuleSettings>(); @@ -298,6 +324,11 @@ namespace Tango.MachineStudio.Technician.ViewModels _settings.GraphsDuration = GraphsDurationSeconds; ClearAllGraphs(); }); + + AddTabCommand = new RelayCommand(() => AddNewTab()); + RemoveTabCommand = new RelayCommand<MachineTechTabVM>(RemoveTab); + NewProjectCommand = new RelayCommand(CreateNewProject); + RenameTabCommand = new RelayCommand(RenameTab); } #endregion @@ -1544,7 +1575,7 @@ namespace Tango.MachineStudio.Technician.ViewModels #endregion - #region Public Methods + #region Project Management /// <summary> /// Opens a file open dialog to select a project file. @@ -1567,8 +1598,31 @@ namespace Tango.MachineStudio.Technician.ViewModels /// <param name="fileName">File path.</param> public void OpenProjectFile(String fileName) { - LoadProject(MachineTechViewProject.Load(fileName)); - _lastTechProjectFile = fileName; + try + { + MachineTechViewProject project = null; + + project = MachineTechViewProject.Load(fileName); + + if (project.Tabs.Count == 0) + { + LogManager.Log($"Error loading project file {fileName}. Trying to load using legacy project loader.", LogCategory.Warning); + + MachineTechViewProjectTab tab = new MachineTechViewProjectTab(); + tab.Name = "Untitled"; + tab.Items.AddRange(project.Items); + project.Items.Clear(); + project.Tabs.Add(tab); + } + + LoadProject(project); + _lastTechProjectFile = fileName; + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error loading project file {fileName}."); + _notification.ShowError("An error occurred while trying to load the tech board project file."); + } } /// <summary> @@ -1587,9 +1641,10 @@ namespace Tango.MachineStudio.Technician.ViewModels { MachineTechTabVM t = new MachineTechTabVM(); t.Name = tab.Name; - t.IsSelected = true; Tabs.Add(t); + SelectedTab = t; + foreach (var item in tab.Items) { if (item is MotorGroupItem) @@ -1600,6 +1655,8 @@ namespace Tango.MachineStudio.Technician.ViewModels AddTechItem(item); } } + + SelectedTab = Tabs.ElementAt(project.SelectedTabIndex); } } @@ -1654,6 +1711,7 @@ namespace Tango.MachineStudio.Technician.ViewModels private MachineTechViewProject GenerateProjectFile() { MachineTechViewProject project = new MachineTechViewProject(); + project.SelectedTabIndex = Tabs.IndexOf(SelectedTab); foreach (var tab in Tabs) { @@ -1678,6 +1736,90 @@ namespace Tango.MachineStudio.Technician.ViewModels return project; } + /// <summary> + /// Removes the specified tab. + /// </summary> + /// <param name="tab">The tab.</param> + private void RemoveTab(MachineTechTabVM tab) + { + if (_notification.ShowQuestion("Are you sure you want to delete the selected tab?")) + { + Tabs.Remove(tab); + SelectedTab = Tabs.LastOrDefault(); + + if (SelectedTab == null) + { + AddNewTab("Untitled"); + } + } + } + + /// <summary> + /// Adds a new tab. + /// </summary> + private bool AddNewTab(String name = null) + { + if (Tabs.Count > 7) + { + _notification.ShowError("Cannot exceed the maximum number of 8 tabs. You can remove a tab, or create a new project."); + return false; + } + + if (name == null) + { + name = _notification.ShowTextInput("Enter tab name", "Tab Name", "Untitled"); + } + + if (!String.IsNullOrWhiteSpace(name)) + { + MachineTechTabVM t = new MachineTechTabVM(); + t.Name = name; + Tabs.Add(t); + SelectedTab = t; + return true; + } + else + { + return false; + } + } + + /// <summary> + /// Creates a new project. + /// </summary> + private void CreateNewProject() + { + var to_remove = Tabs.ToList(); + + if (AddNewTab()) + { + _singleControllers.Clear(); + _multiControllers.Clear(); + + foreach (var tab in to_remove) + { + Tabs.Remove(tab); + } + } + } + + /// <summary> + /// Renames the tab. + /// </summary> + /// <param name="tab">The tab.</param> + private void RenameTab() + { + if (SelectedTab != null) + { + var name = _notification.ShowTextInput("Enter tab name", "Tab Name", SelectedTab.Name); + + if (!String.IsNullOrWhiteSpace(name)) + { + SelectedTab.Name = name; + } + } + } + #endregion #region IStudioModuleVM diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml deleted file mode 100644 index fc14343a2..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml +++ /dev/null @@ -1,13 +0,0 @@ -<UserControl x:Class="Tango.MachineStudio.Technician.Views.MachineTechTabView" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:vm="clr-namespace:Tango.MachineStudio.Technician.ViewModels" - xmlns:local="clr-namespace:Tango.MachineStudio.Technician.Views" - mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MachineTechTabVM, IsDesignTimeCreatable=False}"> - <Grid> - - </Grid> -</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs deleted file mode 100644 index 38b1ae045..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechTabView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.MachineStudio.Technician.Views -{ - /// <summary> - /// Interaction logic for MachineTechTabView.xaml - /// </summary> - public partial class MachineTechTabView : UserControl - { - public MachineTechTabView() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 99ecf72f2..dec4cee44 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -134,6 +134,12 @@ <Menu Padding="5" Background="#C6ECECEC" Visibility="{Binding HideMenu,Converter={StaticResource BooleanToVisibilityInverseConverter}}"> <MenuItem Header="File"> + <MenuItem Command="{Binding NewProjectCommand}" MinWidth="180" Header="New" VerticalContentAlignment="Center"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="File" Width="16" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> <MenuItem Command="{Binding OpenProjectCommand}" MinWidth="180" Header="Open" VerticalContentAlignment="Center"> <MenuItem.Icon> <fa:ImageAwesome Icon="FolderOpen" Width="16" /> @@ -152,58 +158,58 @@ </MenuItem> </MenuItem> <MenuItem Header="Edit"> - <MenuItem Header="Cut (Ctrl+X)" Command="{Binding ElementName=editor,Path=CutCommand}" MinWidth="210"> + <MenuItem Header="Cut (Ctrl+X)" Command="{Binding SelectedTab.Editor.CutCommand}" MinWidth="210"> <MenuItem.Icon> <fa:ImageAwesome Icon="Cut" Width="16" /> </MenuItem.Icon> </MenuItem> - <MenuItem Header="Copy (Ctrl+C)" Command="{Binding ElementName=editor,Path=CopyCommand}"> + <MenuItem Header="Copy (Ctrl+C)" Command="{Binding SelectedTab.Editor.CopyCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Copy" Width="16" /> </MenuItem.Icon> </MenuItem> - <MenuItem Header="Paste (Ctrl+V)" Command="{Binding ElementName=editor,Path=PasteCommand}"> + <MenuItem Header="Paste (Ctrl+V)" Command="{Binding SelectedTab.Editor.PasteCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Paste" Width="16" /> </MenuItem.Icon> </MenuItem> <Separator/> - <MenuItem Header="Undo (Ctrl+Z)" Command="{Binding ElementName=editor,Path=UndoCommand}"> + <MenuItem Header="Undo (Ctrl+Z)" Command="{Binding SelectedTab.Editor.UndoCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Undo" Width="16" /> </MenuItem.Icon> </MenuItem> - <MenuItem Header="Redo (Ctrl+Y)" Command="{Binding ElementName=editor,Path=RedoCommand}"> + <MenuItem Header="Redo (Ctrl+Y)" Command="{Binding SelectedTab.Editor.RedoCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="RotateRight" Width="16"></fa:ImageAwesome> </MenuItem.Icon> </MenuItem> <Separator/> - <MenuItem Header="Delete (DELETE)" Command="{Binding ElementName=editor,Path=DeleteCommand}"> + <MenuItem Header="Delete (DELETE)" Command="{Binding SelectedTab.Editor.DeleteCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Recycle" Width="16" /> </MenuItem.Icon> </MenuItem> <Separator/> - <MenuItem Header="Select All (Ctrl+A)" Command="{Binding ElementName=editor,Path=SelectAllCommand}"> + <MenuItem Header="Select All (Ctrl+A)" Command="{Binding SelectedTab.Editor.SelectAllCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Th" Width="16" /> </MenuItem.Icon> </MenuItem> </MenuItem> <MenuItem Header="View"> - <MenuItem Header="Zoom In" Command="{Binding ElementName=editor,Path=ZoomCommand}" CommandParameter="0.1"> + <MenuItem Header="Zoom In" Command="{Binding SelectedTab.Editor.ZoomCommand}" CommandParameter="0.1"> <MenuItem.Icon> <fa:ImageAwesome Icon="SearchPlus" Width="16" /> </MenuItem.Icon> </MenuItem> - <MenuItem Header="Zoom Out" Command="{Binding ElementName=editor,Path=ZoomCommand}" CommandParameter="-0.1"> + <MenuItem Header="Zoom Out" Command="{Binding SelectedTab.Editor.ZoomCommand}" CommandParameter="-0.1"> <MenuItem.Icon> <fa:ImageAwesome Icon="SearchMinus" Width="16" /> </MenuItem.Icon> </MenuItem> <Separator/> - <MenuItem Header="Reset Zoom" Command="{Binding ElementName=editor,Path=ResetZoomCommand}"> + <MenuItem Header="Reset Zoom" Command="{Binding SelectedTab.Editor.ResetZoomCommand}"> <MenuItem.Icon> <fa:ImageAwesome Icon="Search" Width="16" /> </MenuItem.Icon> @@ -355,28 +361,73 @@ <Grid Grid.Row="1"> <Grid.RowDefinitions> - <RowDefinition Height="40"/> + <RowDefinition Height="30"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> - <ListBox Style="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}"> - <ListBox.ItemsPanel> - <ItemsPanelTemplate> - <StackPanel HorizontalAlignment="Left" Orientation="Horizontal"></StackPanel> - </ItemsPanelTemplate> - </ListBox.ItemsPanel> + <StackPanel Orientation="Horizontal" Margin="35 0 0 0"> + <ListBox Style="{x:Null}" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ItemContainerStyle="{StaticResource basicListBoxItem}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}"> + <ListBox.ItemsPanel> + <ItemsPanelTemplate> + <StackPanel HorizontalAlignment="Left" Orientation="Horizontal"></StackPanel> + </ItemsPanelTemplate> + </ListBox.ItemsPanel> + + <ListBox.ItemTemplate> + <DataTemplate> + <Border Padding="5 5" Width="160" CornerRadius="10 10 0 0" Margin="1 0" Tag="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext}"> + <Border.ContextMenu> + <ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"> + <MenuItem Header="Rename" Command="{Binding RenameTabCommand}" MinWidth="210"> + <MenuItem.Icon> + <fa:ImageAwesome Icon="Pencil" Width="16" /> + </MenuItem.Icon> + </MenuItem> + </ContextMenu> + </Border.ContextMenu> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="Background" Value="#CBCBCB"></Setter> + <Setter Property="TextElement.Foreground" Value="#202020"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsSelected}" Value="True"> + <Setter Property="Background" Value="{StaticResource AccentColorBrush}"></Setter> + <Setter Property="TextElement.Foreground" Value="White"></Setter> + </DataTrigger> + <Trigger Property="IsMouseOver" Value="True"> + <Setter Property="Opacity" Value="0.8"></Setter> + </Trigger> + </Style.Triggers> + </Style> + </Border.Style> + <DockPanel VerticalAlignment="Center"> + <Button Cursor="Hand" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RemoveTabCommand}" CommandParameter="{Binding}" DockPanel.Dock="Right" Margin="5 0 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="2" Height="Auto"> + <materialDesign:PackIcon Kind="Close"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Foreground" Value="#202020"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsSelected}" Value="True"> + <Setter Property="Foreground" Value="White"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + </Button> + <TextBlock Text="{Binding Name}" VerticalAlignment="Center" TextAlignment="Center" TextTrimming="CharacterEllipsis" FontSize="11"></TextBlock> + </DockPanel> + </Border> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + + <Button Margin="10 0 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="2" Height="24" Cursor="Hand" Command="{Binding AddTabCommand}" ToolTip="New tab"> + <materialDesign:PackIcon Width="20" Height="20" Kind="Plus" Foreground="{StaticResource AccentColorBrush}" /> + </Button> + </StackPanel> - - <ListBox.ItemTemplate> - <DataTemplate> - <Border Background="Gray" Padding="5" CornerRadius="5 5 0 0"> - <TextBlock Text="{Binding Name}"></TextBlock> - </Border> - </DataTemplate> - </ListBox.ItemTemplate> - </ListBox> - - <Grid Margin="5" Grid.Row="1"> + <Grid Margin="5 0 5 5" Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="300"/> |
