@@ -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 _badgePath ;
27
+
21
28
/// <summary>
22
29
/// The title of the result. This is always required.
23
30
/// </summary>
@@ -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 BadgePath
96
+ {
97
+ get => _badgePath ;
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
+ _badgePath = Path . Combine ( PluginDirectory , value ) ;
109
+ }
110
+ else
111
+ {
112
+ _badgePath = value ;
113
+ }
114
+ }
115
+ }
116
+
83
117
/// <summary>
84
118
/// Determines if Icon has a border radius
85
119
/// </summary>
@@ -94,7 +128,12 @@ 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)
@@ -154,47 +193,6 @@ public string PluginDirectory
154
193
}
155
194
}
156
195
157
- /// <inheritdoc />
158
- public override string ToString ( )
159
- {
160
- return Title + SubTitle + Score ;
161
- }
162
-
163
- /// <summary>
164
- /// Clones the current result
165
- /// </summary>
166
- public Result Clone ( )
167
- {
168
- return new Result
169
- {
170
- Title = Title ,
171
- SubTitle = SubTitle ,
172
- ActionKeywordAssigned = ActionKeywordAssigned ,
173
- CopyText = CopyText ,
174
- AutoCompleteText = AutoCompleteText ,
175
- IcoPath = IcoPath ,
176
- RoundedIcon = RoundedIcon ,
177
- Icon = Icon ,
178
- Glyph = Glyph ,
179
- Action = Action ,
180
- AsyncAction = AsyncAction ,
181
- Score = Score ,
182
- TitleHighlightData = TitleHighlightData ,
183
- OriginQuery = OriginQuery ,
184
- PluginDirectory = PluginDirectory ,
185
- ContextData = ContextData ,
186
- PluginID = PluginID ,
187
- TitleToolTip = TitleToolTip ,
188
- SubTitleToolTip = SubTitleToolTip ,
189
- PreviewPanel = PreviewPanel ,
190
- ProgressBar = ProgressBar ,
191
- ProgressBarColor = ProgressBarColor ,
192
- Preview = Preview ,
193
- AddSelectedCount = AddSelectedCount ,
194
- RecordKey = RecordKey
195
- } ;
196
- }
197
-
198
196
/// <summary>
199
197
/// Additional data associated with this result
200
198
/// </summary>
@@ -223,16 +221,6 @@ public Result Clone()
223
221
/// </summary>
224
222
public Lazy < UserControl > PreviewPanel { get ; set ; }
225
223
226
- /// <summary>
227
- /// Run this result, asynchronously
228
- /// </summary>
229
- /// <param name="context"></param>
230
- /// <returns></returns>
231
- public ValueTask < bool > ExecuteAsync ( ActionContext context )
232
- {
233
- return AsyncAction ? . Invoke ( context ) ?? ValueTask . FromResult ( Action ? . Invoke ( context ) ?? false ) ;
234
- }
235
-
236
224
/// <summary>
237
225
/// Progress bar display. Providing an int value between 0-100 will trigger the progress bar to be displayed on the result
238
226
/// </summary>
@@ -254,11 +242,6 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
254
242
/// </summary>
255
243
public bool AddSelectedCount { get ; set ; } = true ;
256
244
257
- /// <summary>
258
- /// 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.
259
- /// </summary>
260
- public const int MaxScore = int . MaxValue ;
261
-
262
245
/// <summary>
263
246
/// 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.
264
247
/// This can be useful when your plugin will change the Title or SubTitle of the result dynamically.
@@ -267,6 +250,59 @@ public ValueTask<bool> ExecuteAsync(ActionContext context)
267
250
/// </summary>
268
251
public string RecordKey { get ; set ; } = null ;
269
252
253
+ /// <summary>
254
+ /// Run this result, asynchronously
255
+ /// </summary>
256
+ /// <param name="context"></param>
257
+ /// <returns></returns>
258
+ public ValueTask < bool > ExecuteAsync ( ActionContext context )
259
+ {
260
+ return AsyncAction ? . Invoke ( context ) ?? ValueTask . FromResult ( Action ? . Invoke ( context ) ?? false ) ;
261
+ }
262
+
263
+ /// <inheritdoc />
264
+ public override string ToString ( )
265
+ {
266
+ return Title + SubTitle + Score ;
267
+ }
268
+
269
+ /// <summary>
270
+ /// Clones the current result
271
+ /// </summary>
272
+ public Result Clone ( )
273
+ {
274
+ return new Result
275
+ {
276
+ Title = Title ,
277
+ SubTitle = SubTitle ,
278
+ ActionKeywordAssigned = ActionKeywordAssigned ,
279
+ CopyText = CopyText ,
280
+ AutoCompleteText = AutoCompleteText ,
281
+ IcoPath = IcoPath ,
282
+ BadgePath = BadgePath ,
283
+ RoundedIcon = RoundedIcon ,
284
+ Icon = Icon ,
285
+ BadgeIcon = BadgeIcon ,
286
+ Glyph = Glyph ,
287
+ Action = Action ,
288
+ AsyncAction = AsyncAction ,
289
+ Score = Score ,
290
+ TitleHighlightData = TitleHighlightData ,
291
+ OriginQuery = OriginQuery ,
292
+ PluginDirectory = PluginDirectory ,
293
+ ContextData = ContextData ,
294
+ PluginID = PluginID ,
295
+ TitleToolTip = TitleToolTip ,
296
+ SubTitleToolTip = SubTitleToolTip ,
297
+ PreviewPanel = PreviewPanel ,
298
+ ProgressBar = ProgressBar ,
299
+ ProgressBarColor = ProgressBarColor ,
300
+ Preview = Preview ,
301
+ AddSelectedCount = AddSelectedCount ,
302
+ RecordKey = RecordKey
303
+ } ;
304
+ }
305
+
270
306
/// <summary>
271
307
/// Info of the preview section of a <see cref="Result"/>
272
308
/// </summary>
0 commit comments