From 555ce228d41a1fbb02d428cb24db38e6396bab91 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sun, 24 Mar 2024 20:28:19 +0100 Subject: [PATCH] [#31] ContextWindow: Add shortcuts for Ctrl+R and F5 --- Elwig/Windows/ContextWindow.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Elwig/Windows/ContextWindow.cs b/Elwig/Windows/ContextWindow.cs index e16b919..aa81549 100644 --- a/Elwig/Windows/ContextWindow.cs +++ b/Elwig/Windows/ContextWindow.cs @@ -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;