FileItem now support work as a selector.
Move To now works.
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
x:Class="Progrart.Controls.FileItem" HorizontalAlignment="Stretch">
|
x:Class="Progrart.Controls.FileItem" HorizontalAlignment="Stretch">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Border Background="#2288EE" Margin="2,5" Width="4" CornerRadius="4" HorizontalAlignment="Left" Name="SelectIndicator" IsVisible="False"/>
|
||||||
<Button Name="MainButton" HorizontalAlignment="Stretch">
|
<Button Name="MainButton" HorizontalAlignment="Stretch">
|
||||||
|
|
||||||
<Button.ContextMenu>
|
<Button.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="_Open" Name="OpenFileMenuItem">
|
<MenuItem Header="_Open" Name="OpenFileMenuItem">
|
||||||
@@ -30,9 +30,9 @@
|
|||||||
<MenuItem Header="_Folder" Name="CreateFolderItem"/>
|
<MenuItem Header="_Folder" Name="CreateFolderItem"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Header="_Copy"/>
|
<MenuItem Header="_Copy To" Name="CopyToMenuItem"/>
|
||||||
<MenuItem Header="Cut (_x)"/>
|
<MenuItem Header="_Move to" Name="MoveToMenuItem"/>
|
||||||
<MenuItem Header="_Paste"/>
|
<!--<MenuItem Header="_Paste"/>-->
|
||||||
<Separator/>
|
<Separator/>
|
||||||
<MenuItem Header="_Delete"/>
|
<MenuItem Header="_Delete"/>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Progrart.Controls.TabSystem;
|
|||||||
using Progrart.Dialogs;
|
using Progrart.Dialogs;
|
||||||
using Progrart.Icons;
|
using Progrart.Icons;
|
||||||
using Progrart.Pages;
|
using Progrart.Pages;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -18,14 +19,23 @@ public partial class FileItem : UserControl
|
|||||||
IStorageItem? currentItem;
|
IStorageItem? currentItem;
|
||||||
bool isOpen = false;
|
bool isOpen = false;
|
||||||
string extension = "";
|
string extension = "";
|
||||||
|
FileItem? root = null;
|
||||||
|
bool isSelectOnly = false;
|
||||||
|
public IStorageItem? CurrentItem => currentItem;
|
||||||
|
public Action<FileItem>? onSelected = null;
|
||||||
public FileItem()
|
public FileItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
public FileItem(IStorageItem storageItem)
|
public FileItem(IStorageItem storageItem, FileItem? RootItem, bool SelectOnly = false)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
this.root = RootItem;
|
||||||
|
isSelectOnly = SelectOnly;
|
||||||
|
if (isSelectOnly)
|
||||||
|
{
|
||||||
|
MainButton.ContextMenu = null;
|
||||||
|
}
|
||||||
currentItem = storageItem;
|
currentItem = storageItem;
|
||||||
if (storageItem is IStorageFolder folder)
|
if (storageItem is IStorageFolder folder)
|
||||||
{
|
{
|
||||||
@@ -63,6 +73,11 @@ public partial class FileItem : UserControl
|
|||||||
IconContainer.IsVisible = true;
|
IconContainer.IsVisible = true;
|
||||||
}
|
}
|
||||||
NameBlock.Text = storageItem.Name;
|
NameBlock.Text = storageItem.Name;
|
||||||
|
if (isSelectOnly)
|
||||||
|
MainButton.Click += (a, b) =>
|
||||||
|
{
|
||||||
|
(root ?? this).SelectFileItem(this);
|
||||||
|
};
|
||||||
MainButton.DoubleTapped += async (_, _) =>
|
MainButton.DoubleTapped += async (_, _) =>
|
||||||
{
|
{
|
||||||
await OpenItem();
|
await OpenItem();
|
||||||
@@ -87,7 +102,7 @@ public partial class FileItem : UserControl
|
|||||||
if (isOpen)
|
if (isOpen)
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
var fitem = new FileItem(fldr);
|
var fitem = new FileItem(fldr, root ?? this, SelectOnly);
|
||||||
ItemContainer.Children.Add(fitem);
|
ItemContainer.Children.Add(fitem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -107,6 +122,8 @@ public partial class FileItem : UserControl
|
|||||||
};
|
};
|
||||||
await DialogHost.Show(content);
|
await DialogHost.Show(content);
|
||||||
};
|
};
|
||||||
|
CopyToMenuItem.Click += CopyToMenuItem_Click;
|
||||||
|
MoveToMenuItem.Click += MoveToMenuItem_Click;
|
||||||
CreateProgrartItem.Click += async (a, b) =>
|
CreateProgrartItem.Click += async (a, b) =>
|
||||||
{
|
{
|
||||||
InputDialog content = new();
|
InputDialog content = new();
|
||||||
@@ -123,7 +140,7 @@ public partial class FileItem : UserControl
|
|||||||
if (isOpen)
|
if (isOpen)
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
var fitem = new FileItem(fldr);
|
var fitem = new FileItem(fldr, root ?? this, SelectOnly);
|
||||||
ItemContainer.Children.Add(fitem);
|
ItemContainer.Children.Add(fitem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -144,6 +161,46 @@ public partial class FileItem : UserControl
|
|||||||
await DialogHost.Show(content);
|
await DialogHost.Show(content);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void MoveToMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var content = new BrowserDialog();
|
||||||
|
content.Title = "";
|
||||||
|
content.onOK = async (si) =>
|
||||||
|
{
|
||||||
|
if (si is IStorageFolder destFolder)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (currentItem is not null)
|
||||||
|
{
|
||||||
|
await currentItem.MoveAsync(destFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
if ((root ?? this).CurrentItem is IStorageItem item)
|
||||||
|
content.SetFileITem(new FileItem(item, null, true));
|
||||||
|
await DialogHost.Show(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void CopyToMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var content = new BrowserDialog();
|
||||||
|
content.onOK = async (si) =>
|
||||||
|
{
|
||||||
|
if (currentItem is IStorageFolder folder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (currentItem is IStorageFile file)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
if ((root ?? this).CurrentItem is IStorageItem item)
|
||||||
|
content.SetFileITem(new FileItem(item, null, true));
|
||||||
|
await DialogHost.Show(content);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task OpenItem()
|
public async Task OpenItem()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -198,9 +255,14 @@ public partial class FileItem : UserControl
|
|||||||
{
|
{
|
||||||
await foreach (var item in folder.GetItemsAsync())
|
await foreach (var item in folder.GetItemsAsync())
|
||||||
{
|
{
|
||||||
|
if (isSelectOnly)
|
||||||
|
{
|
||||||
|
if (item is IStorageFile)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
var fitem = new FileItem(item);
|
var fitem = new FileItem(item, root ?? this, isSelectOnly);
|
||||||
ItemContainer.Children.Add(fitem);
|
ItemContainer.Children.Add(fitem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -209,4 +271,16 @@ public partial class FileItem : UserControl
|
|||||||
{
|
{
|
||||||
ItemContainer.Children.Clear();
|
ItemContainer.Children.Clear();
|
||||||
}
|
}
|
||||||
|
public void SelectFileItem(FileItem item)
|
||||||
|
{
|
||||||
|
if (root == null) onSelected?.Invoke(item);
|
||||||
|
SelectIndicator.IsVisible = this == item;
|
||||||
|
foreach (var citem in ItemContainer.Children)
|
||||||
|
{
|
||||||
|
if (citem is FileItem fi)
|
||||||
|
{
|
||||||
|
fi.SelectFileItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
25
Progrart/Dialogs/BrowserDialog.axaml
Normal file
25
Progrart/Dialogs/BrowserDialog.axaml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="Progrart.Dialogs.BrowserDialog">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Name="DialogTitle" FontSize="16" TextWrapping="Wrap">Select A Folder</TextBlock>
|
||||||
|
<StackPanel Name="FileRoot">
|
||||||
|
<StackPanel.Styles>
|
||||||
|
<Style Selector="Button">
|
||||||
|
<Setter Property="Background" Value="#01000000"/>
|
||||||
|
</Style>
|
||||||
|
</StackPanel.Styles>
|
||||||
|
</StackPanel>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Classes="accent" Name="OKBtn" Content="OK"/>
|
||||||
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Name="CancelBtn" Grid.Column="1" Content="Cancel"/>
|
||||||
|
</Grid>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
67
Progrart/Dialogs/BrowserDialog.axaml.cs
Normal file
67
Progrart/Dialogs/BrowserDialog.axaml.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using DialogHostAvalonia;
|
||||||
|
using Progrart.Controls;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Progrart.Dialogs;
|
||||||
|
|
||||||
|
public partial class BrowserDialog : UserControl
|
||||||
|
{
|
||||||
|
public Func<IStorageItem, Task<bool>>? onOK = null;
|
||||||
|
public Func<bool>? onCancel = null;
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get => DialogTitle.Text ?? "";
|
||||||
|
set => DialogTitle.Text = value;
|
||||||
|
}
|
||||||
|
public BrowserDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
OKBtn.Click += OKBtn_Click;
|
||||||
|
CancelBtn.Click += CancelBtn_Click;
|
||||||
|
}
|
||||||
|
IStorageItem? currentItem = null;
|
||||||
|
public void SetFileITem(FileItem item)
|
||||||
|
{
|
||||||
|
FileRoot.Children.Add(item);
|
||||||
|
item.onSelected = async (it) =>
|
||||||
|
{
|
||||||
|
currentItem = it.CurrentItem;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private void CancelBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel()
|
||||||
|
{
|
||||||
|
if (!(onCancel?.Invoke()) ?? true)
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OKBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await Confirmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Confirmed()
|
||||||
|
{
|
||||||
|
if (currentItem is null) return;
|
||||||
|
if (onOK is not null)
|
||||||
|
{
|
||||||
|
if (!await onOK(currentItem))
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -109,7 +109,7 @@ public partial class MainView : UserControl
|
|||||||
FileContainer.Children.Clear();
|
FileContainer.Children.Clear();
|
||||||
var folder = folders[0];
|
var folder = folders[0];
|
||||||
App.CurrentOpenFolder = folder;
|
App.CurrentOpenFolder = folder;
|
||||||
FileItem item1 = new(folder);
|
FileItem item1 = new(folder, null, false);
|
||||||
FileContainer.Children.Add(item1);
|
FileContainer.Children.Add(item1);
|
||||||
await foreach (var item in folder.GetItemsAsync())
|
await foreach (var item in folder.GetItemsAsync())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user