Skip to content

Commit 34f53fd

Browse files
authored
Merge pull request #3702 from stefanroelofs/dev
Refactor ActionKeywords UI and improve keyword handling
2 parents 9367dfc + 8e740c8 commit 34f53fd

File tree

2 files changed

+118
-115
lines changed

2 files changed

+118
-115
lines changed

Flow.Launcher/ActionKeywords.xaml

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -14,118 +14,118 @@
1414
<WindowChrome.WindowChrome>
1515
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
1616
</WindowChrome.WindowChrome>
17+
1718
<Grid>
1819
<Grid.RowDefinitions>
20+
<RowDefinition />
21+
<RowDefinition />
22+
<RowDefinition />
23+
<RowDefinition />
1924
<RowDefinition />
2025
<RowDefinition Height="80" />
2126
</Grid.RowDefinitions>
22-
<Grid>
23-
<StackPanel Grid.Row="0">
24-
<StackPanel>
25-
<Grid>
26-
<Grid.ColumnDefinitions>
27-
<ColumnDefinition Width="Auto" />
28-
<ColumnDefinition Width="*" />
29-
<ColumnDefinition Width="Auto" />
30-
<ColumnDefinition Width="Auto" />
31-
<ColumnDefinition Width="Auto" />
32-
</Grid.ColumnDefinitions>
33-
<Button
34-
Grid.Column="4"
35-
Click="BtnCancel_OnClick"
36-
Style="{StaticResource TitleBarCloseButtonStyle}">
37-
<Path
38-
Width="46"
39-
Height="32"
40-
Data="M 18,11 27,20 M 18,20 27,11"
41-
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
42-
StrokeThickness="1">
43-
<Path.Style>
44-
<Style TargetType="Path">
45-
<Style.Triggers>
46-
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
47-
<Setter Property="Opacity" Value="0.5" />
48-
</DataTrigger>
49-
</Style.Triggers>
50-
</Style>
51-
</Path.Style>
52-
</Path>
53-
</Button>
54-
</Grid>
55-
</StackPanel>
56-
<StackPanel Margin="26 12 26 0">
57-
<StackPanel Grid.Row="0" Margin="0 0 0 12">
58-
<TextBlock
59-
Grid.Column="0"
60-
Margin="0 0 0 0"
61-
FontSize="20"
62-
FontWeight="SemiBold"
63-
Text="{DynamicResource actionKeywordsTitle}"
64-
TextAlignment="Left" />
65-
</StackPanel>
66-
<StackPanel>
67-
<TextBlock
68-
FontSize="14"
69-
Text="{DynamicResource actionkeyword_tips}"
70-
TextAlignment="Left"
71-
TextWrapping="WrapWithOverflow" />
72-
</StackPanel>
27+
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="Auto" />
29+
<ColumnDefinition Width="*" />
30+
</Grid.ColumnDefinitions>
7331

74-
<StackPanel Margin="0 18 0 0" Orientation="Horizontal">
75-
<TextBlock
76-
Grid.Row="0"
77-
Grid.Column="1"
78-
HorizontalAlignment="Left"
79-
VerticalAlignment="Center"
80-
FontSize="14"
81-
Text="{DynamicResource currentActionKeywords}" />
82-
<TextBlock
83-
x:Name="tbOldActionKeyword"
84-
Grid.Row="0"
85-
Grid.Column="1"
86-
Margin="14 10 10 10"
87-
HorizontalAlignment="Left"
88-
VerticalAlignment="Center"
89-
FontSize="14"
90-
FontWeight="SemiBold"
91-
Foreground="{DynamicResource Color05B}" />
92-
</StackPanel>
93-
<StackPanel Margin="0 0 0 10" Orientation="Horizontal">
94-
<TextBlock
95-
Grid.Row="1"
96-
Grid.Column="1"
97-
HorizontalAlignment="Left"
98-
VerticalAlignment="Center"
99-
FontSize="14"
100-
Text="{DynamicResource newActionKeyword}" />
101-
<TextBox
102-
x:Name="tbAction"
103-
Width="105"
104-
Margin="10 10 15 10"
105-
HorizontalAlignment="Left"
106-
VerticalAlignment="Center" />
107-
</StackPanel>
108-
</StackPanel>
109-
</StackPanel>
110-
</Grid>
111-
<Border
32+
<Button
33+
Grid.Row="0"
34+
Grid.Column="1"
35+
HorizontalAlignment="Right"
36+
Click="BtnCancel_OnClick"
37+
Style="{StaticResource TitleBarCloseButtonStyle}">
38+
<Path
39+
Width="46"
40+
Height="32"
41+
Data="M 18,11 27,20 M 18,20 27,11"
42+
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
43+
StrokeThickness="1">
44+
<Path.Style>
45+
<Style TargetType="Path">
46+
<Style.Triggers>
47+
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False">
48+
<Setter Property="Opacity" Value="0.5" />
49+
</DataTrigger>
50+
</Style.Triggers>
51+
</Style>
52+
</Path.Style>
53+
</Path>
54+
</Button>
55+
56+
<TextBlock
11257
Grid.Row="1"
58+
Grid.Column="0"
59+
Grid.ColumnSpan="2"
60+
Margin="26 12 26 12"
61+
FontSize="20"
62+
FontWeight="SemiBold"
63+
Text="{DynamicResource actionKeywordsTitle}"
64+
TextAlignment="Left" />
65+
<TextBlock
66+
Grid.Row="2"
67+
Grid.Column="0"
68+
Grid.ColumnSpan="2"
69+
Margin="26 0 26 10"
70+
FontSize="14"
71+
Text="{DynamicResource actionkeyword_tips}"
72+
TextAlignment="Left"
73+
TextWrapping="WrapWithOverflow" />
74+
75+
<TextBlock
76+
Grid.Row="3"
77+
Grid.Column="0"
78+
Margin="26 0 10 0"
79+
VerticalAlignment="Center"
80+
FontSize="14"
81+
Text="{DynamicResource currentActionKeywords}" />
82+
<TextBox
83+
x:Name="tbOldActionKeyword"
84+
Grid.Row="3"
85+
Grid.Column="1"
86+
Margin="10 10 26 6"
87+
VerticalAlignment="Center"
88+
FontSize="14"
89+
FontWeight="SemiBold"
90+
Foreground="{DynamicResource Color05B}"
91+
IsReadOnly="True"
92+
Text="List of old keyword(s)" />
93+
94+
<TextBlock
95+
Grid.Row="4"
96+
Grid.Column="0"
97+
Margin="26 6 10 12"
98+
VerticalAlignment="Center"
99+
FontSize="14"
100+
Text="{DynamicResource newActionKeyword}" />
101+
<TextBox
102+
x:Name="tbAction"
103+
Grid.Row="4"
104+
Grid.Column="1"
105+
Margin="10 6 26 10"
106+
VerticalAlignment="Center" />
107+
108+
<Border
109+
Grid.Row="5"
110+
Grid.Column="0"
111+
Grid.ColumnSpan="2"
112+
Margin="0 10 0 0"
113113
Background="{DynamicResource PopupButtonAreaBGColor}"
114114
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
115115
BorderThickness="0 1 0 0">
116116
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
117117
<Button
118118
x:Name="btnCancel"
119119
Width="145"
120-
Height="30"
121-
Margin="10 0 5 0"
120+
Height="38"
121+
Margin="10 0 10 0"
122122
Click="BtnCancel_OnClick"
123123
Content="{DynamicResource cancel}" />
124124
<Button
125125
x:Name="btnDone"
126126
Width="145"
127-
Height="30"
128-
Margin="5 0 10 0"
127+
Height="38"
128+
Margin="10 0 10 0"
129129
Click="btnDone_OnClick"
130130
Style="{StaticResource AccentButtonStyle}">
131131
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />

Flow.Launcher/ActionKeywords.xaml.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public ActionKeywords(PluginViewModel pluginViewModel)
2020

2121
private void ActionKeyword_OnLoaded(object sender, RoutedEventArgs e)
2222
{
23-
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, _plugin.Metadata.ActionKeywords.ToArray());
23+
tbOldActionKeyword.Text = string.Join(Query.ActionKeywordSeparator, _plugin.Metadata.ActionKeywords);
24+
tbAction.Text = tbOldActionKeyword.Text;
25+
tbAction.SelectAll();
2426
tbAction.Focus();
2527
}
2628

@@ -33,38 +35,39 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
3335
{
3436
var oldActionKeywords = _plugin.Metadata.ActionKeywords;
3537

36-
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator).ToList();
37-
newActionKeywords.RemoveAll(string.IsNullOrEmpty);
38-
newActionKeywords = newActionKeywords.Distinct().ToList();
38+
var newActionKeywords = tbAction.Text.Split(Query.ActionKeywordSeparator)
39+
.Where(s => !string.IsNullOrEmpty(s))
40+
.Distinct()
41+
.ToList();
3942

4043
newActionKeywords = newActionKeywords.Count > 0 ? newActionKeywords : new() { Query.GlobalPluginWildcardSign };
4144

4245
var addedActionKeywords = newActionKeywords.Except(oldActionKeywords).ToList();
4346
var removedActionKeywords = oldActionKeywords.Except(newActionKeywords).ToList();
44-
if (!addedActionKeywords.Any(App.API.ActionKeywordAssigned))
47+
48+
if (addedActionKeywords.Any(App.API.ActionKeywordAssigned))
49+
{
50+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
51+
return;
52+
}
53+
54+
if (oldActionKeywords.Count != newActionKeywords.Count)
4555
{
46-
if (oldActionKeywords.Count != newActionKeywords.Count)
47-
{
48-
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
49-
return;
50-
}
56+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
57+
return;
58+
}
5159

52-
var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
53-
var sortedNewActionKeywords = newActionKeywords.OrderBy(s => s).ToList();
60+
var sortedOldActionKeywords = oldActionKeywords.OrderBy(s => s).ToList();
61+
var sortedNewActionKeywords = newActionKeywords.OrderBy(s => s).ToList();
5462

55-
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
56-
{
57-
// User just changes the sequence of action keywords
58-
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
59-
}
60-
else
61-
{
62-
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
63-
}
63+
if (sortedOldActionKeywords.SequenceEqual(sortedNewActionKeywords))
64+
{
65+
// User just changes the sequence of action keywords
66+
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsSameAsOld"));
6467
}
6568
else
6669
{
67-
App.API.ShowMsgBox(App.API.GetTranslation("newActionKeywordsHasBeenAssigned"));
70+
ReplaceActionKeyword(_plugin.Metadata.ID, removedActionKeywords, addedActionKeywords);
6871
}
6972
}
7073

0 commit comments

Comments
 (0)