Exemplo n.º 1
0
 public void CanCreateHumanReadableString()
 {
     Assert.AreEqual("Left Alt + Tab", KeyboardShortcut.FromString("A4+09:1").ToHumanReadableString());
     Assert.AreEqual("Left Alt + Tab + Tab", KeyboardShortcut.FromString("A4+09:2").ToHumanReadableString());
     Assert.AreEqual("Left Win + Tab", KeyboardShortcut.FromString("5B+09:1").ToHumanReadableString());
     Assert.AreEqual("Left Win + Tab + Tab", KeyboardShortcut.FromString("5B+09:2").ToHumanReadableString());
 }
Exemplo n.º 2
0
        public void Load()
        {
            // Settings
            WindowListSingleClick = Settings.Default.WindowListSingleClick;

            // Shortcut
            var shortcut = KeyboardShortcut.FromString(Settings.Default.OpenShortcut);

            ShortcutControlKey        = Enum.IsDefined(typeof(ModifierVirtualKeys), shortcut.ControlVirtualKeyCode) ? (ModifierVirtualKeys)shortcut.ControlVirtualKeyCode : ModifierVirtualKeys.Undefined;
            ShortcutKey               = shortcut.VirtualKeyCode;
            ShortcutPressesBeforeOpen = shortcut.ShortcutPressesBeforeOpen;

            // Warnings
            NoElevatedPrivilegesWarning = !WindowsRuntimeHelper.GetHasElevatedPrivileges();

            // Plugins
            var disabledPlugins = Settings.Default.DisabledPlugins ?? new StringCollection();

            Plugins = _context.PluginsContainer.Plugins
                      .Select(plugin => new SettingsPluginViewModel
            {
                Id      = plugin.Id,
                Enabled = !disabledPlugins.Contains(plugin.Id),
                Name    = plugin.Title
            })
                      .OrderBy(plugin => plugin.Name)
                      .ToList();
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;

            Version = String.Format("{0}.{1}.{2}", currentVersion.Major, currentVersion.Minor, currentVersion.Build);

            // Updates
            UpdateAvailable = CheckForUpdatesStatus.Checking;
            _updater.CheckForUpdates(CheckForUpdatesCallback, CheckForUpdatesError);
        }
Exemplo n.º 3
0
        public void FromStringContainsAllOptions()
        {
            var shortcut = KeyboardShortcut.FromString("A4+09:2");

            Assert.AreEqual(0x09, shortcut.VirtualKeyCode);
            Assert.AreEqual(0xA4, shortcut.ControlVirtualKeyCode);
            Assert.AreEqual(2, shortcut.ShortcutPressesBeforeOpen);
        }
Exemplo n.º 4
0
        public void ShowStartupTooltip()
        {
            var shortcut = KeyboardShortcut.FromString(Properties.Settings.Default.OpenShortcut);
            var openShortcutDescription = shortcut.ToHumanReadableString();

            var tooltipMessage = $"Press {openShortcutDescription} and start typing to find a window.";

            if (!WindowsRuntimeHelper.GetHasElevatedPrivileges())
            {
                tooltipMessage += Environment.NewLine + Environment.NewLine + "NOTE: Not running with elevated privileges. Performance will be affected; Will not work in applications running as an administrator.";
            }

            _trayIcon.ShowBalloonTip(
                "Go To Window",
                tooltipMessage,
                BalloonIcon.None);
        }
Exemplo n.º 5
0
        private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.LeftCtrl)
            {
                ViewModel.IsRowIndexVisible = false;
            }

            var controlVirtualKeyCode = KeyboardShortcut.FromString(Settings.Default.OpenShortcut).ControlVirtualKeyCode;

            if (KeyInterop.VirtualKeyFromKey(e.Key) != controlVirtualKeyCode && (e.Key != Key.System || e.SystemKey != Key.LeftAlt))
            {
                return;
            }

            if (_closeOnControlKeyUp)
            {
                FocusSelectedWindowItem();
            }

            _releasedControlKey = true;
        }
Exemplo n.º 6
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var isFirstRun = false;

            if (e.Args.Any() && e.Args[0].StartsWith("--squirrel"))
            {
                var cliHandler = new SquirrelCommandLineArgumentsHandler();
                if (cliHandler.HandleSquirrelArguments(e.Args))
                {
                    Log.Info("Handled Squirrel arguments. Shutting down.");
                    Current.Shutdown(1);
                    return;
                }

                isFirstRun = cliHandler.IsFirstRun;
            }

            if (!WaitForOtherInstancesToShutDown())
            {
                MessageBox.Show(
                    "Another Go To Window instance is already running." + Environment.NewLine +
                    "Exit by right-clicking the icon in the tray, and selecting 'Exit'.",
                    "Go To Window",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information
                    );
                Log.Warn("Application already running. Shutting down.");
                Current.Shutdown(1);
                return;
            }

            // http://stackoverflow.com/questions/14635862/exception-occurs-while-pressing-a-button-on-touchscreen-using-a-stylus-or-a-fing
            DisableWpfTabletSupport();

            _context = new GoToWindowContext();

            _menu = new GoToWindowTrayIcon(_context);

            var shortcut = KeyboardShortcut.FromString(GoToWindow.Properties.Settings.Default.OpenShortcut);

            _context.EnableKeyboardHook(shortcut);

            _context.Init();

            if (shortcut.IsValid)
            {
                Log.InfoFormat("Application started. Shortcut is '{0}' ({1})", shortcut.ToHumanReadableString(), GoToWindow.Properties.Settings.Default.OpenShortcut);
            }
            else
            {
                Log.WarnFormat("Application started with invalid shortcut. Shortcut is '{0}', reason: {1}", GoToWindow.Properties.Settings.Default.OpenShortcut, shortcut.InvalidReason);
            }

            if (isFirstRun)
            {
                Log.Info("Squirrel: First run");
                Dispatcher.InvokeAsync(() =>
                {
                    new FirstRunWindow(_context)
                    {
                        DataContext = new FirstRunViewModel()
                    }.Show();
                });
            }
            else
            {
                _menu.ShowStartupTooltip();
            }

            SquirrelContext.AcquireUpdater().CheckForUpdates(_context.UpdateAvailable, null);
        }
Exemplo n.º 7
0
        public void FromEmptyStringEnabledIsFalse()
        {
            var shortcut = KeyboardShortcut.FromString("");

            Assert.AreEqual(false, shortcut.Enabled);
        }