Settings + PowerLauncher integration

* Fix project references

* Fix MaxResultsToShow

* Fix Alt + Space display

* Fix settings defaults
This commit is contained in:
Tomas Raies 2020-04-27 22:05:20 -07:00
parent fe77a7e01a
commit c505875fef
14 changed files with 244 additions and 199 deletions

View File

@ -20,6 +20,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runner", "src\runner\runner
{E364F67B-BB12-4E91-B639-355866EBCD8B} = {E364F67B-BB12-4E91-B639-355866EBCD8B}
{DA425894-6E13-404F-8DCB-78584EC0557A} = {DA425894-6E13-404F-8DCB-78584EC0557A}
{2BE46397-4DFA-414C-9BD4-41E4BBF8CB34} = {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}
{A7D5099E-F0FD-4BF3-8522-5A682759F915} = {A7D5099E-F0FD-4BF3-8522-5A682759F915}
{0B43679E-EDFA-4DA0-AD30-F4628B308B1B} = {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}
{B25AC7A5-FB9F-4789-B392-D5C85E948670} = {B25AC7A5-FB9F-4789-B392-D5C85E948670}
{E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F} = {E4E0D2AE-B17D-4BD4-8BEE-AFC8CC464C5F}
@ -30,7 +31,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runner", "src\runner\runner
{F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99} = {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}
{07C389E3-6BC8-41CF-923E-307B1265FA2D} = {07C389E3-6BC8-41CF-923E-307B1265FA2D}
{89F34AF7-1C34-4A72-AA6E-534BCF972BD9} = {89F34AF7-1C34-4A72-AA6E-534BCF972BD9}
{A7D5099E-F0FD-4BF3-8522-5A682759F915} = {A7D5099E-F0FD-4BF3-8522-5A682759F915}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{74485049-C722-400F-ABE5-86AC52D929B3}"
@ -171,9 +171,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wox", "src\modules\launcher
ProjectSection(ProjectDependencies) = postProject
{FDB3555B-58EF-4AE6-B5F1-904719637AB4} = {FDB3555B-58EF-4AE6-B5F1-904719637AB4}
{59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E}
{74F1B9ED-F59C-4FE7-B473-7B453E30837E} = {74F1B9ED-F59C-4FE7-B473-7B453E30837E}
{C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0} = {C21BFF9C-2C99-4B5F-B7C9-A5E6DDDB37B0}
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {787B8AA6-CA93-4C84-96FE-DF31110AD1C4}
{F8B870EB-D5F5-45BA-9CF7-A5C459818820} = {F8B870EB-D5F5-45BA-9CF7-A5C459818820}
{74F1B9ED-F59C-4FE7-B473-7B453E30837E} = {74F1B9ED-F59C-4FE7-B473-7B453E30837E}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wox.Core", "src\modules\launcher\Wox.Core\Wox.Core.csproj", "{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}"
@ -252,6 +253,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common-md-flag", "src\commo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "interop-tests", "src\common\interop-tests\interop-tests.csproj", "{437AD818-3F1F-4CA5-A79B-25233A157026}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wox.Plugin.Folder", "src\modules\launcher\Plugins\Wox.Plugin.Folder\Wox.Plugin.Folder.csproj", "{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
@ -817,6 +820,13 @@ Global
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|ARM64.ActiveCfg = Release|Win32
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x64.ActiveCfg = Release|x64
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x64.Build.0 = Release|x64
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x86.ActiveCfg = Release|x64
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x86.Build.0 = Release|x64
{A7D5099E-F0FD-4BF3-8522-5A682759F915}.Release|x86.Deploy.0 = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|ARM64.Build.0 = Debug|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.ActiveCfg = Debug|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x64.Build.0 = Debug|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Debug|x86.ActiveCfg = Debug|Any CPU
@ -827,8 +837,8 @@ Global
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|ARM64.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.ActiveCfg = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x64.Build.0 = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.ActiveCfg = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.Build.0 = Release|Any CPU
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.ActiveCfg = Release|x64
{B1BCC8C6-46B5-4BFA-8F22-20F32D99EC6A}.Release|x86.Build.0 = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|ARM.ActiveCfg = Debug|ARM
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|ARM.Build.0 = Debug|ARM
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Debug|ARM.Deploy.0 = Debug|ARM
@ -848,9 +858,9 @@ Global
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|ARM64.Deploy.0 = Release|ARM64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.ActiveCfg = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x64.Build.0 = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.ActiveCfg = Release|x86
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.Build.0 = Release|x86
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.Deploy.0 = Release|x86
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.ActiveCfg = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.Build.0 = Release|x64
{A80355C2-780D-4245-BD80-25B8DE698EE3}.Release|x86.Deploy.0 = Release|x64
{F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM.ActiveCfg = Debug|x64
{F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.ActiveCfg = Debug|x64
{F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.ActiveCfg = Debug|x64
@ -881,6 +891,16 @@ Global
{437AD818-3F1F-4CA5-A79B-25233A157026}.Release|x64.ActiveCfg = Release|x64
{437AD818-3F1F-4CA5-A79B-25233A157026}.Release|x64.Build.0 = Release|x64
{437AD818-3F1F-4CA5-A79B-25233A157026}.Release|x86.ActiveCfg = Release|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|ARM.ActiveCfg = Debug|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|ARM64.ActiveCfg = Debug|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|x64.ActiveCfg = Debug|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|x64.Build.0 = Debug|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Debug|x86.ActiveCfg = Debug|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|ARM.ActiveCfg = Release|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|ARM64.ActiveCfg = Release|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|x64.ActiveCfg = Release|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|x64.Build.0 = Release|x64
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4}.Release|x86.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -950,6 +970,7 @@ Global
{F055103B-F80B-4D0C-BF48-057C55620033} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{985B3F2F-CEED-4C0A-A249-69257E719145} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{437AD818-3F1F-4CA5-A79B-25233A157026} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
this.FileExplorerPreview = false;
this.PowerRename = false;
this.ShortcutGuide = false;
this.PowerLauncher = false;
this.PowerLauncher = true;
}
[JsonPropertyName("FancyZones")]

View File

@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using System.Text;
using System.Text.Json.Serialization;
@ -61,7 +62,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
output.Append("Shift + ");
}
output.Append(Key);
var localKey = Helper.GetKeyName((uint) Code);
output.Append(localKey);
return output.ToString();
}

View File

@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
properties = new PowerLauncherProperties();
version = "1";
name = "_unset_";
name = POWERTOYNAME;
}
public virtual void Save()

View File

@ -20,7 +20,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private readonly SendCallback callback;
public PowerLauncherViewModel()
{
{
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings)));
};
if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME))
{
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);
@ -28,24 +34,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
else
{
settings = new PowerLauncherSettings();
settings.properties.open_powerlauncher.Alt = true;
settings.properties.open_powerlauncher.Code = (int)Windows.System.VirtualKey.Space;
settings.properties.maximum_number_of_results = 4;
callback(settings);
}
if (SettingsUtils.SettingsExists())
{
generalSettings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
generalSettings = SettingsUtils.GetSettings<GeneralSettings>();
}
else
{
generalSettings = new GeneralSettings();
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
var propertiesJson = JsonSerializer.Serialize(settings.properties);
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
};
}
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
@ -59,7 +61,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Notify UI of property change
OnPropertyChanged(propertyName);
settings.Save();
callback(settings);
}
@ -76,7 +77,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
generalSettings.Enabled.PowerLauncher = value;
OnPropertyChanged(nameof(EnablePowerLauncher));
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettings);
ShellPage.DefaultSndMSGCallback(outgoing.ToString());
}

View File

@ -47,17 +47,6 @@ namespace ViewModelTests
);
}
[TestMethod]
public void IsEnabled_ShouldEnableModule()
{
viewModel.EnablePowerLauncher = true;
Assert.AreEqual(sendCallbackMock.TimesSent, 1);
Assert.AreEqual(mockSettings.TimesSaved, 1);
Assert.IsTrue(mockSettings.properties.enable_powerlauncher == true);
}
[TestMethod]
public void SearchPreference_ShouldUpdatePreferences()
{

View File

@ -43,6 +43,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
</ItemGroup>

View File

@ -1,3 +1,4 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -283,5 +284,10 @@ namespace Wox.Plugin.Folder
{
return _contextMenuLoader.LoadContextMenus(selectedResult);
}
public void UpdateSettings(PowerLauncherSettings settings)
{
}
}
}

View File

@ -93,6 +93,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
</ItemGroup>

View File

@ -35,9 +35,7 @@ namespace PowerLauncher
private Settings _settings;
private MainViewModel _viewModel;
private bool _isTextSetProgramatically;
const int ROW_COUNT = 4;
const int ROW_HEIGHT = 75;
const int MAX_LIST_HEIGHT = 300;
#endregion
public MainWindow(Settings settings, MainViewModel mainVM)
@ -304,8 +302,8 @@ namespace PowerLauncher
private void SuggestionList_UpdateListSize(object sender, ContainerContentChangingEventArgs e)
{
int count = _viewModel?.Results?.Results.Count ?? 0;
int maxHeight = count < ROW_COUNT ? count * ROW_HEIGHT : MAX_LIST_HEIGHT;
_resultList.Height = maxHeight;
int displayCount = Math.Min(count, _settings.MaxResultsToShow);
_resultList.Height = displayCount * ROW_HEIGHT;
}
private void SuggestionsList_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)

View File

@ -62,13 +62,10 @@ namespace PowerLauncher
shellSettings.UpdateSettings(overloadSettings);
}
var indexer = PluginManager.AllPlugins.Find(pp => pp.Metadata.Name == "Windows Indexer Plugin");
if (indexer != null)
if (_settings.MaxResultsToShow != overloadSettings.properties.maximum_number_of_results)
{
var indexerSettings = indexer.Plugin as ISettingProvider;
indexerSettings.UpdateSettings(overloadSettings);
_settings.MaxResultsToShow = overloadSettings.properties.maximum_number_of_results;
}
}
catch (Exception e)
{

View File

@ -82,7 +82,23 @@ namespace Wox.Infrastructure.UserSettings
public double WindowLeft { get; set; }
public double WindowTop { get; set; }
public int MaxResultsToShow { get; set; } = 6;
private int _maxResultsToShow = 6;
public int MaxResultsToShow
{
get
{
return _maxResultsToShow;
}
set
{
if (_maxResultsToShow != value)
{
_maxResultsToShow = value;
OnPropertyChanged();
}
}
}
public int ActivateTimes { get; set; }
// Order defaults to 0 or -1, so 1 will let this property appear last

View File

@ -6,7 +6,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Input;
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
@ -21,7 +21,7 @@ namespace Wox.ViewModel
private readonly object _addResultsLock = new object();
private readonly object _collectionLock = new object();
private readonly Settings _settings;
private int MaxResults => _settings?.MaxResultsToShow ?? 6;
// private int MaxResults => _settings?.MaxResultsToShow ?? 6;
public ResultsViewModel()
{
@ -35,7 +35,10 @@ namespace Wox.ViewModel
{
if (e.PropertyName == nameof(_settings.MaxResultsToShow))
{
OnPropertyChanged(nameof(MaxHeight));
Application.Current.Dispatcher.Invoke(() =>
{
OnPropertyChanged(nameof(MaxHeight));
});
}
};
}
@ -44,31 +47,36 @@ namespace Wox.ViewModel
#region Properties
public int MaxHeight => MaxResults * 50;
public int MaxHeight
{
get
{
return _settings.MaxResultsToShow * 75;
}
}
public int SelectedIndex { get; set; }
private ResultViewModel _selectedItem;
public ResultViewModel SelectedItem
public ResultViewModel SelectedItem
{
get { return _selectedItem; }
set
{
//value can be null when selecting an item in a virtualized list
if (value != null)
{
if (_selectedItem != null)
{
_selectedItem.DeactivateContextButtons(ResultViewModel.ActivationType.Selection);
}
_selectedItem = value;
_selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection);
}
else
{
_selectedItem = value;
}
set
{
//value can be null when selecting an item in a virtualized list
if (value != null)
{
if (_selectedItem != null)
{
_selectedItem.DeactivateContextButtons(ResultViewModel.ActivationType.Selection);
}
_selectedItem = value;
_selectedItem.ActivateContextButtons(ResultViewModel.ActivationType.Selection);
}
else
{
_selectedItem = value;
}
}
}
@ -127,12 +135,12 @@ namespace Wox.ViewModel
public void SelectNextPage()
{
SelectedIndex = NewIndex(SelectedIndex + MaxResults);
SelectedIndex = NewIndex(SelectedIndex + _settings.MaxResultsToShow);
}
public void SelectPrevPage()
{
SelectedIndex = NewIndex(SelectedIndex - MaxResults);
SelectedIndex = NewIndex(SelectedIndex - _settings.MaxResultsToShow);
}
public void SelectFirstResult()
@ -153,26 +161,26 @@ namespace Wox.ViewModel
public void RemoveResultsFor(PluginMetadata metadata)
{
Results.RemoveAll(r => r.Result.PluginID == metadata.ID);
}
public void SelectNextTabItem()
{
if(!SelectedItem.SelectNextContextButton())
{
SelectNextResult();
}
}
public void SelectPrevTabItem()
{
if (!SelectedItem.SelectPrevContextButton())
{
//Tabbing backwards should highlight the last item of the previous row
SelectPrevResult();
SelectedItem.SelectLastContextButton();
}
}
}
public void SelectNextTabItem()
{
if(!SelectedItem.SelectNextContextButton())
{
SelectNextResult();
}
}
public void SelectPrevTabItem()
{
if (!SelectedItem.SelectPrevContextButton())
{
//Tabbing backwards should highlight the last item of the previous row
SelectPrevResult();
SelectedItem.SelectLastContextButton();
}
}
/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>