Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to only show keys which have a modifier #157

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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