aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.FileSystem
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
committerAvi Levkovich <avi@twine-s.com>2020-03-25 17:46:56 +0200
commitaa732a33f7c63ce4438ec2b79fedb641ffd22b05 (patch)
tree86ccf57c1dfb6801de16f15d681539c02b007508 /Software/Visual_Studio/Tango.FileSystem
parentd29da53d6f71f45749c0ede5b4cd7281ed3a270e (diff)
parent8f57d4962fa84499c8a153ebfff6e7766434ee1c (diff)
downloadTango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.tar.gz
Tango-aa732a33f7c63ce4438ec2b79fedb641ffd22b05.zip
merge conflicts -take remote
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem')
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs476
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs10
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs106
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/CopyRequest.cs14
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/CopyResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderRequest.cs14
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderResponse.cs13
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/DeleteRequest.cs13
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/DeleteResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/GetFileSystemItemRequest.cs2
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcRequest.cs13
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/MoveRequest.cs14
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Network/MoveResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Tango.FileSystem.csproj10
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/Themes/Generic.xaml17
16 files changed, 710 insertions, 40 deletions
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs b/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs
index 23cac7733..3660a18f0 100644
--- a/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs
+++ b/Software/Visual_Studio/Tango.FileSystem/FileExplorerControl.cs
@@ -16,6 +16,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Tango.Core.Commands;
using Tango.Core.IO;
namespace Tango.FileSystem
@@ -28,6 +29,41 @@ namespace Tango.FileSystem
private Point _dragOutStartPoint;
private bool _isMouseDown;
private List<FileSystemItem> _selectedItemsBeforeDrag;
+ private List<FileSystemItem> _copyItems;
+ private bool _isCut;
+ private bool _isAfterContextMenu;
+
+ #region IsCut Attached Property
+
+ /// <summary>
+ /// Determines whether the draggable element is currently being dragged.
+ /// </summary>
+ public static readonly DependencyProperty IsCutProperty =
+ DependencyProperty.RegisterAttached("IsCut",
+ typeof(bool), typeof(FileExplorerControl),
+ new FrameworkPropertyMetadata(false));
+
+ /// <summary>
+ /// Sets the IsCut attached property.
+ /// </summary>
+ /// <param name="element">The element.</param>
+ /// <param name="value">if set to <c>true</c> [value].</param>
+ public static void SetIsCut(FrameworkElement element, bool value)
+ {
+ element.SetValue(IsCutProperty, value);
+ }
+
+ /// <summary>
+ /// Gets the is dragging attached property.
+ /// </summary>
+ /// <param name="element">The element.</param>
+ /// <returns></returns>
+ public static bool GetIsCut(FrameworkElement element)
+ {
+ return (bool)element.GetValue(IsCutProperty);
+ }
+
+ #endregion
public IFileSystemContainer CurrentItem
{
@@ -35,7 +71,7 @@ namespace Tango.FileSystem
set { SetValue(CurrentItemProperty, value); }
}
public static readonly DependencyProperty CurrentItemProperty =
- DependencyProperty.Register("CurrentItem", typeof(IFileSystemContainer), typeof(FileExplorerControl), new PropertyMetadata(null));
+ DependencyProperty.Register("CurrentItem", typeof(IFileSystemContainer), typeof(FileExplorerControl), new PropertyMetadata(null, (d, e) => (d as FileExplorerControl).OnCurrentItemChanged()));
public FileSystemItem SelectedItem
{
@@ -61,6 +97,30 @@ namespace Tango.FileSystem
public static readonly DependencyProperty DeleteCommandProperty =
DependencyProperty.Register("DeleteCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+ public ICommand DeleteCommandInternal
+ {
+ get { return (ICommand)GetValue(DeleteCommandInternalProperty); }
+ set { SetValue(DeleteCommandInternalProperty, value); }
+ }
+ public static readonly DependencyProperty DeleteCommandInternalProperty =
+ DependencyProperty.Register("DeleteCommandInternal", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand NewFolderCommandInternal
+ {
+ get { return (ICommand)GetValue(NewFolderCommandInternalProperty); }
+ set { SetValue(NewFolderCommandInternalProperty, value); }
+ }
+ public static readonly DependencyProperty NewFolderCommandInternalProperty =
+ DependencyProperty.Register("NewFolderCommandInternal", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand NewFolderCommand
+ {
+ get { return (ICommand)GetValue(NewFolderCommandProperty); }
+ set { SetValue(NewFolderCommandProperty, value); }
+ }
+ public static readonly DependencyProperty NewFolderCommandProperty =
+ DependencyProperty.Register("NewFolderCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
public ICommand DropCommand
{
get { return (ICommand)GetValue(DropCommandProperty); }
@@ -77,6 +137,110 @@ namespace Tango.FileSystem
public static readonly DependencyProperty DragCommandProperty =
DependencyProperty.Register("DragCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+ public ICommand CopyCommand
+ {
+ get { return (ICommand)GetValue(CopyCommandProperty); }
+ set { SetValue(CopyCommandProperty, value); }
+ }
+ public static readonly DependencyProperty CopyCommandProperty =
+ DependencyProperty.Register("CopyCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand CutCommand
+ {
+ get { return (ICommand)GetValue(CutCommandProperty); }
+ set { SetValue(CutCommandProperty, value); }
+ }
+ public static readonly DependencyProperty CutCommandProperty =
+ DependencyProperty.Register("CutCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand CopyPasteCommand
+ {
+ get { return (ICommand)GetValue(CopyPasteCommandProperty); }
+ set { SetValue(CopyPasteCommandProperty, value); }
+ }
+ public static readonly DependencyProperty CopyPasteCommandProperty =
+ DependencyProperty.Register("CopyPasteCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand CutPasteCommand
+ {
+ get { return (ICommand)GetValue(CutPasteCommandProperty); }
+ set { SetValue(CutPasteCommandProperty, value); }
+ }
+ public static readonly DependencyProperty CutPasteCommandProperty =
+ DependencyProperty.Register("CutPasteCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand PasteCommandInternal
+ {
+ get { return (ICommand)GetValue(PasteCommandInternalProperty); }
+ set { SetValue(PasteCommandInternalProperty, value); }
+ }
+ public static readonly DependencyProperty PasteCommandInternalProperty =
+ DependencyProperty.Register("PasteCommandInternal", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand SelectAllCommand
+ {
+ get { return (ICommand)GetValue(SelectAllCommandProperty); }
+ set { SetValue(SelectAllCommandProperty, value); }
+ }
+ public static readonly DependencyProperty SelectAllCommandProperty =
+ DependencyProperty.Register("SelectAllCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand DownloadCommandInternal
+ {
+ get { return (ICommand)GetValue(DownloadCommandInternalProperty); }
+ set { SetValue(DownloadCommandInternalProperty, value); }
+ }
+ public static readonly DependencyProperty DownloadCommandInternalProperty =
+ DependencyProperty.Register("DownloadCommandInternal", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand DownloadCommand
+ {
+ get { return (ICommand)GetValue(DownloadCommandProperty); }
+ set { SetValue(DownloadCommandProperty, value); }
+ }
+ public static readonly DependencyProperty DownloadCommandProperty =
+ DependencyProperty.Register("DownloadCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand OpenCommand
+ {
+ get { return (ICommand)GetValue(OpenCommandProperty); }
+ set { SetValue(OpenCommandProperty, value); }
+ }
+ public static readonly DependencyProperty OpenCommandProperty =
+ DependencyProperty.Register("OpenCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand BackCommand
+ {
+ get { return (ICommand)GetValue(BackCommandProperty); }
+ set { SetValue(BackCommandProperty, value); }
+ }
+ public static readonly DependencyProperty BackCommandProperty =
+ DependencyProperty.Register("BackCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand RenameCommand
+ {
+ get { return (ICommand)GetValue(RenameCommandProperty); }
+ set { SetValue(RenameCommandProperty, value); }
+ }
+ public static readonly DependencyProperty RenameCommandProperty =
+ DependencyProperty.Register("RenameCommand", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public ICommand RenameCommandInternal
+ {
+ get { return (ICommand)GetValue(RenameCommandInternalProperty); }
+ set { SetValue(RenameCommandInternalProperty, value); }
+ }
+ public static readonly DependencyProperty RenameCommandInternalProperty =
+ DependencyProperty.Register("RenameCommandInternal", typeof(ICommand), typeof(FileExplorerControl), new PropertyMetadata(null));
+
+ public bool IsContextMenuOpened
+ {
+ get { return (bool)GetValue(IsContextMenuOpenedProperty); }
+ set { SetValue(IsContextMenuOpenedProperty, value); }
+ }
+ public static readonly DependencyProperty IsContextMenuOpenedProperty =
+ DependencyProperty.Register("IsContextMenuOpened", typeof(bool), typeof(FileExplorerControl), new PropertyMetadata(false, (d, e) => (d as FileExplorerControl).OnIsContextMenuOpenedChanged()));
+
public ImageSource DriveIcon
{
get { return (ImageSource)GetValue(DriveIconProperty); }
@@ -117,6 +281,14 @@ 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)));
@@ -124,7 +296,161 @@ namespace Tango.FileSystem
public FileExplorerControl()
{
+ Focusable = true;
+
+ _copyItems = new List<FileSystemItem>();
_selectedItemsBeforeDrag = new List<FileSystemItem>();
+
+ CopyCommand = new RelayCommand(() =>
+ {
+ ResetItemsCut();
+ _copyItems.Clear();
+ _copyItems.AddRange(SelectedItems.ToList());
+ _isCut = false;
+ }, () => SelectedItems != null && SelectedItems.Count > 0);
+
+ CutCommand = new RelayCommand(() =>
+ {
+ _copyItems.Clear();
+ _copyItems.AddRange(SelectedItems.ToList());
+ CutSelectedItems();
+ _isCut = true;
+
+ }, () => SelectedItems != null && SelectedItems.Count > 0);
+
+ PasteCommandInternal = new RelayCommand(() =>
+ {
+ if (_isCut)
+ {
+ CutPasteCommand?.Execute(_copyItems.ToList());
+ }
+ else
+ {
+ CopyPasteCommand?.Execute(_copyItems.ToList());
+ }
+
+ ResetItemsCut();
+ _copyItems.Clear();
+ }, () => _copyItems.Count > 0);
+
+ SelectAllCommand = new RelayCommand(() =>
+ {
+ ResetItemsCut();
+ _copyItems.Clear();
+ SelectedItems.Clear();
+
+ if (CurrentItem != null)
+ {
+ foreach (var item in CurrentItem.Items)
+ {
+ SelectedItems.Add(item);
+ }
+ }
+ });
+
+ DownloadCommandInternal = new RelayCommand(() =>
+ {
+
+ DownloadCommand?.Execute(SelectedItems.ToList());
+
+ }, () => SelectedItems != null && SelectedItems.Count > 0 && SelectedItems.All(x => x.Type != FileSystemItemType.Drive));
+
+ OpenCommand = new RelayCommand(() =>
+ {
+ ItemDoubleClickedCommand?.Execute(SelectedItems.FirstOrDefault());
+ }, () =>
+ {
+ return SelectedItems != null && SelectedItems.Count == 1;
+ });
+
+ DeleteCommandInternal = new RelayCommand(() =>
+ {
+
+ DeleteCommand?.Execute(SelectedItems.ToList());
+
+ }, () => SelectedItems != null && SelectedItems.Count > 0 && SelectedItems.All(x => x.Type != FileSystemItemType.Drive));
+
+ RenameCommandInternal = new RelayCommand(() =>
+ {
+
+ RenameCommand?.Execute(SelectedItems.FirstOrDefault());
+
+ }, () => SelectedItems != null && SelectedItems.Count == 1 && SelectedItems.All(x => x.Type != FileSystemItemType.Drive));
+
+ NewFolderCommandInternal = new RelayCommand(() =>
+ {
+ NewFolderCommand?.Execute(null);
+ },
+ () =>
+ {
+ if (CurrentItem == null) return false;
+
+ if (CurrentItem is FolderItem)
+ {
+ if ((CurrentItem as FolderItem).IsRoot)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ });
+ }
+
+ private void OnIsContextMenuOpenedChanged()
+ {
+ _isMouseDown = false;
+ (PasteCommandInternal as RelayCommand)?.RaiseCanExecuteChanged();
+ (CutCommand as RelayCommand)?.RaiseCanExecuteChanged();
+ (CopyCommand as RelayCommand)?.RaiseCanExecuteChanged();
+ (DownloadCommandInternal as RelayCommand)?.RaiseCanExecuteChanged();
+ (OpenCommand as RelayCommand)?.RaiseCanExecuteChanged();
+ (DeleteCommandInternal as RelayCommand)?.RaiseCanExecuteChanged();
+ (RenameCommandInternal as RelayCommand)?.RaiseCanExecuteChanged();
+ (NewFolderCommandInternal as RelayCommand)?.RaiseCanExecuteChanged();
+
+ if (IsContextMenuOpened)
+ {
+ _isAfterContextMenu = true;
+ }
+ }
+
+ private void ResetItemsCut()
+ {
+ foreach (var item in _listBox.Items)
+ {
+ var element = _listBox.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
+ if (element != null)
+ {
+ SetIsCut(element, false);
+ }
+
+ element = _datagrid.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
+ if (element != null)
+ {
+ SetIsCut(element, false);
+ }
+ }
+ }
+
+ private void CutSelectedItems()
+ {
+ ResetItemsCut();
+
+ foreach (var item in SelectedItems.ToList())
+ {
+ var element = _listBox.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
+ if (element != null)
+ {
+ SetIsCut(element, true);
+ }
+
+ element = _datagrid.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
+ if (element != null)
+ {
+ SetIsCut(element, true);
+ }
+ }
}
public override void OnApplyTemplate()
@@ -138,54 +464,127 @@ namespace Tango.FileSystem
_datagrid.SelectionChanged += _datagrid_SelectionChanged;
}
- protected override void OnPreviewKeyUp(KeyEventArgs e)
+ protected override void OnPreviewKeyDown(KeyEventArgs e)
{
- base.OnPreviewKeyUp(e);
+ base.OnPreviewKeyDown(e);
if (e.Key == Key.Delete)
{
- if (SelectedItems != null && SelectedItems.Count > 0)
+ if (DeleteCommandInternal != null && DeleteCommandInternal.CanExecute(null))
+ {
+ DeleteCommandInternal?.Execute(null);
+ }
+ }
+ else if (e.Key == Key.Return)
+ {
+ if (OpenCommand != null && OpenCommand.CanExecute(null))
+ {
+ OpenCommand?.Execute(null);
+ }
+ }
+ else if (e.Key == Key.C && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (CopyCommand != null && CopyCommand.CanExecute(null))
+ {
+ CopyCommand.Execute(null);
+ }
+ }
+ else if (e.Key == Key.X && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (CutCommand != null && CutCommand.CanExecute(null))
+ {
+ CutCommand.Execute(null);
+ }
+ }
+ else if (e.Key == Key.V && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (PasteCommandInternal != null && PasteCommandInternal.CanExecute(null))
{
- DeleteCommand?.Execute(SelectedItems);
+ PasteCommandInternal.Execute(null);
}
}
+ else if (e.Key == Key.A && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (SelectAllCommand != null && SelectAllCommand.CanExecute(null))
+ {
+ SelectAllCommand.Execute(null);
+ }
+ }
+ else if (e.Key == Key.D && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (DownloadCommandInternal != null && DownloadCommandInternal.CanExecute(null))
+ {
+ DownloadCommandInternal.Execute(null);
+ }
+ }
+ else if (e.Key == Key.N && Keyboard.IsKeyDown(Key.LeftCtrl))
+ {
+ if (NewFolderCommandInternal != null && NewFolderCommandInternal.CanExecute(null))
+ {
+ DownloadCommandInternal.Execute(null);
+ }
+ }
+ else if (e.Key == Key.F2)
+ {
+ if (RenameCommandInternal != null && RenameCommandInternal.CanExecute(null))
+ {
+ RenameCommandInternal.Execute(null);
+ }
+ }
+ else if (e.Key == Key.Down)
+ {
+ if (SelectedItems != null && SelectedItems.Count == 0 && CurrentItem != null && CurrentItem.Items.Count > 0)
+ {
+ SelectedItems.Add(CurrentItem.Items.FirstOrDefault());
+ }
+ }
+ else if (e.Key == Key.Back)
+ {
+ BackCommand?.Execute(null);
+ }
}
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;
+ }
}
}
@@ -279,6 +678,12 @@ namespace Tango.FileSystem
{
base.OnPreviewMouseLeftButtonDown(e);
+ if (_isAfterContextMenu)
+ {
+ _isAfterContextMenu = false;
+ return;
+ }
+
if (!AllowDrag) return;
if (e.OriginalSource is FrameworkElement)
@@ -309,7 +714,7 @@ namespace Tango.FileSystem
{
base.OnPreviewMouseMove(e);
- if (_isMouseDown)
+ if (_isMouseDown && !IsContextMenuOpened)
{
Point mpos = e.GetPosition(null);
Vector diff = this._dragOutStartPoint - mpos;
@@ -375,7 +780,7 @@ namespace Tango.FileSystem
}
//Notify to user with all items!
- Dispatcher.BeginInvoke(new Action(() =>
+ Dispatcher.BeginInvoke(new Action(() =>
{
DragCommand?.Execute(notifyItems);
}));
@@ -400,7 +805,16 @@ namespace Tango.FileSystem
}
string[] files = dropItems.Select(x => x.Item2.Path).ToArray();
- var ef = DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, files, false), DragDropEffects.Copy);
+
+ try
+ {
+ var ef = DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, files, false), DragDropEffects.Copy);
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ Debugger.Break();
+ }
await Task.Delay(3000);
@@ -419,5 +833,15 @@ namespace Tango.FileSystem
}
}
}
+
+ private async void OnCurrentItemChanged()
+ {
+ if (IsVisible)
+ {
+ await Task.Delay(100);
+ this.Focus();
+ Keyboard.Focus(this);
+ }
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs
index 536409f63..c8b2fce32 100644
--- a/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs
+++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemItem.cs
@@ -5,13 +5,19 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
+using Tango.Core;
using Tango.FileSystem.Network;
namespace Tango.FileSystem
{
- public abstract class FileSystemItem
+ public abstract class FileSystemItem : ExtendedObject
{
- public String Path { get; set; }
+ private String _path;
+ public String Path
+ {
+ get { return _path; }
+ set { _path = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(Name)); }
+ }
public FileSystemItemType Type { get; protected set; }
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
index 44c8f1901..46ca080a2 100644
--- a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
+++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Tango.Core.Helpers;
using Tango.FileSystem.Network;
namespace Tango.FileSystem
@@ -72,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()
@@ -91,6 +95,32 @@ namespace Tango.FileSystem
};
}
+ 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, bool foldersOnly = false, String filter = "*.*")
+ {
+ return Task.Factory.StartNew<FileSystemItem>(() =>
+ {
+ return FileSystemItem.FromDTO(GetFolder(new GetFileSystemItemRequest()
+ {
+ SpecialFolder = specialFolder,
+ FoldersOnly = foldersOnly,
+ Filter = filter,
+ }));
+ });
+ }
+
public void Delete(String path)
{
if (Directory.Exists(path))
@@ -106,5 +136,67 @@ namespace Tango.FileSystem
throw new FileNotFoundException("Could not locate the specified file or directory.");
}
}
+
+ public void Move(MoveRequest request)
+ {
+ if (Directory.Exists(request.Destination))
+ {
+ throw new IOException($"'{Path.GetFileName(request.Destination)}' already exists on the target folder.");
+ }
+
+ if (File.Exists(request.Source))
+ {
+ File.Move(request.Source, request.Destination);
+ }
+ else if (Directory.Exists(request.Source))
+ {
+ Directory.Move(request.Source, request.Destination);
+ }
+ else
+ {
+ throw new FileNotFoundException("Could not locate the source file or folder.");
+ }
+ }
+
+ public void Copy(CopyRequest request)
+ {
+ if (File.Exists(request.Source))
+ {
+ if (request.Source == request.Destination)
+ {
+ while (File.Exists(request.Destination))
+ {
+ request.Destination = Path.Combine(Path.GetDirectoryName(request.Destination), Path.GetFileNameWithoutExtension(request.Destination)) + " copy" + Path.GetExtension(request.Destination);
+ }
+ }
+ File.Copy(request.Source, request.Destination, true);
+ }
+ else if (Directory.Exists(request.Source))
+ {
+ Directory.CreateDirectory(Path.GetDirectoryName(request.Destination));
+ PathHelper.CopyDirectory(request.Source, request.Destination, true);
+ }
+ else
+ {
+ throw new FileNotFoundException("Could not locate the source file or folder.");
+ }
+ }
+
+ public FileSystemItemDTO CreateFolder(String path, String folderName)
+ {
+ String fullPath = Path.Combine(path, folderName);
+
+ if (Directory.Exists(fullPath))
+ {
+ throw new IOException("The specified directory name already exists.");
+ }
+
+ Directory.CreateDirectory(fullPath);
+
+ return GetFolder(new GetFileSystemItemRequest()
+ {
+ Path = fullPath
+ });
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/CopyRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/CopyRequest.cs
new file mode 100644
index 000000000..2e7b8a406
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/CopyRequest.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class CopyRequest
+ {
+ public String Source { get; set; }
+ public String Destination { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/CopyResponse.cs b/Software/Visual_Studio/Tango.FileSystem/Network/CopyResponse.cs
new file mode 100644
index 000000000..e22ce6542
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/CopyResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class CopyResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderRequest.cs
new file mode 100644
index 000000000..77452dcdf
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderRequest.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class CreateFolderRequest
+ {
+ public String Path { get; set; }
+ public String FolderName { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderResponse.cs b/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderResponse.cs
new file mode 100644
index 000000000..d52e52c47
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/CreateFolderResponse.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class CreateFolderResponse
+ {
+ public FileSystemItemDTO FolderItem { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/DeleteRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/DeleteRequest.cs
new file mode 100644
index 000000000..300acdb09
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/DeleteRequest.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class DeleteRequest
+ {
+ public String Path { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/DeleteResponse.cs b/Software/Visual_Studio/Tango.FileSystem/Network/DeleteResponse.cs
new file mode 100644
index 000000000..37afdab0b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/DeleteResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class DeleteResponse
+ {
+ }
+}
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; } = "*.*";
}
}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcRequest.cs
new file mode 100644
index 000000000..5d8f1eb3a
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcRequest.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class InitWebRtcRequest
+ {
+ public String DataChannelName { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcResponse.cs b/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcResponse.cs
new file mode 100644
index 000000000..3425a9096
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/InitWebRtcResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class InitWebRtcResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/MoveRequest.cs b/Software/Visual_Studio/Tango.FileSystem/Network/MoveRequest.cs
new file mode 100644
index 000000000..0d9f593d3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/MoveRequest.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class MoveRequest
+ {
+ public String Source { get; set; }
+ public String Destination { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Network/MoveResponse.cs b/Software/Visual_Studio/Tango.FileSystem/Network/MoveResponse.cs
new file mode 100644
index 000000000..05d78c573
--- /dev/null
+++ b/Software/Visual_Studio/Tango.FileSystem/Network/MoveResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.FileSystem.Network
+{
+ public class MoveResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.FileSystem/Tango.FileSystem.csproj b/Software/Visual_Studio/Tango.FileSystem/Tango.FileSystem.csproj
index 733493f02..a31af216c 100644
--- a/Software/Visual_Studio/Tango.FileSystem/Tango.FileSystem.csproj
+++ b/Software/Visual_Studio/Tango.FileSystem/Tango.FileSystem.csproj
@@ -58,6 +58,16 @@
<Compile Include="Network\ChunkUploadResponse.cs" />
<Compile Include="Network\ChunkDownloadRequest.cs" />
<Compile Include="Network\ChunkDownloadResponse.cs" />
+ <Compile Include="Network\CopyRequest.cs" />
+ <Compile Include="Network\CopyResponse.cs" />
+ <Compile Include="Network\CreateFolderRequest.cs" />
+ <Compile Include="Network\CreateFolderResponse.cs" />
+ <Compile Include="Network\DeleteRequest.cs" />
+ <Compile Include="Network\DeleteResponse.cs" />
+ <Compile Include="Network\InitWebRtcRequest.cs" />
+ <Compile Include="Network\InitWebRtcResponse.cs" />
+ <Compile Include="Network\MoveRequest.cs" />
+ <Compile Include="Network\MoveResponse.cs" />
<Compile Include="VirtualFileDataObject.cs" />
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
diff --git a/Software/Visual_Studio/Tango.FileSystem/Themes/Generic.xaml b/Software/Visual_Studio/Tango.FileSystem/Themes/Generic.xaml
index f793be947..9cc27c7c6 100644
--- a/Software/Visual_Studio/Tango.FileSystem/Themes/Generic.xaml
+++ b/Software/Visual_Studio/Tango.FileSystem/Themes/Generic.xaml
@@ -21,6 +21,13 @@
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
+ <ContextMenu x:Key="ItemContextMenu">
+ <MenuItem Header="Copy"/>
+ <MenuItem Header="Paste"/>
+ <MenuItem Header="Delete"/>
+ <MenuItem Header="Select All"/>
+ </ContextMenu>
+
<Style TargetType="{x:Type local:FileExplorerControl}">
<Setter Property="DriveIcon" Value="pack://application:,,,/Tango.FileSystem;component/Images/drive.png"></Setter>
<Setter Property="FolderIcon" Value="pack://application:,,,/Tango.FileSystem;component/Images/folder.png"></Setter>
@@ -34,7 +41,6 @@
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
-
<Grid Background="Transparent">
<ListBox x:Name="PART_listbox" 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.Style>
@@ -51,6 +57,7 @@
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Padding" Value="5"></Setter>
<Setter Property="Margin" Value="10"></Setter>
+ <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
@@ -123,7 +130,7 @@
</DataGrid.Style>
<DataGrid.Columns>
- <DataGridTemplateColumn Header="Name" Width="300*">
+ <DataGridTemplateColumn Header="Name" Width="300*" SortMemberPath="Name">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel Background="Transparent">
@@ -149,7 +156,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
- <DataGridTemplateColumn Header="Date Modified" Width="170*">
+ <DataGridTemplateColumn Header="Date Modified" Width="170*" SortMemberPath="DateModified">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel Background="Transparent">
@@ -158,7 +165,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
- <DataGridTemplateColumn Header="Type" Width="140*">
+ <DataGridTemplateColumn Header="Type" Width="140*" SortMemberPath="Type">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel Background="Transparent">
@@ -167,7 +174,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
- <DataGridTemplateColumn Header="Size" Width="100*">
+ <DataGridTemplateColumn Header="Size" Width="100*" SortMemberPath="Size">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DockPanel Background="Transparent">