@@ -13,10 +13,10 @@ use cosmic::{
1313 Apply , Element , Task ,
1414} ;
1515use cosmic_settings_page:: { self as page, section, Section } ;
16+ use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopEntryIter } ;
1617use mime_apps:: App ;
1718use slotmap:: SlotMap ;
1819use tokio:: sync:: mpsc;
19- use freedesktop_desktop_entry:: { default_paths, DesktopEntry , Iter as DesktopEntryIter } ;
2020
2121const DROPDOWN_WEB_BROWSER : usize = 0 ;
2222const DROPDOWN_FILE_MANAGER : usize = 1 ;
@@ -26,6 +26,7 @@ const DROPDOWN_VIDEO: usize = 4;
2626const DROPDOWN_PHOTO : usize = 5 ;
2727const DROPDOWN_CALENDAR : usize = 6 ;
2828const DROPDOWN_TERMINAL : usize = 7 ;
29+ const DROPDOWN_TEXT_EDITOR : usize = 8 ;
2930
3031#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
3132pub enum Category {
@@ -38,6 +39,7 @@ pub enum Category {
3839 Terminal ,
3940 Video ,
4041 WebBrowser ,
42+ TextEditor ,
4143}
4244
4345#[ derive( Clone , Debug ) ]
@@ -128,6 +130,7 @@ impl page::Page<crate::pages::Message> for Page {
128130 load_defaults( & assocs, & [ "image/png" ] ) . await ,
129131 load_defaults( & assocs, & [ "text/calendar" ] ) . await ,
130132 load_terminal_apps( & assocs) . await ,
133+ load_defaults( & assocs, & [ "text/plain" ] ) . await ,
131134 ] ;
132135
133136 Message :: Update ( CachedMimeApps {
@@ -201,10 +204,13 @@ impl Page {
201204 & mime_types
202205 } ) ,
203206 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+ ) ,
208214 Category :: Video => ( DROPDOWN_VIDEO , {
209215 mime_types = mime_apps
210216 . known_mimes
@@ -224,6 +230,7 @@ impl Page {
224230 "x-scheme-handler/https" ,
225231 ] ,
226232 ) ,
233+ Category :: TextEditor => ( DROPDOWN_TEXT_EDITOR , & [ "text/plain" ] ) ,
227234 Category :: Mime ( _mime_type) => return Task :: none ( ) ,
228235 } ;
229236
@@ -346,6 +353,16 @@ fn apps() -> Section<crate::pages::Message> {
346353 . icons ( & meta. icons ) ,
347354 )
348355 } )
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+ } )
349366 . apply ( Element :: from)
350367 . map ( crate :: pages:: Message :: DefaultApps )
351368 } )
@@ -454,7 +471,11 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
454471 if let Ok ( bytes) = std:: fs:: read_to_string ( & path) {
455472 if let Ok ( entry) = DesktopEntry :: from_str ( & path, & bytes, None :: < & [ & str ] > ) {
456473 // 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+ {
458479 let id = entry. id ( ) ;
459480 if let Some ( app) = assocs. get ( id) {
460481 if current_appid. as_ref ( ) . map ( |c| * c == id) . unwrap_or ( false ) {
0 commit comments