private void OnKeyDown(object sender, KeyEventArgs e) {
if (Keyboard.Modifiers != ModifierKeys.Alt && Keyboard.Modifiers != (ModifierKeys.Alt | ModifierKeys.Shift) ||
!SettingsHolder.Drive.QuickSwitches) return;
switch (e.SystemKey) {
case Key.OemTilde:
ToggleQuickSwitches();
break;
default:
var k = e.SystemKey - Key.D1;
if (k < 0 || k > 9) return;
InitializePopup();
var child = GetQuickSwitches().ElementAtOrDefault(k);
if (child == null) break;
QuickSwitchesNotification.SetValue(TextBlock.ForegroundProperty, child.GetValue(TextBlock.ForegroundProperty));
var toggle = child as ModernToggleButton;
if (toggle != null) {
toggle.IsChecked = !toggle.IsChecked;
ShowQuickSwitchesPopup(toggle.IconData, $@"{toggle.Content}: {toggle.IsChecked.ToReadableBoolean()}", child.ToolTip);
break;
}
var button = child as ModernButton;
if (button != null) {
button.Command?.Execute(null);
ShowQuickSwitchesPopup(button.IconData, button.Content?.ToString(), child.ToolTip);
break;
}
var presets = child as QuickSwitchPresetsControl;
if (presets != null) {
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) {
presets.SwitchToPrevious();
} else {
presets.SwitchToNext();
}
ShowQuickSwitchesPopup(presets.IconData, $@"{presets.CurrentUserPreset.DisplayName}", child.ToolTip);
break;
}
var combo = child as QuickSwitchComboBox;
if (combo != null && combo.Items.Count > 1) {
var index = combo.SelectedIndex;
combo.SelectedItem = combo.Items[(index + (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) ? -1 : 1) +
combo.Items.Count) % combo.Items.Count];
ShowQuickSwitchesPopup(combo.IconData, $@"{combo.SelectedItem}", child.ToolTip);
break;
}
var slider = child as QuickSwitchSlider;
if (slider != null) {
var step = (slider.Maximum - slider.Minimum) / 6d;
var position = (((slider.Value - slider.Minimum) / step - 1).Clamp(0, 4).Round(1d) +
(Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) ? -1 : 1) + 5) % 5;
slider.Value = slider.Minimum + (position + 1) * step;
ShowQuickSwitchesPopup(slider.IconData, $@"{slider.Content}: {slider.DisplayValue}", child.ToolTip);
}
// special case for controls presets
var dock = child as DockPanel;
if (dock != null) {
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) {
ControlsPresets.Instance.SwitchToPrevious();
} else {
ControlsPresets.Instance.SwitchToNext();
}
ShowQuickSwitchesPopup(dock.FindLogicalChild<Path>()?.Data, $@"{AcSettingsHolder.Controls.CurrentPresetName}", child.ToolTip);
}
break;
}
e.Handled = true;
}