Skip to content

Commit

Permalink
feat: redefine configuration, use template instead of prefix and suffix.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitism committed Sep 13, 2020
1 parent e8375cc commit 3f149c6
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 77 deletions.
Binary file modified GeMS-Key-Plus/GeMS-Key-Plus/ApplicationData.db
Binary file not shown.
14 changes: 14 additions & 0 deletions GeMS-Key-Plus/GeMS-Key-Plus/Controls/GuideControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="GeMS_Key_Plus.Controls.GuideControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GeMS_Key_Plus.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel>
<TextBlock>1. Press Alt+G to pass highlighted text into Keyz.</TextBlock>
<TextBlock>2. Press Button with mouse or Hotkey on keyboard.</TextBlock>
<TextBlock>3. You can define you own hotkey in Setting.</TextBlock>
</StackPanel>
</UserControl>
26 changes: 26 additions & 0 deletions GeMS-Key-Plus/GeMS-Key-Plus/Controls/GuideControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GeMS_Key_Plus.Controls
{
/// <summary>
/// Interaction logic for GuideControl.xaml
/// </summary>
public partial class GuideControl : UserControl
{
public GuideControl()
{
InitializeComponent();
}
}
}
10 changes: 7 additions & 3 deletions GeMS-Key-Plus/GeMS-Key-Plus/GeMS-Key-Plus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<ApplicationIcon>Key.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<None Remove="ApplicationData.db" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MaterialDesignColors" Version="1.2.6" />
<PackageReference Include="MaterialDesignThemes" Version="3.1.3" />
Expand All @@ -35,9 +39,9 @@
</ItemGroup>

<ItemGroup>
<None Update="ApplicationData.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Resource Include="ApplicationData.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion GeMS-Key-Plus/GeMS-Key-Plus/Global/GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class GlobalVariables
public static List<string> AllHotKeys { get; } = new List<string>()
{
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","D1","D2","D3"
,"D4","D5","D6","D7","D8","D9","D10",
,"D4","D5","D6","D7","D8","D9","D0",
};

public static LRUCache<string, string> ActionHistory { get; set; } = new LRUCache<string, string>(30);
Expand Down
11 changes: 11 additions & 0 deletions GeMS-Key-Plus/GeMS-Key-Plus/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
>
<materialDesign:PackIcon Kind="Settings" Foreground="{StaticResource PrimaryHueMidForegroundBrush}"></materialDesign:PackIcon>
</Button>
<materialDesign:PopupBox>
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon
Kind="QuestionMark"
VerticalAlignment="Top"
Foreground="{StaticResource PrimaryHueMidForegroundBrush}"
IsTabStop="False"
></materialDesign:PackIcon>
</materialDesign:PopupBox.ToggleContent>
<controls:GuideControl></controls:GuideControl>
</materialDesign:PopupBox>
<Button
Style="{StaticResource MaterialDesignToolForegroundButton}"
IsTabStop="False"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GeMS_Key_Plus.Migrations
{
public partial class InitialCreate : Migration
public partial class InitializeProject : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
Expand All @@ -15,8 +15,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
Hotkey = table.Column<string>(nullable: true),
ButtonName = table.Column<string>(nullable: true),
Category = table.Column<string>(nullable: true),
Prefix = table.Column<string>(nullable: true),
Suffix = table.Column<string>(nullable: true),
Template = table.Column<string>(nullable: true),
RequireSplit = table.Column<bool>(nullable: false),
IsPrimary = table.Column<bool>(nullable: false),
SpecialDelimiters = table.Column<string>(nullable: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<bool>("IsPrimary")
.HasColumnType("INTEGER");

b.Property<string>("Prefix")
.HasColumnType("TEXT");

b.Property<bool>("RequireSplit")
.HasColumnType("INTEGER");

b.Property<string>("SpecialDelimiters")
.HasColumnType("TEXT");

b.Property<string>("Suffix")
b.Property<string>("Template")
.HasColumnType("TEXT");

b.HasKey("Id");
Expand Down
3 changes: 1 addition & 2 deletions GeMS-Key-Plus/GeMS-Key-Plus/Models/LinkButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class LinkButton
public string Hotkey { get; set; }
public string ButtonName { get; set; }
public string Category { get; set; }
public string Prefix { get; set; }
public string Suffix { get; set; }
public string Template { get; set; }
public bool RequireSplit { get; set; }
public bool IsPrimary { get; set; }
public string SpecialDelimiters { get; set; }
Expand Down
24 changes: 9 additions & 15 deletions GeMS-Key-Plus/GeMS-Key-Plus/ViewModels/LinkButtonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ public string Category {
set { _category = value; RaisePropertyChanged(nameof(Category)); }
}

private string _prefix;
public string Prefix {
get { return _prefix; }
set { _prefix = value; RaisePropertyChanged(nameof(Prefix)); }
}

private string _suffix;
public string Suffix {
get { return _suffix; }
set { _suffix = value; RaisePropertyChanged(nameof(Suffix)); }
private string _template;
public string Template {
get { return _template; }
set { _template = value; RaisePropertyChanged(nameof(Template)); }
}

private bool _requireSplit;
Expand Down Expand Up @@ -87,26 +81,26 @@ public LinkButtonViewModel(LinkButton button)
this.HotKey = button.Hotkey;
this.Id = button.Id;
this.IsPrimary = button.IsPrimary;
this.Prefix = button.Prefix;
this.Suffix = button.Suffix;
this.Template = button.Template;
this.RequireSplit = button.RequireSplit;
this.SpecialDelimiters = button.SpecialDelimiters;
QueryCommand = new DelegateCommand(Query);
}

public void Query()
{

if (string.IsNullOrWhiteSpace(GlobalVariables.QueryString))
{
return;
}
if (RequireSplit)
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
MultipleQuery();
}
else
{
var target = Prefix + GlobalVariables.QueryString + Suffix;
var target = Template.Replace("{%s}", GlobalVariables.QueryString);
var psi = new ProcessStartInfo
{
FileName = target,
Expand All @@ -124,7 +118,7 @@ private void MultipleQuery()
foreach(string word in words)
{
if (string.IsNullOrWhiteSpace(word)) continue;
var target = Prefix + word + Suffix;
var target = Template.Replace("{%s}", word);
var psi = new ProcessStartInfo
{
FileName = target,
Expand Down
6 changes: 2 additions & 4 deletions GeMS-Key-Plus/GeMS-Key-Plus/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public MainViewModel()
context.Buttons.Add(new LinkButton()
{
SpecialDelimiters = "",
Suffix = "",
Prefix = "https://www.google.com/search?q=",
Template = "https://www.google.com/search?q={%s}",
RequireSplit= false,
ButtonName = "Google",
Category = "Search",
Expand All @@ -81,8 +80,7 @@ public MainViewModel()
context.Buttons.Add(new LinkButton()
{
SpecialDelimiters = "",
Suffix = "",
Prefix = "https://www.youdao.com/w/eng/",
Template = "https://www.youdao.com/w/eng/{%s}",
RequireSplit = false,
ButtonName = "Youdao",
Category = "Search",
Expand Down
5 changes: 1 addition & 4 deletions GeMS-Key-Plus/GeMS-Key-Plus/ViewModels/SettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public ObservableCollection<string> AvailableCategories {
set { _availableCategories = value; RaisePropertyChanged(nameof(AvailableCategories)); }
}



private ObservableCollection<LinkButton> _buttons;

public ObservableCollection<LinkButton> Buttons {
Expand Down Expand Up @@ -96,13 +94,12 @@ private void SubmitNewButton()
LinkButton button = new LinkButton()
{
SpecialDelimiters = NewButton.SpecialDelimiters,
Suffix = NewButton.Suffix,
RequireSplit = NewButton.RequireSplit,
ButtonName = NewButton.ButtonName,
Category = NewButton.Category,
Hotkey = NewButton.HotKey,
IsPrimary = NewButton.IsPrimary,
Prefix = NewButton.Prefix,
Template = NewButton.Template,
};
using(ApplicationContext context = new ApplicationContext())
{
Expand Down
39 changes: 4 additions & 35 deletions GeMS-Key-Plus/GeMS-Key-Plus/Views/Setting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,11 @@
Header="Category"
DisplayMemberBinding="{Binding Category}"/>
<GridViewColumn
Header="Prefix"
DisplayMemberBinding="{Binding Prefix}"/>
<GridViewColumn
Header="Suffix"
DisplayMemberBinding="{Binding Suffix}"/>
Header="Template"
DisplayMemberBinding="{Binding Template}"/>
<GridViewColumn
Header="Delimiters"
DisplayMemberBinding="{Binding SpecialDelimiters}"/>
<GridViewColumn
Header="Require Split"
>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox
IsChecked="{Binding RequireSplit}"
IsEnabled="False"
></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Header="Primary"
>
Expand Down Expand Up @@ -119,31 +104,15 @@
IsEditable="True">
</ComboBox>
<TextBox
Text="{Binding NewButton.Prefix}"
materialDesign:HintAssist.Hint="Prefix"
Text="{Binding NewButton.Template}"
materialDesign:HintAssist.Hint="Template (use {%s} as placeholder)"
Margin="0 0 0 4"
Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox
Text="{Binding NewButton.Suffix}"
materialDesign:HintAssist.Hint="Suffix"
Margin="0 0 0 4"
Style="{StaticResource MaterialDesignFloatingHintTextBox}" />

<StackPanel Orientation="Horizontal" Margin="0 4 0 4">
<CheckBox
IsChecked="{Binding NewButton.RequireSplit}"
Margin="0 4 0 4"
>
Require Split
</CheckBox>
<TextBox
Text="{Binding NewButton.SpecialDelimiters}"
IsEnabled="{Binding NewButton.RequireSplit}"
materialDesign:HintAssist.Hint="Special delimiters other than white spaces."
Margin="0 0 0 4"
Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</StackPanel>

<CheckBox
IsChecked="{Binding NewButton.IsPrimary}"
Margin="0 4 0 4"
Expand Down

0 comments on commit 3f149c6

Please sign in to comment.