Skip to content

Commit

Permalink
Separated KeyGesture per OS
Browse files Browse the repository at this point in the history
Now MacOS will use cmd key instead of ctrl key.
  • Loading branch information
EX3exp committed Oct 28, 2024
1 parent 03fd179 commit dcf3221
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
34 changes: 34 additions & 0 deletions Mirivoice/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Platform.Storage;
using global::Mirivoice.Views;
using Mirivoice.Commands;
Expand All @@ -26,6 +27,7 @@ namespace Mirivoice.ViewModels
public class MainViewModel : VoicerSelectingViewModelBase
{
MainWindow mainWindow;

public static FilePickerFileType MiriVoiceProject { get; } = new("MiriVoice Project File")
{
Patterns = new[] { "*.mrp" },
Expand Down Expand Up @@ -729,6 +731,7 @@ public async void OnNewButtonClick()

}



public MainViewModel(MainWindow window) : base(true)
{
Expand All @@ -740,6 +743,7 @@ public MainViewModel(MainWindow window) : base(true)
LoadRecentFIles();

SetCommands();
SetGestures();

SingleTextBoxEditorEnabled = false;
IsVisibleProgressbar = false;
Expand Down Expand Up @@ -940,6 +944,36 @@ public void LoadRecentFIles()
}
RecentFiles.UpdateUI(this); // update UI
}

// Key gestures
public KeyGesture UndoGesture { get; set; }
public KeyGesture RedoGesture { get; set; }
public KeyGesture OpenGesture { get; set; }
public KeyGesture SaveGesture { get; set; }
public KeyGesture SaveAsGesture { get; set; }
public KeyGesture NewGesture { get; set; }

void SetGestures()
{
if (OS.IsWindows() || OS.IsLinux())
{
UndoGesture = new KeyGesture(Key.Z, KeyModifiers.Control);
RedoGesture = new KeyGesture(Key.Y, KeyModifiers.Control);
OpenGesture = new KeyGesture(Key.O, KeyModifiers.Control);
SaveGesture = new KeyGesture(Key.S, KeyModifiers.Control);
SaveAsGesture = new KeyGesture(Key.S, KeyModifiers.Control | KeyModifiers.Shift);
NewGesture = new KeyGesture(Key.N, KeyModifiers.Control);
}
else // MacOS
{
UndoGesture = new KeyGesture(Key.Z, KeyModifiers.Meta);
RedoGesture = new KeyGesture(Key.Y, KeyModifiers.Meta);
OpenGesture = new KeyGesture(Key.O, KeyModifiers.Meta);
SaveGesture = new KeyGesture(Key.S, KeyModifiers.Meta);
SaveAsGesture = new KeyGesture(Key.S, KeyModifiers.Meta | KeyModifiers.Shift);
NewGesture = new KeyGesture(Key.N, KeyModifiers.Meta);
}
}
// Commands
public MCommand AddLineBoxCommand { get; set; }
AddLineBoxReceiver addLineBoxReceiver;
Expand Down
12 changes: 6 additions & 6 deletions Mirivoice/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="{DynamicResource menu.files.title }">
<MenuItem Header="{DynamicResource menu.files.new}" Command="{Binding OnNewButtonClick}" InputGesture="Ctrl+N"/>
<MenuItem Header="{DynamicResource menu.files.new}" Command="{Binding OnNewButtonClick}" InputGesture="{Binding NewGesture}"/>
<Separator/>
<MenuItem Header="{DynamicResource menu.files.open}" Command="{Binding OnOpenButtonClick}" InputGesture="Ctrl+O"/>
<MenuItem Header="{DynamicResource menu.files.open}" Command="{Binding OnOpenButtonClick}" InputGesture="{Binding OpenGesture}"/>
<MenuItem Header="{DynamicResource menu.files.recent}" ItemsSource="{Binding RecentMenuCollection}">

</MenuItem>
<MenuItem Header="{DynamicResource menu.files.save}" Command="{Binding OnSaveButtonClick}" InputGesture="Ctrl+S"/>
<MenuItem Header="{DynamicResource menu.files.saveas}" Command="{Binding OnSaveAsButtonClick}" InputGesture="Ctrl+Shift+S"/>
<MenuItem Header="{DynamicResource menu.files.save}" Command="{Binding OnSaveButtonClick}" InputGesture="{Binding SaveGesture}"/>
<MenuItem Header="{DynamicResource menu.files.saveas}" Command="{Binding OnSaveAsButtonClick}" InputGesture="{Binding SaveAsGesture}"/>
<Separator/>
<MenuItem Header="{DynamicResource menu.files.export}">
<MenuItem Header="{DynamicResource menu.files.export.perLine}" Command="{Binding OnExportAudioPerLineClick}"></MenuItem>
Expand All @@ -46,8 +46,8 @@


<MenuItem Header="{DynamicResource menu.project.title}">
<MenuItem Header="{DynamicResource menu.project.undo}" InputGesture="Ctrl+Z" Command="{Binding Undo}"></MenuItem>
<MenuItem Header="{DynamicResource menu.project.redo}" InputGesture="Ctrl+Y" Command="{Binding Redo}"></MenuItem>
<MenuItem Header="{DynamicResource menu.project.undo}" InputGesture="{Binding UndoGesture}" Command="{Binding Undo}"></MenuItem>
<MenuItem Header="{DynamicResource menu.project.redo}" InputGesture="{Binding RedoGesture}" Command="{Binding Redo}"></MenuItem>
<Separator/>
<MenuItem Header="{DynamicResource menu.project.pref}" IsEnabled="False"></MenuItem>
<Separator/>
Expand Down
12 changes: 6 additions & 6 deletions Mirivoice/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
Icon="/Assets/mirivoice-logo.ico"
Title="{Binding Title}">
<Window.KeyBindings>
<KeyBinding Gesture="Ctrl + Z" Command="{Binding Undo}" />
<KeyBinding Gesture="Ctrl + Y" Command="{Binding Redo}" />
<KeyBinding Gesture="Ctrl + O" Command="{Binding OnOpenButtonClicked}" />
<KeyBinding Gesture="Ctrl + S" Command="{Binding OnSaveButtonClick}" />
<KeyBinding Gesture="Ctrl + Shift + S" Command="{Binding OnSaveAsButtonClick}" />
<KeyBinding Gesture="Ctrl + N" Command="{Binding OnNewButtonClick}" />
<KeyBinding Gesture="{Binding UndoGesture}" Command="{Binding Undo}" />
<KeyBinding Gesture="{Binding RedoGesture}" Command="{Binding Redo}" />
<KeyBinding Gesture="{Binding OpenGesture}" Command="{Binding OnOpenButtonClicked}" />
<KeyBinding Gesture="{Binding SaveGesture}" Command="{Binding OnSaveButtonClick}" />
<KeyBinding Gesture="{Binding SaveAsGesture}" Command="{Binding OnSaveAsButtonClick}" />
<KeyBinding Gesture="{Binding NewGesture}" Command="{Binding OnNewButtonClick}" />
</Window.KeyBindings>
<views:MainView />
</Window>

0 comments on commit dcf3221

Please sign in to comment.