Skip to content

Commit

Permalink
[AdvancedPaste] Improved paste window menu layout
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbyperpetual committed Sep 18, 2024
1 parent 35e6375 commit a25fbe3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

using System;
using System.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;

namespace AdvancedPaste.Converters;

public sealed partial class PasteFormatsToHeightConverter : IValueConverter
{
private const int ItemHeight = 40;

public int MaxItems { get; set; } = 5;

public object Convert(object value, Type targetType, object parameter, string language) =>
new GridLength(Convert((value is ICollection collection) ? collection.Count : (value is int intValue) ? intValue : 0));

public int Convert(int itemCount) => Math.Min(MaxItems, itemCount) * ItemHeight;

public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
xmlns:pages="using:AdvancedPaste.Pages"
xmlns:winuiex="using:WinUIEx"
Width="420"
Height="308"
Height="188"
MinWidth="420"
MinHeight="308"
MinHeight="188"
Closed="WindowEx_Closed"
IsAlwaysOnTop="True"
IsMaximizable="False"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

using System;
using System.Linq;
using AdvancedPaste.Converters;
using AdvancedPaste.Helpers;
using AdvancedPaste.Models;
using AdvancedPaste.Settings;
using ManagedCommon;
using Microsoft.UI.Windowing;
Expand All @@ -23,16 +25,19 @@ public sealed partial class MainWindow : WindowEx, IDisposable

public MainWindow()
{
this.InitializeComponent();
InitializeComponent();

_userSettings = App.GetService<IUserSettings>();

var baseHeight = MinHeight;
var coreActionCount = PasteFormat.MetadataDict.Values.Count(metadata => metadata.IsCoreAction);

void UpdateHeight()
{
double GetHeight(int maxCustomActionCount) =>
baseHeight + (40 * (_userSettings.AdditionalActions.Count + Math.Min(_userSettings.CustomActions.Count, maxCustomActionCount)));
baseHeight +
new PasteFormatsToHeightConverter().Convert(coreActionCount + _userSettings.AdditionalActions.Count) +
new PasteFormatsToHeightConverter() { MaxItems = maxCustomActionCount }.Convert(_userSettings.CustomActions.Count);

MinHeight = GetHeight(1);
Height = GetHeight(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<Page.Resources>
<tkconverters:BoolToVisibilityConverter x:Name="BoolToVisibilityConverter" />
<converters:CountToVisibilityConverter x:Name="countToVisibilityConverter" />
<converters:PasteFormatsToHeightConverter x:Name="standardPasteFormatsToHeightConverter" />
<converters:CountToDoubleConverter
x:Name="customActionsCountToMinHeightConverter"
x:Name="customActionsToMinHeightConverter"
ValueIfNonZero="40"
ValueIfZero="0" />
<Style
Expand Down Expand Up @@ -179,9 +180,9 @@
BorderThickness="0,1,0,0"
RowSpacing="4">
<Grid.RowDefinitions>
<RowDefinition Height="{x:Bind ViewModel.StandardPasteFormats.Count, Mode=OneWay, Converter={StaticResource standardPasteFormatsToHeightConverter}}" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="{x:Bind ViewModel.CustomActionPasteFormats.Count, Mode=OneWay, Converter={StaticResource customActionsCountToMinHeightConverter}}" />
<RowDefinition Height="*" MinHeight="{x:Bind ViewModel.CustomActionPasteFormats.Count, Mode=OneWay, Converter={StaticResource customActionsToMinHeightConverter}}" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
Expand All @@ -193,6 +194,8 @@
ItemContainerTransitions="{x:Null}"
ItemTemplate="{StaticResource PasteFormatTemplate}"
ItemsSource="{x:Bind ViewModel.StandardPasteFormats, Mode=OneWay}"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Auto"
SelectionMode="None"
TabIndex="1">
<ListView.ItemContainerStyle>
Expand Down

0 comments on commit a25fbe3

Please sign in to comment.