Skip to content

Commit 82af6ab

Browse files
authored
Merge pull request #3344 from Jack251970/system_plugin_translation
Use Command Keyword to Search System Command
2 parents c34fd63 + ab3cd8a commit 82af6ab

File tree

11 files changed

+553
-132
lines changed

11 files changed

+553
-132
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace Flow.Launcher.Plugin.Sys
4+
{
5+
public class Command : BaseModel
6+
{
7+
public string Key { get; set; }
8+
9+
private string name;
10+
[JsonIgnore]
11+
public string Name
12+
{
13+
get => name;
14+
set
15+
{
16+
name = value;
17+
OnPropertyChanged();
18+
}
19+
}
20+
21+
private string description;
22+
[JsonIgnore]
23+
public string Description
24+
{
25+
get => description;
26+
set
27+
{
28+
description = value;
29+
OnPropertyChanged();
30+
}
31+
}
32+
33+
private string keyword;
34+
public string Keyword
35+
{
36+
get => keyword;
37+
set
38+
{
39+
keyword = value;
40+
OnPropertyChanged();
41+
}
42+
}
43+
}
44+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<Window
2+
x:Class="Flow.Launcher.Plugin.Sys.CommandKeywordSettingWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
Title="{DynamicResource lowlauncher_plugin_sys_command_keyword_setting_window_title}"
8+
Width="550"
9+
Background="{DynamicResource PopupBGColor}"
10+
Foreground="{DynamicResource PopupTextColor}"
11+
ResizeMode="NoResize"
12+
SizeToContent="Height"
13+
WindowStartupLocation="CenterScreen"
14+
mc:Ignorable="d">
15+
<WindowChrome.WindowChrome>
16+
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
17+
</WindowChrome.WindowChrome>
18+
<Grid>
19+
<Grid.RowDefinitions>
20+
<RowDefinition />
21+
<RowDefinition Height="80" />
22+
</Grid.RowDefinitions>
23+
24+
<StackPanel Grid.Row="0">
25+
<StackPanel>
26+
<Grid>
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="*" />
29+
<ColumnDefinition Width="Auto" />
30+
</Grid.ColumnDefinitions>
31+
<Button
32+
Grid.Column="1"
33+
Click="OnCancelButtonClick"
34+
Style="{StaticResource TitleBarCloseButtonStyle}">
35+
<Path
36+
Width="46"
37+
Height="32"
38+
Data="M 18,11 27,20 M 18,20 27,11"
39+
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
40+
StrokeThickness="1">
41+
<Path.Style>
42+
<Style TargetType="Path">
43+
<Style.Triggers>
44+
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
45+
<Setter Property="Opacity" Value="0.5" />
46+
</DataTrigger>
47+
</Style.Triggers>
48+
</Style>
49+
</Path.Style>
50+
</Path>
51+
</Button>
52+
</Grid>
53+
</StackPanel>
54+
<StackPanel Margin="26 12 26 0">
55+
<StackPanel Margin="0 0 0 12">
56+
<TextBlock
57+
Grid.Column="0"
58+
Margin="0 0 0 0"
59+
FontSize="20"
60+
FontWeight="SemiBold"
61+
Text="{DynamicResource flowlauncher_plugin_sys_custom_command_keyword}"
62+
TextAlignment="Left" />
63+
</StackPanel>
64+
65+
<StackPanel>
66+
<TextBlock
67+
x:Name="CommandKeywordTips"
68+
FontSize="14"
69+
TextAlignment="Left"
70+
TextWrapping="WrapWithOverflow" />
71+
</StackPanel>
72+
73+
<Grid Margin="0 24 0 24">
74+
<Grid.ColumnDefinitions>
75+
<ColumnDefinition Width="Auto" />
76+
<ColumnDefinition Width="*" />
77+
<ColumnDefinition Width="Auto" />
78+
</Grid.ColumnDefinitions>
79+
<TextBlock
80+
Grid.Column="0"
81+
HorizontalAlignment="Right"
82+
VerticalAlignment="Center"
83+
FontSize="14"
84+
Text="{DynamicResource flowlauncher_plugin_sys_command_keyword}" />
85+
<TextBox
86+
x:Name="CommandKeyword"
87+
Grid.Column="1"
88+
Margin="10"
89+
HorizontalAlignment="Stretch" />
90+
<Button
91+
x:Name="btnTestActionKeyword"
92+
Grid.Row="1"
93+
Grid.Column="2"
94+
Margin="0 0 10 0"
95+
Padding="10 5 10 5"
96+
Click="OnResetButtonClick"
97+
Content="{DynamicResource flowlauncher_plugin_sys_reset}" />
98+
</Grid>
99+
</StackPanel>
100+
</StackPanel>
101+
<Border
102+
Grid.Row="1"
103+
Background="{DynamicResource PopupButtonAreaBGColor}"
104+
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
105+
BorderThickness="0 1 0 0">
106+
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
107+
<Button
108+
MinWidth="140"
109+
Margin="10 0 5 0"
110+
Click="OnCancelButtonClick"
111+
Content="{DynamicResource flowlauncher_plugin_sys_cancel}" />
112+
<Button
113+
MinWidth="140"
114+
Margin="5 0 10 0"
115+
Click="OnConfirmButtonClick"
116+
Content="{DynamicResource flowlauncher_plugin_sys_confirm}"
117+
Style="{DynamicResource AccentButtonStyle}" />
118+
</StackPanel>
119+
</Border>
120+
</Grid>
121+
</Window>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Windows;
2+
3+
namespace Flow.Launcher.Plugin.Sys
4+
{
5+
public partial class CommandKeywordSettingWindow
6+
{
7+
private readonly Command _oldSearchSource;
8+
private readonly PluginInitContext _context;
9+
10+
public CommandKeywordSettingWindow(PluginInitContext context, Command old)
11+
{
12+
_context = context;
13+
_oldSearchSource = old;
14+
InitializeComponent();
15+
CommandKeyword.Text = old.Keyword;
16+
CommandKeywordTips.Text = string.Format(_context.API.GetTranslation("flowlauncher_plugin_sys_custom_command_keyword_tip"), old.Name);
17+
}
18+
19+
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
20+
{
21+
Close();
22+
}
23+
24+
private void OnConfirmButtonClick(object sender, RoutedEventArgs e)
25+
{
26+
var keyword = CommandKeyword.Text;
27+
if (string.IsNullOrEmpty(keyword))
28+
{
29+
var warning = _context.API.GetTranslation("flowlauncher_plugin_sys_input_command_keyword");
30+
_context.API.ShowMsgBox(warning);
31+
}
32+
else
33+
{
34+
_oldSearchSource.Keyword = keyword;
35+
Close();
36+
}
37+
}
38+
39+
private void OnResetButtonClick(object sender, RoutedEventArgs e)
40+
{
41+
// Key is the default value of this command
42+
CommandKeyword.Text = _oldSearchSource.Key;
43+
}
44+
}
45+
}

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
xmlns:system="clr-namespace:System;assembly=mscorlib">
55

66
<!-- Command List -->
7-
<system:String x:Key="flowlauncher_plugin_sys_command">Command</system:String>
7+
<system:String x:Key="flowlauncher_plugin_sys_name">Name</system:String>
88
<system:String x:Key="flowlauncher_plugin_sys_desc">Description</system:String>
9+
<system:String x:Key="flowlauncher_plugin_sys_command">Command</system:String>
910

1011
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer_cmd">Shutdown</system:String>
1112
<system:String x:Key="flowlauncher_plugin_sys_restart_computer_cmd">Restart</system:String>
@@ -29,6 +30,8 @@
2930
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode_cmd">Toggle Game Mode</system:String>
3031
<system:String x:Key="flowlauncher_plugin_sys_theme_selector_cmd">Set the Flow Launcher Theme</system:String>
3132

33+
<system:String x:Key="flowlauncher_plugin_sys_edit">Edit</system:String>
34+
3235
<!-- Command Descriptions -->
3336
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer">Shutdown Computer</system:String>
3437
<system:String x:Key="flowlauncher_plugin_sys_restart_computer">Restart Computer</system:String>
@@ -61,6 +64,15 @@
6164
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_restart_computer_advanced">Are you sure you want to restart the computer with Advanced Boot Options?</system:String>
6265
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_logoff_computer">Are you sure you want to log off?</system:String>
6366

67+
<system:String x:Key="flowlauncher_plugin_sys_command_keyword_setting_window_title">Command Keyword Setting</system:String>
68+
<system:String x:Key="flowlauncher_plugin_sys_custom_command_keyword">Custom Command Keyword</system:String>
69+
<system:String x:Key="flowlauncher_plugin_sys_custom_command_keyword_tip">Enter a keyword to search for command: {0}. This keyword is used to match your query.</system:String>
70+
<system:String x:Key="flowlauncher_plugin_sys_command_keyword">Command Keyword</system:String>
71+
<system:String x:Key="flowlauncher_plugin_sys_reset">Reset</system:String>
72+
<system:String x:Key="flowlauncher_plugin_sys_confirm">Confirm</system:String>
73+
<system:String x:Key="flowlauncher_plugin_sys_cancel">Cancel</system:String>
74+
<system:String x:Key="flowlauncher_plugin_sys_input_command_keyword">Please enter a non-empty command keyword</system:String>
75+
6476
<system:String x:Key="flowlauncher_plugin_sys_plugin_name">System Commands</system:String>
6577
<system:String x:Key="flowlauncher_plugin_sys_plugin_description">Provides System related commands. e.g. shutdown, lock, settings etc.</system:String>
6678

0 commit comments

Comments
 (0)