Beispiel #1
0
        private void RefreshHotkeys()
        {
            // Unregister all hotkeys.
            foreach (var hotkey in _hotkeys)
            {
                hotkey.Dispose();
            }
            _hotkeys.Clear();

            // Remove any hotkeys for profiles that no longer exist (but keep hotkeys for system commands).
            if (SettingsFiles.ApplicationSettings.Hotkeys.RemoveAll(x => !SystemCommands.IsSystemCommand(x.Id) && !_profiles.ContainsKey(x.Id)) != 0)
            {
                SettingsFiles.SaveApplicationSettings();
            }

            // Register hotkeys.
            foreach (var hotkeySetting in SettingsFiles.ApplicationSettings.Hotkeys)
            {
                var id = hotkeySetting.Id;
                try
                {
                    _hotkeys.Add(new WinFormsHotkey(hotkeySetting.Hotkey, true, () => ExecuteSystemCommandOrLoadProfile(hotkeySetting.Id)));
                }
                catch (Exception ex)
                {
                    BalloonTip("Could not bind hotkey " + WinFormsHotkey.HotkeyString(hotkeySetting.Hotkey) + " to " + SystemCommands.GetTitle(id), ex.Message, ToolTipIcon.Warning);
                }
            }
        }
Beispiel #2
0
        private void BuildTrayMenu()
        {
            contextMenuStrip.Items.Clear();

            // Add to load menu
            foreach (var kvp in _profiles)
            {
                var name    = kvp.Key;
                var profile = kvp.Value;
                var item    = new ToolStripMenuItem(name, Resources.Profile.ToBitmap(), (_, __) => LoadProfile(name));
                var ex      = profile.Exception ?? profile.Value.Validate();
                if (ex != null)
                {
                    item.Image = Resources.Warning.ToBitmap();
                    var message      = ex.Message;
                    var extraMessage = profile.Match(_ => null, value => value.MissingAdaptersMessage());
                    if (!string.IsNullOrEmpty(extraMessage))
                    {
                        message += "\r\n" + extraMessage;
                    }
                    item.ToolTipText = message;
                }
                contextMenuStrip.Items.Add(item);
            }

            contextMenuStrip.Items.Add(new ToolStripMenuItem(SystemCommands.GetTitle(SystemCommands.MonitorsOffCommand), Resources.MainIcon.ToBitmap(),
                                                             (_, __) => ExecuteSystemCommand(SystemCommands.MonitorsOffCommand)));
            contextMenuStrip.Items.Add(new ToolStripSeparator());

            // Menu for saving items
            var newProfileMenuItem = new ToolStripMenuItem("New Profile...", Resources.NewProfile.ToBitmap(), OnMenuSaveAs);

            if (_profiles.Count != 0)
            {
                var saveMenu = new ToolStripMenuItem("Save Profile", Resources.SaveProfile.ToBitmap())
                {
                    DropDown = new ToolStripDropDownMenu()
                };
                saveMenu.DropDownItems.Add(newProfileMenuItem);
                saveMenu.DropDownItems.Add(new ToolStripSeparator());
                foreach (var profile in _profiles.Keys)
                {
                    saveMenu.DropDownItems.Add(new ToolStripMenuItem(profile, Resources.SaveProfile.ToBitmap(), (_, __) => SaveProfile(profile)));
                }
                contextMenuStrip.Items.Add(saveMenu);
            }
            else
            {
                contextMenuStrip.Items.Add(newProfileMenuItem);
            }

            // Menu for deleting items
            if (_profiles.Count != 0)
            {
                var deleteMenu = new ToolStripMenuItem("Delete Profile", Resources.DeleteProfile.ToBitmap())
                {
                    DropDown = new ToolStripDropDownMenu()
                };
                foreach (var profile in _profiles.Keys)
                {
                    deleteMenu.DropDownItems.Add(new ToolStripMenuItem(profile, Resources.DeleteProfile.ToBitmap(), (_, __) => DeleteProfile(profile)));
                }
                contextMenuStrip.Items.Add(deleteMenu);
            }

            // Menu for hotkeys
            if (_profiles.Count != 0)
            {
                var hotkeyMenu = new ToolStripMenuItem("Hotkeys", Resources.Hotkey.ToBitmap())
                {
                    DropDown = new ToolStripDropDownMenu()
                };
                foreach (var profile in _profiles.Keys)
                {
                    hotkeyMenu.DropDownItems.Add(HotkeyMenuItem(Resources.Profile, profile));
                }
                hotkeyMenu.DropDownItems.Add(HotkeyMenuItem(Resources.MainIcon, SystemCommands.MonitorsOffCommand));
                contextMenuStrip.Items.Add(hotkeyMenu);
            }

            contextMenuStrip.Items.Add(new ToolStripSeparator());
            contextMenuStrip.Items.Add(new ToolStripMenuItem("About", Resources.About.ToBitmap(), OnAbout));
            contextMenuStrip.Items.Add(new ToolStripMenuItem("Exit", null, (_, __) => Application.Exit()));
        }