Skip to content

Commit

Permalink
Added option to only show keys which have a modifier. Fix shortcutOnl…
Browse files Browse the repository at this point in the history
…y to work only with keymaps file. Maybe shortcutOnly should be renamed or better explained?
  • Loading branch information
bfritscher committed Jul 8, 2017
1 parent 241e8e3 commit 4d391d0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/Carnac.Logic/MessageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ public IObservable<Message> 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;
});
}
}
}
11 changes: 8 additions & 3 deletions src/Carnac.Logic/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<KeyPress>(new[] { key });
textCollection = new ReadOnlyCollection<string>(CreateTextSequence(key).ToArray());
}

public Message(IEnumerable<KeyPress> keys, KeyShortcut shortcut)
public Message(IEnumerable<KeyPress> keys, KeyShortcut shortcut, Boolean isShortcut = false)
: this()
{
var allKeys = keys.ToArray();
Expand All @@ -48,7 +50,8 @@ public Message(IEnumerable<KeyPress> 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<KeyPress>(allKeys);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Carnac.Logic/Models/PopupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 1 addition & 1 deletion src/Carnac.Logic/ShortcutAccumulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Carnac/UI/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@
</ui:PreferencesField>

<ui:PreferencesField Header="Shortcuts Only">
<CheckBox IsChecked="{Binding Settings.DetectShortcutsOnly}" />
<CheckBox IsChecked="{Binding Settings.DetectShortcutsOnly}" Content="shows only keys which are listed in keymaps folder" />
</ui:PreferencesField>
<ui:PreferencesField Header="Show Application Icon">
<ui:PreferencesField Header="Show Only Modifiers">
<CheckBox IsChecked="{Binding Settings.ShowOnlyModifiers}" Content="shows only keys which have ctrl, shift, alt or windows" />
</ui:PreferencesField>
<ui:PreferencesField Header="Show Application Icon">
<CheckBox IsChecked="{Binding Settings.ShowApplicationIcon}" />
</ui:PreferencesField>
</StackPanel>
Expand Down

0 comments on commit 4d391d0

Please sign in to comment.