Skip to content

Commit b842f08

Browse files
committed
Add logic to block space key input when registering an action keyword for plugins that do not support multiple action keywords.
1 parent d06a803 commit b842f08

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
Width="135"
8181
HorizontalAlignment="Left"
8282
VerticalAlignment="Center"
83+
DataObject.Pasting="TextBox_Pasting"
8384
PreviewKeyDown="TxtCurrentActionKeyword_OnKeyDown"
8485
Text="{Binding ActionKeyword}" />
8586
</StackPanel>

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.ComponentModel;
3+
using System.Linq;
34
using System.Runtime.CompilerServices;
45
using System.Windows;
56
using System.Windows.Input;
@@ -93,7 +94,27 @@ private void TxtCurrentActionKeyword_OnKeyDown(object sender, KeyEventArgs e)
9394
OnDoneButtonClick(sender, e);
9495
e.Handled = true;
9596
}
97+
if (e.Key == Key.Space)
98+
{
99+
e.Handled = true;
100+
}
101+
}
102+
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
103+
{
104+
if (e.DataObject.GetDataPresent(DataFormats.Text))
105+
{
106+
string text = e.DataObject.GetData(DataFormats.Text) as string;
107+
if (!string.IsNullOrEmpty(text) && text.Any(char.IsWhiteSpace))
108+
{
109+
e.CancelCommand();
110+
}
111+
}
112+
else
113+
{
114+
e.CancelCommand();
115+
}
96116
}
117+
97118
public event PropertyChangedEventHandler PropertyChanged;
98119
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
99120
{

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
</Button>
5757
</Grid>
5858
</StackPanel>
59-
<StackPanel Margin="26,12,26,0">
59+
<StackPanel Margin="26 12 26 0">
6060
<Grid>
6161
<StackPanel>
62-
<StackPanel Grid.Row="0" Margin="0,0,0,12">
62+
<StackPanel Grid.Row="0" Margin="0 0 0 12">
6363
<TextBlock
6464
Grid.Column="0"
65-
Margin="0,0,0,0"
65+
Margin="0 0 0 0"
6666
FontSize="20"
6767
FontWeight="SemiBold"
6868
Text="{DynamicResource flowlauncher_plugin_websearch_window_title}"
@@ -75,15 +75,15 @@
7575
TextAlignment="Left"
7676
TextWrapping="WrapWithOverflow" />
7777
<TextBox
78-
Margin="0,12,0,12"
78+
Margin="0 12 0 12"
7979
FontSize="14"
8080
FontWeight="SemiBold"
8181
IsReadOnly="True"
8282
Text="{DynamicResource flowlauncher_plugin_websearch_guide_2}"
8383
TextAlignment="Center"
8484
TextWrapping="WrapWithOverflow" />
8585
<TextBlock
86-
Margin="0,0,0,14"
86+
Margin="0 0 0 14"
8787
FontSize="14"
8888
Text="{DynamicResource flowlauncher_plugin_websearch_guide_3}"
8989
TextAlignment="Left"
@@ -105,7 +105,7 @@
105105
<TextBlock
106106
Grid.Row="0"
107107
Grid.Column="0"
108-
Margin="10,10,15,10"
108+
Margin="10 10 15 10"
109109
HorizontalAlignment="Stretch"
110110
VerticalAlignment="Center"
111111
FontSize="14"
@@ -120,7 +120,7 @@
120120
<TextBlock
121121
Grid.Row="1"
122122
Grid.Column="0"
123-
Margin="10,10,15,10"
123+
Margin="10 10 15 10"
124124
HorizontalAlignment="Left"
125125
VerticalAlignment="Center"
126126
FontSize="14"
@@ -131,21 +131,21 @@
131131
Orientation="Horizontal">
132132
<Button
133133
Height="35"
134-
Margin="10,0,0,0"
134+
Margin="10 0 0 0"
135135
VerticalAlignment="Center"
136136
Click="OnSelectIconClick"
137137
Content="{DynamicResource flowlauncher_plugin_websearch_select_icon}" />
138138
<Image
139139
Name="imgPreviewIcon"
140140
Width="24"
141141
Height="24"
142-
Margin="14,0,0,0"
142+
Margin="14 0 0 0"
143143
VerticalAlignment="Center" />
144144
</StackPanel>
145145
<TextBlock
146146
Grid.Row="2"
147147
Grid.Column="0"
148-
Margin="10,10,15,10"
148+
Margin="10 10 15 10"
149149
HorizontalAlignment="Left"
150150
VerticalAlignment="Center"
151151
FontSize="14"
@@ -160,30 +160,32 @@
160160
<TextBlock
161161
Grid.Row="3"
162162
Grid.Column="0"
163-
Margin="10,10,15,10"
163+
Margin="10 10 15 10"
164164
HorizontalAlignment="Left"
165165
VerticalAlignment="Center"
166166
FontSize="14"
167167
Text="{DynamicResource flowlauncher_plugin_websearch_action_keyword}" />
168168
<TextBox
169169
Grid.Row="3"
170170
Grid.Column="1"
171-
Margin="10,0,10,0"
171+
Margin="10 0 10 0"
172172
HorizontalAlignment="Stretch"
173173
VerticalAlignment="Center"
174+
DataObject.Pasting="TextBox_Pasting"
175+
PreviewKeyDown="TextBox_PreviewKeyDown"
174176
Text="{Binding SearchSource.ActionKeyword}" />
175177
<TextBlock
176178
Grid.Row="4"
177179
Grid.Column="0"
178-
Margin="10,10,15,15"
180+
Margin="10 10 15 15"
179181
HorizontalAlignment="Left"
180182
VerticalAlignment="Center"
181183
FontSize="14"
182184
Text="{DynamicResource flowlauncher_plugin_websearch_enabled_label}" />
183185
<CheckBox
184186
Grid.Row="4"
185187
Grid.Column="1"
186-
Margin="10,10,10,15"
188+
Margin="10 10 10 15"
187189
VerticalAlignment="Center"
188190
IsChecked="{Binding SearchSource.Enabled}" />
189191
</Grid>
@@ -196,16 +198,16 @@
196198
Grid.Row="1"
197199
Background="{DynamicResource PopupButtonAreaBGColor}"
198200
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
199-
BorderThickness="0,1,0,0">
201+
BorderThickness="0 1 0 0">
200202
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
201203
<Button
202204
MinWidth="140"
203-
Margin="10,0,5,0"
205+
Margin="10 0 5 0"
204206
Click="OnCancelButtonClick"
205207
Content="{DynamicResource flowlauncher_plugin_websearch_cancel}" />
206208
<Button
207209
MinWidth="140"
208-
Margin="5,0,10,0"
210+
Margin="5 0 10 0"
209211
Click="OnConfirmButtonClick"
210212
Content="{DynamicResource flowlauncher_plugin_websearch_confirm}"
211213
Style="{DynamicResource AccentButtonStyle}" />

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceSetting.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Windows;
4+
using System.Windows.Input;
35
using Microsoft.Win32;
46

57
namespace Flow.Launcher.Plugin.WebSearch
@@ -143,6 +145,30 @@ private async void OnSelectIconClick(object sender, RoutedEventArgs e)
143145
}
144146
}
145147
}
148+
149+
//Block Space Input
150+
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
151+
{
152+
if (e.Key == Key.Space)
153+
{
154+
e.Handled = true;
155+
}
156+
}
157+
private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
158+
{
159+
if (e.DataObject.GetDataPresent(DataFormats.Text))
160+
{
161+
string text = e.DataObject.GetData(DataFormats.Text) as string;
162+
if (!string.IsNullOrEmpty(text) && text.Any(char.IsWhiteSpace))
163+
{
164+
e.CancelCommand();
165+
}
166+
}
167+
else
168+
{
169+
e.CancelCommand();
170+
}
171+
}
146172
}
147173

148174
public enum Action

0 commit comments

Comments
 (0)