public static KeyboardShortcut FromKeys(Keys keys) { KeyboardShortcut ks = new KeyboardShortcut(); // check for modifers and remove from val if (IsSet(keys, Keys.Control)) { ks.Modifiers |= Keys.Control; keys ^= Keys.Control; } if (IsSet(keys, Keys.Alt)) { ks.Modifiers |= Keys.Alt; keys ^= Keys.Alt; } if (IsSet(keys, Keys.Shift)) { ks.Modifiers |= Keys.Shift; keys ^= Keys.Shift; } // remaining should be the key ks.Key = keys; return(ks); }
public static KeyboardShortcut FromKeys(Keys keys) { KeyboardShortcut ks = new KeyboardShortcut(); // check for modifers and remove from val if (IsSet(keys, Keys.Control)) { ks.Modifiers |= Keys.Control; keys ^= Keys.Control; } if (IsSet(keys, Keys.Alt)) { ks.Modifiers |= Keys.Alt; keys ^= Keys.Alt; } if (IsSet(keys, Keys.Shift)) { ks.Modifiers |= Keys.Shift; keys ^= Keys.Shift; } // remaining should be the key ks.Key = keys; return ks; }
public GlobalHotkey(Form form, KeyboardShortcut shortcut) { this.Form = form; this.Shortcut = shortcut; // convert the Keys to modifiers this.Modifiers = NativeMethods.HotKeysConstants.NOMOD; if (IsControlSet) { this.Modifiers += NativeMethods.HotKeysConstants.CTRL; } if (IsAltSet) { this.Modifiers += NativeMethods.HotKeysConstants.ALT; } if (IsShiftSet) { this.Modifiers += NativeMethods.HotKeysConstants.SHIFT; } // make uid this.Id = this.Shortcut.GetHashCode() ^ this.Form.Handle.ToInt32(); this.Register(); }
public override bool Equals(object thatObj) { KeyboardShortcut that = thatObj as KeyboardShortcut; return(that != null && this.Name == that.Name && this.Key == that.Key && this.Modifiers == that.Modifiers); }
public void ToStringTest() { KeyboardShortcut ks = new KeyboardShortcut(); Assert.AreEqual("", ks.ShortcutString); ks.Key = Keys.F11; Assert.AreEqual("F11", ks.ShortcutString); ks.Key = Keys.PageUp; ks.Modifiers = Keys.Control; Assert.AreEqual("Ctrl+PageUp", ks.ShortcutString); ks.Modifiers |= Keys.Shift; Assert.AreEqual("Ctrl+Shift+PageUp", ks.ShortcutString); }
/// <summary> /// Show dialog to edit shortcut /// </summary> /// <param name="parent"></param> /// <param name="shortcut"></param> /// <returns>return null if canceled</returns> public DialogResult ShowDialog(IWin32Window parent, KeyboardShortcut shortcut) { // init values this.Text = string.Format("Edit Shortcut - {0}", shortcut.Name); this.KeyboardShortcut.Key = shortcut.Key; this.KeyboardShortcut.Modifiers = shortcut.Modifiers; this.textBoxKeys.Text = this.KeyboardShortcut.ShortcutString; // show dialog DialogResult result = ShowDialog(parent); if (result == DialogResult.OK) { // update values shortcut.Key = this.KeyboardShortcut.Key; shortcut.Modifiers = this.KeyboardShortcut.Modifiers; } return result; }
public KeyboardShortcutEditor() { InitializeComponent(); this.KeyboardShortcut = new KeyboardShortcut(); }
private void buttonOk_Click(object sender, EventArgs e) { List<String> errors = new List<string>(); if (String.IsNullOrEmpty(textBoxPscpLocation.Text) || File.Exists(textBoxPscpLocation.Text)) { SuperPuTTY.Settings.PscpExe = textBoxPscpLocation.Text; } string settingsDir = textBoxSettingsFolder.Text; if (String.IsNullOrEmpty(settingsDir) || !Directory.Exists(settingsDir)) { errors.Add("Settings Folder must be set to valid directory"); } else { SuperPuTTY.Settings.SettingsFolder = settingsDir; } if (this.comboBoxLayouts.SelectedValue != null) { SuperPuTTY.Settings.DefaultLayoutName = (string) comboBoxLayouts.SelectedValue; } if (!String.IsNullOrEmpty(textBoxPuttyLocation.Text) && File.Exists(textBoxPuttyLocation.Text)) { SuperPuTTY.Settings.PuttyExe = textBoxPuttyLocation.Text; } else { errors.Insert(0, "PuTTY is required to properly use this application."); } string mintty = this.textBoxMinttyLocation.Text; if (!string.IsNullOrEmpty(mintty) && File.Exists(mintty)) { SuperPuTTY.Settings.MinttyExe = mintty; } if (errors.Count == 0) { SuperPuTTY.Settings.SingleInstanceMode = this.checkSingleInstanceMode.Checked; SuperPuTTY.Settings.RestrictContentToDocumentTabs = this.checkConstrainPuttyDocking.Checked; SuperPuTTY.Settings.MultipleTabCloseConfirmation= this.checkConfirmTabClose.Checked; SuperPuTTY.Settings.RestoreWindowLocation = this.checkRestoreWindow.Checked; SuperPuTTY.Settings.ExitConfirmation = this.checkExitConfirmation.Checked; SuperPuTTY.Settings.ExpandSessionsTreeOnStartup = this.checkExpandTree.Checked; SuperPuTTY.Settings.EnableControlTabSwitching = this.checkEnableControlTabSwitching.Checked; SuperPuTTY.Settings.EnableKeyboadShortcuts = this.checkEnableKeyboardShortcuts.Checked; SuperPuTTY.Settings.MinimizeToTray = this.checkMinimizeToTray.Checked; SuperPuTTY.Settings.TabTextBehavior = (string) this.comboBoxTabText.SelectedItem; SuperPuTTY.Settings.TabSwitcher = (string)this.comboBoxTabSwitching.SelectedItem.GetType().FullName; SuperPuTTY.Settings.SessionsTreeShowLines = this.checkSessionsTreeShowLines.Checked; SuperPuTTY.Settings.SessionsTreeFont = this.btnFont.Font; SuperPuTTY.Settings.WindowActivator = (string) this.comboBoxActivatorType.SelectedItem; SuperPuTTY.Settings.Opacity = (double) this.numericUpDownOpacity.Value / 100.0; SuperPuTTY.Settings.SessionsSearchMode = (string) this.comboSearchMode.SelectedItem; SuperPuTTY.Settings.QuickSelectorCaseSensitiveSearch = this.checkQuickSelectorCaseSensitiveSearch.Checked; SuperPuTTY.Settings.ShowDocumentIcons = this.checkShowDocumentIcons.Checked; SuperPuTTY.Settings.DockingRestrictFloatingWindows = this.checkRestrictFloatingWindows.Checked; SuperPuTTY.Settings.SessionsShowSearch = this.checkSessionsShowSearch.Checked; SuperPuTTY.Settings.PuttyPanelShowNewSessionMenu = this.checkPuttyEnableNewSessionMenu.Checked; SuperPuTTY.Settings.AutoUpdateCheck = this.checkBoxCheckForUpdates.Checked; SuperPuTTY.Settings.PscpHomePrefix = this.textBoxHomeDirPrefix.Text; SuperPuTTY.Settings.PscpRootHomePrefix = this.textBoxRootDirPrefix.Text; // save shortcuts KeyboardShortcut[] shortcuts = new KeyboardShortcut[this.Shortcuts.Count]; this.Shortcuts.CopyTo(shortcuts, 0); SuperPuTTY.Settings.UpdateFromShortcuts(shortcuts); SuperPuTTY.Settings.Save(); // @TODO - move this to a better place...maybe event handler after opening if (OrigSettingsFolder != SuperPuTTY.Settings.SettingsFolder) { SuperPuTTY.LoadLayouts(); SuperPuTTY.LoadSessions(); } else if (OrigDefaultLayoutName != SuperPuTTY.Settings.DefaultLayoutName) { SuperPuTTY.LoadLayouts(); } DialogResult = DialogResult.OK; } else { StringBuilder sb = new StringBuilder(); foreach (String s in errors) { sb.Append(s).AppendLine().AppendLine(); } if (MessageBox.Show(sb.ToString(), "Errors", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { DialogResult = DialogResult.Cancel; } } }
public KeyboardShortcut[] LoadShortcuts() { List<KeyboardShortcut> shortcuts = new List<KeyboardShortcut>(); foreach (SuperPuttyAction action in Enum.GetValues(typeof(SuperPuttyAction))) { string name = string.Format("Action_{0}_Shortcut", action); // default KeyboardShortcut ks = new KeyboardShortcut { Key = Keys.None }; // try load froms settings, note that Ctrl/Strg have conflicts // http://blogs.msdn.com/b/michkap/archive/2010/06/05/10019465.aspx try { Keys keys = (Keys)this[name]; ks = KeyboardShortcut.FromKeys(keys); } catch (ArgumentException ex) { Log.Warn("Could not convert shortcut text to Keys, possible localization bug with Ctrl and Strg. Setting to None: " + name, ex); } catch (SettingsPropertyNotFoundException) { Log.Debug("Could not load shortcut for " + name + ", Setting to None."); } ks.Name = action.ToString(); shortcuts.Add(ks); } return shortcuts.ToArray(); }
public void UpdateFromShortcuts(KeyboardShortcut[] shortcuts) { foreach (KeyboardShortcut ks in shortcuts) { SuperPuttyAction action = (SuperPuttyAction)Enum.Parse(typeof(SuperPuttyAction), ks.Name); string name = string.Format("Action_{0}_Shortcut", action); try { this[name] = ks.Key | ks.Modifiers; } catch (ArgumentException ex) { this[name] = Keys.None; Log.WarnFormat("Could not update shortcut for " + name + ". Setting to None.", ex); } } }