public void SetKeydata(string category, HotkeyCommand command) { this.category = category; this.command = command; keyData = command.KeyData; UpdateText(); }
public static HotkeyCommand[] LoadHotkeys(string name) { //var settings = LoadSettings().FirstOrDefault(s => s.Name == name); HotkeySettings[] allSettings; HotkeySettings settings = new HotkeySettings(); HotkeySettings scriptkeys = new HotkeySettings(); allSettings = LoadSettings(); GetUsedHotkeys(allSettings); foreach(HotkeySettings hs in allSettings) { if(hs.Name == name) settings = hs; if(hs.Name == "Scripts") scriptkeys = hs; } //HotkeyCommand[] scriptkeys = LoadSettings().FirstOrDefault(s => s.Name == name); if(settings != null) { //append general hotkeys to every form //HotkeyCommand[] scriptkeys = LoadScriptHotkeys(); HotkeyCommand[] allkeys = new HotkeyCommand[settings.Commands.Length + scriptkeys.Commands.Length]; settings.Commands.CopyTo(allkeys,0); scriptkeys.Commands.CopyTo(allkeys,settings.Commands.Length); return allkeys; } //return settings != null ? settings.Commands : null; return null; }
private void Form5_FormClosing(object sender, FormClosingEventArgs e) { Settings.WinSize = this.Size; Settings.WinLoc = this.Location; Settings.Form5Fields[0] = textBox1.Text; Settings.Form5Fields[1] = textBox2.Text; Settings.Form5Fields[2] = textBox3.Text; Settings.Form5Fields[3] = textBox4.Text; Settings.Form5Fields[4] = textBox5.Text; Settings.Form5Fields[5] = textBox6.Text; Settings.Form5Fields[6] = textBox7.Text; Settings.Form5Fields[7] = textBox8.Text; Settings.Form5Fields[8] = textBox9.Text; Settings.Form5Fields[9] = textBox10.Text; Settings.Form5Fields[10] = textBox11.Text; Settings.Form5Fields[11] = textBox12.Text; Settings.Save(); HotkeyComm?.Dispose(); HotkeyComm = null; if (!Actions.SwitchingForms) { Environment.Exit(0); } }
private void Form1_Load(object sender, EventArgs e) { HotkeyCommand = new HotkeyCommand(this) { SetHotkeysGlobally = true }; HotkeyCommand.KeyActionCall += HotkeyCommand_KeyActionCall; HotkeyCommand.KeyRegisteredCall += HotkeyCommand_KeyRegisteredCall; HotkeyCommand.KeyUnregisteredCall += HotkeyCommand_KeyUnregisteredCall; }
public void WillInstantiateAllHotkeysCommandsNoExceptions() { IEnumerable <Type> hotkeyCommands = Assembly.GetAssembly(typeof(Engine)).GetTypes() .Where(i => i.IsSubclassOf(typeof(HotkeyCommand))); ObservableCollectionEx <HotkeyCommand> hotkeys = new ObservableCollectionEx <HotkeyCommand>(); foreach (Type hotkeyCommand in hotkeyCommands) { HotkeyCommand hkc = (HotkeyCommand)Activator.CreateInstance(hotkeyCommand); hotkeys.Add(hkc); } }
protected HotkeyEntryViewModel(string name) { _category = new HotkeyCommand { Name = name, IsCategory = true }; HotkeyManager hotkey = HotkeyManager.GetInstance(); hotkey.AddCategory(_category); Items.CollectionChanged += OnCollectionChanged; _category.Children = new ObservableCollectionEx <HotkeyEntry>(); }
private void lvCommands_SelectedIndexChanged(object sender, EventArgs e) { if (lvCommands.SelectedItems.Count != 1) { return; } HotkeyCommand command = lvCommands.SelectedItems[0].Tag as HotkeyCommand; if (command == null) { return; } selectedCommand = command; lblHotkey.Text = string.Format(RootLang.dlgPreferences_Keyboard_lblHotkey, selectedCategory, selectedCommand.Name); tbHotkey.SetKeydata(selectedCategory, selectedCommand); // save // revert/cancel. }
private void SetHotkeys(string[] hklist) { if (HotkeyComm == null) { HotkeyComm = new HotkeyCommand(this) { SetHotkeysGlobally = true, SetSuppressExceptions = false }; HotkeyComm.KeyActionCall += Actions.OnKeyAction; //Do work on keypress using the Action class HotkeyComm.KeyRegisteredCall += Registrations; HotkeyComm.KeyUnregisteredCall += UnRegistrations; Actions.ActionComplete += OnActionComplete; //Followup on completed task from the Action class } if (HotkeyComm.IsRegistered) { HotkeyComm.StopHotkeys(); } HotkeyComm.HotkeyAddKeyList(hklist, true); HotkeyComm.StartHotkeys(); }
public static HotkeyCommand[] LoadScriptHotkeys() { var curScripts = GitUI.Script.ScriptManager.GetScripts(); HotkeyCommand[] scriptKeys = new HotkeyCommand[curScripts.Count]; /* define unusable int for identifying a shortcut for a custom script is pressed * all integers above 9000 represent a scripthotkey * these integers are never matched in the 'switch' routine on a form and * therefore execute the 'default' action */ int i=0; foreach (GitUI.Script.ScriptInfo s in curScripts) { if (!string.IsNullOrEmpty(s.Name)) { scriptKeys[i] = new HotkeyCommand((int)s.HotkeyCommandIdentifier, s.Name) { KeyData = (Keys.None) }; i++; } } return scriptKeys; }
public void ExecuteDualCommand(HotkeyCommand cmd) { view.ExecuteDualCommand(cmd.CommandCode); }
/// <summary> /// Invoked when an unhandled <see cref="UIElement.PreviewKeyDown"/> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs"/> that contains the event data.</param> protected override void OnPreviewKeyDown([NotNull] KeyEventArgs e) { Assert.ArgumentNotNull(e, "e"); var hotkeyCommand = new HotkeyCommand { Key = e.Key == Key.System ? e.SystemKey : e.Key, ModifierKeys = Keyboard.Modifiers, Handled = false, }; // For hotkeys, only Numpad Enter is processed var canPush = true; if (e.Key == Key.Enter && Keyboard.Modifiers == ModifierKeys.None) { var isExtended = (bool)typeof(KeyEventArgs).InvokeMember("IsExtendedKey", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, e, null); if (!isExtended) { canPush = false; } } if (canPush) { RootModel.PushCommandToConveyor(hotkeyCommand); } if (hotkeyCommand.Handled) { e.Handled = true; return; } if (e.Key == Key.Up && Keyboard.Modifiers == 0 && txtCommandInput.IsFocused) { txtCommandInput.ShowPreviousCommand(); e.Handled = true; } if (e.Key == Key.Down && Keyboard.Modifiers == 0 && txtCommandInput.IsFocused) { txtCommandInput.ShowNextCommand(); e.Handled = true; } if (e.Key == Key.Enter && txtCommandInput.IsFocused) { txtCommandInput.SendCurrentCommand(); e.Handled = true; } if (e.Key == Key.PageUp && Keyboard.Modifiers == 0) { PageUp(); e.Handled = true; } if (e.Key == Key.PageDown && Keyboard.Modifiers == 0) { PageDown(); e.Handled = true; } if (e.Key == Key.End && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { ScrollToEnd(); e.Handled = true; } //Очищение коммандной строки клавишей escape if (e.Key == Key.Escape && Keyboard.Modifiers == 0 && txtCommandInput.IsFocused) { txtCommandInput.Clear(); e.Handled = true; } if (!e.Handled) { base.OnPreviewKeyDown(e); } }
private void UpdateListViewItems(HotkeySettings setting) { this.SelectedHotkeyCommand = null; this.listMappings.Items.Clear(); if (setting != null) { foreach (var cmd in setting.Commands) { if (cmd != null) { var item = new ListViewItem(new[] {cmd.Name, cmd.KeyData.ToText() ?? _hotkeyNotSet.Text}); item.Tag = cmd; this.listMappings.Items.Add(item); } } } }
private void listMappings_SelectedIndexChanged(object sender, EventArgs e) { var lvi = this.listMappings.SelectedItems.Count > 0 ? this.listMappings.SelectedItems[0] : null; if (lvi != null) { var hotkey = lvi.Tag as HotkeyCommand; this.SelectedHotkeyCommand = hotkey; } }
private void UpdateTextBox(HotkeyCommand command) { txtHotkey.KeyData = (command != null) ? command.KeyData : Keys.None; }