Skip to content

Commit 66a5e1a

Browse files
authored
Merge pull request #1768 from Flow-Launcher/dynamic_height
2 parents 1fd1a37 + f6eeec7 commit 66a5e1a

File tree

17 files changed

+415
-86
lines changed

17 files changed

+415
-86
lines changed

.github/actions/spelling/expect.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,25 @@ TobiasSekan
6262
Img
6363
img
6464
resx
65+
directx
66+
mvvm
67+
dlg
68+
ddd
69+
dddd
70+
clearlogfolder
71+
ACCENT_ENABLE_TRANSPARENTGRADIENT
72+
ACCENT_ENABLE_BLURBEHIND
73+
WCA_ACCENT_POLICY
74+
HGlobal
75+
dopusrt
76+
firefox
77+
msedge
78+
svgc
79+
ime
80+
zindex
81+
txb
82+
btn
83+
otf
84+
searchplugin
85+
Noresult
86+
wpftk

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Theme()
3636
{
3737
_themeDirectories.Add(DirectoryPath);
3838
_themeDirectories.Add(UserDirectoryPath);
39-
MakesureThemeDirectoriesExist();
39+
MakeSureThemeDirectoriesExist();
4040

4141
var dicts = Application.Current.Resources.MergedDictionaries;
4242
_oldResource = dicts.First(d =>
@@ -55,20 +55,17 @@ public Theme()
5555
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
5656
}
5757

58-
private void MakesureThemeDirectoriesExist()
58+
private void MakeSureThemeDirectoriesExist()
5959
{
60-
foreach (string dir in _themeDirectories)
60+
foreach (var dir in _themeDirectories.Where(dir => !Directory.Exists(dir)))
6161
{
62-
if (!Directory.Exists(dir))
62+
try
6363
{
64-
try
65-
{
66-
Directory.CreateDirectory(dir);
67-
}
68-
catch (Exception e)
69-
{
70-
Log.Exception($"|Theme.MakesureThemeDirectoriesExist|Exception when create directory <{dir}>", e);
71-
}
64+
Directory.CreateDirectory(dir);
65+
}
66+
catch (Exception e)
67+
{
68+
Log.Exception($"|Theme.MakesureThemeDirectoriesExist|Exception when create directory <{dir}>", e);
7269
}
7370
}
7471
}
@@ -82,13 +79,14 @@ public bool ChangeTheme(string theme)
8279
{
8380
if (string.IsNullOrEmpty(path))
8481
throw new DirectoryNotFoundException("Theme path can't be found <{path}>");
85-
86-
Settings.Theme = theme;
87-
82+
8883
// reload all resources even if the theme itself hasn't changed in order to pickup changes
8984
// to things like fonts
90-
UpdateResourceDictionary(GetResourceDictionary());
85+
UpdateResourceDictionary(GetResourceDictionary(theme));
86+
87+
Settings.Theme = theme;
9188

89+
9290
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
9391
if (_oldTheme != theme || theme == defaultTheme)
9492
{
@@ -134,9 +132,9 @@ private void UpdateResourceDictionary(ResourceDictionary dictionaryToUpdate)
134132
_oldResource = dictionaryToUpdate;
135133
}
136134

137-
private ResourceDictionary CurrentThemeResourceDictionary()
135+
private ResourceDictionary GetThemeResourceDictionary(string theme)
138136
{
139-
var uri = GetThemePath(Settings.Theme);
137+
var uri = GetThemePath(theme);
140138
var dict = new ResourceDictionary
141139
{
142140
Source = new Uri(uri, UriKind.Absolute)
@@ -145,10 +143,12 @@ private ResourceDictionary CurrentThemeResourceDictionary()
145143
return dict;
146144
}
147145

148-
public ResourceDictionary GetResourceDictionary()
146+
private ResourceDictionary CurrentThemeResourceDictionary() => GetThemeResourceDictionary(Settings.Theme);
147+
148+
public ResourceDictionary GetResourceDictionary(string theme)
149149
{
150-
var dict = CurrentThemeResourceDictionary();
151-
150+
var dict = GetThemeResourceDictionary(theme);
151+
152152
if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
153153
dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
154154
{
@@ -200,6 +200,11 @@ public ResourceDictionary GetResourceDictionary()
200200
return dict;
201201
}
202202

203+
private ResourceDictionary GetCurrentResourceDictionary( )
204+
{
205+
return GetResourceDictionary(Settings.Theme);
206+
}
207+
203208
public List<string> LoadAvailableThemes()
204209
{
205210
List<string> themes = new List<string>();
@@ -229,7 +234,7 @@ private string GetThemePath(string themeName)
229234

230235
public void AddDropShadowEffectToCurrentTheme()
231236
{
232-
var dict = GetResourceDictionary();
237+
var dict = GetCurrentResourceDictionary();
233238

234239
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
235240

@@ -273,7 +278,7 @@ public void AddDropShadowEffectToCurrentTheme()
273278

274279
public void RemoveDropShadowEffectFromCurrentTheme()
275280
{
276-
var dict = CurrentThemeResourceDictionary();
281+
var dict = GetCurrentResourceDictionary();
277282
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
278283

279284
var effectSetter = windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == Border.EffectProperty) as Setter;

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
1313
public class Settings : BaseModel
1414
{
1515
private string language = "en";
16+
private string _theme = Constant.DefaultTheme;
1617
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
1718
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
1819
public string ColorScheme { get; set; } = "System";
@@ -29,7 +30,18 @@ public string Language
2930
OnPropertyChanged();
3031
}
3132
}
32-
public string Theme { get; set; } = Constant.DefaultTheme;
33+
public string Theme
34+
{
35+
get => _theme;
36+
set
37+
{
38+
if (value == _theme)
39+
return;
40+
_theme = value;
41+
OnPropertyChanged();
42+
OnPropertyChanged(nameof(MaxResultsToShow));
43+
}
44+
}
3345
public bool UseDropShadowEffect { get; set; } = false;
3446
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
3547
public string QueryBoxFontStyle { get; set; }
@@ -214,7 +226,7 @@ public bool HideNotifyIcon
214226
}
215227
}
216228
public bool LeaveCmdOpen { get; set; }
217-
public bool HideWhenDeactive { get; set; } = true;
229+
public bool HideWhenDeactivated { get; set; } = true;
218230
public SearchWindowPositions SearchWindowPosition { get; set; } = SearchWindowPositions.MouseScreenCenter;
219231
public bool IgnoreHotkeysOnFullscreen { get; set; }
220232

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace Flow.Launcher.Converters
7+
{
8+
public class DiameterToCenterPointConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (value is double d)
13+
{
14+
return new Point(d / 2, d / 2);
15+
}
16+
17+
return new Point(0, 0);
18+
}
19+
20+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
21+
{
22+
throw new NotSupportedException();
23+
}
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using Windows.Devices.PointOfService;
5+
6+
namespace Flow.Launcher.Converters
7+
{
8+
public class IconRadiusConverter : IMultiValueConverter
9+
{
10+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (values.Length != 2)
13+
throw new ArgumentException("IconRadiusConverter must have 2 parameters");
14+
15+
return values[1] switch
16+
{
17+
true => (double)values[0] / 2,
18+
false => (double)values[0],
19+
_ => throw new ArgumentException("The second argument should be boolean", nameof(values))
20+
};
21+
}
22+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
23+
{
24+
throw new NotSupportedException();
25+
}
26+
}
27+
}

Flow.Launcher/MainWindow.xaml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
1010
xmlns:ui="http://schemas.modernwpf.com/2019"
1111
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
12-
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
1312
Name="FlowMainWindow"
1413
Title="Flow Launcher"
1514
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
1615
MaxWidth="{Binding MainWindowWidth, Mode=OneWay}"
16+
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
1717
AllowDrop="True"
1818
AllowsTransparency="True"
1919
Background="Transparent"
@@ -38,9 +38,9 @@
3838
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
3939
<converters:BorderClipConverter x:Key="BorderClipConverter" />
4040
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
41-
<converters:BoolToIMEConversionModeConverter x:Key="BoolToIMEConversionModeConverter"/>
42-
<converters:BoolToIMEStateConverter x:Key="BoolToIMEStateConverter"/>
43-
<converters:StringToKeyBindingConverter x:Key="StringToKeyBindingConverter"/>
41+
<converters:BoolToIMEConversionModeConverter x:Key="BoolToIMEConversionModeConverter" />
42+
<converters:BoolToIMEStateConverter x:Key="BoolToIMEStateConverter" />
43+
<converters:StringToKeyBindingConverter x:Key="StringToKeyBindingConverter" />
4444
</Window.Resources>
4545
<Window.InputBindings>
4646
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
@@ -180,11 +180,11 @@
180180
<KeyBinding
181181
Key="F12"
182182
Command="{Binding ToggleGameModeCommand}"
183-
Modifiers="Ctrl"/>
183+
Modifiers="Ctrl" />
184184
<KeyBinding
185185
Key="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
186186
Command="{Binding TogglePreviewCommand}"
187-
Modifiers="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}"/>
187+
Modifiers="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
188188
</Window.InputBindings>
189189
<Grid>
190190
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">
@@ -207,12 +207,12 @@
207207
<TextBox
208208
x:Name="QueryTextBox"
209209
AllowDrop="True"
210+
InputMethod.PreferredImeConversionMode="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEConversionModeConverter}}"
211+
InputMethod.PreferredImeState="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEStateConverter}}"
210212
PreviewDragOver="OnPreviewDragOver"
211213
PreviewKeyUp="QueryTextBox_KeyUp"
212214
Style="{DynamicResource QueryBoxStyle}"
213215
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
214-
InputMethod.PreferredImeConversionMode="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEConversionModeConverter}}"
215-
InputMethod.PreferredImeState="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEStateConverter}}"
216216
Visibility="Visible">
217217
<TextBox.CommandBindings>
218218
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
@@ -273,9 +273,6 @@
273273
<Grid>
274274
<Image
275275
x:Name="PluginActivationIcon"
276-
Width="32"
277-
Height="32"
278-
Margin="0,0,18,0"
279276
HorizontalAlignment="Right"
280277
VerticalAlignment="Center"
281278
Panel.ZIndex="2"
@@ -403,10 +400,10 @@
403400
VerticalAlignment="Stretch"
404401
Style="{DynamicResource PreviewArea}"
405402
Visibility="{Binding PreviewVisible, Converter={StaticResource BoolToVisibilityConverter}}">
406-
<Border
407-
Style="{DynamicResource PreviewBorderStyle}"
403+
<Border
408404
d:DataContext="{d:DesignInstance vm:ResultViewModel}"
409405
DataContext="{Binding SelectedItem, ElementName=ResultListBox}"
406+
Style="{DynamicResource PreviewBorderStyle}"
410407
Visibility="{Binding ShowDefaultPreview}">
411408
<Grid
412409
Margin="20,0,10,0"
@@ -478,10 +475,10 @@
478475
</StackPanel>
479476
</Grid>
480477
</Border>
481-
<Border
478+
<Border
482479
d:DataContext="{d:DesignInstance vm:ResultViewModel}"
483480
DataContext="{Binding SelectedItem, ElementName=ResultListBox}"
484-
Style="{DynamicResource PreviewBorderStyle}"
481+
Style="{DynamicResource PreviewBorderStyle}"
485482
Visibility="{Binding ShowCustomizedPreview}">
486483
<ContentControl Content="{Binding Result.PreviewPanel.Value}" />
487484
</Border>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private async void OnDeactivated(object sender, EventArgs e)
485485
if (_settings.UseAnimation)
486486
await Task.Delay(100);
487487

488-
if (_settings.HideWhenDeactive)
488+
if (_settings.HideWhenDeactivated)
489489
{
490490
_viewModel.Hide();
491491
}

0 commit comments

Comments
 (0)