Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Flow.Launcher.Infrastructure/UserSettings/PluginHotkey.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
using Flow.Launcher.Plugin;
using System;
using Flow.Launcher.Plugin;

namespace Flow.Launcher.Infrastructure.UserSettings
{
public class CustomPluginHotkey : BaseModel
{
public string Hotkey { get; set; }
public string ActionKeyword { get; set; }

public CustomPluginHotkey(string hotkey, string actionKeyword)
{
Hotkey = hotkey;
ActionKeyword = actionKeyword;
}

public override bool Equals(object other)
{
if (other is CustomPluginHotkey otherHotkey)
{
return Hotkey == otherHotkey.Hotkey && ActionKeyword == otherHotkey.ActionKeyword;
}

return false;
}

public override int GetHashCode()
{
return HashCode.Combine(Hotkey, ActionKeyword);
}
}
}
18 changes: 16 additions & 2 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
Title="{DynamicResource customeQueryHotkeyTitle}"

Check warning on line 7 in Flow.Launcher/CustomQueryHotkeySetting.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`custome` is not a recognized word. (unrecognized-spelling)
Width="530"
Background="{DynamicResource PopuBGColor}"

Check warning on line 9 in Flow.Launcher/CustomQueryHotkeySetting.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`Popu` is not a recognized word. (unrecognized-spelling)
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Foreground="{DynamicResource PopupTextColor}"
Icon="Images\app.png"
Expand Down Expand Up @@ -63,11 +63,11 @@
Margin="0 0 0 12"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource customeQueryHotkeyTitle}"

Check warning on line 66 in Flow.Launcher/CustomQueryHotkeySetting.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`custome` is not a recognized word. (unrecognized-spelling)
TextAlignment="Left" />
<TextBlock
FontSize="14"
Text="{DynamicResource customeQueryHotkeyTips}"

Check warning on line 70 in Flow.Launcher/CustomQueryHotkeySetting.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`custome` is not a recognized word. (unrecognized-spelling)
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
<Image
Expand Down Expand Up @@ -119,7 +119,8 @@
Grid.Column="1"
Margin="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
VerticalAlignment="Center"
Text="{Binding ActionKeyword}" />
<Button
x:Name="btnTestActionKeyword"
Grid.Row="1"
Expand Down Expand Up @@ -150,7 +151,20 @@
Margin="5 0 10 0"
Click="btnAdd_OnClick"
Style="{StaticResource AccentButtonStyle}">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock
x:Name="lblAdd"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{DynamicResource done}"
Visibility="Collapsed" />
<TextBlock
x:Name="lblUpdate"

Check warning on line 162 in Flow.Launcher/CustomQueryHotkeySetting.xaml

View workflow job for this annotation

GitHub Actions / Check Spelling

`lbl` is not a recognized word. (unrecognized-spelling)
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{DynamicResource update}"
Visibility="Collapsed" />
</Grid>
</Button>
</StackPanel>
</Border>
Expand Down
70 changes: 25 additions & 45 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,52 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using Flow.Launcher.Helper;
using System.Windows.Input;
using Flow.Launcher.Infrastructure.UserSettings;

namespace Flow.Launcher
{
public partial class CustomQueryHotkeySetting : Window
{
private readonly Settings _settings;
public string Hotkey { get; set; } = string.Empty;
public string ActionKeyword { get; set; } = string.Empty;

private bool update;
private CustomPluginHotkey updateCustomHotkey;
private readonly bool update;
private readonly CustomPluginHotkey originalCustomHotkey;

public CustomQueryHotkeySetting(Settings settings)
public CustomQueryHotkeySetting()
{
_settings = settings;
InitializeComponent();
lblAdd.Visibility = Visibility.Visible;

Check warning on line 19 in Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`lbl` is not a recognized word. (unrecognized-spelling)
}

private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
public CustomQueryHotkeySetting(CustomPluginHotkey hotkey)
{
Close();
originalCustomHotkey = hotkey;
update = true;
ActionKeyword = originalCustomHotkey.ActionKeyword;
InitializeComponent();
lblUpdate.Visibility = Visibility.Visible;

Check warning on line 28 in Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`lbl` is not a recognized word. (unrecognized-spelling)
HotkeyControl.SetHotkey(originalCustomHotkey.Hotkey, false);
}

private void btnAdd_OnClick(object sender, RoutedEventArgs e)
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
if (!update)
{
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();

var pluginHotkey = new CustomPluginHotkey
{
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
};
_settings.CustomPluginHotkeys.Add(pluginHotkey);

HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
}
else
{
var oldHotkey = updateCustomHotkey.Hotkey;
updateCustomHotkey.ActionKeyword = tbAction.Text;
updateCustomHotkey.Hotkey = HotkeyControl.CurrentHotkey.ToString();
//remove origin hotkey
HotKeyMapper.RemoveHotkey(oldHotkey);
HotKeyMapper.SetCustomQueryHotkey(updateCustomHotkey);
}

DialogResult = false;
Close();
}

public void UpdateItem(CustomPluginHotkey item)
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
{
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
Hotkey = HotkeyControl.CurrentHotkey.ToString();

if (string.IsNullOrEmpty(Hotkey) && string.IsNullOrEmpty(ActionKeyword))
{
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
Close();
App.API.ShowMsgBox(App.API.GetTranslation("emptyPluginHotkey"));
return;
}

tbAction.Text = updateCustomHotkey.ActionKeyword;
HotkeyControl.SetHotkey(updateCustomHotkey.Hotkey, false);
update = true;
lblAdd.Text = App.API.GetTranslation("update");
DialogResult = !update || originalCustomHotkey.Hotkey != Hotkey || originalCustomHotkey.ActionKeyword != ActionKeyword;
Close();
}

private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
Expand All @@ -79,6 +58,7 @@

private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
{
DialogResult = false;
Close();
}

Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
App.API.ShowMsgBox(App.API.GetTranslation("emptyShortcut"));
return;
}

// Check if key is modified or adding a new one
if (((update && originalKey != Key) || !update) && _hotkeyVm.DoesShortcutExist(Key))
{
App.API.ShowMsgBox(App.API.GetTranslation("duplicateShortcut"));
return;
}

DialogResult = !update || originalKey != Key || originalValue != Value;
Close();
}
Expand Down
4 changes: 3 additions & 1 deletion Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,14 @@
<system:String x:Key="customeQueryHotkeyTips">Press a custom hotkey to open Flow Launcher and input the specified query automatically.</system:String>
<system:String x:Key="preview">Preview</system:String>
<system:String x:Key="hotkeyIsNotUnavailable">Hotkey is unavailable, please select a new hotkey</system:String>
<system:String x:Key="invalidPluginHotkey">Invalid plugin hotkey</system:String>
<system:String x:Key="invalidPluginHotkey">Hotkey is invalid</system:String>
<system:String x:Key="update">Update</system:String>
<system:String x:Key="hotkeyRegTitle">Binding Hotkey</system:String>
<system:String x:Key="hotkeyUnavailable">Current hotkey is unavailable.</system:String>
<system:String x:Key="hotkeyUnavailableUneditable">This hotkey is reserved for "{0}" and can't be used. Please choose another hotkey.</system:String>
<system:String x:Key="hotkeyUnavailableEditable">This hotkey is already in use by "{0}". If you press "Overwrite", it will be removed from "{0}".</system:String>
<system:String x:Key="hotkeyRegGuide">Press the keys you want to use for this function.</system:String>
<system:String x:Key="emptyPluginHotkey">Hotkey and action keyword are empty</system:String>

<!-- Custom Query Shortcut Dialog -->
<system:String x:Key="customeQueryShortcutTitle">Custom Query Shortcut</system:String>
Expand All @@ -444,6 +445,7 @@
</system:String>
<system:String x:Key="duplicateShortcut">Shortcut already exists, please enter a new Shortcut or edit the existing one.</system:String>
<system:String x:Key="emptyShortcut">Shortcut and/or its expansion is empty.</system:String>
<system:String x:Key="invalidShortcut">Shortcut is invalid</system:String>

<!-- Common Action -->
<system:String x:Key="commonSave">Save</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,33 @@ private void CustomHotkeyEdit()
return;
}

var window = new CustomQueryHotkeySetting(Settings);
window.UpdateItem(item);
window.ShowDialog();
var settingItem = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (settingItem == null)
{
App.API.ShowMsgBox(App.API.GetTranslation("invalidPluginHotkey"));
return;
}

var window = new CustomQueryHotkeySetting(settingItem);
if (window.ShowDialog() is not true) return;

var index = Settings.CustomPluginHotkeys.IndexOf(settingItem);
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
}

[RelayCommand]
private void CustomHotkeyAdd()
{
new CustomQueryHotkeySetting(Settings).ShowDialog();
var window = new CustomQueryHotkeySetting();
if (window.ShowDialog() is true)
{
var customHotkey = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
Settings.CustomPluginHotkeys.Add(customHotkey);
HotKeyMapper.SetCustomQueryHotkey(customHotkey); // set new hotkey
}
}

[RelayCommand]
Expand Down Expand Up @@ -114,10 +132,18 @@ private void CustomShortcutEdit()
return;
}

var window = new CustomShortcutSetting(item.Key, item.Value, this);
var settingItem = Settings.CustomShortcuts.FirstOrDefault(o =>
o.Key == item.Key && o.Value == item.Value);
if (settingItem == null)
{
App.API.ShowMsgBox(App.API.GetTranslation("invalidShortcut"));
return;
}

var window = new CustomShortcutSetting(settingItem.Key, settingItem.Value, this);
if (window.ShowDialog() is not true) return;

var index = Settings.CustomShortcuts.IndexOf(item);
var index = Settings.CustomShortcuts.IndexOf(settingItem);
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
}

Expand Down
Loading