Compare commits

...

3 Commits

6 changed files with 86 additions and 7 deletions

View File

@@ -163,6 +163,13 @@ public partial class MainListPage : DynamicListPage,
public override void UpdateSearchText(string oldSearch, string newSearch) public override void UpdateSearchText(string oldSearch, string newSearch)
{ {
var oldWasEmpty = string.IsNullOrEmpty(oldSearch);
var newWasEmpty = string.IsNullOrEmpty(newSearch);
if (oldWasEmpty != newWasEmpty)
{
WeakReferenceMessenger.Default.Send<ExpandCompactModeMessage>(new(!newWasEmpty));
}
// Handle changes to the filter text here // Handle changes to the filter text here
if (!string.IsNullOrEmpty(SearchText)) if (!string.IsNullOrEmpty(SearchText))
{ {

View File

@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.CmdPal.UI.ViewModels.Messages;
public record ExpandCompactModeMessage(bool Expanded)
{
}

View File

@@ -44,6 +44,8 @@ public partial class SettingsModel : ObservableObject
public bool AllowExternalReload { get; set; } public bool AllowExternalReload { get; set; }
public bool CompactMode { get; set; } = true;
public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = []; public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = [];
public Dictionary<string, CommandAlias> Aliases { get; set; } = []; public Dictionary<string, CommandAlias> Aliases { get; set; } = [];

View File

@@ -46,6 +46,7 @@ public sealed partial class MainWindow : WindowEx,
IRecipient<ShowWindowMessage>, IRecipient<ShowWindowMessage>,
IRecipient<HideWindowMessage>, IRecipient<HideWindowMessage>,
IRecipient<QuitMessage>, IRecipient<QuitMessage>,
IRecipient<ExpandCompactModeMessage>,
IDisposable IDisposable
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Stylistically, window messages are WM_")] [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Stylistically, window messages are WM_")]
@@ -87,6 +88,7 @@ public sealed partial class MainWindow : WindowEx,
WeakReferenceMessenger.Default.Register<QuitMessage>(this); WeakReferenceMessenger.Default.Register<QuitMessage>(this);
WeakReferenceMessenger.Default.Register<ShowWindowMessage>(this); WeakReferenceMessenger.Default.Register<ShowWindowMessage>(this);
WeakReferenceMessenger.Default.Register<HideWindowMessage>(this); WeakReferenceMessenger.Default.Register<HideWindowMessage>(this);
WeakReferenceMessenger.Default.Register<ExpandCompactModeMessage>(this);
// Hide our titlebar. // Hide our titlebar.
// We need to both ExtendsContentIntoTitleBar, then set the height to Collapsed // We need to both ExtendsContentIntoTitleBar, then set the height to Collapsed
@@ -175,6 +177,8 @@ public sealed partial class MainWindow : WindowEx,
_ignoreHotKeyWhenFullScreen = settings.IgnoreShortcutWhenFullscreen; _ignoreHotKeyWhenFullScreen = settings.IgnoreShortcutWhenFullscreen;
this.SetVisibilityInSwitchers(Debugger.IsAttached); this.SetVisibilityInSwitchers(Debugger.IsAttached);
HandleExpandCompactOnUiThread(false);
} }
// We want to use DesktopAcrylicKind.Thin and custom colors as this is the default material // We want to use DesktopAcrylicKind.Thin and custom colors as this is the default material
@@ -747,4 +751,25 @@ public sealed partial class MainWindow : WindowEx,
_localKeyboardListener.Dispose(); _localKeyboardListener.Dispose();
DisposeAcrylic(); DisposeAcrylic();
} }
public void Receive(ExpandCompactModeMessage message)
{
this.DispatcherQueue.TryEnqueue(() => HandleExpandCompactOnUiThread(message.Expanded));
}
private void HandleExpandCompactOnUiThread(bool expanded)
{
var settings = App.Current.Services.GetService<SettingsModel>()!;
if (settings.CompactMode == false)
{
return;
}
// Cloak();
this.MinHeight = expanded ? 240 : 64;
this.Height = expanded ? 480 : 64;
// Uncloak();
// PInvoke.SetWindowPos(_hwnd, HWND.HWND_TOPMOST, 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE);
}
} }

View File

@@ -157,17 +157,15 @@
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Background="{ThemeResource LayerOnAcrylicPrimaryBackgroundBrush}"> <Grid Grid.Row="0" Background="{ThemeResource LayerOnAcrylicPrimaryBackgroundBrush}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Back button and search box --> <!-- Back button and search box -->
<Grid <Grid
Padding="0,12,0,12" Padding="0,12,0,12"
@@ -349,6 +347,19 @@
</animations:Implicit.HideAnimations> </animations:Implicit.HideAnimations>
</ProgressBar> </ProgressBar>
</Grid>
<Grid
Grid.Row="1"
Background="{ThemeResource LayerOnAcrylicPrimaryBackgroundBrush}"
Visibility="{x:Bind ExpandedMode, Mode=OneWay}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid <Grid
x:Name="ContentGrid" x:Name="ContentGrid"
Grid.Row="1" Grid.Row="1"
@@ -472,12 +483,13 @@
See https://github.com/microsoft/microsoft-ui-xaml/issues/5741 See https://github.com/microsoft/microsoft-ui-xaml/issues/5741
--> -->
<StackPanel <StackPanel
Grid.Row="0" Grid.Row="1"
Margin="16,8,16,8" Margin="16,8,16,8"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" VerticalAlignment="Bottom"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
CornerRadius="{ThemeResource ControlCornerRadius}"> CornerRadius="{ThemeResource ControlCornerRadius}"
Visibility="Collapsed">
<InfoBar <InfoBar
CornerRadius="{ThemeResource ControlCornerRadius}" CornerRadius="{ThemeResource ControlCornerRadius}"
IsOpen="{x:Bind ViewModel.CurrentPage.HasStatusMessage, Mode=OneWay}" IsOpen="{x:Bind ViewModel.CurrentPage.HasStatusMessage, Mode=OneWay}"
@@ -495,7 +507,10 @@
</InfoBar> </InfoBar>
</StackPanel> </StackPanel>
<Grid Grid.Row="1" Background="{ThemeResource LayerOnAcrylicSecondaryBackgroundBrush}"> <Grid
Grid.Row="2"
Background="{ThemeResource LayerOnAcrylicSecondaryBackgroundBrush}"
Visibility="{x:Bind ExpandedMode, Mode=OneWay}">
<cpcontrols:CommandBar CurrentPageViewModel="{x:Bind ViewModel.CurrentPage, Mode=OneWay}" /> <cpcontrols:CommandBar CurrentPageViewModel="{x:Bind ViewModel.CurrentPage, Mode=OneWay}" />
</Grid> </Grid>

View File

@@ -12,6 +12,7 @@ using Microsoft.CmdPal.UI.Events;
using Microsoft.CmdPal.UI.Messages; using Microsoft.CmdPal.UI.Messages;
using Microsoft.CmdPal.UI.Settings; using Microsoft.CmdPal.UI.Settings;
using Microsoft.CmdPal.UI.ViewModels; using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.PowerToys.Telemetry; using Microsoft.PowerToys.Telemetry;
@@ -42,6 +43,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
IRecipient<ShowConfirmationMessage>, IRecipient<ShowConfirmationMessage>,
IRecipient<ShowToastMessage>, IRecipient<ShowToastMessage>,
IRecipient<NavigateToPageMessage>, IRecipient<NavigateToPageMessage>,
IRecipient<ExpandCompactModeMessage>,
INotifyPropertyChanged INotifyPropertyChanged
{ {
private readonly DispatcherQueue _queue = DispatcherQueue.GetForCurrentThread(); private readonly DispatcherQueue _queue = DispatcherQueue.GetForCurrentThread();
@@ -61,8 +63,13 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
public bool ExpandedMode { get; set; }
public ShellPage() public ShellPage()
{ {
var settings = App.Current.Services.GetService<SettingsModel>()!;
this.ExpandedMode = !settings.CompactMode;
this.InitializeComponent(); this.InitializeComponent();
// how we are doing navigation around // how we are doing navigation around
@@ -83,6 +90,8 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
WeakReferenceMessenger.Default.Register<ShowToastMessage>(this); WeakReferenceMessenger.Default.Register<ShowToastMessage>(this);
WeakReferenceMessenger.Default.Register<NavigateToPageMessage>(this); WeakReferenceMessenger.Default.Register<NavigateToPageMessage>(this);
WeakReferenceMessenger.Default.Register<ExpandCompactModeMessage>(this);
AddHandler(PreviewKeyDownEvent, new KeyEventHandler(ShellPage_OnPreviewKeyDown), true); AddHandler(PreviewKeyDownEvent, new KeyEventHandler(ShellPage_OnPreviewKeyDown), true);
AddHandler(PointerPressedEvent, new PointerEventHandler(ShellPage_OnPointerPressed), true); AddHandler(PointerPressedEvent, new PointerEventHandler(ShellPage_OnPointerPressed), true);
@@ -479,4 +488,16 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
Logger.LogError("Error handling mouse button press event", ex); Logger.LogError("Error handling mouse button press event", ex);
} }
} }
public void Receive(ExpandCompactModeMessage message)
{
this.DispatcherQueue.TryEnqueue(() => HandleExpandCompactOnUiThread(message.Expanded));
}
private void HandleExpandCompactOnUiThread(bool expanded)
{
var settings = App.Current.Services.GetService<SettingsModel>()!;
this.ExpandedMode = settings.CompactMode ? expanded : true;
PropertyChanged?.Invoke(this, new(nameof(ExpandedMode)));
}
} }