From 4d391d00284488f99e15d12dafbb7e3148ce8d83 Mon Sep 17 00:00:00 2001 From: Boris Fritscher Date: Sat, 10 Jun 2017 01:50:07 +0200 Subject: [PATCH] Added option to only show keys which have a modifier. Fix shortcutOnly to work only with keymaps file. Maybe shortcutOnly should be renamed or better explained? --- src/Carnac.Logic/MessageProvider.cs | 17 ++++++++++++++++- src/Carnac.Logic/Models/Message.cs | 11 ++++++++--- src/Carnac.Logic/Models/PopupSettings.cs | 1 + src/Carnac.Logic/ShortcutAccumulator.cs | 2 +- src/Carnac/UI/PreferencesView.xaml | 7 +++++-- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Carnac.Logic/MessageProvider.cs b/src/Carnac.Logic/MessageProvider.cs index e69a13d9..8a3ca989 100644 --- a/src/Carnac.Logic/MessageProvider.cs +++ b/src/Carnac.Logic/MessageProvider.cs @@ -37,7 +37,22 @@ public IObservable GetMessageStream() .Where(c => c.HasCompletedValue) .SelectMany(c => c.GetMessages()) .Scan(new Message(), (acc, key) => Message.MergeIfNeeded(acc, key)) - .Where(m => !settings.DetectShortcutsOnly || m.IsShortcut); + .Where(m => + { + if (settings.DetectShortcutsOnly && settings.ShowOnlyModifiers) + { + return m.IsShortcut && m.IsModifier; + } + if (settings.DetectShortcutsOnly) + { + return m.IsShortcut; + } + if (settings.ShowOnlyModifiers) + { + return m.IsModifier; + } + return true; + }); } } } \ No newline at end of file diff --git a/src/Carnac.Logic/Models/Message.cs b/src/Carnac.Logic/Models/Message.cs index 415492b0..43c46cd0 100644 --- a/src/Carnac.Logic/Models/Message.cs +++ b/src/Carnac.Logic/Models/Message.cs @@ -15,6 +15,7 @@ public sealed class Message readonly string shortcutName; readonly bool canBeMerged; readonly bool isShortcut; + readonly bool isModifier; readonly bool isDeleting; readonly DateTime lastMessage; readonly Message previous; @@ -30,12 +31,13 @@ public Message(KeyPress key) processName = key.Process.ProcessName; processIcon = key.Process.ProcessIcon; canBeMerged = !key.HasModifierPressed; + isModifier = key.HasModifierPressed; keys = new ReadOnlyCollection(new[] { key }); textCollection = new ReadOnlyCollection(CreateTextSequence(key).ToArray()); } - public Message(IEnumerable keys, KeyShortcut shortcut) + public Message(IEnumerable keys, KeyShortcut shortcut, Boolean isShortcut = false) : this() { var allKeys = keys.ToArray(); @@ -48,7 +50,8 @@ public Message(IEnumerable keys, KeyShortcut shortcut) processName = distinctProcessName.Single(); processIcon = allKeys.First().Process.ProcessIcon; shortcutName = shortcut.Name; - isShortcut = true; + this.isShortcut = isShortcut; + this.isModifier = allKeys.Any(k => k.HasModifierPressed); canBeMerged = false; this.keys = new ReadOnlyCollection(allKeys); @@ -91,7 +94,9 @@ private Message(Message initial, bool isDeleting) public DateTime LastMessage { get { return lastMessage; } } public bool IsDeleting { get { return isDeleting; } } - + + public bool IsModifier { get { return isModifier; } } + public Message Merge(Message other) { return new Message(this, other); diff --git a/src/Carnac.Logic/Models/PopupSettings.cs b/src/Carnac.Logic/Models/PopupSettings.cs index 8331f73f..809f603a 100644 --- a/src/Carnac.Logic/Models/PopupSettings.cs +++ b/src/Carnac.Logic/Models/PopupSettings.cs @@ -85,5 +85,6 @@ public string SortDescription public bool DetectShortcutsOnly { get; set; } public bool ShowApplicationIcon { get; set; } public bool SettingsConfigured { get; set; } + public bool ShowOnlyModifiers { get; set; } } } diff --git a/src/Carnac.Logic/ShortcutAccumulator.cs b/src/Carnac.Logic/ShortcutAccumulator.cs index f709903f..00168e61 100644 --- a/src/Carnac.Logic/ShortcutAccumulator.cs +++ b/src/Carnac.Logic/ShortcutAccumulator.cs @@ -88,7 +88,7 @@ void ShortcutCompleted(KeyShortcut shortcut) if (HasCompletedValue) throw new InvalidOperationException(); - messages = new[] { new Message(Keys, shortcut) }; + messages = new[] { new Message(Keys, shortcut, true) }; HasCompletedValue = true; } diff --git a/src/Carnac/UI/PreferencesView.xaml b/src/Carnac/UI/PreferencesView.xaml index bcbcecac..4942d15c 100644 --- a/src/Carnac/UI/PreferencesView.xaml +++ b/src/Carnac/UI/PreferencesView.xaml @@ -138,9 +138,12 @@ - + - + + + +