mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Add settings to hide non-apps from results
- Adds two checkboxes to All Apps settingsQ - Allows users to hide generic files on Desktop and Start Menu from results
This commit is contained in:
@@ -48,6 +48,10 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface
|
||||
|
||||
public bool EnablePathEnvironmentVariableSource => _enablePathEnvironmentVariableSource.Value;
|
||||
|
||||
public bool HideGenericFilesOnDesktop => _hideGenericFilesOnDesktop.Value;
|
||||
|
||||
public bool HideGenericFilesInStartMenu => _hideGenericFilesInStartMenu.Value;
|
||||
|
||||
private readonly ChoiceSetSetting _searchResultLimitSource = new(
|
||||
Namespaced(nameof(SearchResultLimit)),
|
||||
Resources.limit_fallback_results_source,
|
||||
@@ -80,6 +84,18 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface
|
||||
string.Empty,
|
||||
false); // this one is very VERY noisy
|
||||
|
||||
private readonly ToggleSetting _hideGenericFilesOnDesktop = new(
|
||||
Namespaced(nameof(HideGenericFilesOnDesktop)),
|
||||
" " + Resources.hide_generic_files_on_desktop,
|
||||
string.Empty,
|
||||
true);
|
||||
|
||||
private readonly ToggleSetting _hideGenericFilesInStartMenu = new(
|
||||
Namespaced(nameof(HideGenericFilesInStartMenu)),
|
||||
" " + Resources.hide_generic_files_in_start_menu,
|
||||
string.Empty,
|
||||
false);
|
||||
|
||||
public double MinScoreThreshold { get; set; } = 0.75;
|
||||
|
||||
internal const char SuffixSeparator = ';';
|
||||
@@ -98,7 +114,9 @@ public class AllAppsSettings : JsonSettingsManager, ISettingsInterface
|
||||
FilePath = SettingsJsonPath();
|
||||
|
||||
Settings.Add(_enableStartMenuSource);
|
||||
Settings.Add(_hideGenericFilesInStartMenu);
|
||||
Settings.Add(_enableDesktopSource);
|
||||
Settings.Add(_hideGenericFilesOnDesktop);
|
||||
Settings.Add(_enableRegistrySource);
|
||||
Settings.Add(_enablePathEnvironmentVariableSource);
|
||||
Settings.Add(_searchResultLimitSource);
|
||||
|
||||
@@ -409,9 +409,37 @@ public class Win32Program : IProgram
|
||||
program.Description = info.FileDescription;
|
||||
}
|
||||
}
|
||||
|
||||
if (program.AppType is ApplicationType.GenericFile or ApplicationType.Folder)
|
||||
{
|
||||
var hideNonAppsOnDesktop = AllAppsSettings.Instance.HideGenericFilesOnDesktop;
|
||||
var hideNonAppsInStartMenu = AllAppsSettings.Instance.HideGenericFilesInStartMenu;
|
||||
|
||||
var lnk = program.LnkFilePath;
|
||||
if (!string.IsNullOrEmpty(lnk))
|
||||
{
|
||||
var isDesktop = StartsWithFolder(lnk, Environment.SpecialFolder.Desktop) ||
|
||||
StartsWithFolder(lnk, Environment.SpecialFolder.CommonDesktopDirectory);
|
||||
|
||||
var isStartMenu = StartsWithFolder(lnk, Environment.SpecialFolder.StartMenu) ||
|
||||
StartsWithFolder(lnk, Environment.SpecialFolder.CommonStartMenu);
|
||||
|
||||
if ((isDesktop && hideNonAppsOnDesktop) || (isStartMenu && hideNonAppsInStartMenu))
|
||||
{
|
||||
program.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return program;
|
||||
|
||||
static bool StartsWithFolder(string path, Environment.SpecialFolder folder)
|
||||
{
|
||||
var folderPath = Environment.GetFolderPath(folder);
|
||||
return !string.IsNullOrEmpty(folderPath)
|
||||
&& path.StartsWith(folderPath, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
catch (System.IO.FileLoadException e)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
@@ -141,6 +141,24 @@ namespace Microsoft.CmdPal.Ext.Apps.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Hide shortcuts to non-executable files in Start menu.
|
||||
/// </summary>
|
||||
internal static string hide_generic_files_in_start_menu {
|
||||
get {
|
||||
return ResourceManager.GetString("hide_generic_files_in_start_menu", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Hide shortcuts to non-executable files on Desktop.
|
||||
/// </summary>
|
||||
internal static string hide_generic_files_on_desktop {
|
||||
get {
|
||||
return ResourceManager.GetString("hide_generic_files_on_desktop", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Installed apps.
|
||||
/// </summary>
|
||||
|
||||
@@ -234,4 +234,10 @@
|
||||
<data name="limit_none" xml:space="preserve">
|
||||
<value>Unlimited</value>
|
||||
</data>
|
||||
<data name="hide_generic_files_on_desktop" xml:space="preserve">
|
||||
<value>Hide shortcuts to non-executable files on Desktop</value>
|
||||
</data>
|
||||
<data name="hide_generic_files_in_start_menu" xml:space="preserve">
|
||||
<value>Hide shortcuts to non-executable files in Start menu</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user