Skip to content

Commit 67ab0cb

Browse files
Refactor hotkey selection and display logic
Co-authored-by: toniolo.luca <toniolo.luca@outlook.com>
1 parent 1d9e55f commit 67ab0cb

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/Captura.Hotkeys/HotKey.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Windows.Forms;
44
using Captura.Native;
@@ -68,9 +68,27 @@ public void Register()
6868
}
6969
}
7070

71-
public Keys Key { get; private set; }
71+
Keys _key;
72+
public Keys Key
73+
{
74+
get => _key;
75+
private set
76+
{
77+
_key = value;
78+
OnPropertyChanged();
79+
}
80+
}
7281

73-
public Modifiers Modifiers { get; private set; }
82+
Modifiers _modifiers;
83+
public Modifiers Modifiers
84+
{
85+
get => _modifiers;
86+
private set
87+
{
88+
_modifiers = value;
89+
OnPropertyChanged();
90+
}
91+
}
7492

7593
public void Change(Keys NewKey, Modifiers NewModifiers)
7694
{

src/Captura.ViewCore/ViewModels/HotkeysViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.Generic;
2+
using System.Collections.ObjectModel;
23
using System.Windows.Input;
34
using Captura.Hotkeys;
45
using Reactive.Bindings;
@@ -10,6 +11,8 @@ public class HotkeysViewModel
1011
{
1112
public ReadOnlyObservableCollection<Hotkey> Hotkeys { get; }
1213

14+
public IEnumerable<Service> AllServices => HotKeyManager.AllServices;
15+
1316
public HotkeysViewModel(HotKeyManager HotKeyManager)
1417
{
1518
Hotkeys = HotKeyManager.Hotkeys;

src/Captura/Controls/HotkeySelector.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ static void HotkeyModelChangedCallback(DependencyObject Sender, DependencyProper
3333
{
3434
if (E.PropertyName == nameof(Hotkey.IsActive))
3535
selector.TextColor();
36+
37+
// Update display when Key or Modifiers change
38+
if (E.PropertyName == nameof(Hotkey.Key) || E.PropertyName == nameof(Hotkey.Modifiers))
39+
{
40+
if (!selector._editing)
41+
selector.Content = hotkey.ToString();
42+
}
3643
};
3744

3845
selector.Content = hotkey.ToString();

src/Captura/Pages/HotkeysPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:Captura"
55
xmlns:hotkeys="clr-namespace:Captura.Hotkeys;assembly=Captura.Hotkeys"
6-
DataContext="{Binding HotKeyManager, Source={StaticResource ServiceLocator}}">
6+
DataContext="{Binding HotkeysViewModel, Source={StaticResource ServiceLocator}}">
77
<Grid>
88
<DockPanel Margin="5">
99
<Grid DockPanel.Dock="Top">
@@ -61,7 +61,7 @@
6161
<local:ModernButton DockPanel.Dock="Right"
6262
CommandParameter="{Binding}"
6363
IconData="{Binding Icons.Close, Source={StaticResource ServiceLocator}}"
64-
Command="{Binding HotKeyManager.RemoveCommand, Source={StaticResource ServiceLocator}}">
64+
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=Page}}">
6565
<local:ModernButton.LayoutTransform>
6666
<ScaleTransform ScaleX="0.8" ScaleY="0.8"/>
6767
</local:ModernButton.LayoutTransform>

0 commit comments

Comments
 (0)