Skip to content

Commit

Permalink
option to exclude visual studio instances
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Jan 24, 2024
1 parent 65312bd commit f6ac426
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VisualStudioService()
{
}

public void InitInstances()
public void InitInstances(string[] excludedVersions)
{
var paths = new string?[] { null, VsWhereDir };
var exceptions = new List<(string? Path, Exception Exception)>(paths.Length);
Expand Down Expand Up @@ -78,6 +78,11 @@ public void InitInstances()
continue;
}

if (excludedVersions.Contains(instance.Catalog.ProductLineVersion))
{
continue;
}

instances.Add(new VisualStudioInstance(instance, applicationPrivateSettingsPath));
}

Expand Down
13 changes: 13 additions & 0 deletions Community.PowerToys.Run.Plugin.VisualStudio/Json/Catalog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Text.Json.Serialization;

namespace Community.PowerToys.Run.Plugin.VisualStudio.Json
{
public sealed class Catalog
{
[JsonPropertyName("productLineVersion")]
public required string ProductLineVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ public sealed class VisualStudioInstance

[JsonPropertyName("displayName")]
public required string DisplayName { get; set; }

[JsonPropertyName("catalog")]
public required Catalog Catalog { get; set; }
}
}
45 changes: 38 additions & 7 deletions Community.PowerToys.Run.Plugin.VisualStudio/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,49 @@ namespace Community.PowerToys.Run.Plugin.VisualStudio
public class Main : IPlugin, ISettingProvider, IContextMenu
{
private const string ShowPrerelease = nameof(ShowPrerelease);
private const string ExcludedVersions = nameof(ExcludedVersions);
private const bool ShowPrereleaseDefaultValue = true;
private const string ExcludedVersionsDefaultValue = "";
private static readonly string _pluginName = Assembly.GetExecutingAssembly().GetName().Name ?? string.Empty;

public static string PluginID => "D0998A1863424336A86A2B6E936C0E8E";

private readonly VisualStudioService _visualStudioService;
private bool _showPrerelease;
private string _excludedVersions;

public string Name => "Visual Studio";

public string Description => "Open Visual Studio recents.";

public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>
{
new PluginAdditionalOption
new()
{
Key = ShowPrerelease,
Value = ShowPrereleaseDefaultValue,
DisplayLabel = "Show prerelease",
DisplayDescription = "Include results from prerelease",
},
new()
{
PluginOptionType = PluginAdditionalOption.AdditionalOptionType.Textbox,
Key = ExcludedVersions,
TextValue = ExcludedVersionsDefaultValue,
DisplayLabel = "Excluded versions",
DisplayDescription = "Add multiple versions separated by space. Example: 2019 2022",
},
};

public Main()
{
_excludedVersions = ExcludedVersionsDefaultValue;
_visualStudioService = new VisualStudioService();
}

public void Init(PluginInitContext context)
{
_visualStudioService.InitInstances();
ReloadVisualStudioInstances();
}

public List<Result> Query(Query query)
Expand All @@ -74,9 +86,23 @@ public Control CreateSettingPanel()

public void UpdateSettings(PowerLauncherPluginSettings settings)
{
_showPrerelease = settings != null && settings.AdditionalOptions != null
? settings.AdditionalOptions.FirstOrDefault(x => x.Key == ShowPrerelease)?.Value ?? ShowPrereleaseDefaultValue
: ShowPrereleaseDefaultValue;
var oldExcludedVersions = _excludedVersions;

if (settings != null && settings.AdditionalOptions != null)
{
_showPrerelease = settings.AdditionalOptions.FirstOrDefault(x => x.Key == ShowPrerelease)?.Value ?? ShowPrereleaseDefaultValue;
_excludedVersions = settings.AdditionalOptions.FirstOrDefault(x => x.Key == ExcludedVersions)?.TextValue ?? ExcludedVersionsDefaultValue;
}
else
{
_showPrerelease = ShowPrereleaseDefaultValue;
_excludedVersions = ExcludedVersionsDefaultValue;
}

if (oldExcludedVersions != _excludedVersions)
{
ReloadVisualStudioInstances();
}
}

public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
Expand All @@ -88,7 +114,7 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)

return new List<ContextMenuResult>
{
new ContextMenuResult
new()
{
Title = "Run as administrator (Ctrl+Shift+Enter)",
Glyph = "\xE7EF",
Expand All @@ -102,7 +128,7 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
return true;
},
},
new ContextMenuResult
new()
{
Title = "Open containing folder (Ctrl+Shift+E)",
Glyph = "\xE838",
Expand All @@ -118,5 +144,10 @@ public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
},
};
}

private void ReloadVisualStudioInstances()
{
_visualStudioService.InitInstances(_excludedVersions.Split(' ').ToArray());
}
}
}
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit f6ac426

Please sign in to comment.