Skip to content
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

[PTRun] Run preview #34274

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.Globalization;
using System.Windows.Data;

namespace PowerLauncher.Converters
{
public class NegativeValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double doubleValue)
{
return -doubleValue;
}

return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
41 changes: 41 additions & 0 deletions src/modules/launcher/PowerLauncher/Converters/SumConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.Globalization;
using System.Windows.Data;

namespace PowerLauncher.Converters
{
public class SumConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var sum = 0.0d;

foreach (var value in values)
{
if (value is double number)
{
sum += number;
}
else if (value is string strNumber)
{
sum += double.Parse(strNumber, NumberStyles.Any, CultureInfo.InvariantCulture);
}
else
{
throw new NotImplementedException();
}
}

return sum;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
386 changes: 221 additions & 165 deletions src/modules/launcher/PowerLauncher/ResultList.xaml

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/modules/launcher/PowerLauncher/SettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using System.Linq;
using System.Threading;
using System.Windows.Input;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Library;
using PowerLauncher.Helper;
using PowerLauncher.Plugin;
using PowerToys.GPOWrapperProjection;
using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
Expand Down Expand Up @@ -185,6 +185,11 @@ public void ReadSettings()
_settings.TitleFontSize = overloadSettings.Properties.TitleFontSize;
}

if (_settings.ShowPreview != overloadSettings.Properties.ShowPreview)
{
_settings.ShowPreview = overloadSettings.Properties.ShowPreview;
}

retry = false;
}

Expand Down
14 changes: 13 additions & 1 deletion src/modules/launcher/PowerLauncher/ViewModel/ResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public ResultViewModel(Result result, IMainViewModel mainViewModel, PowerToysRun
}

_settings = settings;
_settings.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(_settings.ShowPreview))
{
if (!string.IsNullOrEmpty(Result.IcoPath))
{
_imageLoaded = false;
ImageLoader.Unload(Result.IcoPath);
}
}
};

ContextMenuSelectedIndex = NoSelectionIndex;
LoadContextMenu();
Expand Down Expand Up @@ -237,7 +248,8 @@ private async Task LoadImageAsync()
{
var imagePath = Result.IcoPath;
var iconDelegate = Result.Icon;
Image = await LoadImageInternalAsync(imagePath, iconDelegate, false).ConfigureAwait(false);

Image = await LoadImageInternalAsync(imagePath, iconDelegate, _settings.ShowPreview).ConfigureAwait(false);
}

// Returns false if we've already reached the last item.
Expand Down
15 changes: 15 additions & 0 deletions src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public ResultsViewModel(PowerToysRunSettings settings, IMainViewModel mainViewMo
OnPropertyChanged(nameof(MaxHeight));
});
}

if (e.PropertyName == nameof(_settings.ShowPreview))
{
Application.Current.Dispatcher.Invoke(() =>
{
OnPropertyChanged(nameof(ShowPreview));
});
}
};
}

Expand All @@ -54,6 +62,11 @@ public int MaxHeight
}
}

public bool ShowPreview
{
get => _settings.ShowPreview;
}

private int _selectedIndex;

public int SelectedIndex
Expand Down Expand Up @@ -94,6 +107,8 @@ public ResultViewModel SelectedItem
{
_selectedItem = value;
}

OnPropertyChanged(nameof(SelectedItem));
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/modules/launcher/Wox.Infrastructure/Image/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public ImageSource this[string path]
}
}

public void Remove(string path)
{
Usage.TryRemove(path, out _);
_data.TryRemove(path, out _);
}

public void Cleanup()
{
var images = Usage
Expand Down
5 changes: 5 additions & 0 deletions src/modules/launcher/Wox.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ private static ImageResult GetThumbnailResult(ref string path, bool generateThum

private const bool _enableImageHash = true;

public static void Unload(string path)
{
ImageCache.Remove(path);
}

public static async ValueTask<ImageSource> LoadAsync(string path, bool generateThumbnailsFromFiles, bool loadFullImage = false)
{
var imageResult = await LoadInternalAsync(path, generateThumbnailsFromFiles, loadFullImage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ public ShowPluginsOverviewMode ShowPluginsOverview

[JsonConverter(typeof(JsonStringEnumConverter))]
public LastQueryMode LastQueryMode { get; set; } = LastQueryMode.Selected;

private bool _showPreview;

public bool ShowPreview
{
get => _showPreview;

set
{
if (_showPreview != value)
{
_showPreview = value;
OnPropertyChanged(nameof(ShowPreview));
}
}
}
}

public enum LastQueryMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class PowerLauncherProperties
[JsonPropertyName("generate_thumbnails_from_files")]
public bool GenerateThumbnailsFromFiles { get; set; }

[JsonPropertyName("show_preview")]
public bool ShowPreview { get; set; }

[CmdConfigureIgnoreAttribute]
public HotkeySettings DefaultOpenPowerLauncher => new HotkeySettings(false, false, true, false, 32);

Expand Down Expand Up @@ -127,6 +130,7 @@ public PowerLauncherProperties()
UsePinyin = false;
ShowPluginsOverview = 0;
TitleFontSize = 16;
ShowPreview = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@
<tkcontrols:SettingsCard x:Uid="PowerLauncher_GenerateThumbnailsFromFiles" HeaderIcon="{ui:FontIcon Glyph=&#xE91B;}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.GenerateThumbnailsFromFiles, Mode=TwoWay}" />
</tkcontrols:SettingsCard>

<tkcontrols:SettingsCard x:Uid="PowerLauncher_ShowPreview" HeaderIcon="{ui:FontIcon Glyph=&#xE91B;}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.ShowPreview, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</controls:SettingsGroup>

<!--<ComboBox x:Uid="PowerLauncher_SearchResultPreference"
Expand Down
6 changes: 6 additions & 0 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@
<data name="PowerLauncher_UsePinyin.Description" xml:space="preserve">
<value>Experimental: Use Pinyin on the search query. May not work for every plugin.</value>
</data>
<data name="PowerLauncher_ShowPreview.Header" xml:space="preserve">
<value>Show preview</value>
</data>
<data name="PowerLauncher_ShowPreview.Description" xml:space="preserve">
<value>Show the preview panel.</value>
</data>
<data name="PowerLauncher_SearchResultPreference_MostRecentlyUsed" xml:space="preserve">
<value>Most recently used</value>
</data>
Expand Down
17 changes: 17 additions & 0 deletions src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,23 @@ public bool UsePinyin
}
}

public bool ShowPreview
{
get
{
return settings.Properties.ShowPreview;
}

set
{
if (settings.Properties.ShowPreview != value)
{
settings.Properties.ShowPreview = value;
UpdateSettings();
}
}
}

public int ShowPluginsOverviewIndex
{
get
Expand Down
Loading