Skip to content

Commit

Permalink
Add some logging regarding command palette usage (#6821)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Pretty straightforward. Logs three scenarios:
* The user opened the command palette (and which mode it was opened in)
* The user ran a command from the palette
* The user dismissed the palette without running an action.

We discussed this in team sync yesterday.

## PR Checklist
* [x] I work here
* [n/a] Requires documentation to be updated
  • Loading branch information
zadjii-msft authored Jul 7, 2020
1 parent edd8ac8 commit 934ad98
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
64 changes: 54 additions & 10 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ namespace winrt::TerminalApp::implementation
{
_searchBox().Focus(FocusState::Programmatic);
_filteredActionsView().SelectedIndex(0);

TraceLoggingWrite(
g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
"CommandPaletteOpened",
TraceLoggingDescription("Event emitted when the Command Palette is opened"),
TraceLoggingWideString(L"Action", "Mode", "which mode the palette was opened in"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance));
}
else
{
// Raise an event to return control to the Terminal.
_close();
_dismissPalette();
}
});
}
Expand Down Expand Up @@ -101,12 +109,7 @@ namespace winrt::TerminalApp::implementation

if (const auto selectedItem = _filteredActionsView().SelectedItem())
{
if (const auto data = selectedItem.try_as<Command>())
{
const auto actionAndArgs = data.Action();
_dispatch.DoAction(actionAndArgs);
_close();
}
_dispatchCommand(selectedItem.try_as<Command>());
}

e.Handled(true);
Expand All @@ -116,7 +119,7 @@ namespace winrt::TerminalApp::implementation
// Action Mode: Dismiss the palette if the text is empty, otherwise clear the search string.
if (_searchBox().Text().empty())
{
_close();
_dismissPalette();
}
else
{
Expand All @@ -138,7 +141,7 @@ namespace winrt::TerminalApp::implementation
void CommandPalette::_rootPointerPressed(Windows::Foundation::IInspectable const& /*sender*/,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const& /*e*/)
{
_close();
_dismissPalette();
}

// Method Description:
Expand Down Expand Up @@ -166,14 +169,55 @@ namespace winrt::TerminalApp::implementation
void CommandPalette::_listItemClicked(Windows::Foundation::IInspectable const& /*sender*/,
Windows::UI::Xaml::Controls::ItemClickEventArgs const& e)
{
if (auto command{ e.ClickedItem().try_as<TerminalApp::Command>() })
_dispatchCommand(e.ClickedItem().try_as<TerminalApp::Command>());
}

// Method Description:
// - Helper method for retrieving the action from a command the user
// selected, and dispatching that command. Also fires a tracelogging event
// indicating that the user successfully found the action they were
// looking for.
// Arguments:
// - command: the Command to dispatch. This might be null.
// Return Value:
// - <none>
void CommandPalette::_dispatchCommand(const TerminalApp::Command& command)
{
if (command)
{
const auto actionAndArgs = command.Action();
_dispatch.DoAction(actionAndArgs);
_close();

TraceLoggingWrite(
g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
"CommandPaletteDispatchedAction",
TraceLoggingDescription("Event emitted when the user selects an action in the Command Palette"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance));
}
}

// Method Description:
// - Helper method for closing the command palette, when the user has _not_
// selected an action. Also fires a tracelogging event indicating that the
// user closed the palette without running a command.
// Arguments:
// - <none>
// Return Value:
// - <none>
void CommandPalette::_dismissPalette()
{
_close();

TraceLoggingWrite(
g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
"CommandPaletteDismissed",
TraceLoggingDescription("Event emitted when the user dismisses the Command Palette without selecting an action"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance));
}

// Method Description:
// - Event handler for when the text in the input box changes. In Action
// Mode, we'll update the list of displayed commands, and select the first one.
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace winrt::TerminalApp::implementation
void _updateFilteredActions();
static int _getWeight(const winrt::hstring& searchText, const winrt::hstring& name);
void _close();

void _dispatchCommand(const TerminalApp::Command& command);

void _dismissPalette();
};
}

Expand Down

0 comments on commit 934ad98

Please sign in to comment.