aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-11-29 13:15:09 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-11-29 13:15:09 +0200
commit9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966 (patch)
tree131c98a3b19bfca2ce81259f8921c409fda7bee7 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage
parentac3c227bb5d12339fee6fb4c243f3a5f67217915 (diff)
downloadTango-9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966.tar.gz
Tango-9e6d1ddfb42c4e8357bd75c2b1d6f84df1ea1966.zip
Working on machine studio storage module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerModel.cs26
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerType.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage.csproj2
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs151
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml306
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml.cs21
6 files changed, 452 insertions, 68 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerModel.cs
new file mode 100644
index 000000000..764512e77
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerModel.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Integration.Storage;
+
+namespace Tango.MachineStudio.Storage.Models
+{
+ public class StorageFileHandlerModel : ExtendedObject
+ {
+ public StorageFileHandler Handler { get; set; }
+
+ public StorageFileHandlerType Type { get; set; }
+
+ public String FilePath { get; set; }
+
+ public StorageFileHandlerModel(StorageFileHandler handler, String filePath, StorageFileHandlerType type)
+ {
+ FilePath = filePath;
+ Handler = handler;
+ Type = type;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerType.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerType.cs
new file mode 100644
index 000000000..548b0fc86
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Models/StorageFileHandlerType.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.Storage.Models
+{
+ public enum StorageFileHandlerType
+ {
+ Download,
+ Upload
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage.csproj
index 0ce2a1cb4..991e9fa2e 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage.csproj
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Tango.MachineStudio.Storage.csproj
@@ -66,6 +66,8 @@
</Compile>
<Compile Include="Converters\StorageItemToImageConverter.cs" />
<Compile Include="Helpers\FileIconHelper.cs" />
+ <Compile Include="Models\StorageFileHandlerModel.cs" />
+ <Compile Include="Models\StorageFileHandlerType.cs" />
<Compile Include="StorageModule.cs" />
<Compile Include="ViewModelLocator.cs" />
<Compile Include="ViewModels\MainViewVM.cs" />
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
index f28783590..1c6371f43 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/ViewModels/MainViewVM.cs
@@ -1,19 +1,28 @@
using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
+using Tango.Core.IO;
using Tango.Integration.ExternalBridge;
using Tango.Integration.Storage;
using Tango.MachineStudio.Common;
+using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.Common.StudioApplication;
+using Tango.MachineStudio.Storage.Models;
namespace Tango.MachineStudio.Storage.ViewModels
{
public class MainViewVM : StudioViewModel
{
+ public event EventHandler CurrentFolderChanged;
+
private IStudioApplicationManager _applicationManager;
+ private INotificationProvider _notification;
private bool _machine_operator_changed = true;
private StorageManager _storageManager;
@@ -43,12 +52,38 @@ namespace Tango.MachineStudio.Storage.ViewModels
public RelayCommand GoCommand { get; set; }
- public MainViewVM(IStudioApplicationManager applicationManager)
+ public RelayCommand<StorageFileHandlerModel> CancelFileHandlerCommand { get; set; }
+
+ public RelayCommand<StorageFileHandlerModel> OpenFileHandlerCommand { get; set; }
+
+ public RelayCommand<StorageFileHandlerModel> RemoveFileHandlerCommand { get; set; }
+
+ public ObservableCollection<StorageFileHandlerModel> FileHandlers { get; set; }
+
+ public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider)
{
_applicationManager = applicationManager;
+ _notification = notificationProvider;
_applicationManager.ConnectedMachineChanged += _applicationManager_ConnectedMachineChanged;
- GoCommand = new RelayCommand(NavigateToCurrentPath);
+ FileHandlers = new ObservableCollection<StorageFileHandlerModel>();
+
+ GoCommand = new RelayCommand(() => NavigateToPath(CurrentPath), () => StorageManager != null);
+ BackCommand = new RelayCommand(NavigateBack, () => StorageManager != null && StorageManager.CurrentFolder.Parent != null);
+ CancelFileHandlerCommand = new RelayCommand<StorageFileHandlerModel>(CancelFileHandler);
+ OpenFileHandlerCommand = new RelayCommand<StorageFileHandlerModel>(OpenFileHandler);
+ RefreshCommand = new RelayCommand(Refresh, () => StorageManager != null);
+ RemoveFileHandlerCommand = new RelayCommand<StorageFileHandlerModel>(RemoveFileHandler);
+ }
+
+ private void OpenFileHandler(StorageFileHandlerModel handler)
+ {
+ ShowInExplorer(handler.FilePath);
+ }
+
+ private async void CancelFileHandler(StorageFileHandlerModel handler)
+ {
+ await handler.Handler.Cancel();
}
private void _applicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient e)
@@ -63,7 +98,7 @@ namespace Tango.MachineStudio.Storage.ViewModels
public override void OnApplicationReady()
{
-
+
}
public override void OnNavigatedTo()
@@ -77,19 +112,117 @@ namespace Tango.MachineStudio.Storage.ViewModels
}
}
- private async void NavigateToCurrentPath()
+ private async void NavigateToPath(String path)
{
- await StorageManager.GetFolder(CurrentPath);
+ IsFree = false;
+
+ try
+ {
+ await StorageManager.GetFolder(path);
+ CurrentPath = StorageManager.CurrentPath;
+ CurrentFolderChanged?.Invoke(this, new EventArgs());
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"Error navigating to the specified path.\n{ex.Message}");
+ }
+
+ IsFree = true;
+
+ InvalidateRelayCommands();
}
private async void Initialize()
{
if (_applicationManager.ConnectedMachine != null)
{
- StorageManager = _applicationManager.ConnectedMachine.CreateStorageManager();
- await StorageManager.GetStorageDrive();
- await StorageManager.GetRootFolder();
- CurrentPath = StorageManager.StorageDrive.Root;
+ try
+ {
+ StorageManager = _applicationManager.ConnectedMachine.CreateStorageManager();
+ await StorageManager.GetStorageDrive();
+ await StorageManager.GetRootFolder();
+ CurrentPath = StorageManager.StorageDrive.Root;
+ }
+ catch (Exception ex)
+ {
+ _notification.ShowError($"An error occurred while trying to initialize the storage manager.\n{ex.Message}");
+ }
+
+ InvalidateRelayCommands();
+ }
+ }
+
+ public void OnStorageItemDoubleClicked(StorageItem storageItem)
+ {
+ if (storageItem is StorageFolder && storageItem != null)
+ {
+ NavigateToPath(storageItem.Path);
+ }
+ else
+ {
+ DownloadStorageItem(storageItem as StorageFile);
+ }
+ }
+
+ private void NavigateBack()
+ {
+ NavigateToPath(StorageManager.CurrentFolder.Parent);
+ }
+
+ private void Refresh()
+ {
+ NavigateToPath(StorageManager.CurrentFolder.Path);
+ }
+
+ private async void DownloadStorageItem(StorageFile storageFile)
+ {
+ var downloadsFolder = KnownFolders.GetPath(KnownFolder.Downloads);
+ var file = Path.Combine(downloadsFolder, storageFile.Name);
+
+ FileStream fs = new FileStream(Path.Combine(downloadsFolder, storageFile.Name), FileMode.Create);
+ var handler = await StorageManager.DownloadFile(storageFile, fs);
+ handler.Completed += (_, __) =>
+ {
+ fs.Dispose();
+ };
+
+ handler.Canceled += (_, __) =>
+ {
+ fs.Dispose();
+ File.Delete(file);
+ };
+
+ handler.Failed += (_, __) =>
+ {
+ fs.Dispose();
+ File.Delete(file);
+ };
+
+ FileHandlers.Insert(0, new StorageFileHandlerModel(handler, file, StorageFileHandlerType.Download));
+ }
+
+ /// <summary>
+ /// Shows the file in explorer.
+ /// </summary>
+ /// <param name="path">Name of the file/folder.</param>
+ public static void ShowInExplorer(String path)
+ {
+ Process.Start("explorer.exe", string.Format("/select,\"{0}\"", path));
+ }
+
+ private void RemoveFileHandler(StorageFileHandlerModel handler)
+ {
+ if (handler.Handler.Status == StorageFileHandlerStatus.Active)
+ {
+ if (_notification.ShowQuestion("Are you sure you want to cancel this file operation?"))
+ {
+ handler.Handler.Cancel();
+ FileHandlers.Remove(handler);
+ }
+ }
+ else
+ {
+ FileHandlers.Remove(handler);
}
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
index 46ef31c6b..a4a5c2946 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml
@@ -11,22 +11,76 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:Tango.MachineStudio.Storage.Views"
mc:Ignorable="d"
- d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}">
+ d:DesignHeight="1080" x:Name="control" d:DesignWidth="1920" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}">
<UserControl.Resources>
<localConverters:StorageItemToImageConverter x:Key="StorageItemToImageConverter" />
<converters:ByteArrayToFileSizeConverter x:Key="ByteArrayToFileSizeConverter" />
</UserControl.Resources>
-
+
<Grid>
<Grid>
<DockPanel>
- <Border Background="#ECECEC" Margin="20" Width="350" CornerRadius="5">
+ <Border Background="#ECECEC" Margin="20" Width="350" CornerRadius="5" IsEnabled="{Binding IsFree}">
+ <Border.Effect>
+ <DropShadowEffect ShadowDepth="0" BlurRadius="10" Color="Gray" />
+ </Border.Effect>
<DockPanel>
- <TextBlock HorizontalAlignment="Center" DockPanel.Dock="Top" Margin="20 55 20 20" FontSize="30" FontStyle="Italic" Foreground="{StaticResource AccentColorBrush}" FontWeight="Bold">ACTIONS</TextBlock>
+ <TextBlock HorizontalAlignment="Left" DockPanel.Dock="Top" Margin="30 55 20 20" FontSize="30" FontStyle="Italic" Foreground="{StaticResource AccentColorBrush}" FontWeight="Bold">ACTIONS</TextBlock>
<StackPanel Margin="0 40 0 0">
-
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="FolderPlus" Foreground="#E79F20" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">CREATE FOLDER</TextBlock>
+ </DockPanel>
+ </Button>
+ <Separator/>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="Upload" Foreground="#E97E28" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">UPLOAD FILE</TextBlock>
+ </DockPanel>
+ </Button>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="Download" Foreground="#2DD42D" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">DOWNLOAD FILE</TextBlock>
+ </DockPanel>
+ </Button>
+ <Separator/>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="Delete" Foreground="#E14141" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">DELETE FILE</TextBlock>
+ </DockPanel>
+ </Button>
+ <Separator/>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="BriefcaseUpload" Foreground="#833CEC" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">UPLOAD VERSION</TextBlock>
+ </DockPanel>
+ </Button>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="CheckAll" Foreground="#682EBE" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">VALIDATE VERSION</TextBlock>
+ </DockPanel>
+ </Button>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="Flash" Foreground="#532990" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">ACTIVATE VERSION</TextBlock>
+ </DockPanel>
+ </Button>
+ <Separator/>
+ <Button Margin="0 5 0 0" Style="{StaticResource MaterialDesignFlatButton}" Padding="20 10" Height="Auto" Foreground="#363636" HorizontalContentAlignment="Left">
+ <DockPanel>
+ <materialDesign:PackIcon Kind="Refresh" Foreground="{StaticResource AccentColorBrush}" Width="32" Height="32" />
+ <TextBlock VerticalAlignment="Center" Margin="20 0 0 0" FontSize="18">REFRESH</TextBlock>
+ </DockPanel>
+ </Button>
</StackPanel>
</DockPanel>
</Border>
@@ -34,13 +88,16 @@
<Grid>
<DockPanel>
<Border DockPanel.Dock="Top" Background="#ECECEC" Margin="20" Height="150" CornerRadius="5" Padding="20 0">
+ <Border.Effect>
+ <DropShadowEffect ShadowDepth="0" BlurRadius="10" Color="Gray" />
+ </Border.Effect>
<DockPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" DockPanel.Dock="Left">
- <Button Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding BackCommand}">
+ <Button Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding BackCommand}" IsEnabled="{Binding IsFree}">
<materialDesign:PackIcon Kind="ArrowLeft" Width="60" Height="60" />
</Button>
- <Button Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding RefreshCommand}">
+ <Button Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding RefreshCommand}" IsEnabled="{Binding IsFree}">
<materialDesign:PackIcon Kind="Refresh" Width="60" Height="60" />
</Button>
</StackPanel>
@@ -55,21 +112,21 @@
</TextBlock>
<TextBlock Margin="0 5 0 0">
<Run>Capacity:</Run>
- <Run FontWeight="Bold" FontStyle="Italic" Text="{Binding StorageManager.StorageDrive.Capacity}"></Run>
+ <Run FontWeight="Bold" FontStyle="Italic" Text="{Binding StorageManager.StorageDrive.Capacity,Converter={StaticResource ByteArrayToFileSizeConverter}}"></Run>
</TextBlock>
<TextBlock Margin="0 5 0 0">
<Run>Free Space:</Run>
- <Run FontWeight="Bold" FontStyle="Italic" Text="{Binding StorageManager.StorageDrive.FreeSpace}"></Run>
+ <Run FontWeight="Bold" FontStyle="Italic" Text="{Binding StorageManager.StorageDrive.FreeSpace,Converter={StaticResource ByteArrayToFileSizeConverter}}"></Run>
</TextBlock>
</StackPanel>
</DockPanel>
</Border>
<DockPanel VerticalAlignment="Center" Margin="50 0 50 0">
- <Button Margin="10 0 0 0" DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding GoCommand}">
+ <Button Margin="10 0 0 0" DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatButton}" Width="80" Height="80" Padding="0" Command="{Binding GoCommand}" IsEnabled="{Binding IsFree}">
<materialDesign:PackIcon Kind="SubdirectoryArrowRight" Width="60" Height="60" />
</Button>
- <Border Height="35" Background="{StaticResource AccentColorBrush}" CornerRadius="5" Padding="5">
+ <Border Height="35" Background="{StaticResource AccentColorBrush}" CornerRadius="5" Padding="5" IsEnabled="{Binding IsFree}">
<TextBox Style="{x:Null}" Background="Transparent" Foreground="White" FontSize="18" BorderThickness="0" CaretBrush="White" Text="{Binding CurrentPath,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Command="{Binding Path=GoCommand}" Key="Enter"/>
@@ -81,54 +138,185 @@
</Border>
<Grid Margin="20">
- <Border Background="#1DFFFFFF" CornerRadius="5" Padding="20">
- <DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" IsReadOnly="True" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding StorageManager.CurrentFolder.Items}" SelectedItem="{Binding SelectedStorageItem}">
- <DataGrid.CellStyle>
- <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
- <Setter Property="BorderThickness" Value="0"/>
- <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
- <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
- </Style>
- </DataGrid.CellStyle>
- <DataGrid.Columns>
- <DataGridTemplateColumn Width="100">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <Image Width="40" Height="40" HorizontalAlignment="Left" Source="{Binding Converter={StaticResource StorageItemToImageConverter}}"></Image>
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- <DataGridTemplateColumn Header="NAME" Width="1*" SortMemberPath="Name">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="16" />
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- <DataGridTemplateColumn Header="TYPE" Width="150" SortMemberPath="Attribute">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Attribute}" VerticalAlignment="Center" FontSize="16" />
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- <DataGridTemplateColumn Header="SIZE" Width="150" SortMemberPath="Length">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Length,Converter={StaticResource ByteArrayToFileSizeConverter},FallbackValue='',TargetNullValue=''}" VerticalAlignment="Center" FontSize="16" />
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- <DataGridTemplateColumn Header="LAST MODIFIED" Width="200" SortMemberPath="LastModified">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding LastModified}" VerticalAlignment="Center" FontSize="16" />
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- </DataGrid.Columns>
- </DataGrid>
- </Border>
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="100*" MinHeight="150" />
+ <RowDefinition Height="5" />
+ <RowDefinition Height="40*" MinHeight="150" />
+ </Grid.RowDefinitions>
+ <Border Background="#8BFFFFFF" CornerRadius="5" Padding="20">
+ <DataGrid x:Name="gridStorageItems" IsEnabled="{Binding IsFree}" MouseDoubleClick="DataGrid_MouseDoubleClick" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" IsReadOnly="True" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding StorageManager.CurrentFolder.Items}" SelectedItem="{Binding SelectedStorageItem}">
+ <DataGrid.CellStyle>
+ <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
+ <Setter Property="BorderThickness" Value="0"/>
+ <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
+ <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
+ </Style>
+ </DataGrid.CellStyle>
+ <DataGrid.Columns>
+ <DataGridTemplateColumn Width="100">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <Image Width="32" Height="32" HorizontalAlignment="Left" Source="{Binding Converter={StaticResource StorageItemToImageConverter}}"></Image>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="NAME" Width="1*" SortMemberPath="Name">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="14" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="TYPE" Width="150" SortMemberPath="Attribute">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding Attribute}" VerticalAlignment="Center" FontSize="14" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="SIZE" Width="150" SortMemberPath="Length">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding Length,Converter={StaticResource ByteArrayToFileSizeConverter},FallbackValue='',TargetNullValue=''}" VerticalAlignment="Center" FontSize="14" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="LAST MODIFIED" Width="200" SortMemberPath="LastModified">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding LastModified}" VerticalAlignment="Center" FontSize="14" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ </DataGrid.Columns>
+ </DataGrid>
+ </Border>
+
+ <GridSplitter Grid.Row="1" Height="5" VerticalAlignment="Center" HorizontalAlignment="Stretch" Background="Gray" Margin="5 0" />
+
+ <Border Background="#8BFFFFFF" CornerRadius="5" Padding="20" Grid.Row="3">
+ <DockPanel>
+ <TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontStyle="Italic" Foreground="{StaticResource AccentColorBrush}" FontWeight="Bold">FILE TRANSFERS</TextBlock>
+ <DataGrid AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" IsReadOnly="True" Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding FileHandlers}">
+ <DataGrid.CellStyle>
+ <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
+ <Setter Property="BorderThickness" Value="0"/>
+ <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
+ <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
+ </Style>
+ </DataGrid.CellStyle>
+ <DataGrid.Columns>
+ <DataGridTemplateColumn Width="100">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <materialDesign:PackIcon Width="32" Height="32" HorizontalAlignment="Left">
+ <materialDesign:PackIcon.Style>
+ <Style TargetType="materialDesign:PackIcon">
+ <Setter Property="Kind" Value="Download"></Setter>
+ <Setter Property="Foreground" Value="#20BB20"></Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding Type}" Value="Upload">
+ <Setter Property="Kind" Value="Upload"></Setter>
+ <Setter Property="Foreground" Value="#E76311"></Setter>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </materialDesign:PackIcon.Style>
+ </materialDesign:PackIcon>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="FILE" Width="450">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding FilePath}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" FontSize="14" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="PROGRESS" Width="1*">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <ProgressBar Height="15" Margin="0 0 30 0" VerticalAlignment="Center" Maximum="{Binding Handler.Total,Mode=OneWay}" Value="{Binding Handler.Current,Mode=OneWay}">
+ <ProgressBar.Style>
+ <Style TargetType="ProgressBar">
+ <Setter Property="Foreground" Value="#2FD42F"></Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding Handler.Status}" Value="Canceled">
+ <Setter Property="Foreground" Value="#EF832B"></Setter>
+ </DataTrigger>
+ <DataTrigger Binding="{Binding Handler.Status}" Value="Failed">
+ <Setter Property="Foreground" Value="#E11A1A"></Setter>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </ProgressBar.Style>
+ </ProgressBar>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Header="STATUS" Width="150">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding Handler.Status}" VerticalAlignment="Center" FontSize="14" FontWeight="SemiBold" FontStyle="Italic" />
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Width="150">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <ContentControl Content="{Binding}">
+ <ContentControl.Style>
+ <Style TargetType="ContentControl">
+ <Setter Property="ContentTemplate">
+ <Setter.Value>
+ <DataTemplate></DataTemplate>
+ </Setter.Value>
+ </Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding Handler.Status}" Value="Active">
+ <Setter Property="ContentTemplate">
+ <Setter.Value>
+ <DataTemplate>
+ <Button Command="{Binding Source={x:Reference control},Path=DataContext.CancelFileHandlerCommand}" CommandParameter="{Binding}" Margin="5" Background="#FF6A6A" BorderBrush="#FF6A6A">CANCEL</Button>
+ </DataTemplate>
+ </Setter.Value>
+ </Setter>
+ </DataTrigger>
+ <MultiDataTrigger>
+ <MultiDataTrigger.Conditions>
+ <Condition Binding="{Binding Handler.Status}" Value="Completed"></Condition>
+ <Condition Binding="{Binding Type}" Value="Download"></Condition>
+ </MultiDataTrigger.Conditions>
+ <Setter Property="ContentTemplate">
+ <Setter.Value>
+ <DataTemplate>
+ <Button Command="{Binding Source={x:Reference control},Path=DataContext.OpenFileHandlerCommand}" CommandParameter="{Binding}" Margin="5" Background="#2CC62C" BorderBrush="#2CC62C">OPEN</Button>
+ </DataTemplate>
+ </Setter.Value>
+ </Setter>
+ </MultiDataTrigger>
+ </Style.Triggers>
+ </Style>
+ </ContentControl.Style>
+ </ContentControl>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ <DataGridTemplateColumn Width="60">
+ <DataGridTemplateColumn.CellTemplate>
+ <DataTemplate>
+ <Button Foreground="#FF5A5A" Style="{StaticResource MaterialDesignFlatButton}" Padding="0" Width="24" Height="24" Command="{Binding Source={x:Reference control},Path=DataContext.RemoveFileHandlerCommand}" CommandParameter="{Binding}" Margin="5">
+ <materialDesign:PackIcon Kind="Close" Width="24" Height="24" />
+ </Button>
+ </DataTemplate>
+ </DataGridTemplateColumn.CellTemplate>
+ </DataGridTemplateColumn>
+ </DataGrid.Columns>
+ </DataGrid>
+ </DockPanel>
+ </Border>
+ </Grid>
</Grid>
</DockPanel>
</Grid>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml.cs
index be7e82ca5..5da808b8c 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Storage/Views/MainView.xaml.cs
@@ -12,6 +12,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Tango.Integration.Storage;
+using Tango.MachineStudio.Storage.ViewModels;
namespace Tango.MachineStudio.Storage.Views
{
@@ -20,9 +22,28 @@ namespace Tango.MachineStudio.Storage.Views
/// </summary>
public partial class MainView : UserControl
{
+ private MainViewVM _vm;
+
public MainView()
{
InitializeComponent();
+ Loaded += (_, __) =>
+ {
+ _vm = DataContext as MainViewVM;
+ _vm.CurrentFolderChanged += _vm_CurrentFolderChanged;
+ };
+
+ }
+
+ private void _vm_CurrentFolderChanged(object sender, EventArgs e)
+ {
+ ScrollViewer scrollViewer = gridStorageItems.FindChild<ScrollViewer>();
+ scrollViewer.ScrollToVerticalOffset(0);
+ }
+
+ private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+ {
+ _vm.OnStorageItemDoubleClicked(gridStorageItems.SelectedItem as StorageItem);
}
}
}