Skip to content
Open
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
3 changes: 3 additions & 0 deletions EverythingToolbar.App/ToolbarSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public interface IToolbarSettings
[Option(DefaultValue = false)]
bool IsPreviewPaneEnabled { get; set; }

[Option(DefaultValue = 380)]
int PreviewPaneWidth { get; set; }

[Option(DefaultValue = "")]
string InstanceName { get; set; }

Expand Down
26 changes: 23 additions & 3 deletions EverythingToolbar/SearchWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,27 @@
<controls:UpdateBanner Grid.Row="{DynamicResource UpdateBannerGridRow}" />
<controls:UpdateSuccessfulBanner Grid.Row="{DynamicResource UpdateBannerGridRow}" />

<Grid Grid.Row="{DynamicResource SearchResultsViewGridRow}">
<Grid
x:Name="ResultsGrid"
Grid.Row="{DynamicResource SearchResultsViewGridRow}"
SizeChanged="OnResultsGridSizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<controls:SearchResultsView x:Name="SearchResultsView" Grid.Column="0" />

<ContentControl Grid.Column="1" Content="{Binding ElementName=SearchResultsView, Path=SelectedSearchResult}">
<ContentControl
x:Name="PreviewPane"
Grid.Column="1"
Content="{Binding ElementName=SearchResultsView, Path=SelectedSearchResult}">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={markup:Service {x:Type app:ISettings}}, Path=IsPreviewPaneEnabled}" Value="True">
<Setter Property="Visibility" Value="Visible" />
<Setter Property="Width" Value="380" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
Expand All @@ -92,6 +97,21 @@
</Style>
</ContentControl.Style>
</ContentControl>

<Thumb
Grid.Column="1"
Width="6"
HorizontalAlignment="Left"
Cursor="SizeWE"
DragCompleted="OnPreviewPaneResizeCompleted"
DragDelta="OnPreviewPaneResize"
Visibility="{Binding ElementName=PreviewPane, Path=Visibility}">
<Thumb.Template>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="Transparent" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>

<controls:SearchBox
Expand Down
30 changes: 30 additions & 0 deletions EverythingToolbar/SearchWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.DependencyInjection;
using EverythingToolbar.Controls;
using EverythingToolbar.ViewModels;
using Windows.Win32;
Expand All @@ -28,6 +30,8 @@ public partial class SearchWindow

private const int WM_SIZING = 0x0214;
private const int WM_EXITSIZEMOVE = 0x0232;
private const double MinPreviewPaneWidth = 240;
private const double MinResultsWidth = 240;

private bool _isFirstShow = true;
private bool _isHiding;
Expand All @@ -36,13 +40,15 @@ public partial class SearchWindow
private readonly SearchWindowViewModel _viewModel;
private readonly SearchWindowController _controller;
private readonly SearchWindowAnimator _animator;
private readonly ISettings _settings = Ioc.Default.GetRequiredService<ISettings>();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small cleanup note: since SearchWindow already gets its dependencies via the constructor, could we inject ISettings directly into public SearchWindow(...) instead of calling Ioc.Default.GetRequiredService<ISettings>()?


public SearchWindow(SearchWindowViewModel viewModel, SearchWindowController controller)
: base(viewModel.ThemeService, viewModel.WindowsPolicy)
{
_viewModel = viewModel;
_controller = controller;
InitializeComponent();
PreviewPane.Width = _settings.PreviewPaneWidth;

_animator = new SearchWindowAnimator(
this,
Expand Down Expand Up @@ -82,6 +88,30 @@ private void OnLostKeyboardFocus(object? sender, KeyboardFocusChangedEventArgs e
}
}

private void OnPreviewPaneResize(object sender, DragDeltaEventArgs e)
{
// The handle is on the side facing the results, so dragging toward them makes the pane wider.
SetPreviewPaneWidth(PreviewPane.Width - e.HorizontalChange);
}

private void OnPreviewPaneResizeCompleted(object sender, DragCompletedEventArgs e)
{
_settings.PreviewPaneWidth = (int)Math.Round(PreviewPane.Width);
}

// Keep room for the results when the window gets smaller. The saved width is left alone, so the pane
// grows back once there is space again.
private void OnResultsGridSizeChanged(object sender, SizeChangedEventArgs e)
{
SetPreviewPaneWidth(_settings.PreviewPaneWidth);
}

private void SetPreviewPaneWidth(double width)
{
double max = ResultsGrid.ActualWidth - MinResultsWidth;
PreviewPane.Width = Math.Max(MinPreviewPaneWidth, Math.Min(width, max));
}

private void OpenSearchInEverything(object? sender, RoutedEventArgs e)
{
_viewModel.OpenSearchInEverything();
Expand Down