Beispiel #1
0
        private CommandHandler(DTE2 dte, Options options)
        {
            _options = options;
            _dte = dte;
            _control = new StatusbarControl(options, _dte);
            _events = _dte.Events.CommandEvents;

            _events.AfterExecute += AfterExecute;
            _events.BeforeExecute += BeforeExecute;

            var injector = new StatusBarInjector(Application.Current.MainWindow);
            injector.InjectControl(_control);

            _timer = new Timer();
            _timer.Elapsed += (s, e) =>
            {
                _timer.Stop();
                _control.SetVisibility(Visibility.Collapsed);
            };

            _options.Saved += (s, e) =>
            {
                SetTimeout();

                if (!_options.LogToStatusBar)
                    _control.SetVisibility(Visibility.Collapsed);

                if (!_options.LogToOutputWindow)
                    Logger.DeletePane();
            };

            SetTimeout();
        }
Beispiel #2
0
        private void AfterExecute(string Guid, int ID, object CustomIn, object CustomOut)
        {
            if (!_showShortcut)
            {
                return;
            }

            try
            {
                var cmd = _dte.Commands.Item(Guid, ID);

                if (string.IsNullOrWhiteSpace(cmd?.Name) || ShouldCommandBeIgnored(cmd))
                {
                    return;
                }

                string shortcut = GetShortcut(cmd);

                if (!string.IsNullOrWhiteSpace(shortcut))
                {
                    if (_options.LogToStatusBar)
                    {
                        string prettyName = Prettify(cmd);
                        string text       = $"{prettyName} ({shortcut})";

                        _control.SetVisibility(Visibility.Visible);
                        _control.Text = text;
                    }

                    if (_options.ShowTooltip)
                    {
                        _control.SetTooltip(cmd);
                    }

                    if (_options.LogToOutputWindow)
                    {
                        Logger.Log($"{cmd.Name} ({shortcut})");
                    }

                    if (_options.Timeout > 0)
                    {
                        _timer.Stop();
                        _timer.Start();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Telemetry.TrackException(ex);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }