mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 14:59:16 +08:00
parent
579619952d
commit
a5757fd525
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user