Skip to content

Commit d4b231b

Browse files
committed
feat: Update layout and add clear cache command.
1 parent 482a2fb commit d4b231b

File tree

8 files changed

+96
-8
lines changed

8 files changed

+96
-8
lines changed

GeMS-Key-Plus/GeMS-Key-Plus/GeMS-Key-Plus.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<TargetFramework>netcoreapp5.0</TargetFramework>
66
<RootNamespace>GeMS_Key_Plus</RootNamespace>
77
<UseWPF>true</UseWPF>
8+
<Version>0.1.0</Version>
9+
<Authors>Rabbitism</Authors>
10+
<Company>Galaxism</Company>
11+
<Product>GEMS Key Plus</Product>
812
</PropertyGroup>
913

1014
<ItemGroup>

GeMS-Key-Plus/GeMS-Key-Plus/MainWindow.xaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
SizeToContent="WidthAndHeight"
1515
AllowsTransparency="True"
1616
FontSize="16"
17-
WindowStartupLocation="CenterScreen"
1817
d:DataContext="{x:Type vms:MainViewModel}"
1918
Title="GeMS Key Plus" d:DesignHeight="450" d:DesignWidth="800">
2019
<materialDesign:Card Margin="2" Background="White" Opacity="0.95">
@@ -71,7 +70,11 @@
7170
>
7271

7372
</TextBox>
74-
<materialDesign:PopupBox Grid.Column="1" Padding="8" IsTabStop="False" StaysOpen="True">
73+
<materialDesign:PopupBox
74+
Grid.Column="1"
75+
Padding="8"
76+
IsTabStop="False"
77+
StaysOpen="True">
7578
<i:Interaction.Triggers>
7679
<i:EventTrigger EventName="Opened">
7780
<i:InvokeCommandAction Command="{Binding ReloadActionHistoryCommand}" ></i:InvokeCommandAction>
@@ -87,12 +90,26 @@
8790
</materialDesign:PopupBox.ToggleContent>
8891

8992
<StackPanel>
90-
<Grid>
91-
93+
<Grid Margin="16 8 16 0">
94+
<Grid.ColumnDefinitions>
95+
<ColumnDefinition Width="*"/>
96+
<ColumnDefinition Width="auto"/>
97+
</Grid.ColumnDefinitions>
98+
<TextBlock Text="History"></TextBlock>
99+
<Button
100+
Style="{StaticResource MaterialDesignToolForegroundButton}"
101+
Grid.Column="1"
102+
Command="{Binding ClearCacheCommand}"
103+
>
104+
<materialDesign:PackIcon
105+
Kind="Eraser"
106+
></materialDesign:PackIcon>
107+
</Button>
92108
</Grid>
93109
<ListView
94110
ItemsSource="{Binding ActionHistory}"
95-
Width="600"
111+
MaxWidth="600"
112+
MinWidth="200"
96113
MaxHeight="600"
97114
SelectedItem="{Binding SelectedActionRecord}"
98115
ScrollViewer.VerticalScrollBarVisibility="Auto"

GeMS-Key-Plus/GeMS-Key-Plus/Models/LRUCache.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public IEnumerable<Tuple<TKey, TValue>> GetAll()
5959
}
6060
}
6161

62+
public void Clear()
63+
{
64+
_list.Clear();
65+
_nodeDictionary.Clear();
66+
_dictionary.Clear();
67+
}
6268

6369
}
6470
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<Configuration>Release</Configuration>
8+
<Platform>Any CPU</Platform>
9+
<PublishDir>bin\Release\netcoreapp5.0\publish\</PublishDir>
10+
<PublishProtocol>FileSystem</PublishProtocol>
11+
<TargetFramework>netcoreapp5.0</TargetFramework>
12+
<SelfContained>false</SelfContained>
13+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
14+
</PropertyGroup>
15+
</Project>

GeMS-Key-Plus/GeMS-Key-Plus/ViewModels/MainViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MainViewModel:BindableBase
2222
public DelegateCommand ReloadActionHistoryCommand { get; set; }
2323
public DelegateCommand<ActionRecordViewModel> QueryHistoryCommand { get; set; }
2424
public DelegateCommand ReloadButtonsCommand { get; set; }
25+
public DelegateCommand ClearCacheCommand { get; set; }
2526

2627
private string _queryString;
2728
public string QueryString {
@@ -94,6 +95,7 @@ public MainViewModel()
9495
ReloadActionHistoryCommand = new DelegateCommand(ReloadActionHistory);
9596
QueryHistoryCommand = new DelegateCommand<ActionRecordViewModel>(QueryHistory);
9697
ReloadButtonsCommand = new DelegateCommand(ReloadButtons);
98+
ClearCacheCommand = new DelegateCommand(ClearCache);
9799
}
98100

99101
public void Query(KeyEventArgs args)
@@ -124,6 +126,12 @@ private void QueryHistory(ActionRecordViewModel record)
124126
this.ButtonPanel.Query(key);
125127
}
126128
}
129+
130+
private void ClearCache()
131+
{
132+
GlobalVariables.ActionHistory.Clear();
133+
ReloadActionHistory();
134+
}
127135

128136
}
129137
}

GeMS-Key-Plus/GeMS-Key-Plus/ViewModels/SettingViewModel.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System.Text;
1212
using System.Threading.Tasks;
13+
using System.Windows;
1314
using System.Windows.Controls;
1415

1516
namespace GeMS_Key_Plus.ViewModels
@@ -26,6 +27,16 @@ public LinkButtonViewModel NewButton {
2627
}
2728
}
2829

30+
private LinkButton _selectedButton = new LinkButton();
31+
32+
public LinkButton SelectedButton {
33+
get => _selectedButton;
34+
set {
35+
_selectedButton = value;
36+
RaisePropertyChanged(nameof(SelectedButton));
37+
}
38+
}
39+
2940
private ObservableCollection<string> _availableKeys;
3041

3142
public ObservableCollection<string> AvailableKeys {
@@ -50,11 +61,13 @@ public ObservableCollection<LinkButton> Buttons {
5061
}
5162

5263
public DelegateCommand SubmitCommand { get; set; }
64+
public DelegateCommand<int?> DeleteCommand { get; set; }
5365

5466
public SettingViewModel()
5567
{
5668
ReloadButtons();
5769
SubmitCommand = new DelegateCommand(SubmitNewButton);
70+
DeleteCommand = new DelegateCommand<int?>(DeleteButton);
5871
}
5972

6073
private void ReloadButtons()
@@ -99,5 +112,18 @@ private void SubmitNewButton()
99112
ReloadButtons();
100113
this.NewButton = new LinkButtonViewModel();
101114
}
115+
116+
private void DeleteButton(int? i)
117+
{
118+
if (!i.HasValue) return;
119+
using (ApplicationContext context = new ApplicationContext())
120+
{
121+
LinkButton b = context.Buttons.FirstOrDefault(a => a.Id == i);
122+
if (b is null) return;
123+
context.Remove(b);
124+
context.SaveChanges();
125+
}
126+
ReloadButtons();
127+
}
102128
}
103129
}

GeMS-Key-Plus/GeMS-Key-Plus/Views/Setting.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@
3131
<materialDesign:PackIcon Kind="Close"></materialDesign:PackIcon>
3232
</Button>
3333
</Grid>
34-
<ListView ItemsSource="{Binding Buttons}">
34+
<ListView
35+
ItemsSource="{Binding Buttons}"
36+
SelectedItem="{Binding SelectedButton}"
37+
>
38+
<ListView.ContextMenu>
39+
<ContextMenu >
40+
<MenuItem Header="Delete" Command="{Binding DeleteCommand}" CommandParameter="{Binding SelectedButton.Id}">
41+
42+
</MenuItem>
43+
</ContextMenu>
44+
</ListView.ContextMenu>
3545
<ListView.View>
3646
<GridView>
3747
<GridViewColumn

GeMS-Key-Plus/GeMS-Key-Plus/Views/Setting.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GeMS_Key_Plus.ViewModels;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Linq;
56
using System.Text;
67
using System.Threading.Tasks;
@@ -31,13 +32,14 @@ public Setting()
3132
public Setting(MainViewModel mainViewModel)
3233
{
3334
InitializeComponent();
34-
_mainViewModel = new MainViewModel();
35+
_mainViewModel = mainViewModel;
3536
this.DataContext = new SettingViewModel();
3637
}
3738

3839
private void CloseButton_Click(object sender, RoutedEventArgs e)
3940
{
40-
_mainViewModel?.ReloadButtonsCommand?.Execute();
41+
_mainViewModel.ReloadButtonsCommand.Execute();
42+
Debug.WriteLine("Close Settings");
4143
this.Close();
4244
}
4345

0 commit comments

Comments
 (0)