mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Refactor custom query hotkey setting window
This commit is contained in:
parent
42e20352e1
commit
ff99669772
4 changed files with 61 additions and 49 deletions
|
|
@ -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"
|
||||
|
|
@ -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"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{DynamicResource update}"
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
|
|
|||
|
|
@ -1,71 +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;
|
||||
}
|
||||
|
||||
public CustomQueryHotkeySetting(CustomPluginHotkey hotkey)
|
||||
{
|
||||
originalCustomHotkey = hotkey;
|
||||
update = true;
|
||||
ActionKeyword = originalCustomHotkey.ActionKeyword;
|
||||
InitializeComponent();
|
||||
lblUpdate.Visibility = Visibility.Visible;
|
||||
HotkeyControl.SetHotkey(originalCustomHotkey.Hotkey, false);
|
||||
}
|
||||
|
||||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DialogResult = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!update)
|
||||
{
|
||||
var pluginHotkey = new CustomPluginHotkey
|
||||
{
|
||||
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
|
||||
};
|
||||
_settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
Hotkey = HotkeyControl.CurrentHotkey.ToString();
|
||||
|
||||
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
|
||||
}
|
||||
else
|
||||
if (string.IsNullOrEmpty(Hotkey) && string.IsNullOrEmpty(ActionKeyword))
|
||||
{
|
||||
var oldHotkey = updateCustomHotkey.Hotkey;
|
||||
updateCustomHotkey.ActionKeyword = tbAction.Text;
|
||||
updateCustomHotkey.Hotkey = HotkeyControl.CurrentHotkey.ToString();
|
||||
//remove origin hotkey
|
||||
HotKeyMapper.RemoveHotkey(oldHotkey);
|
||||
HotKeyMapper.SetCustomQueryHotkey(updateCustomHotkey);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
public void UpdateItem(CustomPluginHotkey item)
|
||||
{
|
||||
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
||||
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
|
||||
if (updateCustomHotkey == null)
|
||||
{
|
||||
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)
|
||||
|
|
@ -77,6 +58,7 @@ namespace Flow.Launcher
|
|||
|
||||
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
DialogResult = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -438,6 +438,7 @@
|
|||
<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>
|
||||
|
|
|
|||
|
|
@ -62,15 +62,30 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
|
|||
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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
|
|
|||
Loading…
Reference in a new issue