Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Added Hotkeys Reset Button
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewSachin committed May 9, 2017
1 parent b7ba991 commit 8b995ec
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Captura.Core/Models/Hotkeys/HotKeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ public static class HotKeyManager

public static void RegisterAll()
{
InitStorage();

foreach (var model in Settings.Instance.Hotkeys)
Hotkeys.Add(new Hotkey(model));
Populate();

ServiceProvider.HotKeyPressed += ProcessHotkey;
}

static void InitStorage()
public static void Populate()
{
if (Settings.Instance.Hotkeys == null)
Settings.Instance.Hotkeys = new List<HotkeyModel>();

if (Settings.Instance.Hotkeys.Count == 0)
Reset();

foreach (var model in Settings.Instance.Hotkeys)
Hotkeys.Add(new Hotkey(model));
}

public static void Reset()
Expand Down
37 changes: 21 additions & 16 deletions src/Views/HotkeyView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Captura"
x:Class="Captura.HotkeyView">
<Grid Name="HotkeyGrid" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="3"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="3"/>
</Style>
<Style TargetType="local:HotkeySelector">
<Setter Property="Margin" Value="3"/>
<Setter Property="Background" Value="#EEEEEE"/>
</Style>
</Grid.Resources>
</Grid>
<DockPanel Margin="5">
<Button Content="Reset"
DockPanel.Dock="Top"
Click="Reset_Click"/>
<Grid Name="HotkeyGrid" Margin="0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="3"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="3"/>
</Style>
<Style TargetType="local:HotkeySelector">
<Setter Property="Margin" Value="3"/>
<Setter Property="Background" Value="#EEEEEE"/>
</Style>
</Grid.Resources>
</Grid>
</DockPanel>
</Page>
23 changes: 21 additions & 2 deletions src/Views/HotkeyView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ public partial class HotkeyView
public HotkeyView()
{
InitializeComponent();


Render();
}

void Reset_Click(object sender, RoutedEventArgs e)
{
HotKeyManager.Dispose();
Settings.Instance.Hotkeys.Clear();

HotKeyManager.Hotkeys.Clear();
HotKeyManager.Populate();

HotkeyGrid.RowDefinitions.Clear();
HotkeyGrid.Children.Clear();

Render();
}

void Render()
{
for (int i = 0; i < HotKeyManager.Hotkeys.Count; ++i)
{
var hotkey = HotKeyManager.Hotkeys[i];
Expand All @@ -20,7 +39,7 @@ public HotkeyView()
Content = hotkey.Description,
IsChecked = hotkey.IsActive
};

HotkeyGrid.Children.Add(desc);
Grid.SetRow(desc, i);

Expand Down

0 comments on commit 8b995ec

Please sign in to comment.