Skip to content

Code Quality: Implemented Command Palette mode in Omnibar #17104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/Configure-AppxManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ elseif ($Branch -eq "StorePreview")
$xmlDoc.Package.Identity.Name="49306atecsolution.FilesPreview"
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="49306atecsolution.FilesPreview"

# Remove capability that is only used for the sideload package
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Identity
Name="FilesDev"
Publisher="CN=Files"
Version="3.9.9.0" />
Version="3.9.8.0" />

<Properties>
<DisplayName>Files - Dev</DisplayName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Files.App.CsWin32/Files.App.CsWin32.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Configurations>Debug;Release</Configurations>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 1 addition & 6 deletions src/Files.App.CsWin32/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ RemoveDirectoryFromApp
GetKeyState
CreateDirectoryFromApp
WNetCancelConnection2
NET_USE_CONNECT_FLAGS
NETRESOURCEW
WNetAddConnection3
CREDENTIALW
Expand Down Expand Up @@ -78,7 +77,6 @@ GetAce
SetEntriesInAcl
ACL_SIZE_INFORMATION
DeleteAce
EXPLICIT_ACCESS
ACCESS_ALLOWED_ACE
LookupAccountSid
GetComputerName
Expand All @@ -97,6 +95,7 @@ SendMessage
IsWindowVisible
COPYDATASTRUCT
WINDOW_LONG_PTR_INDEX
GetDpiForWindow
CallWindowProc
MINMAXINFO
SUBCLASSPROC
Expand Down Expand Up @@ -133,7 +132,6 @@ ShellExecuteEx
CoTaskMemFree
QueryDosDevice
DeviceIoControl
GetLastError
CreateFile
GetVolumeInformation
COMPRESSION_FORMAT
Expand Down Expand Up @@ -225,6 +223,3 @@ _SICHINTF
RoGetAgileReference
IQueryInfo
QITIPF_FLAGS
GetKeyboardState
MapVirtualKey
GetKeyboardLayout
1 change: 1 addition & 0 deletions src/Files.App.Storage/Files.App.Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public unsafe static HRESULT TryGetThumbnail(this IWindowsStorable storable, int
{
thumbnailData = null;

using ComPtr<IShellItemImageFactory> pShellItemImageFactory = storable.ThisPtr.As<IShellItemImageFactory>();
using ComPtr<IShellItemImageFactory> pShellItemImageFactory = default;
storable.ThisPtr.As(pShellItemImageFactory.GetAddressOf());
if (pShellItemImageFactory.IsNull)
return HRESULT.E_NOINTERFACE;

Expand Down
1 change: 1 addition & 0 deletions src/Files.App.Storage/Watchers/RecycleBinWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Files.App.Storage.Watchers
{
[Obsolete]
public class RecycleBinWatcher : ITrashWatcher
{
private readonly List<SystemIO.FileSystemWatcher> _watchers = [];
Expand Down
7 changes: 3 additions & 4 deletions src/Files.App/Data/Commands/HotKey/HotKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Frozen;
using System.Runtime.InteropServices;
using System.Text;
using Windows.Win32;
using Forms = System.Windows.Forms;

namespace Files.App.Data.Commands
Expand Down Expand Up @@ -375,17 +374,17 @@ private static string GetKeyCharacter(Forms.Keys key)
var state = new byte[256];

// Get the current keyboard state
if (!PInvoke.GetKeyboardState(state))
if (!Win32PInvoke.GetKeyboardState(state))
return buffer.ToString();

// Convert the key to its virtual key code
var virtualKey = (uint)key;

// Map the virtual key to a scan code
var scanCode = PInvoke.MapVirtualKey(virtualKey, 0);
var scanCode = Win32PInvoke.MapVirtualKey(virtualKey, 0);

// Get the active keyboard layout
var keyboardLayout = PInvoke.GetKeyboardLayout(0);
var keyboardLayout = Win32PInvoke.GetKeyboardLayout(0);

if (Win32PInvoke.ToUnicodeEx(virtualKey, scanCode, state, buffer, buffer.Capacity, 0, keyboardLayout) > 0)
return buffer[^1].ToString();
Expand Down
15 changes: 14 additions & 1 deletion src/Files.App/Data/Items/NavigationBarSuggestionItem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Controls;

namespace Files.App.Data.Items
{
[Obsolete("Remove once Omnibar goes out of experimental.")]
public sealed partial class NavigationBarSuggestionItem : ObservableObject
public sealed partial class NavigationBarSuggestionItem : ObservableObject, IOmnibarTextMemberPathProvider
{
private string? _Text;
public string? Text
Expand Down Expand Up @@ -88,5 +90,16 @@ private void UpdatePrimaryDisplay()
}
}
}

public string GetTextMemberPath(string textMemberPath)
{
return textMemberPath switch
{
nameof(Text) => Text,
nameof(PrimaryDisplay) => PrimaryDisplay,
nameof(SearchText) => SearchText,
_ => string.Empty
};
}
}
}
5 changes: 2 additions & 3 deletions src/Files.App/Data/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.UI.Xaml.Controls;
using System.Runtime.InteropServices;
using Windows.ApplicationModel.DataTransfer;
using Windows.Win32;
using Windows.Win32.Foundation;

namespace Files.App.Data.Models
{
Expand Down Expand Up @@ -129,8 +127,9 @@ public string PCloudDrivePath

/// <summary>
/// Gets or sets a value indicating the AppWindow DPI.
/// TODO update value if the DPI changes
/// </summary>
private float _AppWindowDPI = PInvoke.GetDpiForWindow((HWND)MainWindow.Instance.WindowHandle) / 96f;
private float _AppWindowDPI = Win32PInvoke.GetDpiForWindow(MainWindow.Instance.WindowHandle) / 96f;
public float AppWindowDPI
{
get => _AppWindowDPI;
Expand Down
22 changes: 22 additions & 0 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public static extern bool SetEvent(
IntPtr hEvent
);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetDpiForWindow(
IntPtr hwnd
);

[DllImport("ole32.dll")]
public static extern uint CoWaitForMultipleObjects(
uint dwFlags,
Expand Down Expand Up @@ -223,6 +228,23 @@ public static extern int ToUnicodeEx(
IntPtr keyboardLayout
);

[DllImport("user32.dll")]
public static extern bool GetKeyboardState(
byte[] lpKeyState
);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetKeyboardLayout
(
uint idThread
);

[DllImport("user32.dll")]
public static extern uint MapVirtualKey(
uint code,
uint mapType
);

[DllImport("user32.dll")]
public static extern bool TranslateMessage(
ref MSG lpMsg
Expand Down
64 changes: 32 additions & 32 deletions src/Files.App/UserControls/NavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IsFilled=True}"
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Path}, IconType=Outline}"
IsDefault="True"
ModeName="{x:Bind Commands.EditPath.LabelWithHotKey, Mode=OneWay}"
ModeName="{helpers:ResourceString Name=Path}"
PlaceholderText="{helpers:ResourceString Name=OmnibarPathModeTextPlaceholder}"
SuggestionItemsSource="{x:Bind ViewModel.PathModeSuggestionItems, Mode=OneWay}"
Text="{x:Bind ViewModel.PathText, Mode=TwoWay}"
Expand Down Expand Up @@ -382,50 +382,50 @@
x:Name="OmnibarCommandPaletteMode"
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IsFilled=True}"
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Commands}, IconType=Outline}"
ModeName="{x:Bind Commands.OpenCommandPalette.LabelWithHotKey, Mode=OneWay}"
PlaceholderText="{helpers:ResourceString Name=OmnibarCommandPaletteModeTextPlaceholder}">
<!--<controls:OmnibarMode.SuggestionItemTemplate>
<DataTemplate x:DataType="data:OmnibarPaletteSuggestionItem">
<Grid Height="48" ColumnSpacing="12">
ModeName="{helpers:ResourceString Name=CommandPalette}"
PlaceholderText="{helpers:ResourceString Name=OmnibarCommandPaletteModeTextPlaceholder}"
SuggestionItemsSource="{x:Bind ViewModel.OmnibarCommandPaletteModeSuggestionItems, Mode=OneWay}"
Text="{x:Bind ViewModel.OmnibarCommandPaletteModeText, Mode=TwoWay}"
TextMemberPath="Text">
<controls:OmnibarMode.SuggestionItemTemplate>
<DataTemplate x:DataType="dataitems:NavigationBarSuggestionItem">
<Grid ColumnSpacing="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:ThemedIcon
Width="20"
Height="20"
VerticalAlignment="Center"
Style="{StaticResource App.ThemedIcons.Actions.Copying}" />
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock
Style="{StaticResource BodyStrongTextBlockStyle}"
Text="{x:Bind Title}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
<TextBlock
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind Description}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
</StackPanel>
<StackPanel Grid.Column="2" VerticalAlignment="Center">
<TextBlock
Text="{x:Bind HotKeys}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
</StackPanel>

<ContentPresenter Grid.Column="0">
<controls:ThemedIcon Style="{ThemeResource App.ThemedIcons.Filter}" />
</ContentPresenter>

<!-- Primary Title -->
<TextBlock
x:Name="PrimaryDisplayBlock"
Grid.Column="1"
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
MaxLines="1"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap">
<Run FontWeight="Normal" Text="{x:Bind PrimaryDisplayPreMatched, Mode=OneWay}" /><Run FontWeight="Bold" Text="{x:Bind PrimaryDisplayMatched, Mode=OneWay}" /><Run FontWeight="Normal" Text="{x:Bind PrimaryDisplayPostMatched, Mode=OneWay}" />
</TextBlock>

<!-- Keyboard Shortcuts -->
<keyboard:KeyboardShortcut
x:Name="RightAlignedKeyboardShortcut"
Grid.Column="2"
HotKeys="{x:Bind HotKeys, Mode=OneWay}" />
</Grid>
</DataTemplate>
</controls:OmnibarMode.SuggestionItemTemplate>-->
</controls:OmnibarMode.SuggestionItemTemplate>
</controls:OmnibarMode>

<controls:OmnibarMode
x:Name="OmnibarSearchMode"
IconOnActive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Search}, IsFilled=True}"
IconOnInactive="{controls:ThemedIconMarkup Style={StaticResource App.ThemedIcons.Omnibar.Search}, IconType=Outline}"
ModeName="{x:Bind Commands.Search.LabelWithHotKey, Mode=OneWay}"
ModeName="{helpers:ResourceString Name=Search}"
PlaceholderText="{helpers:ResourceString Name=OmnibarSearchModeTextPlaceholder}" />

</controls:Omnibar>
Expand Down
38 changes: 33 additions & 5 deletions src/Files.App/UserControls/NavigationToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,47 @@ private void ClickablePath_GettingFocus(UIElement sender, GettingFocusEventArgs

private async void Omnibar_QuerySubmitted(Omnibar sender, OmnibarQuerySubmittedEventArgs args)
{
await ViewModel.HandleItemNavigationAsync(args.Text);
if (Omnibar.CurrentSelectedMode == OmnibarPathMode)
{
await ViewModel.HandleItemNavigationAsync(args.Text);
}
else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
{
}
else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode)
{
}
}

private async void Omnibar_SuggestionChosen(Omnibar sender, OmnibarSuggestionChosenEventArgs args)
{
if (args.SelectedItem is OmnibarPathModeSuggestionModel item &&
!string.IsNullOrEmpty(item.Path))
await ViewModel.HandleItemNavigationAsync(item.Path);
if (Omnibar.CurrentSelectedMode == OmnibarPathMode)
{
if (args.SelectedItem is OmnibarPathModeSuggestionModel item &&
!string.IsNullOrEmpty(item.Path))
await ViewModel.HandleItemNavigationAsync(item.Path);
}
else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
{
}
else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode)
{
}
}

private async void Omnibar_TextChanged(Omnibar sender, OmnibarTextChangedEventArgs args)
{
await ViewModel.PopulateOmnibarSuggestionsForPathMode();
if (Omnibar.CurrentSelectedMode == OmnibarPathMode)
{
await ViewModel.PopulateOmnibarSuggestionsForPathMode();
}
else if (Omnibar.CurrentSelectedMode == OmnibarCommandPaletteMode)
{
ViewModel.PopulateOmnibarSuggestionsForCommandPaletteMode();
}
else if (Omnibar.CurrentSelectedMode == OmnibarSearchMode)
{
}
}

private async void BreadcrumbBar_ItemClicked(Controls.BreadcrumbBar sender, Controls.BreadcrumbBarItemClickedEventArgs args)
Expand Down
Loading
Loading