diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-24 18:31:31 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-24 18:31:31 +0200 |
| commit | 912e8423fbf63a025dac977d5749e60d4c57df68 (patch) | |
| tree | f7bf2901f49cc2d970a8e5c2fb79069b03798ae2 /Software | |
| parent | 74090438f4bbd60ad561c35b63b351a54014e4d2 (diff) | |
| download | Tango-912e8423fbf63a025dac977d5749e60d4c57df68.tar.gz Tango-912e8423fbf63a025dac977d5749e60d4c57df68.zip | |
Working on storage.
Diffstat (limited to 'Software')
10 files changed, 131 insertions, 40 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/FileSystemControl.xaml b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/FileSystemControl.xaml index fcea26001..eb1007609 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/FileSystemControl.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Controls/FileSystemControl.xaml @@ -93,7 +93,7 @@ </Border.ContextMenu> <Grid Background="Transparent"> - <ListBox x:Name="PART_listbox" IsTextSearchEnabled="True" TextSearch.TextPath="Name" Background="Transparent" SelectionMode="Extended" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentItem.Items}" SelectedItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SelectedItem,Mode=TwoWay}"> + <ListBox x:Name="PART_listbox" IsTextSearchEnabled="True" TextSearch.TextPath="Name" Background="Transparent" SelectionMode="{TemplateBinding SelectionMode}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentItem.Items}" SelectedItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SelectedItem,Mode=TwoWay}"> <ListBox.Style> <Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}"> <Setter Property="Visibility" Value="Collapsed"></Setter> @@ -164,7 +164,7 @@ </Style.Triggers> </Style> </Grid.Style> - <local:FileSystemDataGrid x:Name="PART_datagrid" IsTextSearchEnabled="True" TextSearch.TextPath="Name" ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentItem.Items}" CellStyle="{StaticResource FileSystemCellStyle}"> + <local:FileSystemDataGrid x:Name="PART_datagrid" IsTextSearchEnabled="True" TextSearch.TextPath="Name" ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentItem.Items}" SelectedItem="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SelectedItem,Mode=TwoWay}" CellStyle="{StaticResource FileSystemCellStyle}"> <DataGrid.Style> <Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}"> <Setter Property="Background" Value="Transparent"></Setter> @@ -176,13 +176,18 @@ <Setter Property="CanUserResizeRows" Value="False"></Setter> <Setter Property="CanUserSortColumns" Value="True"></Setter> <Setter Property="IsReadOnly" Value="True"></Setter> - <Setter Property="SelectionMode" Value="Extended"></Setter> <Setter Property="SelectionUnit" Value="FullRow"></Setter> + <Setter Property="SelectionMode" Value="Extended"></Setter> <Setter Property="RowHeight" Value="30"></Setter> <Setter Property="HorizontalGridLinesBrush" Value="Transparent"></Setter> <Setter Property="VerticalGridLinesBrush" Value="Transparent"></Setter> <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"></Setter> <Setter Property="CellStyle" Value="{StaticResource FileSystemCellStyle}" /> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SelectionMode}" Value="Single"> + <Setter Property="SelectionMode" Value="Single"></Setter> + </DataTrigger> + </Style.Triggers> </Style> </DataGrid.Style> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/IStorageProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/IStorageProvider.cs index 00ec312a5..602e6057c 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/IStorageProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/IStorageProvider.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Controls; using Tango.Core.Commands; using Tango.FileSystem; @@ -19,6 +20,10 @@ namespace Tango.FSE.Common.Storage FileSystemItem CurrentItem { get; set; } String CurrentPath { get; set; } ObservableCollection<FileSystemItem> SelectedItems { get; set; } + FileSystemItem SelectedItem { get; set; } + SelectionMode SelectionMode { get; set; } + StorageMode StorageMode { get; set; } + String Filter { get; set; } List<DriveItem> Drives { get; } RelayCommand OKCommand { get; } RelayCommand CancelCommand { get; } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/StorageMode.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/StorageMode.cs new file mode 100644 index 000000000..d2d519b84 --- /dev/null +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Storage/StorageMode.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Common.Storage +{ + public enum StorageMode + { + OpenFile, + OpenFiles, + SaveFile, + SelectFolder, + } +} 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 8c4165245..ce56e7f69 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 @@ -144,6 +144,7 @@ <Compile Include="Storage\IStorageResult.cs" /> <Compile Include="Storage\SingleStorageResult.cs" /> <Compile Include="Storage\MultiStorageResult.cs" /> + <Compile Include="Storage\StorageMode.cs" /> <Compile Include="SystemInfo\ISystemInfoProvider.cs" /> <Compile Include="Threading\IDispatcherProvider.cs" /> <Page Include="App.xaml"> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Storage/DefaultStorageProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Storage/DefaultStorageProvider.cs index c37400cf6..9a40888a3 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Storage/DefaultStorageProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Storage/DefaultStorageProvider.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Controls; using System.Windows.Input; using Tango.Core; using Tango.Core.Commands; @@ -65,6 +66,8 @@ namespace Tango.FSE.UI.Storage set { _currentPath = value; RaisePropertyChangedAuto(); } } + public String Filter { get; set; } = "*.*"; + private bool _isBusy; public bool IsBusy { @@ -81,6 +84,27 @@ namespace Tango.FSE.UI.Storage public ObservableCollection<FileSystemItem> SelectedItems { get; set; } + private FileSystemItem _selectedItem; + public FileSystemItem SelectedItem + { + get { return _selectedItem; } + set { _selectedItem = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private SelectionMode _selectionMode; + public SelectionMode SelectionMode + { + get { return _selectionMode; } + set { _selectionMode = value; RaisePropertyChangedAuto(); } + } + + private StorageMode _storageMode; + public StorageMode StorageMode + { + get { return _storageMode; } + set { _storageMode = value; RaisePropertyChangedAuto(); } + } + public RelayCommand OKCommand { get; } public RelayCommand CancelCommand { get; } public RelayCommand BackCommand { get; set; } @@ -99,7 +123,7 @@ namespace Tango.FSE.UI.Storage BackCommand = new RelayCommand(NavigateBack, () => !(CurrentItem is FolderItem) || !(CurrentItem as FolderItem).IsRoot); NavigateSpecialFolderCommand = new RelayCommand<string>(NavigateToSpecialFolder); NavigateToFolderCommand = new RelayCommand<string>(async (x) => await Navigate(x)); - OKCommand = new RelayCommand(OnAccept); + OKCommand = new RelayCommand(OnAccept, CanOK); CancelCommand = new RelayCommand(OnCancel); } @@ -152,7 +176,11 @@ namespace Tango.FSE.UI.Storage var root = await _manager.GetFolder(String.Empty); Drives = (root as IFileSystemContainer).Items.Cast<DriveItem>().ToList(); - CurrentItem = await _manager.GetFolder(Environment.CurrentDirectory); + StorageMode = StorageMode.SelectFolder; + SelectionMode = SelectionMode.Single; + + await Navigate(Environment.CurrentDirectory); + IsOpened = true; _okCompletionAction = () => @@ -160,7 +188,7 @@ namespace Tango.FSE.UI.Storage SingleStorageResult result = new SingleStorageResult() { Confirmed = true, - SelectedItem = SelectedItems.First().Path, + SelectedItem = CurrentItem.Path, }; _completionSource.SetResult(result); @@ -237,15 +265,15 @@ namespace Tango.FSE.UI.Storage if (path != null) { - CurrentItem = await _manager.GetFolder(path) as FileSystemItem; + CurrentItem = await _manager.GetFolder(path, StorageMode == StorageMode.SelectFolder, Filter) as FileSystemItem; } else if (specialFolder != null) { - CurrentItem = await _manager.GetFolder(specialFolder.Value) as FileSystemItem; + CurrentItem = await _manager.GetFolder(specialFolder.Value, StorageMode == StorageMode.SelectFolder, Filter) as FileSystemItem; } else { - CurrentItem = await _manager.GetFolder(String.Empty) as FileSystemItem; + CurrentItem = await _manager.GetFolder(String.Empty, StorageMode == StorageMode.SelectFolder, Filter) as FileSystemItem; } } catch (Exception ex) @@ -267,6 +295,16 @@ namespace Tango.FSE.UI.Storage InvalidateRelayCommands(); } + private bool CanOK() + { + if (StorageMode == StorageMode.SelectFolder && CurrentItem.Type == FileSystemItemType.Drive) + { + return false; + } + + return true; + } + #endregion #region Native diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/ViewModels/LoginViewVM.cs index 8b14ac69e..8622daab2 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/ViewModels/LoginViewVM.cs @@ -131,9 +131,9 @@ namespace Tango.FSE.UI.ViewModels try { - //var s = await StorageProvider.SelectFolder("Select download destination folder"); + var s = await StorageProvider.SelectFolder("Select download destination folder"); - //return; + return; if (!Validate()) { diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Views/MainView.xaml b/Software/Visual_Studio/FSE/Tango.FSE.UI/Views/MainView.xaml index 6a386947f..6941b830a 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Views/MainView.xaml @@ -233,7 +233,7 @@ <Grid DockPanel.Dock="Bottom"> <Border Background="{StaticResource FSE_PrimaryBackgroundBrush}" CornerRadius="0 0 5 5" Padding="10"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> - <Button Height="40" MinWidth="150" Margin="0 0 5 0" Style="{StaticResource FSE_RaisedButton_Dark_Hover}" Command="{Binding StorageProvider.CancelCommand}" Visibility="{Binding DataContext.CanClose,Converter={StaticResource BooleanToVisibilityConverter}}">CANCEL</Button> + <Button Height="40" MinWidth="150" Margin="0 0 5 0" Style="{StaticResource FSE_RaisedButton_Dark_Hover}" Command="{Binding StorageProvider.CancelCommand}">CANCEL</Button> <Button Height="40" MinWidth="150" Style="{StaticResource FSE_RaisedButton_Dark_Hover}" Command="{Binding StorageProvider.OKCommand}">OK</Button> </StackPanel> </Border> @@ -341,6 +341,8 @@ Mode="{Binding ElementName=listView,Path=SelectedItem.Tag}" CurrentItem="{Binding StorageProvider.CurrentItem,Mode=TwoWay}" SelectedItems="{Binding StorageProvider.SelectedItems}" + SelectedItem="{Binding StorageProvider.SelectedItem}" + SelectionMode="{Binding StorageProvider.SelectionMode}" BackCommand="{Binding StorageProvider.BackCommand}" ItemDoubleClickedCommand="{Binding StorageProvider.OpenCommand}" OpenCommand="{Binding StorageProvider.OpenCommand}"/> diff --git a/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs b/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs index 60061780b..c624178a0 100644 --- a/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs +++ b/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs @@ -265,6 +265,15 @@ namespace Tango.FileSystem public static readonly DependencyProperty AllowDragProperty = DependencyProperty.Register("AllowDrag", typeof(bool), typeof(FileExplorerControl), new PropertyMetadata(null)); + public SelectionMode SelectionMode + { + get { return (SelectionMode)GetValue(SelectionModeProperty); } + set { SetValue(SelectionModeProperty, value); } + } + public static readonly DependencyProperty SelectionModeProperty = + DependencyProperty.Register("SelectionMode", typeof(SelectionMode), typeof(FileExplorerControl), new PropertyMetadata(SelectionMode.Extended)); + + static FileExplorerControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(FileExplorerControl), new FrameworkPropertyMetadata(typeof(FileExplorerControl))); @@ -492,39 +501,45 @@ namespace Tango.FileSystem private void _datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (!_preventSynchronization) + if (SelectionMode == SelectionMode.Extended) { - _preventSynchronization = true; + if (!_preventSynchronization) + { + _preventSynchronization = true; - _listBox.SelectedItems.Clear(); + _listBox.SelectedItems.Clear(); - foreach (var item in _datagrid.SelectedItems) - { - _listBox.SelectedItems.Add(item); - } + foreach (var item in _datagrid.SelectedItems) + { + _listBox.SelectedItems.Add(item); + } - SynchronizeSelectedItems(_listBox.SelectedItems); + SynchronizeSelectedItems(_listBox.SelectedItems); - _preventSynchronization = false; + _preventSynchronization = false; + } } } private void _listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (!_preventSynchronization) + if (SelectionMode == SelectionMode.Extended) { - _preventSynchronization = true; + if (!_preventSynchronization) + { + _preventSynchronization = true; - _datagrid.SelectedItems.Clear(); + _datagrid.SelectedItems.Clear(); - foreach (var item in _listBox.SelectedItems) - { - _datagrid.SelectedItems.Add(item); - } + foreach (var item in _listBox.SelectedItems) + { + _datagrid.SelectedItems.Add(item); + } - SynchronizeSelectedItems(_listBox.SelectedItems); + SynchronizeSelectedItems(_listBox.SelectedItems); - _preventSynchronization = false; + _preventSynchronization = false; + } } } diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs index c18df97c9..f72785f81 100644 --- a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs +++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs @@ -73,15 +73,18 @@ namespace Tango.FileSystem }); } - foreach (var file in Directory.GetFiles(request.Path)) + if (!request.FoldersOnly) { - items.Add(new FileSystemItemDTO() + foreach (var file in Directory.GetFiles(request.Path, request.Filter != null ? request.Filter : "*.*")) { - Path = file, - Type = FileSystemItemType.File, - DateModified = File.GetLastWriteTimeUtc(file), - Size = new FileInfo(file).Length - }); + items.Add(new FileSystemItemDTO() + { + Path = file, + Type = FileSystemItemType.File, + DateModified = File.GetLastWriteTimeUtc(file), + Size = new FileInfo(file).Length + }); + } } return new FileSystemItemDTO() @@ -92,24 +95,28 @@ namespace Tango.FileSystem }; } - public Task<FileSystemItem> GetFolder(String path) + public Task<FileSystemItem> GetFolder(String path, bool foldersOnly = false, String filter = "*.*") { return Task.Factory.StartNew<FileSystemItem>(() => { return FileSystemItem.FromDTO(GetFolder(new GetFileSystemItemRequest() { Path = path, + FoldersOnly = foldersOnly, + Filter = filter, })); }); } - public Task<FileSystemItem> GetFolder(Environment.SpecialFolder specialFolder) + public Task<FileSystemItem> GetFolder(Environment.SpecialFolder specialFolder, bool foldersOnly = false, String filter = "*.*") { return Task.Factory.StartNew<FileSystemItem>(() => { return FileSystemItem.FromDTO(GetFolder(new GetFileSystemItemRequest() { - SpecialFolder = specialFolder + SpecialFolder = specialFolder, + FoldersOnly = foldersOnly, + Filter = filter, })); }); } diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/GetFileSystemItemRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/GetFileSystemItemRequest.cs index 1ed6c19e4..3cf91e869 100644 --- a/Software/Visual_Studio/Tango.FileSystem/Network/GetFileSystemItemRequest.cs +++ b/Software/Visual_Studio/Tango.FileSystem/Network/GetFileSystemItemRequest.cs @@ -11,5 +11,7 @@ namespace Tango.FileSystem.Network { public String Path { get; set; } public SpecialFolder? SpecialFolder { get; set; } + public bool FoldersOnly { get; set; } + public String Filter { get; set; } = "*.*"; } } |
