Skip to content

Commit 442589f

Browse files
authored
feat(default_apps): add text editor default
Signed-off-by: Dusan <[email protected]>
1 parent bdf9e6a commit 442589f

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

cosmic-settings/src/pages/system/default_apps.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use cosmic::{
1313
Apply, Element, Task,
1414
};
1515
use cosmic_settings_page::{self as page, section, Section};
16+
use freedesktop_desktop_entry::{default_paths, DesktopEntry, Iter as DesktopEntryIter};
1617
use mime_apps::App;
1718
use slotmap::SlotMap;
1819
use tokio::sync::mpsc;
19-
use freedesktop_desktop_entry::{default_paths, DesktopEntry, Iter as DesktopEntryIter};
2020

2121
const DROPDOWN_WEB_BROWSER: usize = 0;
2222
const DROPDOWN_FILE_MANAGER: usize = 1;
@@ -26,6 +26,7 @@ const DROPDOWN_VIDEO: usize = 4;
2626
const DROPDOWN_PHOTO: usize = 5;
2727
const DROPDOWN_CALENDAR: usize = 6;
2828
const DROPDOWN_TERMINAL: usize = 7;
29+
const DROPDOWN_TEXT_EDITOR: usize = 8;
2930

3031
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
3132
pub 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) {

i18n/en/cosmic_settings.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,4 @@ default-apps = Default Applications
800800
.calendar = Calendar
801801
.terminal = Terminal
802802
.other-associations = Other Associations
803+
.text-editor = Text Editor

0 commit comments

Comments
 (0)