Skip to content

Commit 31ea653

Browse files
committed
Provides 'checked' status to Toggle Editor Bar command.
User can now see if the bar is enabled on the button / menu item itself. For this to work, we've to auto-load the VS package. To save resources, package is auto-loaded conditionally only if the bar is enabled.
1 parent fcc876f commit 31ea653

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/EditorBar/Commands/ToggleEditorBarCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
1818
GeneralOptionsModel.Instance.Enabled = !GeneralOptionsModel.Instance.Enabled;
1919
await GeneralOptionsModel.Instance.SaveAsync();
2020
}
21+
22+
protected override Task InitializeCompletedAsync()
23+
{
24+
this.Command.Checked = GeneralOptionsModel.Instance.Enabled;
25+
return base.InitializeCompletedAsync();
26+
}
27+
28+
protected override void BeforeQueryStatus(EventArgs e)
29+
{
30+
base.BeforeQueryStatus(e);
31+
this.Command.Checked = GeneralOptionsModel.Instance.Enabled;
32+
}
2133
}

src/EditorBar/EditorBarPackage.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ namespace JPSoftworks.EditorBar;
3838
[ProvideProfile(typeof(GeneralOptionPage), "Editor Bar", "General", 0, 0, true)]
3939
[ProvideMenuResource("Menus.ctmenu", 1)]
4040
[ProvideService(typeof(EditorBarFileActionMenuBridge), IsAsyncQueryable = true)]
41+
[ProvideAutoLoad(EditorBarPackage.EditorBarEnabledAutoload, PackageAutoLoadFlags.BackgroundLoad)]
42+
[ProvideUIContextRule(EditorBarPackage.EditorBarEnabledAutoload, // we've to load the package to provide Checked status for the ToggleEditorBarCommand
43+
name: "Auto load when Editor Bar is Enabled",
44+
expression: "editorBarEnabled",
45+
termNames: ["editorBarEnabled"],
46+
termValues: ["UserSettingsStoreQuery:" + GeneralOptionsModel.PathToEnabledProperty],
47+
delay: 100)]
4148
public sealed class EditorBarPackage : AsyncPackage
4249
{
50+
private const string EditorBarEnabledAutoload = "3c1dfe70-bb76-4e6d-b86c-a7c6ed149cf2";
51+
4352
/// <summary>
4453
/// EditorBarPackage GUID string.
4554
/// </summary>

src/EditorBar/Options/GeneralOptionsModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ public class GeneralOptionsModel : BaseOptionModel<GeneralOptionsModel>, IRating
3030
private const string AdditionalActionCategoryName = "Actions";
3131
private const string ExternalEditorCategoryName = "External Editor";
3232

33+
private const string RegistryCollectionName = "JPSoftworks.EditorBar.Options.GeneralPage";
34+
internal const string PathToEnabledProperty = RegistryCollectionName + @"\" + nameof(Enabled);
35+
3336
// keep legacy name to keep settings for existing users intact
34-
protected override string CollectionName => "JPSoftworks.EditorBar.Options.GeneralPage";
37+
protected override string CollectionName => RegistryCollectionName;
3538

3639
// -------------------------------------------
3740
// Appearance category

src/EditorBar/VSCommandTable.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ internal sealed partial class PackageGuids
1515
public const string guidEditorBarPackageString = "ef5d9a25-5e0d-4428-8762-56d4dc816eeb";
1616
public static Guid guidEditorBarPackage = new Guid(guidEditorBarPackageString);
1717

18+
public const string guidUIContextGuidString = "3c1dfe70-bb76-4e6d-b86c-a7c6ed149cf2";
19+
public static Guid guidUIContextGuid = new Guid(guidUIContextGuidString);
20+
1821
public const string guidEditorBarPackageCmdSetString = "264c2d6c-e85c-4cbb-a800-0c412f8d91f1";
1922
public static Guid guidEditorBarPackageCmdSet = new Guid(guidEditorBarPackageCmdSetString);
2023

src/EditorBar/VSCommandTable.vsct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Button guid="guidEditorBarPackageCmdSet" id="ToggleEditorBarCommand" priority="0x0100" type="Button">
6363
<!-- placed using command placements -->
6464
<Icon guid="guidImages" id="bmpToggleEditorBar" />
65+
<CommandFlag>TogglePatternAvailable</CommandFlag>
6566
<Strings>
6667
<ButtonText>Toggle &amp;Editor Bar</ButtonText>
6768
<CommandName>Toggle Editor Bar</CommandName>
@@ -177,6 +178,8 @@
177178

178179
<GuidSymbol name="guidEditorBarPackage" value="{ef5d9a25-5e0d-4428-8762-56d4dc816eeb}" />
179180

181+
<GuidSymbol name="guidUIContextGuid" value="{3c1dfe70-bb76-4e6d-b86c-a7c6ed149cf2}" />
182+
180183
<GuidSymbol name="guidEditorBarPackageCmdSet" value="{264c2d6c-e85c-4cbb-a800-0c412f8d91f1}">
181184
<IDSymbol name="EditorBarViewMenuGroup" value="0x1120" />
182185
<IDSymbol name="EditorBarViewSubMenu" value="0x1130" />

0 commit comments

Comments
 (0)