Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
madskristensen committed Jul 21, 2021
1 parent 56461f3 commit 76f09d7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
18 changes: 15 additions & 3 deletions src/Commands/GetMoreThemesCommand.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
using System;
using System.Diagnostics;
using Community.VisualStudio.Toolkit;
using Microsoft.VisualStudio.Shell;

namespace ThemeSwitcher
{
[Command(PackageIds.GetMoreThemes)]
internal sealed class GetMoreThemesCommand : BaseCommand<GetMoreThemesCommand>
{
protected override void Execute(object sender, EventArgs e)
private const string _url = "https://marketplace.visualstudio.com/search?term=theme&target=VS&vsVersion=";

protected override async System.Threading.Tasks.Task ExecuteAsync(OleMenuCmdEventArgs e)
{
System.Diagnostics.Process.Start("https://marketplace.visualstudio.com/search?target=VS&category=Tools&vsVersion=&subCategory=Themes&sortBy=Installs");
EnvDTE80.DTE2 dte = await VS.GetServiceAsync<EnvDTE.DTE, EnvDTE80.DTE2>();

var vs = dte.Version switch
{
"16.0" => "vs2019",
"17.0" => "vs2022",
_ => ""
};

Process.Start(_url + vs);
}
}
}
25 changes: 12 additions & 13 deletions src/Commands/SelectThemeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@ protected override void BeforeQueryStatus(EventArgs e)
{
if (_commands.Any())
{
return;
return; // The commands were already set up
}

IEnumerable<Theme> themes = ThemeStore.Themes.Value;
OleMenuCommandService mcs = Package.GetService<IMenuCommandService, OleMenuCommandService>();
var i = 1;

Theme firstTheme = themes.First();
Command.Enabled = Command.Visible = true;
Command.Text = firstTheme.Name;
Command.Checked = firstTheme.IsActive;
Command.Properties["guid"] = firstTheme.Guid;
_commands.Add(Command);
SetupCommand(Command, themes.First());

foreach (Theme theme in themes.Skip(1))
{
CommandID cmdId = new(PackageGuids.ThemeSwitcher, PackageIds.FirstTheme + i++);

OleMenuCommand command = new(Execute, cmdId);
command.Properties["guid"] = theme.Guid;
command.Text = theme.Name;
command.Checked = theme.IsActive;
SetupCommand(command, theme);
mcs.AddCommand(command);

_commands.Add(command);
}
}

private void SetupCommand(OleMenuCommand command, Theme theme)
{
command.Enabled = command.Visible = true;
command.Text = theme.Name;
command.Checked = theme.IsActive;
command.Properties["guid"] = theme.Guid;
_commands.Add(command);
}

protected override void Execute(object sender, EventArgs e)
{
var command = (OleMenuCommand)sender;
Expand Down
1 change: 1 addition & 0 deletions src/ThemeSwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Design" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
Expand Down

0 comments on commit 76f09d7

Please sign in to comment.