Better handle GoToPath, MessageBox customizations
This commit is contained in:
@@ -91,11 +91,15 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
{
|
{
|
||||||
await OpenSelected();
|
await OpenSelected();
|
||||||
}
|
}
|
||||||
else if (_currentSelectedItem?.Value is IElementViewModel
|
else if (
|
||||||
{Element: {NativePath: not null, Provider: ILocalContentProvider} localFile}
|
_currentSelectedItem?.Value is IElementViewModel
|
||||||
)
|
{
|
||||||
|
Element: {NativePath: not null, Provider: ILocalContentProvider} localFile
|
||||||
|
}
|
||||||
|
)
|
||||||
{
|
{
|
||||||
Process.Start(new ProcessStartInfo(localFile.NativePath!.Path) {UseShellExecute = true});
|
var processStartInfo = new ProcessStartInfo(localFile.NativePath!.Path) {UseShellExecute = true};
|
||||||
|
Process.Start(processStartInfo);
|
||||||
|
|
||||||
if (_viewMode == ViewMode.RapidTravel)
|
if (_viewMode == ViewMode.RapidTravel)
|
||||||
{
|
{
|
||||||
@@ -119,15 +123,38 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
private async Task GoToPath()
|
private async Task GoToPath()
|
||||||
{
|
{
|
||||||
var pathInput = new TextInputElement("Path");
|
var pathInput = new TextInputElement("Path");
|
||||||
await _userCommunicationService.ReadInputs(pathInput);
|
var acceptedForm = await _userCommunicationService.ReadInputs(pathInput);
|
||||||
|
|
||||||
|
if (!acceptedForm) return;
|
||||||
|
|
||||||
|
var path = pathInput.Value!;
|
||||||
|
IItem? resolvedPath = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(path));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: message on empty result and on null pathInput.Value
|
|
||||||
var resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(pathInput.Value));
|
|
||||||
if (resolvedPath is IContainer container)
|
if (resolvedPath is IContainer container)
|
||||||
{
|
{
|
||||||
await _userCommandHandlerService.HandleCommandAsync(
|
await _userCommandHandlerService.HandleCommandAsync(
|
||||||
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, container)));
|
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, container)));
|
||||||
}
|
}
|
||||||
|
else if (resolvedPath is IElement element)
|
||||||
|
{
|
||||||
|
await _userCommandHandlerService.HandleCommandAsync(
|
||||||
|
new OpenContainerCommand(element.Parent!));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _userCommunicationService.ShowMessageBox(
|
||||||
|
$"Path does not exists: {path}",
|
||||||
|
okText: "Ok",
|
||||||
|
showCancel: false
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task GoToHome()
|
private async Task GoToHome()
|
||||||
|
|||||||
@@ -6,5 +6,10 @@ public interface IUserCommunicationService
|
|||||||
Task<bool> ReadInputs(IInputElement field, IEnumerable<IPreviewElement>? previews = null);
|
Task<bool> ReadInputs(IInputElement field, IEnumerable<IPreviewElement>? previews = null);
|
||||||
Task<bool> ReadInputs(IEnumerable<IInputElement> fields, IEnumerable<IPreviewElement>? previews = null);
|
Task<bool> ReadInputs(IEnumerable<IInputElement> fields, IEnumerable<IPreviewElement>? previews = null);
|
||||||
void ShowToastMessage(string text);
|
void ShowToastMessage(string text);
|
||||||
Task<MessageBoxResult> ShowMessageBox(string text);
|
Task<MessageBoxResult> ShowMessageBox(
|
||||||
|
string text,
|
||||||
|
bool showCancel = true,
|
||||||
|
string? okText = null,
|
||||||
|
string? cancelText = null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -9,23 +9,28 @@ public partial class MessageBoxViewModel : IModalViewModel
|
|||||||
{
|
{
|
||||||
private readonly Action<MessageBoxViewModel, MessageBoxResult> _handler;
|
private readonly Action<MessageBoxViewModel, MessageBoxResult> _handler;
|
||||||
public string Text { get; }
|
public string Text { get; }
|
||||||
|
public bool ShowCancel { get; }
|
||||||
|
public string OkText { get; }
|
||||||
|
public string CancelText { get; }
|
||||||
public string Name => "MessageBoxViewModel";
|
public string Name => "MessageBoxViewModel";
|
||||||
|
|
||||||
public MessageBoxViewModel(string text, Action<MessageBoxViewModel, MessageBoxResult> handler) : this()
|
public MessageBoxViewModel(
|
||||||
|
string text,
|
||||||
|
Action<MessageBoxViewModel, MessageBoxResult> handler,
|
||||||
|
bool showCancel = true,
|
||||||
|
string? okText = null,
|
||||||
|
string? cancelText = null) : this()
|
||||||
{
|
{
|
||||||
_handler = handler;
|
_handler = handler;
|
||||||
Text = text;
|
Text = text;
|
||||||
|
ShowCancel = showCancel;
|
||||||
|
OkText = okText ?? "Yes";
|
||||||
|
CancelText = cancelText ?? "No";
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public void Ok()
|
public void Ok() => _handler.Invoke(this, MessageBoxResult.Ok);
|
||||||
{
|
|
||||||
_handler.Invoke(this, MessageBoxResult.Ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public void Cancel()
|
public void Cancel() => _handler.Invoke(this, MessageBoxResult.Cancel);
|
||||||
{
|
|
||||||
_handler.Invoke(this, MessageBoxResult.Cancel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -119,14 +119,26 @@ public class DialogService : IDialogService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<MessageBoxResult> ShowMessageBox(string text)
|
public Task<MessageBoxResult> ShowMessageBox(
|
||||||
|
string text,
|
||||||
|
bool showCancel = true,
|
||||||
|
string? okText = null,
|
||||||
|
string? cancelText = null)
|
||||||
{
|
{
|
||||||
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
|
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
|
||||||
_modalService.OpenModal(new MessageBoxViewModel(text, (vm, result) =>
|
_modalService.OpenModal(
|
||||||
{
|
new MessageBoxViewModel(
|
||||||
_modalService.CloseModal(vm);
|
text,
|
||||||
taskCompletionSource.SetResult(result);
|
(vm, result) =>
|
||||||
}));
|
{
|
||||||
|
_modalService.CloseModal(vm);
|
||||||
|
taskCompletionSource.SetResult(result);
|
||||||
|
},
|
||||||
|
showCancel,
|
||||||
|
okText,
|
||||||
|
cancelText
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return taskCompletionSource.Task;
|
return taskCompletionSource.Task;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -824,13 +824,14 @@
|
|||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding OkCommand}"
|
Command="{Binding OkCommand}"
|
||||||
Content="Yes"
|
Content="{Binding OkText}"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center"
|
||||||
Width="80" />
|
Width="80" />
|
||||||
<Button
|
<Button
|
||||||
Command="{Binding CancelCommand}"
|
Command="{Binding CancelCommand}"
|
||||||
Content="No"
|
Content="{Binding CancelText}"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center"
|
||||||
|
IsVisible="{Binding ShowCancel}"
|
||||||
Margin="10,0,0,0"
|
Margin="10,0,0,0"
|
||||||
Width="80" />
|
Width="80" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
Reference in New Issue
Block a user