Skip to content

Commit

Permalink
Text editor toolbar command buttons (#227)
Browse files Browse the repository at this point in the history
* Add icons to vsct.
* Add "action" commands to text editor toolbar.
* Enable action buttons based on session status.
* Give commands meaningful names.  This fixes the ugly names in Tools | Customize | Toolbar, etc.
* Use toggle glyphs to show session state.  Reflect current state of "enabled in session" mode in its toolbar and menu button icons.
* Remove redundant class.  "Latched" flag functionality is provided by OleMenuCommand.Checked.
* Host action buttons on packaged-defined toolbar.  Optionally, to host on the VS text editor toolbar, specify MSBuild property "VSCTDefinitions=USE_VS_TOOLBAR".
  • Loading branch information
walterpg authored Feb 28, 2021
1 parent 1856b88 commit fbe2bef
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
Binary file added Source/VSSpellChecker/Resources/command-strip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 41 additions & 6 deletions Source/VSSpellChecker/VSSpellChecker.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<Group guid="guidVSSpellCheckerCommandSet" id="SolutionExplorerFileGroup" priority="0x07B0"/>
<Group guid="guidVSSpellCheckerCommandSet" id="SolutionExplorerAddCtx" priority="0x07B0"/>
<Group guid="guidVSSpellCheckerCommandSet" id="NewItemMenuGroup" priority="0x07B0"/>
<Group guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup" priority="0x0c0d"
Condition="Defined(USE_VS_TOOLBAR)">
<Parent guid="guidStdEditor" id="IDM_VS_TOOL_TEXTEDITOR"/>
</Group>
<Group guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup" priority="0x0c0d"
Condition="!Defined(USE_VS_TOOLBAR)">
<Parent guid="guidVSSpellCheckerCommandSet" id="SpellCheckerToolbar"/>
</Group>
</Groups>

<Buttons>
Expand All @@ -43,37 +51,45 @@
</Button>

<Button guid="guidVSSpellCheckerCommandSet" id="SpellCheckInteractive" priority="0x0100">
<Parent guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup"/>
<Icon guid="guidIconBitmap" id="checkDocIcon"/>
<Strings>
<CommandName>cmdidSpellCheckInteractive</CommandName>
<CommandName>Spell Check Current Document</CommandName>
<ButtonText>Spell Check Current Document</ButtonText>
<MenuText>Spell Check Current Document</MenuText>
<ToolTipText>Spell check the current document</ToolTipText>
</Strings>
</Button>

<Button guid="guidVSSpellCheckerCommandSet" id="SpellCheckNextIssue" priority="0x0101">
<Button guid="guidVSSpellCheckerCommandSet" id="SpellCheckNextIssue" priority="0x0102">
<Parent guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup"/>
<Icon guid="guidIconBitmap" id="nextIcon"/>
<Strings>
<CommandName>cmdidSpellCheckNextIssue</CommandName>
<CommandName>Move to Next Spelling Issue</CommandName>
<ButtonText>Move to Next Spelling Issue</ButtonText>
<MenuText>Move to Next Spelling Issue</MenuText>
<ToolTipText>Move to the next spelling issue in the current document</ToolTipText>
</Strings>
</Button>

<Button guid="guidVSSpellCheckerCommandSet" id="SpellCheckPriorIssue" priority="0x0102">
<Button guid="guidVSSpellCheckerCommandSet" id="SpellCheckPriorIssue" priority="0x0101">
<Parent guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup"/>
<Icon guid="guidIconBitmap" id="prevIcon"/>
<Strings>
<CommandName>cmdidSpellCheckPriorIssue</CommandName>
<CommandName>Move to Prior Spelling Issue</CommandName>
<ButtonText>Move to Prior Spelling Issue</ButtonText>
<MenuText>Move to Prior Spelling Issue</MenuText>
<ToolTipText>Move to the prior spelling issue in the current document</ToolTipText>
</Strings>
</Button>

<Button guid="guidVSSpellCheckerCommandSet" id="EnableInCurrentSession" priority="0x0103">
<Parent guid="guidVSSpellCheckerCommandSet" id="TextEditorToolbarGroup"/>
<Icon guid="guidIconBitmap" id="disableIcon"/>
<CommandFlag>DontCache</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
<CommandName>cmdidEnableInCurrentSession</CommandName>
<CommandName>Enable/Disable in Current Session</CommandName>
<ButtonText>Disable in Current Session</ButtonText>
<MenuText>Disable in Current Session</MenuText>
<ToolTipText>Enable or disable interactive spell checking in the current session</ToolTipText>
Expand Down Expand Up @@ -155,6 +171,10 @@
</Strings>
</Button>
</Buttons>

<Bitmaps>
<Bitmap guid="guidIconBitmap" href="Resources\command-strip.png" usedList="disableIcon,checkDocIcon,nextIcon,prevIcon"/>
</Bitmaps>

<Menus>
<Menu guid="guidVSSpellCheckerCommandSet" id="SpellCheckerMenu" type="Menu" priority="0x0100">
Expand All @@ -165,6 +185,12 @@
<ToolTipText>Spell checker options</ToolTipText>
</Strings>
</Menu>
<Menu guid="guidVSSpellCheckerCommandSet" id="SpellCheckerToolbar" type="Toolbar" priority="0x0c00"
toolbarPriorityInBand="0xff00" Condition="!Defined(USE_VS_TOOLBAR)">
<Strings>
<ButtonText>Spell Checker</ButtonText>
</Strings>
</Menu>
</Menus>
</Commands>

Expand Down Expand Up @@ -269,6 +295,15 @@
<IDSymbol name="SolutionExplorerAddCtx" value="0x000C" />
<IDSymbol name="SolutionExplorerFileGroup" value="0x000D" />
<IDSymbol name="NewItemMenuGroup" value="0x000E" />
<IDSymbol name="TextEditorToolbarGroup" value="0x0101"/>
<IDSymbol name="SpellCheckerToolbar" value="0x0102"/>
</GuidSymbol>

<GuidSymbol name="guidIconBitmap" value="{5D3A0C64-BDE8-4016-97EC-3296EB2D4CAE}">
<IDSymbol name ="disableIcon" value="1"/>
<IDSymbol name="checkDocIcon" value="2"/>
<IDSymbol name="nextIcon" value="3"/>
<IDSymbol name="prevIcon" value="4"/>
</GuidSymbol>
</Symbols>

Expand Down
1 change: 1 addition & 0 deletions Source/VSSpellChecker/VSSpellChecker2017AndLater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Resources\command-strip.png" />
<Content Include="VSIXPackage.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
Expand Down
18 changes: 15 additions & 3 deletions Source/VSSpellChecker/VSSpellCheckerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,18 @@ protected override async System.Threading.Tasks.Task InitializeAsync(
mcs.AddCommand(menuItem);

commandId = new CommandID(GuidList.guidVSSpellCheckerCmdSet, (int)PkgCmdIDList.SpellCheckInteractive);
menuItem = new OleMenuCommand(SpellCheckInteractiveExecuteHandler, commandId);
menuItem = new OleMenuCommand(SpellCheckInteractiveExecuteHandler, null,
SpellCheckActionsQueryStatusHandler, commandId);
mcs.AddCommand(menuItem);

commandId = new CommandID(GuidList.guidVSSpellCheckerCmdSet, (int)PkgCmdIDList.SpellCheckNextIssue);
menuItem = new OleMenuCommand(SpellCheckNextPriorIssueExecuteHandler, commandId);
menuItem = new OleMenuCommand(SpellCheckNextPriorIssueExecuteHandler, null,
SpellCheckActionsQueryStatusHandler, commandId);
mcs.AddCommand(menuItem);

commandId = new CommandID(GuidList.guidVSSpellCheckerCmdSet, (int)PkgCmdIDList.SpellCheckPriorIssue);
menuItem = new OleMenuCommand(SpellCheckNextPriorIssueExecuteHandler, commandId);
menuItem = new OleMenuCommand(SpellCheckNextPriorIssueExecuteHandler, null,
SpellCheckActionsQueryStatusHandler, commandId);
mcs.AddCommand(menuItem);

commandId = new CommandID(GuidList.guidVSSpellCheckerCmdSet, (int)PkgCmdIDList.EnableInCurrentSession);
Expand Down Expand Up @@ -379,6 +382,12 @@ private void SpellCheckNextPriorIssueExecuteHandler(object sender, EventArgs e)
}
}

private void SpellCheckActionsQueryStatusHandler(object sender, EventArgs e)
{
if(sender is OleMenuCommand command)
command.Enabled = !SpellingTagger.DisabledInSession;
}

/// <summary>
/// Enable or disable interactive spell checking in the current session
/// </summary>
Expand All @@ -397,7 +406,10 @@ private void EnableInCurrentSessionExecuteHandler(object sender, EventArgs e)
private void EnableInCurrentSessionQueryStatusHandler(object sender, EventArgs e)
{
if(sender is OleMenuCommand command)
{
command.Text = SpellingTagger.DisabledInSession ? "Enable in Current Session" : "Disable in Current Session";
command.Checked = SpellingTagger.DisabledInSession;
}
}

/// <summary>
Expand Down

0 comments on commit fbe2bef

Please sign in to comment.