1
- use std:: { borrow:: Cow , ops:: Deref } ;
1
+ use std:: {
2
+ borrow:: { Borrow , Cow } ,
3
+ ops:: Deref ,
4
+ } ;
2
5
3
6
use crate :: {
4
7
mappings:: Filetype ,
@@ -20,6 +23,9 @@ pub struct CustomAssetContext {
20
23
pub struct ActivityContext {
21
24
pub filename : String ,
22
25
pub filetype : String ,
26
+ pub is_read_only : bool ,
27
+ pub cursor_position : Option < ( i32 , i32 ) > ,
28
+ pub problem_count : i32 ,
23
29
pub custom_asset : Option < CustomAssetContext > ,
24
30
pub resolved_type : Option < Filetype > ,
25
31
}
@@ -36,10 +42,19 @@ impl CustomAssetContext {
36
42
}
37
43
38
44
impl ActivityContext {
39
- pub fn new ( filename : String , filetype : String ) -> Self {
45
+ pub fn new (
46
+ filename : String ,
47
+ filetype : String ,
48
+ is_read_only : bool ,
49
+ cursor_position : Option < ( i32 , i32 ) > ,
50
+ problem_count : i32 ,
51
+ ) -> Self {
40
52
let mut ctx = Self {
41
53
filename,
42
54
filetype,
55
+ is_read_only,
56
+ cursor_position,
57
+ problem_count,
43
58
resolved_type : None ,
44
59
custom_asset : None ,
45
60
} ;
@@ -143,11 +158,11 @@ impl ActivityContext {
143
158
}
144
159
}
145
160
146
- fn build_idle_activity ( & self , config : & Config ) -> Option < Activity > {
161
+ fn build_idle_activity ( & self , config : & Config ) -> Activity {
147
162
let state = self . build_workspace_state ( config, -1 ) ;
148
163
let large_image = get_asset ( "editor" , "idle" ) ;
149
164
150
- Some ( Activity {
165
+ Activity {
151
166
details : Some ( config. idle_text . clone ( ) ) ,
152
167
state,
153
168
large_image : Some ( large_image) ,
@@ -156,27 +171,40 @@ impl ActivityContext {
156
171
small_text : None ,
157
172
timestamp : config. timestamp ,
158
173
buttons : ( !config. buttons . is_empty ( ) ) . then ( || config. buttons . clone ( ) ) ,
159
- } )
174
+ }
160
175
}
161
176
162
- fn build_details (
163
- & self ,
164
- config : & Config ,
165
- is_read_only : bool ,
166
- cursor_position : Option < & str > ,
167
- ) -> String {
177
+ fn build_details ( & self , config : & Config ) -> String {
168
178
let filename = self . get_effective_name ( ) ;
169
179
let filename = filename. deref ( ) ;
170
180
171
- let mut details = if is_read_only {
172
- config. viewing_text . replace ( "{}" , filename)
173
- } else {
174
- config. editing_text . replace ( "{}" , filename)
175
- } ;
181
+ let details = match self . resolved_type . as_ref ( ) . unwrap ( ) {
182
+ Filetype :: Language ( _, _) => {
183
+ let mut details = if self . is_read_only {
184
+ config. viewing_text . replace ( "{}" , filename)
185
+ } else {
186
+ config. editing_text . replace ( "{}" , filename)
187
+ } ;
176
188
177
- if let Some ( pos) = cursor_position {
178
- details = format ! ( "{}:{}" , details, pos) ;
179
- }
189
+ if let Some ( ( line, char) ) = self . cursor_position {
190
+ details = details + ":" + & line. to_string ( ) + ":" + & char. to_string ( ) ;
191
+ }
192
+
193
+ details
194
+ }
195
+ Filetype :: FileBrowser ( _, _) => config
196
+ . file_browser_text
197
+ . replace ( "{}" , self . get_effective_name ( ) . borrow ( ) ) ,
198
+ Filetype :: PluginManager ( _, _) => config
199
+ . plugin_manager_text
200
+ . replace ( "{}" , self . get_effective_name ( ) . borrow ( ) ) ,
201
+ Filetype :: Lsp ( _, _) => config
202
+ . lsp_manager_text
203
+ . replace ( "{}" , self . get_effective_name ( ) . borrow ( ) ) ,
204
+ Filetype :: Vcs ( _, _) => config
205
+ . vcs_text
206
+ . replace ( "{}" , self . get_effective_name ( ) . borrow ( ) ) ,
207
+ } ;
180
208
181
209
details
182
210
}
@@ -244,19 +272,13 @@ impl ActivityContext {
244
272
}
245
273
}
246
274
247
- pub fn build (
248
- & self ,
249
- config : & Config ,
250
- is_read_only : bool ,
251
- cursor_position : Option < & str > ,
252
- problem_count : i32 ,
253
- ) -> Option < Activity > {
275
+ pub fn build ( & self , config : & Config ) -> Activity {
254
276
if self . filetype == "Cord.idle" {
255
277
return self . build_idle_activity ( config) ;
256
278
}
257
279
258
- let details = self . build_details ( config, is_read_only , cursor_position ) ;
259
- let state = self . build_workspace_state ( config, problem_count) ;
280
+ let details = self . build_details ( config) ;
281
+ let state = self . build_workspace_state ( config, self . problem_count ) ;
260
282
261
283
let large_image = Some ( self . get_effective_icon ( ) ) ;
262
284
let large_text = Some ( self . get_effective_tooltip ( ) ) . map ( |s| s. to_owned ( ) ) ;
@@ -265,7 +287,7 @@ impl ActivityContext {
265
287
self . swap_images ( config, large_image, large_text, config. swap_icons ) ;
266
288
let ( details, state) = self . swap_fields ( details, state, config. swap_fields ) ;
267
289
268
- Some ( Activity {
290
+ Activity {
269
291
details : Some ( details) ,
270
292
state : state. map ( |s| s. to_owned ( ) ) ,
271
293
large_image : large_image. map ( |s| s. to_owned ( ) ) ,
@@ -274,6 +296,6 @@ impl ActivityContext {
274
296
small_text,
275
297
timestamp : config. timestamp ,
276
298
buttons : ( !config. buttons . is_empty ( ) ) . then ( || config. buttons . clone ( ) ) ,
277
- } )
299
+ }
278
300
}
279
301
}
0 commit comments