bool HasModifiers(HotkeyDefinition hotkey) { if (hotkey.Extra != Keys.None && !pressed[hotkey.Extra]) { return(false); } if ((hotkey.EnabledOptions & HotkeyDefinition.Options.IgnoreModifiers) == HotkeyDefinition.Options.IgnoreModifiers) { return(true); } bool[,] modifiers = { { (hotkey.Keys & Keys.Alt) == Keys.Alt, pressed[Keys.Alt] || pressed[Keys.LMenu] || pressed[Keys.RMenu], (hotkey.Keys & Keys.LMenu) == Keys.LMenu }, { (hotkey.Keys & Keys.Control) == Keys.Control, pressed[Keys.Control] || pressed[Keys.LControlKey] || pressed[Keys.RControlKey], (hotkey.Keys & Keys.ControlKey) == Keys.ControlKey }, { (hotkey.Keys & Keys.Shift) == Keys.Shift, pressed[Keys.Shift] || pressed[Keys.LShiftKey] || pressed[Keys.RShiftKey], (hotkey.Keys & Keys.ShiftKey) == Keys.ShiftKey } }; for (int i = 0; i < 3; i++) { if ((modifiers[i, 0] && !modifiers[i, 1]) || (modifiers[i, 1] && !modifiers[i, 0] && !modifiers[i, 2])) { return(false); } } return(true); }
bool IsHotkeyVisibleInFilter(HotkeyDefinition hd) { var filter = filterInput.Text; var isFilteredByName = string.IsNullOrWhiteSpace(filter) || hd.Description.Contains(filter, StringComparison.OrdinalIgnoreCase); var isFilteredByContext = currentContext == "Any" || hd.Contexts.Contains(currentContext); return(isFilteredByName && isFilteredByContext); }
void ValidateHotkey() { duplicateHotkeyDefinition = modData.Hotkeys.GetFirstDuplicate(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key, selectedHotkeyDefinition); isHotkeyValid = duplicateHotkeyDefinition == null; isHotkeyDefault = hotkeyEntryWidget.Key == selectedHotkeyDefinition.Default || (!hotkeyEntryWidget.Key.IsValid() && !selectedHotkeyDefinition.Default.IsValid()); if (isHotkeyValid) { SaveHotkey(); } }
static void BindHotkeyPref(HotkeyDefinition hd, HotkeyManager manager, Widget template, Widget parent) { var key = template.Clone() as Widget; key.Id = hd.Name; key.IsVisible = () => true; key.Get <LabelWidget>("FUNCTION").GetText = () => hd.Description + ":"; var textBox = key.Get <HotkeyEntryWidget>("HOTKEY"); textBox.Key = manager[hd.Name].GetValue(); textBox.OnLoseFocus = () => manager.Set(hd.Name, textBox.Key); parent.AddChild(key); }
void ValidateHotkey() { duplicateHotkeyDefinition = modData.Hotkeys.GetFirstDuplicate(selectedHotkeyDefinition.Name, hotkeyEntryWidget.Key, selectedHotkeyDefinition); isHotkeyValid = duplicateHotkeyDefinition == null; isHotkeyDefault = hotkeyEntryWidget.Key == selectedHotkeyDefinition.Default || (!hotkeyEntryWidget.Key.IsValid() && !selectedHotkeyDefinition.Default.IsValid()); if (isHotkeyValid) { hotkeyEntryWidget.Bounds.Width = validHotkeyEntryWidth; SaveHotkey(); } else { hotkeyEntryWidget.Bounds.Width = invalidHotkeyEntryWidth; hotkeyEntryWidget.TakeKeyboardFocus(); } }
void BindHotkeyPref(HotkeyDefinition hd, Widget template, Widget parent) { var key = template.Clone() as Widget; key.Id = hd.Name; key.IsVisible = () => true; key.Get <LabelWidget>("FUNCTION").GetText = () => hd.Description + ":"; var remapButton = key.Get <ButtonWidget>("HOTKEY"); WidgetUtils.TruncateButtonToTooltip(remapButton, modData.Hotkeys[hd.Name].GetValue().DisplayString()); remapButton.IsHighlighted = () => selectedHotkeyDefinition == hd; var hotkeyValidColor = ChromeMetrics.Get <Color>("HotkeyColor"); var hotkeyInvalidColor = ChromeMetrics.Get <Color>("HotkeyColorInvalid"); remapButton.GetColor = () => { return(modData.Hotkeys.GetFirstDuplicate(hd.Name, modData.Hotkeys[hd.Name].GetValue(), hd) != null ? hotkeyInvalidColor : hotkeyValidColor); }; if (selectedHotkeyDefinition == hd) { selectedHotkeyButton = remapButton; hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue(); ValidateHotkey(); } remapButton.OnClick = () => { selectedHotkeyDefinition = hd; selectedHotkeyButton = remapButton; hotkeyEntryWidget.Key = modData.Hotkeys[hd.Name].GetValue(); ValidateHotkey(); hotkeyEntryWidget.TakeKeyboardFocus(); }; parent.AddChild(key); }
public HotkeyDialogLogic(Widget widget, Action onSave, HotkeyDefinition hotkeyDefinition, HotkeyManager hotkeyManager) { panel = widget; this.onSave = onSave; definition = hotkeyDefinition; manager = hotkeyManager; currentHotkey = manager[definition.Name].GetValue(); hotkeyEntry = panel.Get <HotkeyEntryWidget>("HOTKEY_ENTRY"); resetButton = panel.Get <ButtonWidget>("RESET_BUTTON"); clearButton = panel.Get <ButtonWidget>("CLEAR_BUTTON"); cancelButton = panel.Get <ButtonWidget>("CANCEL_BUTTON"); duplicateNotice = panel.Get <LabelWidget>("DUPLICATE_NOTICE"); defaultNotice = panel.Get <LabelWidget>("DEFAULT_NOTICE"); originalNotice = panel.Get <LabelWidget>("ORIGINAL_NOTICE"); panel.Get <LabelWidget>("HOTKEY_LABEL").GetText = () => hotkeyDefinition.Description + ":"; duplicateNotice.TextColor = ChromeMetrics.Get <Color>("NoticeErrorColor"); duplicateNotice.GetText = () => { return((duplicateHotkey != null) ? duplicateNotice.Text.F(duplicateHotkey.Description) : duplicateNotice.Text); }; defaultNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor"); originalNotice.TextColor = ChromeMetrics.Get <Color>("NoticeInfoColor"); originalNotice.Text = originalNotice.Text.F(hotkeyDefinition.Default.DisplayString()); resetButton.OnClick = Reset; clearButton.OnClick = Clear; cancelButton.OnClick = Cancel; hotkeyEntry.Key = currentHotkey; hotkeyEntry.IsValid = () => isValid; hotkeyEntry.OnTakeFocus = OnHotkeyEntryTakeFocus; hotkeyEntry.OnLoseFocus = OnHotkeyEntryLoseFocus; hotkeyEntry.OnEscape = Cancel; hotkeyEntry.OnReturn = Cancel; hotkeyEntry.TakeKeyboardFocus(); Validate(); isFirstValidation = false; }
void Validate() { isValidating = true; duplicateHotkey = manager.GetFirstDuplicate(definition.Name, hotkeyEntry.Key, definition); isValid = duplicateHotkey == null; duplicateNotice.Visible = !isValid; clearButton.Disabled = !hotkeyEntry.Key.IsValid(); if (hotkeyEntry.Key == definition.Default || (!hotkeyEntry.Key.IsValid() && !definition.Default.IsValid())) { defaultNotice.Visible = !duplicateNotice.Visible; originalNotice.Visible = false; resetButton.Disabled = true; } else { defaultNotice.Visible = false; originalNotice.Visible = !duplicateNotice.Visible; resetButton.Disabled = false; } if (isValid && !isFirstValidation) { currentHotkey = hotkeyEntry.Key; hotkeyEntry.YieldKeyboardFocus(); Save(); } else { hotkeyEntry.TakeKeyboardFocus(); } isValidating = false; }
public void Remove(HotkeyDefinition hotkey) { hotkeys.Remove(hotkey); }
public HotkeyDefinition Add(HotkeyDefinition hotkey) { hotkeys.Add(hotkey); return hotkey; }
bool HasModifiers(HotkeyDefinition hotkey) { if (hotkey.Extra != Keys.None && !pressed[hotkey.Extra]) return false; if ((hotkey.EnabledOptions & HotkeyDefinition.Options.IgnoreModifiers) == HotkeyDefinition.Options.IgnoreModifiers) return true; bool[,] modifiers = { { (hotkey.Keys & Keys.Alt) == Keys.Alt, pressed[Keys.Alt] || pressed[Keys.LMenu] || pressed[Keys.RMenu], (hotkey.Keys & Keys.LMenu) == Keys.LMenu }, { (hotkey.Keys & Keys.Control) == Keys.Control, pressed[Keys.Control] || pressed[Keys.LControlKey] || pressed[Keys.RControlKey], (hotkey.Keys & Keys.ControlKey) == Keys.ControlKey }, { (hotkey.Keys & Keys.Shift) == Keys.Shift, pressed[Keys.Shift] || pressed[Keys.LShiftKey] || pressed[Keys.RShiftKey], (hotkey.Keys & Keys.ShiftKey) == Keys.ShiftKey } }; for (int i = 0; i < 3; i++) if ((modifiers[i, 0] && !modifiers[i, 1]) || (modifiers[i, 1] && !modifiers[i, 0] && !modifiers[i, 2])) return false; return true; }
public HotkeyDefinition Add(HotkeyDefinition hotkey) { hotkeys.Add(hotkey); return(hotkey); }
public HotkeyImplementation(HotkeyDefinition definition, string hotkey) { Definition = definition; Hotkey = hotkey; }
static void BindHotkeyPref(HotkeyDefinition hd, HotkeyManager manager, Widget template, Widget parent, Widget remapDialogRoot, Widget remapDialogPlaceholder) { var key = template.Clone() as Widget; key.Id = hd.Name; key.IsVisible = () => true; key.Get <LabelWidget>("FUNCTION").GetText = () => hd.Description + ":"; var remapButton = key.Get <ButtonWidget>("HOTKEY"); remapButton.GetText = () => manager[hd.Name].GetValue().DisplayString(); if (manager.GetFirstDuplicate(hd.Name, manager[hd.Name].GetValue(), hd) != null) { remapButton.GetColor = () => ChromeMetrics.Get <Color>("HotkeyColorInvalid"); } remapButton.OnClick = () => { remapDialogRoot.RemoveChildren(); if (remapButton.IsHighlighted()) { remapButton.IsHighlighted = () => false; if (remapDialogPlaceholder != null) { remapDialogPlaceholder.Visible = true; } return; } if (remapDialogPlaceholder != null) { remapDialogPlaceholder.Visible = false; } var siblings = parent.Children; foreach (var sibling in siblings) { var button = sibling.GetOrNull <ButtonWidget>("HOTKEY"); if (button != null) { button.IsHighlighted = () => false; } } remapButton.IsHighlighted = () => true; Ui.LoadWidget("HOTKEY_DIALOG", remapDialogRoot, new WidgetArgs { { "onSave", () => { remapButton.GetText = () => manager[hd.Name].GetValue().DisplayString(); remapButton.GetColor = () => ChromeMetrics.Get <Color>("ButtonTextColor"); } }, { "hotkeyDefinition", hd }, { "hotkeyManager", manager }, }); }; parent.AddChild(key); }