diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs index 53d729b..3abd8aa 100644 --- a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs @@ -91,11 +91,15 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase { await OpenSelected(); } - else if (_currentSelectedItem?.Value is IElementViewModel - {Element: {NativePath: not null, Provider: ILocalContentProvider} localFile} - ) + else if ( + _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) { @@ -119,15 +123,38 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase private async Task GoToPath() { 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) { await _userCommandHandlerService.HandleCommandAsync( 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() diff --git a/src/Core/FileTime.Core.Abstraction/Interactions/IUserCommunicationService.cs b/src/Core/FileTime.Core.Abstraction/Interactions/IUserCommunicationService.cs index 85ce28f..5365516 100644 --- a/src/Core/FileTime.Core.Abstraction/Interactions/IUserCommunicationService.cs +++ b/src/Core/FileTime.Core.Abstraction/Interactions/IUserCommunicationService.cs @@ -6,5 +6,10 @@ public interface IUserCommunicationService Task ReadInputs(IInputElement field, IEnumerable? previews = null); Task ReadInputs(IEnumerable fields, IEnumerable? previews = null); void ShowToastMessage(string text); - Task ShowMessageBox(string text); + Task ShowMessageBox( + string text, + bool showCancel = true, + string? okText = null, + string? cancelText = null + ); } \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/MessageBoxViewModel.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/MessageBoxViewModel.cs index 9d928ad..702c765 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/MessageBoxViewModel.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/MessageBoxViewModel.cs @@ -9,23 +9,28 @@ public partial class MessageBoxViewModel : IModalViewModel { private readonly Action _handler; public string Text { get; } + public bool ShowCancel { get; } + public string OkText { get; } + public string CancelText { get; } public string Name => "MessageBoxViewModel"; - public MessageBoxViewModel(string text, Action handler) : this() + public MessageBoxViewModel( + string text, + Action handler, + bool showCancel = true, + string? okText = null, + string? cancelText = null) : this() { _handler = handler; Text = text; + ShowCancel = showCancel; + OkText = okText ?? "Yes"; + CancelText = cancelText ?? "No"; } [Command] - public void Ok() - { - _handler.Invoke(this, MessageBoxResult.Ok); - } + public void Ok() => _handler.Invoke(this, MessageBoxResult.Ok); [Command] - public void Cancel() - { - _handler.Invoke(this, MessageBoxResult.Cancel); - } + public void Cancel() => _handler.Invoke(this, MessageBoxResult.Cancel); } \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/DialogService.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/DialogService.cs index 155f4ee..989c02f 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/DialogService.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/DialogService.cs @@ -119,14 +119,26 @@ public class DialogService : IDialogService }); } - public Task ShowMessageBox(string text) + public Task ShowMessageBox( + string text, + bool showCancel = true, + string? okText = null, + string? cancelText = null) { var taskCompletionSource = new TaskCompletionSource(); - _modalService.OpenModal(new MessageBoxViewModel(text, (vm, result) => - { - _modalService.CloseModal(vm); - taskCompletionSource.SetResult(result); - })); + _modalService.OpenModal( + new MessageBoxViewModel( + text, + (vm, result) => + { + _modalService.CloseModal(vm); + taskCompletionSource.SetResult(result); + }, + showCancel, + okText, + cancelText + ) + ); return taskCompletionSource.Task; } diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml index 59693b0..9f8836a 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml @@ -824,13 +824,14 @@ Orientation="Horizontal">