[AdvancedPaste] Custom Actions follow-up fixes #1 (#34404)

This commit is contained in:
Ani 2024-08-23 12:23:23 +02:00 committed by GitHub
parent 579619952d
commit a5757fd525
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 24 deletions

View File

@ -25,6 +25,7 @@ namespace AdvancedPaste.Pages
{
private readonly ObservableCollection<ClipboardItem> clipboardHistory;
private readonly Microsoft.UI.Dispatching.DispatcherQueue _dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
private (VirtualKey Key, DateTime Timestamp) _lastKeyEvent = (VirtualKey.None, DateTime.MinValue);
public OptionsViewModel ViewModel { get; private set; }
@ -145,6 +146,15 @@ namespace AdvancedPaste.Pages
Logger.LogTrace();
var thisKeyEvent = (sender.Key, Timestamp: DateTime.Now);
if (thisKeyEvent.Key == _lastKeyEvent.Key && (thisKeyEvent.Timestamp - _lastKeyEvent.Timestamp) < TimeSpan.FromMilliseconds(200))
{
// Sometimes, multiple keyboard accelerator events are raised for a single Ctrl + VirtualKey press.
return;
}
_lastKeyEvent = thisKeyEvent;
switch (sender.Key)
{
case VirtualKey.Escape:

View File

@ -61,17 +61,11 @@ namespace AdvancedPaste.ViewModels
private bool _pasteFormatsDirty;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsCustomAIEnabled))]
private bool _isCustomAIEnabledOverride = false;
public ObservableCollection<PasteFormat> StandardPasteFormats { get; } = [];
public ObservableCollection<PasteFormat> CustomActionPasteFormats { get; } = [];
public bool IsCustomAIEnabled => IsCustomAIEnabledOverride || IsCustomAIEnabledCore;
private bool IsCustomAIEnabledCore => IsAllowedByGPO && IsClipboardDataText && aiHelper.IsAIEnabled;
public bool IsCustomAIEnabled => IsAllowedByGPO && IsClipboardDataText && aiHelper.IsAIEnabled;
public event EventHandler<CustomActionActivatedEventArgs> CustomActionActivated;
@ -218,20 +212,6 @@ namespace AdvancedPaste.ViewModels
ClipboardHistoryEnabled = IsClipboardHistoryEnabled();
GeneratedResponses.Clear();
_dispatcherQueue.TryEnqueue(async () =>
{
// Work-around for ListViews being disabled but sometimes not appearing grayed out.
// It appears that this is sometimes only triggered by a change event. This
// work-around sometimes still doesn't work, but it's better than not having it.
await Task.Delay(5);
IsClipboardDataText = true;
IsCustomAIEnabledOverride = true;
await Task.Delay(150);
ReadClipboard();
IsCustomAIEnabledOverride = false;
});
}
// List to store generated responses
@ -437,7 +417,7 @@ namespace AdvancedPaste.ViewModels
internal void ExecutePasteFormat(PasteFormat pasteFormat)
{
if (!IsClipboardDataText || (pasteFormat.Format == PasteFormats.Custom && !IsCustomAIEnabledCore))
if (!IsClipboardDataText || (pasteFormat.Format == PasteFormats.Custom && !IsCustomAIEnabled))
{
return;
}

View File

@ -41,6 +41,7 @@ namespace
const wchar_t JSON_KEY_PROPERTIES[] = L"properties";
const wchar_t JSON_KEY_CUSTOM_ACTIONS[] = L"custom-actions";
const wchar_t JSON_KEY_SHORTCUT[] = L"shortcut";
const wchar_t JSON_KEY_IS_SHOWN[] = L"isShown";
const wchar_t JSON_KEY_ID[] = L"id";
const wchar_t JSON_KEY_WIN[] = L"win";
const wchar_t JSON_KEY_ALT[] = L"alt";
@ -220,8 +221,11 @@ private:
{
const auto object = customAction.GetObjectW();
m_custom_action_hotkeys.push_back(parse_single_hotkey(object.GetNamedObject(JSON_KEY_SHORTCUT)));
m_custom_action_ids.push_back(static_cast<int>(object.GetNamedNumber(JSON_KEY_ID)));
if (object.GetNamedBoolean(JSON_KEY_IS_SHOWN, false))
{
m_custom_action_hotkeys.push_back(parse_single_hotkey(object.GetNamedObject(JSON_KEY_SHORTCUT)));
m_custom_action_ids.push_back(static_cast<int>(object.GetNamedNumber(JSON_KEY_ID)));
}
}
}
}