VSCT ファイルで次の設定を使用して、Visual Studio 2015 の VSIX パッケージでツールバーの動的コンボを定義しました。
<Combo guid="cmdExplorerToolbarSearchGUID" id="cmdExplorerToolbarSearchID" priority="0x0" type="DynamicCombo"
defaultWidth="50" idCommandList="cmdExplorerToolbarSearchGetListID">
<Parent guid="grpExplorerToolbar3GUID" id="grpExplorerToolbar3ID" />
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>IconAndText</CommandFlag>
<CommandFlag>StretchHorizontally</CommandFlag>
<Strings>
<CanonicalName>cmdExplorerToolbarSearch</CanonicalName>
<ButtonText>Search</ButtonText>
<ToolTipText>Search elements in the model explorer</ToolTipText>
</Strings>
</Combo>
</Combos>
対応するDynamicStatusMenuCommand
インスタンスは次のように定義されます。
command = new DynamicStatusMenuCommand(
new EventHandler(this.OnPopUpMenuDisplayAction),
new EventHandler(this.OnCmdExplorerToolbarSearchSelected),
new CommandID(CmdExplorerToolbarSearchGUID, CmdExplorerToolbarSearchID));
commands.Add(command);
command = new DynamicStatusMenuCommand(
new EventHandler(this.OnPopUpMenuDisplayAction),
new EventHandler(this.OnCmdExplorerToolbarSearchGetList),
new CommandID(CmdExplorerToolbarSearchGUID, CmdExplorerToolbarSearchGetListID));
commands.Add(command);
そして最後に、次のOnCmdExplorerToolbarSearchSelected
ようなイベント ハンドラー:
private void OnCmdExplorerToolbarSearchSelected(object sender, EventArgs e)
{
// Process the event arguments
OleMenuCmdEventArgs args = e as OleMenuCmdEventArgs;
if (args != null)
{
// Process values
string inValue = args.InValue as string;
IntPtr outValue = args.OutValue;
if (outValue != IntPtr.Zero)
{
// When outValue is not null, the IDE is requesting the current value for the combo
Marshal.GetNativeVariantForObject(this.SearchHandler.CurrentValue, outValue);
}
else if (inValue != null)
{
this.SearchHandler.Search(this.PresentationModel3ExplorerToolWindow.Explorer, inValue);
}
}
}
これにより、ツールボックスに素晴らしいコンボが表示されます。
問題は、たとえば、ユーザーが「Unit」と入力して押すとEnter
、イベント ハンドラーが inValue != null で呼び出され、検索が実行されることです。しかし、その後、彼が何か他のもの (例: Customer) を入力してTab
(いいえEnter
) を押すと、ハンドラーが args.OutValue != IntPtr.Zero で呼び出されるため、コンボは前の値 ("Unit") に戻ります。
ユーザーが何かを入力し、 を押さずにコンボからフォーカスを移動したときにコールバックを取得するトリックは何Enter
ですか? そして、それを考えると、その瞬間にコンボにある値をどのように取得できますか?