@@ -13,10 +13,10 @@ use cosmic::{
13
13
Apply , Element , Task ,
14
14
} ;
15
15
use cosmic_settings_page:: { self as page, section, Section } ;
16
+ use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopEntryIter } ;
16
17
use mime_apps:: App ;
17
18
use slotmap:: SlotMap ;
18
19
use tokio:: sync:: mpsc;
19
- use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopEntryIter } ;
20
20
21
21
const DROPDOWN_WEB_BROWSER : usize = 0 ;
22
22
const DROPDOWN_FILE_MANAGER : usize = 1 ;
@@ -26,6 +26,7 @@ const DROPDOWN_VIDEO: usize = 4;
26
26
const DROPDOWN_PHOTO : usize = 5 ;
27
27
const DROPDOWN_CALENDAR : usize = 6 ;
28
28
const DROPDOWN_TERMINAL : usize = 7 ;
29
+ const DROPDOWN_TEXT_EDITOR : usize = 8 ;
29
30
30
31
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
31
32
pub enum Category {
@@ -38,6 +39,7 @@ pub enum Category {
38
39
Terminal ,
39
40
Video ,
40
41
WebBrowser ,
42
+ TextEditor ,
41
43
}
42
44
43
45
#[ derive( Clone , Debug ) ]
@@ -128,6 +130,7 @@ impl page::Page<crate::pages::Message> for Page {
128
130
load_defaults( & assocs, & [ "image/png" ] ) . await ,
129
131
load_defaults( & assocs, & [ "text/calendar" ] ) . await ,
130
132
load_terminal_apps( & assocs) . await ,
133
+ load_defaults( & assocs, & [ "text/plain" ] ) . await ,
131
134
] ;
132
135
133
136
Message :: Update ( CachedMimeApps {
@@ -201,10 +204,13 @@ impl Page {
201
204
& mime_types
202
205
} ) ,
203
206
Category :: Mail => ( DROPDOWN_MAIL , & [ "x-scheme-handler/mailto" ] ) ,
204
- Category :: Terminal => ( DROPDOWN_TERMINAL , & [
205
- "x-scheme-handler/terminal" ,
206
- "application/x-terminal-emulator"
207
- ] ) ,
207
+ Category :: Terminal => (
208
+ DROPDOWN_TERMINAL ,
209
+ & [
210
+ "x-scheme-handler/terminal" ,
211
+ "application/x-terminal-emulator" ,
212
+ ] ,
213
+ ) ,
208
214
Category :: Video => ( DROPDOWN_VIDEO , {
209
215
mime_types = mime_apps
210
216
. known_mimes
@@ -224,6 +230,7 @@ impl Page {
224
230
"x-scheme-handler/https" ,
225
231
] ,
226
232
) ,
233
+ Category :: TextEditor => ( DROPDOWN_TEXT_EDITOR , & [ "text/plain" ] ) ,
227
234
Category :: Mime ( _mime_type) => return Task :: none ( ) ,
228
235
} ;
229
236
@@ -346,6 +353,16 @@ fn apps() -> Section<crate::pages::Message> {
346
353
. icons ( & meta. icons ) ,
347
354
)
348
355
} )
356
+ . add ( {
357
+ let meta = & mime_apps. apps [ DROPDOWN_TEXT_EDITOR ] ;
358
+ settings:: flex_item (
359
+ fl ! ( "default-apps" , "text-editor" ) ,
360
+ dropdown ( & meta. apps , meta. selected , |id| {
361
+ Message :: SetDefault ( Category :: TextEditor , id)
362
+ } )
363
+ . icons ( & meta. icons ) ,
364
+ )
365
+ } )
349
366
. apply ( Element :: from)
350
367
. map ( crate :: pages:: Message :: DefaultApps )
351
368
} )
@@ -454,7 +471,11 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
454
471
if let Ok ( bytes) = std:: fs:: read_to_string ( & path) {
455
472
if let Ok ( entry) = DesktopEntry :: from_str ( & path, & bytes, None :: < & [ & str ] > ) {
456
473
// Check if it's a terminal application
457
- if entry. categories ( ) . map ( |cats| cats. iter ( ) . any ( |c| * c == "TerminalEmulator" ) ) . unwrap_or ( false ) {
474
+ if entry
475
+ . categories ( )
476
+ . map ( |cats| cats. iter ( ) . any ( |c| * c == "TerminalEmulator" ) )
477
+ . unwrap_or ( false )
478
+ {
458
479
let id = entry. id ( ) ;
459
480
if let Some ( app) = assocs. get ( id) {
460
481
if current_appid. as_ref ( ) . map ( |c| * c == id) . unwrap_or ( false ) {
0 commit comments