Skip to content

Commit d27b396

Browse files
committed
Handled query submitted event
1 parent e1ee482 commit d27b396

File tree

3 files changed

+118
-5
lines changed

3 files changed

+118
-5
lines changed

src/Files.App/UserControls/NavigationToolbar.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@
342342
x:Load="{x:Bind ViewModel.EnableOmnibar, Mode=OneWay}"
343343
CurrentSelectedModeName="{x:Bind ViewModel.OmnibarCurrentSelectedModeName, Mode=TwoWay}"
344344
IsFocused="{x:Bind ViewModel.IsOmnibarFocused, Mode=TwoWay}"
345-
SuggestionChosen="Omnibar_SuggestionChosen">
345+
QuerySubmitted="Omnibar_QuerySubmitted"
346+
SuggestionChosen="Omnibar_SuggestionChosen"
347+
TextChanged="Omnibar_TextChanged">
346348

347349
<controls:OmnibarMode
348350
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IsFilled=True}"
@@ -351,7 +353,7 @@
351353
ModeName="Path"
352354
PlaceholderText="{helpers:ResourceString Name=OmnibarPathModeTextPlaceholder}"
353355
SuggestionItemsSource="{x:Bind ViewModel.PathModeSuggestionItems, Mode=OneWay}"
354-
Text="{x:Bind ViewModel.OmnibarPathModeText, Mode=OneWay}"
356+
Text="{x:Bind ViewModel.OmnibarPathModeText, Mode=TwoWay}"
355357
TextMemberPath="Path">
356358
<controls:OmnibarMode.ContentOnInactive>
357359
<controls:BreadcrumbBar

src/Files.App/UserControls/NavigationToolbar.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,22 @@ private void ClickablePath_GettingFocus(UIElement sender, GettingFocusEventArgs
254254
ViewModel.IsEditModeEnabled = true;
255255
}
256256

257+
private async void Omnibar_QuerySubmitted(Omnibar sender, OmnibarQuerySubmittedEventArgs args)
258+
{
259+
await ViewModel.HandleItemNavigationAsync(args.Text);
260+
}
261+
257262
private async void Omnibar_SuggestionChosen(Omnibar sender, OmnibarSuggestionChosenEventArgs args)
258263
{
259264
if (args.SelectedItem is OmnibarPathModeSuggestionModel item)
260265
await ViewModel.HandleFolderNavigationAsync(item.Path);
261266
}
262267

268+
private async void Omnibar_TextChanged(Omnibar sender, OmnibarTextChangedEventArgs args)
269+
{
270+
await ViewModel.PopulateOmnibarSuggestionsForPathMode();
271+
}
272+
263273
private async void BreadcrumbBar_ItemClicked(Controls.BreadcrumbBar sender, Controls.BreadcrumbBarItemClickedEventArgs args)
264274
{
265275
if (args.IsRootItem)

src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ public void PathBoxItem_PointerPressed(object sender, PointerRoutedEventArgs e)
596596
_pointerRoutedEventArgs = ptrPt.Properties.IsMiddleButtonPressed ? e : null;
597597
}
598598

599-
public async Task HandleFolderNavigationAsync(string path, bool? isMiddleButtonPressed = null)
599+
public async Task HandleFolderNavigationAsync(string path, bool openNewTab = false)
600600
{
601-
isMiddleButtonPressed ??= _pointerRoutedEventArgs is not null;
602-
if (isMiddleButtonPressed is true)
601+
openNewTab |= _pointerRoutedEventArgs is not null;
602+
if (openNewTab)
603603
{
604604
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(
605605
async () =>
@@ -616,6 +616,106 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(
616616
ToolbarPathItemInvoked?.Invoke(this, new() { ItemPath = path });
617617
}
618618

619+
public async Task HandleItemNavigationAsync(string path)
620+
{
621+
if (ContentPageContext.ShellPage is null || PathComponents.LastOrDefault()?.Path is not { } currentPath)
622+
return;
623+
624+
var isFtp = FtpHelpers.IsFtpPath(path);
625+
var normalizedInput = NormalizePathInput(path, isFtp);
626+
if (currentPath.Equals(normalizedInput, StringComparison.OrdinalIgnoreCase) ||
627+
string.IsNullOrWhiteSpace(normalizedInput))
628+
return;
629+
630+
if (normalizedInput.Equals(ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory) &&
631+
ContentPageContext.ShellPage.CurrentPageType != typeof(HomePage))
632+
return;
633+
634+
if (normalizedInput.Equals("Home", StringComparison.OrdinalIgnoreCase) ||
635+
normalizedInput.Equals(Strings.Home.GetLocalizedResource(), StringComparison.OrdinalIgnoreCase))
636+
{
637+
SavePathToHistory("Home");
638+
ContentPageContext.ShellPage.NavigateHome();
639+
}
640+
else if (normalizedInput.Equals("ReleaseNotes", StringComparison.OrdinalIgnoreCase) ||
641+
normalizedInput.Equals(Strings.ReleaseNotes.GetLocalizedResource(), StringComparison.OrdinalIgnoreCase))
642+
{
643+
SavePathToHistory("ReleaseNotes");
644+
ContentPageContext.ShellPage.NavigateToReleaseNotes();
645+
}
646+
else if (normalizedInput.Equals("Settings", StringComparison.OrdinalIgnoreCase) ||
647+
normalizedInput.Equals(Strings.Settings.GetLocalizedResource(), StringComparison.OrdinalIgnoreCase))
648+
{
649+
//SavePathToHistory("Settings");
650+
//ContentPageContext.ShellPage.NavigateToSettings();
651+
}
652+
else
653+
{
654+
normalizedInput = StorageFileExtensions.GetResolvedPath(normalizedInput, isFtp);
655+
if (currentPath.Equals(normalizedInput, StringComparison.OrdinalIgnoreCase))
656+
return;
657+
658+
var item = await FilesystemTasks.Wrap(() => DriveHelpers.GetRootFromPathAsync(normalizedInput));
659+
660+
var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(normalizedInput, item));
661+
if (resFolder || FolderHelpers.CheckFolderAccessWithWin32(normalizedInput))
662+
{
663+
var matchingDrive = drivesViewModel.Drives.Cast<DriveItem>().FirstOrDefault(x => PathNormalization.NormalizePath(normalizedInput).StartsWith(PathNormalization.NormalizePath(x.Path), StringComparison.Ordinal));
664+
if (matchingDrive is not null && matchingDrive.Type == Data.Items.DriveType.CDRom && matchingDrive.MaxSpace == ByteSizeLib.ByteSize.FromBytes(0))
665+
{
666+
bool ejectButton = await DialogDisplayHelper.ShowDialogAsync(Strings.InsertDiscDialog_Title.GetLocalizedResource(), string.Format(Strings.InsertDiscDialog_Text.GetLocalizedResource(), matchingDrive.Path), Strings.InsertDiscDialog_OpenDriveButton.GetLocalizedResource(), Strings.Close.GetLocalizedResource());
667+
if (ejectButton)
668+
DriveHelpers.EjectDeviceAsync(matchingDrive.Path);
669+
return;
670+
}
671+
672+
var pathToNavigate = resFolder.Result?.Path ?? normalizedInput;
673+
SavePathToHistory(pathToNavigate);
674+
ContentPageContext.ShellPage.NavigateToPath(pathToNavigate);
675+
}
676+
else if (isFtp)
677+
{
678+
SavePathToHistory(normalizedInput);
679+
ContentPageContext.ShellPage.NavigateToPath(normalizedInput);
680+
}
681+
else // Not a folder or inaccessible
682+
{
683+
var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(normalizedInput, item));
684+
if (resFile)
685+
{
686+
var pathToInvoke = resFile.Result.Path;
687+
await Win32Helper.InvokeWin32ComponentAsync(pathToInvoke, ContentPageContext.ShellPage);
688+
}
689+
else // Not a file or not accessible
690+
{
691+
var workingDir =
692+
string.IsNullOrEmpty(ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory) ||
693+
ContentPageContext.ShellPage.CurrentPageType == typeof(HomePage)
694+
? Constants.UserEnvironmentPaths.HomePath
695+
: ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
696+
697+
if (await LaunchApplicationFromPath(OmnibarPathModeText, workingDir))
698+
return;
699+
700+
try
701+
{
702+
if (!await Windows.System.Launcher.LaunchUriAsync(new Uri(OmnibarPathModeText)))
703+
await DialogDisplayHelper.ShowDialogAsync(Strings.InvalidItemDialogTitle.GetLocalizedResource(),
704+
string.Format(Strings.InvalidItemDialogContent.GetLocalizedResource(), Environment.NewLine, resFolder.ErrorCode.ToString()));
705+
}
706+
catch (Exception ex) when (ex is UriFormatException || ex is ArgumentException)
707+
{
708+
await DialogDisplayHelper.ShowDialogAsync(Strings.InvalidItemDialogTitle.GetLocalizedResource(),
709+
string.Format(Strings.InvalidItemDialogContent.GetLocalizedResource(), Environment.NewLine, resFolder.ErrorCode.ToString()));
710+
}
711+
}
712+
}
713+
}
714+
715+
PathControlDisplayText = ContentPageContext.ShellPage.ShellViewModel.WorkingDirectory;
716+
IsOmnibarFocused = false;
717+
}
718+
619719
public void PathBoxItem_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
620720
{
621721
switch (e.Key)
@@ -799,6 +899,7 @@ private static string NormalizePathInput(string currentInput, bool isFtp)
799899
return currentInput;
800900
}
801901

902+
[Obsolete("Remove once Omnibar goes out of experimental.")]
802903
public async Task CheckPathInputAsync(string currentInput, string currentSelectedPath, IShellPage shellPage)
803904
{
804905
if (currentInput.StartsWith('>'))

0 commit comments

Comments
 (0)