2
2
using System . Linq ;
3
3
using CommunityToolkit . Mvvm . DependencyInjection ;
4
4
using Flow . Launcher . Core . Resource ;
5
+ using Flow . Launcher . Infrastructure . UserSettings ;
5
6
6
7
namespace Flow . Launcher . Plugin . Sys
7
8
{
8
9
public class ThemeSelector
9
10
{
10
11
public const string Keyword = "fltheme" ;
11
12
13
+ private readonly Settings _settings ;
12
14
private readonly Theme _theme ;
13
15
private readonly PluginInitContext _context ;
14
16
17
+ #region Theme Selection
18
+
19
+ // Theme select codes from SettingsPaneThemeViewModel.cs
20
+
21
+ private Theme . ThemeData _selectedTheme ;
22
+ private Theme . ThemeData SelectedTheme
23
+ {
24
+ get => _selectedTheme ??= Themes . Find ( v => v . FileNameWithoutExtension == _theme . CurrentTheme ) ;
25
+ set
26
+ {
27
+ _selectedTheme = value ;
28
+ _theme . ChangeTheme ( value . FileNameWithoutExtension ) ;
29
+
30
+ if ( _theme . BlurEnabled && _settings . UseDropShadowEffect )
31
+ DropShadowEffect = false ;
32
+ }
33
+ }
34
+
35
+ private List < Theme . ThemeData > Themes => _theme . LoadAvailableThemes ( ) ;
36
+
37
+ private bool DropShadowEffect
38
+ {
39
+ get => _settings . UseDropShadowEffect ;
40
+ set
41
+ {
42
+ if ( _theme . BlurEnabled && value )
43
+ {
44
+ _context . API . ShowMsgBox ( _context . API . GetTranslation ( "shadowEffectNotAllowed" ) ) ;
45
+ return ;
46
+ }
47
+
48
+ if ( value )
49
+ {
50
+ _theme . AddDropShadowEffectToCurrentTheme ( ) ;
51
+ }
52
+ else
53
+ {
54
+ _theme . RemoveDropShadowEffectFromCurrentTheme ( ) ;
55
+ }
56
+
57
+ _settings . UseDropShadowEffect = value ;
58
+ }
59
+ }
60
+
61
+ #endregion
62
+
15
63
public ThemeSelector ( PluginInitContext context )
16
64
{
17
65
_context = context ;
@@ -20,52 +68,66 @@ public ThemeSelector(PluginInitContext context)
20
68
21
69
public List < Result > Query ( Query query )
22
70
{
23
- var themes = _theme . LoadAvailableThemes ( ) . Select ( x => x . FileNameWithoutExtension ) ;
24
-
25
- string search = query . SecondToEndSearch ;
26
-
71
+ var search = query . SecondToEndSearch ;
27
72
if ( string . IsNullOrWhiteSpace ( search ) )
28
73
{
29
- return themes . Select ( CreateThemeResult )
74
+ return Themes . Select ( CreateThemeResult )
30
75
. OrderBy ( x => x . Title )
31
76
. ToList ( ) ;
32
77
}
33
78
34
- return themes . Select ( theme => ( theme , matchResult : _context . API . FuzzySearch ( search , theme ) ) )
79
+ return Themes . Select ( theme => ( theme , matchResult : _context . API . FuzzySearch ( search , theme . Name ) ) )
35
80
. Where ( x => x . matchResult . IsSearchPrecisionScoreMet ( ) )
36
81
. Select ( x => CreateThemeResult ( x . theme , x . matchResult . Score , x . matchResult . MatchData ) )
37
82
. OrderBy ( x => x . Title )
38
83
. ToList ( ) ;
39
84
}
40
85
41
- private Result CreateThemeResult ( string theme ) => CreateThemeResult ( theme , 0 , null ) ;
86
+ private Result CreateThemeResult ( Theme . ThemeData theme ) => CreateThemeResult ( theme , 0 , null ) ;
42
87
43
- private Result CreateThemeResult ( string theme , int score , IList < int > highlightData )
88
+ private Result CreateThemeResult ( Theme . ThemeData theme , int score , IList < int > highlightData )
44
89
{
90
+ string themeName = theme . Name ;
45
91
string title ;
46
- if ( theme == _theme . CurrentTheme )
92
+ if ( theme == SelectedTheme )
47
93
{
48
- title = $ "{ theme } ★";
94
+ title = $ "{ theme . Name } ★";
49
95
// Set current theme to the top
50
96
score = 2000 ;
51
97
}
52
98
else
53
99
{
54
- title = theme ;
100
+ title = theme . Name ;
55
101
// Set them to 1000 so that they are higher than other non-theme records
56
102
score = 1000 ;
57
103
}
58
104
105
+ string description = string . Empty ;
106
+ if ( theme . IsDark == true )
107
+ {
108
+ description += _context . API . GetTranslation ( "TypeIsDarkToolTip" ) ;
109
+ if ( theme . HasBlur == true )
110
+ {
111
+ description += "" ;
112
+ description += _context . API . GetTranslation ( "TypeHasBlurToolTip" ) ;
113
+ }
114
+ }
115
+ else if ( theme . HasBlur == true )
116
+ {
117
+ description += _context . API . GetTranslation ( "TypeHasBlurToolTip" ) ;
118
+ }
119
+
59
120
return new Result
60
121
{
61
122
Title = title ,
62
123
TitleHighlightData = highlightData ,
124
+ SubTitle = description ,
63
125
IcoPath = "Images\\ theme_selector.png" ,
64
126
Glyph = new GlyphInfo ( "/Resources/#Segoe Fluent Icons" , "\ue790 " ) ,
65
127
Score = score ,
66
128
Action = c =>
67
129
{
68
- _theme . ChangeTheme ( theme ) ;
130
+ SelectedTheme = theme ;
69
131
_context . API . ReQuery ( ) ;
70
132
return false ;
71
133
}
0 commit comments