private CommandHandler(DTE2 dte, Options options) { ThreadHelper.ThrowIfNotOnUIThread(); _options = options; _dte = dte; _control = new StatusbarControl(options, _dte); _events = _dte.Events.CommandEvents; _events.AfterExecute += AfterExecute; _events.BeforeExecute += BeforeExecute; StatusBarInjector injector = new StatusBarInjector(Application.Current.MainWindow); injector.InjectControlAsync(_control).ConfigureAwait(false); _timer = new Timer(); _timer.Elapsed += (s, e) => { _timer.Stop(); _control.SetVisibilityAsync(Visibility.Collapsed).ConfigureAwait(false); }; _options.Saved += (s, e) => { SetTimeout(); if (!_options.LogToStatusBar) { _control.SetVisibilityAsync(Visibility.Collapsed).ConfigureAwait(false); } if (!_options.LogToOutputWindow) { Logger.DeletePaneAsync().ConfigureAwait(false); } }; SetTimeout(); }
private void AfterExecute(string Guid, int ID, object CustomIn, object CustomOut) { ThreadHelper.ThrowIfNotOnUIThread(); if (!_showShortcut || !(CustomIn is null) || !(CustomOut is null)) { return; } try { Command cmd = null; try { cmd = _dte.Commands.Item(Guid, ID); } catch (ArgumentException) { return; } if (string.IsNullOrWhiteSpace(cmd?.Name) || ShouldCommandBeIgnored(cmd)) { return; } var shortcut = GetShortcut(cmd); if (string.IsNullOrWhiteSpace(shortcut)) { return; } if (_options.LogToStatusBar) { string prettyName = Prettify(cmd); string text = $"{prettyName} ({shortcut})"; _control.SetVisibilityAsync(Visibility.Visible).ConfigureAwait(false); _control.Text = text; } if (_options.ShowTooltip) { _control.SetTooltip(cmd); } if (_options.LogToOutputWindow) { Logger.LogAsync($"{cmd.Name} ({shortcut})").ConfigureAwait(false); } if (_options.Timeout > 0) { _timer.Stop(); _timer.Start(); } } catch (Exception ex) { Logger.LogAsync(ex).ConfigureAwait(false); } }