Skip to content

Commit

Permalink
Merge pull request #15 from oldtimerza/vim-shortcut-fix
Browse files Browse the repository at this point in the history
Change application shortcuts to match VIM shortcuts without modifiers
Closes #16 and #9
  • Loading branch information
oldtimerza authored Feb 26, 2021
2 parents 7a6b560 + c0382c5 commit e6b19ca
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Clean
run: dotnet clean --configuration Release && dotnet nuget locals all --clear
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
5 changes: 2 additions & 3 deletions Meerkat/ViewModels/TodosViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Meerkat.Models;
using Meerkat.Utilities;
using Meerkat.ViewModels.Commands;
using System.Collections.Generic;
using System.Windows.Input;
Expand Down Expand Up @@ -95,7 +94,7 @@ public ICommand NextTodoItem
{
nextTodoItem = new RelayCommand(p =>
{
SelectedIndex = Math.Mod(SelectedIndex + 1, todoTracker.Todos.Count);
SelectedIndex = Utilities.Math.Mod(SelectedIndex + 1, todoTracker.Todos.Count);
},
p => stateTracker.CurrentState == State.NAVIGATION);
}
Expand All @@ -111,7 +110,7 @@ public ICommand PreviousTodoItem
{
previousTodoItem = new RelayCommand(p =>
{
SelectedIndex = Math.Mod(SelectedIndex - 1, todoTracker.Todos.Count);
SelectedIndex = Utilities.Math.Mod(SelectedIndex - 1, todoTracker.Todos.Count);
},
p => stateTracker.CurrentState == State.NAVIGATION);
}
Expand Down
7 changes: 1 addition & 6 deletions Meerkat/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Focusable="True"
ap:FocusExtension.IsFocused="{ Binding FocusInsertText }"
Visibility="{Binding Path=IsInsertMode, Converter={StaticResource BoolToVis}}"
IsEnabled="{ Binding IsInsertMode }">
IsEnabled="{ Binding IsInsertMode }" PreviewKeyDown="TodoMessageText_PreviewKeyDown">
<TextBox.InputBindings>
<KeyBinding
Key="Return"
Expand All @@ -44,23 +44,18 @@
</Grid>
<Window.InputBindings>
<KeyBinding
Modifiers="Ctrl"
Key="I"
Command="{ Binding EnterInsertMode }" />
<KeyBinding
Modifiers="Ctrl"
Key="J"
Command="{ Binding NextTodoItem }" />
<KeyBinding
Modifiers="Ctrl"
Key="K"
Command="{ Binding PreviousTodoItem }" />
<KeyBinding
Modifiers="Ctrl"
Key="Space"
Command="{ Binding ToggleTodo }" />
<KeyBinding
Modifiers="Ctrl"
Key="D"
Command="{ Binding RemoveTodo }" />
</Window.InputBindings>
Expand Down
32 changes: 31 additions & 1 deletion Meerkat/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NHotkey.Wpf;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand All @@ -13,15 +14,17 @@ public partial class MainWindow : Window
{
public MainWindow()
{
HotkeyManager.Current.AddOrReplace("ShowHideWindow", Key.Space, ModifierKeys.Alt, ShowHide);
InitializeComponent();
HotkeyManager.Current.AddOrReplace("ShowHideWindow", Key.Space, ModifierKeys.Alt, ShowHide);
Topmost = true;
}

public void ShowHide(object sender, EventArgs e)
{
if(WindowState == WindowState.Minimized)
{
WindowState = WindowState.Normal;
Activate();
return;
}
WindowState = WindowState.Minimized;
Expand All @@ -35,5 +38,32 @@ public void TextBoxGotKeyboardFocus(object sender, EventArgs e)
textBox.Clear();
}
}

private void TodoMessageText_PreviewKeyDown(object sender, KeyEventArgs e)
{
/*This is a hack and should be cleaned up with another a proper way to do it.
* For now it works the way I want to the app to though so I'm leaving it this way*/

var shortCutKeys = new List<Tuple<Key, string>> {
new Tuple<Key, string>( Key.I, "i" ),
new Tuple<Key, string>( Key.J, "j" ),
new Tuple<Key, string>( Key.K, "k" ),
new Tuple<Key, string>( Key.D, "d" )
};
if(!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
{
foreach (var shortcutKey in shortCutKeys)
{
if (e.Key == shortcutKey.Item1)
{
TextBox target = (TextBox)sender;
target.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, new TextComposition(InputManager.Current, target, shortcutKey.Item2))
{
RoutedEvent = TextCompositionManager.TextInputEvent
});
}
}
}
}
}
}
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
![Meerkat](https://raw.githubusercontent.com/oldtimerza/meerkat/master/logo.png)

# Meerkat-net

![.NET Core](https://github.com/oldtimerza/meerkat-net/workflows/.NET%20Core/badge.svg)

[Meerkat](https://oldtimerza.github.io/meerkat-site/)

A simple keyboard driven, VIM-styled todo manager. This is very similar to the Meerkat project I have previously worked on, that version used electron js which I had issues with and decided to make the switch to .Net to save on size.

## Requirements:

This application requires [.Net Core 3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1)

## Keyboard shortcuts:
Expand All @@ -16,15 +18,15 @@ This application requires [.Net Core 3.1](https://dotnet.microsoft.com/download/

### In Navigation mode(default):

Ctrl+j - select next todo in list
j - select next todo in list

Ctrl+k - select previous todo in list
k - select previous todo in list

Ctrl+d - delete currently selected todo
d - delete currently selected todo

Ctrl+space - toggle completeness of currently selected todo
space - toggle completeness of currently selected todo

Ctrl+i - enter Insert mode and focus the textbox
i - enter Insert mode and focus the textbox

### In Insert mode:

Expand Down

0 comments on commit e6b19ca

Please sign in to comment.