[#31] ContextWindow: Add shortcuts for Ctrl+R and F5

This commit is contained in:
2024-03-24 20:28:19 +01:00
parent 9d80c5913f
commit 555ce228d4

View File

@ -1,17 +1,38 @@
using Elwig.Helpers;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace Elwig.Windows {
public abstract class ContextWindow : Window {
protected bool LockContext { get; set; } = false;
private bool _lockContext = false;
protected bool LockContext {
get => _lockContext;
set {
_lockContext = value;
if (!_lockContext && _renewPending) {
Dispatcher.BeginInvoke(async () => await RenewContext());
}
}
}
private bool _renewPending = false;
private readonly RoutedCommand CtrlR = new("CtrlR", typeof(ContextWindow), [new KeyGesture(Key.R, ModifierKeys.Control)]);
private readonly RoutedCommand F5 = new("F5", typeof(ContextWindow), [new KeyGesture(Key.F5)]);
public ContextWindow() : base() {
CommandBindings.Add(new CommandBinding(CtrlR, ForceContextReload));
CommandBindings.Add(new CommandBinding(F5, ForceContextReload));
Loaded += OnLoaded;
}
public async void ForceContextReload(object sender, EventArgs evt) {
await HintContextChange();
}
public async Task HintContextChange() {
_renewPending = true;
if (LockContext) return;