@@ -12,12 +12,19 @@ namespace Flow.Launcher.Plugin
12
12
/// </summary>
13
13
public class Result
14
14
{
15
+ /// <summary>
16
+ /// Maximum score. This can be useful when set one result to the top by default. This is the score for the results set to the topmost by users.
17
+ /// </summary>
18
+ public const int MaxScore = int . MaxValue ;
19
+
15
20
private string _pluginDirectory ;
16
21
17
22
private string _icoPath ;
18
23
19
24
private string _copyText = string . Empty ;
20
25
26
+ private string _badgeIcoPath ;
27
+
21
28
/// <summary>
22
29
/// The title of the result. This is always required.
23
30
/// </summary>
@@ -60,7 +67,7 @@ public string CopyText
60
67
/// <remarks>GlyphInfo is prioritized if not null</remarks>
61
68
public string IcoPath
62
69
{
63
- get { return _icoPath ; }
70
+ get => _icoPath ;
64
71
set
65
72
{
66
73
// As a standard this property will handle prepping and converting to absolute local path for icon image processing
@@ -80,6 +87,33 @@ public string IcoPath
80
87
}
81
88
}
82
89
90
+ /// <summary>
91
+ /// The image to be displayed for the badge of the result.
92
+ /// </summary>
93
+ /// <value>Can be a local file path or a URL.</value>
94
+ /// <remarks>If null or empty, will use plugin icon</remarks>
95
+ public string BadgeIcoPath
96
+ {
97
+ get => _badgeIcoPath ;
98
+ set
99
+ {
100
+ // As a standard this property will handle prepping and converting to absolute local path for icon image processing
101
+ if ( ! string . IsNullOrEmpty ( value )
102
+ && ! string . IsNullOrEmpty ( PluginDirectory )
103
+ && ! Path . IsPathRooted ( value )
104
+ && ! value . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase )
105
+ && ! value . StartsWith ( "https://" , StringComparison . OrdinalIgnoreCase )
106
+ && ! value . StartsWith ( "data:image" , StringComparison . OrdinalIgnoreCase ) )
107
+ {
108
+ _badgeIcoPath = Path . Combine ( PluginDirectory , value ) ;
109
+ }
110
+ else
111
+ {
112
+ _badgeIcoPath = value ;
113
+ }
114
+ }
115
+ }
116
+
83
117
/// <summary>
84
118
/// Determines if Icon has a border radius
85
119
/// </summary>
@@ -94,14 +128,18 @@ public string IcoPath
94
128
/// <summary>
95
129
/// Delegate to load an icon for this result.
96
130
/// </summary>
97
- public IconDelegate Icon ;
131
+ public IconDelegate Icon { get ; set ; }
132
+
133
+ /// <summary>
134
+ /// Delegate to load an icon for the badge of this result.
135
+ /// </summary>
136
+ public IconDelegate BadgeIcon { get ; set ; }
98
137
99
138
/// <summary>
100
139
/// Information for Glyph Icon (Prioritized than IcoPath/Icon if user enable Glyph Icons)
101
140
/// </summary>
102
141
public GlyphInfo Glyph { get ; init ; }
103
142
104
-
105
143
/// <summary>
106
144
/// An action to take in the form of a function call when the result has been selected.
107
145
/// </summary>
@@ -143,59 +181,19 @@ public string IcoPath
143
181
/// </summary>
144
182
public string PluginDirectory
145
183
{
146
- get { return _pluginDirectory ; }
184
+ get => _pluginDirectory ;
147
185
set
148
186
{
149
187
_pluginDirectory = value ;
150
188
151
189
// When the Result object is returned from the query call, PluginDirectory is not provided until
152
190
// UpdatePluginMetadata call is made at PluginManager.cs L196. Once the PluginDirectory becomes available
153
- // we need to update (only if not Uri path) the IcoPath with the full absolute path so the image can be loaded.
191
+ // we need to update (only if not Uri path) the IcoPath and BadgeIcoPath with the full absolute path so the image can be loaded.
154
192
IcoPath = _icoPath ;
193
+ BadgeIcoPath = _badgeIcoPath ;
155
194
}
156
195
}
157
196
158
- /// <inheritdoc />
159
- public override string ToString ( )
160
- {
161
- return Title + SubTitle + Score ;
162
- }
163
-
164
- /// <summary>
165
- /// Clones the current result
166
- /// </summary>
167
- public Result Clone ( )
168
- {
169
- return new Result
170
- {
171
- Title = Title ,
172
- SubTitle = SubTitle ,
173
- ActionKeywordAssigned = ActionKeywordAssigned ,
174
- CopyText = CopyText ,
175
- AutoCompleteText = AutoCompleteText ,
176
- IcoPath = IcoPath ,
177
- RoundedIcon = RoundedIcon ,
178
- Icon = Icon ,
179
- Glyph = Glyph ,
180
- Action = Action ,
181
- AsyncAction = AsyncAction ,
182
- Score = Score ,
183
- TitleHighlightData = TitleHighlightData ,
184
- OriginQuery = OriginQuery ,
185
- PluginDirectory = PluginDirectory ,
186
- ContextData = ContextData ,
187
- PluginID = PluginID ,
188
- TitleToolTip = TitleToolTip ,
189
- SubTitleToolTip = SubTitleToolTip ,
190
- PreviewPanel = PreviewPanel ,
191
- ProgressBar = ProgressBar ,
192
- ProgressBarColor = ProgressBarColor ,
193
- Preview = Preview ,
194
- AddSelectedCount = AddSelectedCount ,
195
- RecordKey = RecordKey
196
- } ;
197
- }
198
-
199
197
/// <summary>
200
198
/// Additional data associated with this result
201
199
/// </summary>
@@ -224,16 +222,6 @@ public Result Clone()
224
222
/// </summary>
225
223
public Lazy < UserControl > PreviewPanel { get ; set ; }
226
224
227
- /// <summary>
228
- /// Run this result, asynchronously
229
- /// </summary>
230
- /// <param name="context"></param>
231
- /// <returns></returns>
232
- public ValueTask < bool > ExecuteAsync ( ActionContext context )
233
- {
234
- return AsyncAction ? . Invoke ( context ) ?? ValueTask . FromResult ( Action ? . Invoke ( context ) ?? false ) ;
235
- }
236
-
237
225
/// <summary>
238
226
/// Progress bar display. Providing an int value between 0-100 will trigger the progress bar to be displayed on the result
239
227
/// </summary>
@@ -255,11 +243,6 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
255
243
/// </summary>
256
244
public bool AddSelectedCount { get ; set ; } = true ;
257
245
258
- /// <summary>
259
- /// Maximum score. This can be useful when set one result to the top by default. This is the score for the results set to the topmost by users.
260
- /// </summary>
261
- public const int MaxScore = int . MaxValue ;
262
-
263
246
/// <summary>
264
247
/// The key to identify the record. This is used when FL checks whether the result is the topmost record. Or FL calculates the hashcode of the result for user selected records.
265
248
/// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
@@ -268,6 +251,66 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
268
251
/// </summary>
269
252
public string RecordKey { get ; set ; } = null ;
270
253
254
+ /// <summary>
255
+ /// Determines if the badge icon should be shown.
256
+ /// If users want to show the result badges and here you set this to true, the results will show the badge icon.
257
+ /// </summary>
258
+ public bool ShowBadge { get ; set ; } = false ;
259
+
260
+ /// <summary>
261
+ /// Run this result, asynchronously
262
+ /// </summary>
263
+ /// <param name="context"></param>
264
+ /// <returns></returns>
265
+ public ValueTask < bool > ExecuteAsync ( ActionContext context )
266
+ {
267
+ return AsyncAction ? . Invoke ( context ) ?? ValueTask . FromResult ( Action ? . Invoke ( context ) ?? false ) ;
268
+ }
269
+
270
+ /// <inheritdoc />
271
+ public override string ToString ( )
272
+ {
273
+ return Title + SubTitle + Score ;
274
+ }
275
+
276
+ /// <summary>
277
+ /// Clones the current result
278
+ /// </summary>
279
+ public Result Clone ( )
280
+ {
281
+ return new Result
282
+ {
283
+ Title = Title ,
284
+ SubTitle = SubTitle ,
285
+ ActionKeywordAssigned = ActionKeywordAssigned ,
286
+ CopyText = CopyText ,
287
+ AutoCompleteText = AutoCompleteText ,
288
+ IcoPath = IcoPath ,
289
+ BadgeIcoPath = BadgeIcoPath ,
290
+ RoundedIcon = RoundedIcon ,
291
+ Icon = Icon ,
292
+ BadgeIcon = BadgeIcon ,
293
+ Glyph = Glyph ,
294
+ Action = Action ,
295
+ AsyncAction = AsyncAction ,
296
+ Score = Score ,
297
+ TitleHighlightData = TitleHighlightData ,
298
+ OriginQuery = OriginQuery ,
299
+ PluginDirectory = PluginDirectory ,
300
+ ContextData = ContextData ,
301
+ PluginID = PluginID ,
302
+ TitleToolTip = TitleToolTip ,
303
+ SubTitleToolTip = SubTitleToolTip ,
304
+ PreviewPanel = PreviewPanel ,
305
+ ProgressBar = ProgressBar ,
306
+ ProgressBarColor = ProgressBarColor ,
307
+ Preview = Preview ,
308
+ AddSelectedCount = AddSelectedCount ,
309
+ RecordKey = RecordKey ,
310
+ ShowBadge = ShowBadge ,
311
+ } ;
312
+ }
313
+
271
314
/// <summary>
272
315
/// Info of the preview section of a <see cref="Result"/>
273
316
/// </summary>
0 commit comments