Shortcut settings dialog preview & text & bugfix

This commit is contained in:
Vic 2022-10-08 17:52:27 +08:00
parent e78994874a
commit f3c4120395
5 changed files with 42 additions and 23 deletions

View file

@ -110,14 +110,25 @@
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="14" FontSize="14"
Text="{DynamicResource customShortcutExpansion}" /> Text="{DynamicResource customShortcutExpansion}" />
<TextBox
<DockPanel
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
Margin="10" LastChildFill="True">
HorizontalAlignment="Stretch" <Button
VerticalAlignment="Center" x:Name="btnTestShortcut"
Text="{Binding Value}"/> Padding="10,5,10,5"
</Grid> Click="BtnTestShortcut_OnClick"
Content="{DynamicResource preview}"
DockPanel.Dock="Right" />
<TextBox
x:Name="tbExpand"
Margin="10"
HorizontalAlignment="Stretch"
Text="{Binding Value}"
VerticalAlignment="Center" />
</DockPanel>
</Grid>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

View file

@ -1,29 +1,30 @@
using System; using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure.UserSettings;
using System;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using Flow.Launcher.Core.Resource;
using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher namespace Flow.Launcher
{ {
public partial class CustomShortcutSetting : Window public partial class CustomShortcutSetting : Window
{ {
private SettingWindow _settingWidow;
private bool update;
private Settings _settings; private Settings _settings;
private bool update = false;
public string Key { get; set; } public string Key { get; set; }
public string Value { get; set; } public string Value { get; set; }
public CustomShortcutModel ShortCut => (Key, Value); public CustomShortcutModel ShortCut => (Key, Value);
public CustomShortcutSetting() public CustomShortcutSetting(Settings settings)
{ {
_settings = settings;
InitializeComponent(); InitializeComponent();
} }
public CustomShortcutSetting((string, string) shortcut) public CustomShortcutSetting((string, string) shortcut, Settings settings)
{ {
(Key, Value) = shortcut; (Key, Value) = shortcut;
_settings = settings;
update = true;
InitializeComponent(); InitializeComponent();
} }
@ -35,17 +36,17 @@ namespace Flow.Launcher
private void btnAdd_OnClick(object sender, RoutedEventArgs e) private void btnAdd_OnClick(object sender, RoutedEventArgs e)
{ {
DialogResult = true; if (!update && _settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)))
if (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)))
{ {
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut"));
DialogResult = false; return;
} }
else if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value)) if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value))
{ {
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidShortcut")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidShortcut"));
DialogResult = false; return;
} }
DialogResult = true;
Close(); Close();
} }
@ -54,5 +55,13 @@ namespace Flow.Launcher
DialogResult = false; DialogResult = false;
Close(); Close();
} }
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbExpand.Text);
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Opacity = 1;
Application.Current.MainWindow.Focus();
}
} }
} }

View file

@ -215,7 +215,6 @@
<!-- Custom Query Shortcut Dialog --> <!-- Custom Query Shortcut Dialog -->
<system:String x:Key="customeQueryShortcutTitle">Custom Query Shortcut</system:String> <system:String x:Key="customeQueryShortcutTitle">Custom Query Shortcut</system:String>
<system:String x:Key="customeQueryShortcutTips">Enter a shortcut to automatically expand to the specified query.</system:String> <system:String x:Key="customeQueryShortcutTips">Enter a shortcut to automatically expand to the specified query.</system:String>
<system:String x:Key="preview">Preview</system:String>
<system:String x:Key="dulplicateShortcut">Shortcut is dulplicate, please enter a new Shortcut or edit the existing one.</system:String> <system:String x:Key="dulplicateShortcut">Shortcut is dulplicate, please enter a new Shortcut or edit the existing one.</system:String>
<system:String x:Key="invalidShortcut">Invalid Shortcut</system:String> <system:String x:Key="invalidShortcut">Invalid Shortcut</system:String>

View file

@ -2175,7 +2175,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="14" FontSize="14"
Foreground="{DynamicResource Color05B}" Foreground="{DynamicResource Color05B}"
Text="Shortcut" /> Text="{DynamicResource customQueryShortcut}" />
<ListView <ListView
MinHeight="185" MinHeight="185"
Margin="0,6,0,0" Margin="0,6,0,0"

View file

@ -398,7 +398,7 @@ namespace Flow.Launcher
var item = viewModel.SelectedCustomShortcut; var item = viewModel.SelectedCustomShortcut;
if (item != null) if (item != null)
{ {
var shortcutSettingWindow = new CustomShortcutSetting(item); var shortcutSettingWindow = new CustomShortcutSetting(item, settings);
if (shortcutSettingWindow.ShowDialog() == true) if (shortcutSettingWindow.ShowDialog() == true)
{ {
settings.CustomShortcuts[viewModel.SelectCustomShortcutIndex.Value] = shortcutSettingWindow.ShortCut; settings.CustomShortcuts[viewModel.SelectCustomShortcutIndex.Value] = shortcutSettingWindow.ShortCut;
@ -412,7 +412,7 @@ namespace Flow.Launcher
private void OnAddCustomeShortCutClick(object sender, RoutedEventArgs e) private void OnAddCustomeShortCutClick(object sender, RoutedEventArgs e)
{ {
var shortcutSettingWindow = new CustomShortcutSetting(); var shortcutSettingWindow = new CustomShortcutSetting(settings);
if (shortcutSettingWindow.ShowDialog() == true) if (shortcutSettingWindow.ShowDialog() == true)
{ {
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut); settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);