Skip to content

Commit bae9977

Browse files
committed
feat: add confirmation for resetting panel settings
1 parent fa085f9 commit bae9977

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

cosmic-settings/src/pages/desktop/panel/inner.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ use std::{collections::HashMap, time::Duration};
1919

2020
use crate::pages::desktop::appearance::Roundness;
2121

22+
pub enum PanelInnerDialog {
23+
/// Confirmation dialog for reseting all panel settings
24+
ResetPanelConfirmation,
25+
}
26+
2227
pub struct PageInner {
2328
pub(crate) config_helper: Option<cosmic_config::Config>,
2429
pub(crate) panel_config: Option<CosmicPanelConfig>,
@@ -28,6 +33,7 @@ pub struct PageInner {
2833
pub outputs: Vec<String>,
2934
pub anchors: Vec<String>,
3035
pub backgrounds: Vec<String>,
36+
pub(crate) dialog: Option<PanelInnerDialog>,
3137
pub(crate) container_config: Option<CosmicPanelContainerConfig>,
3238
// TODO move these into panel config
3339
pub(crate) outputs_map: HashMap<ObjectId, (String, WlOutput)>,
@@ -55,6 +61,7 @@ impl Default for PageInner {
5561
Appearance::Light.to_string(),
5662
Appearance::Dark.to_string(),
5763
],
64+
dialog: None,
5865
container_config: Option::default(),
5966
outputs_map: HashMap::default(),
6067
system_default: None,
@@ -347,7 +354,7 @@ pub fn reset_button<
347354
Element::from(space())
348355
} else {
349356
button::standard(&descriptions[reset_to_default])
350-
.on_press(Message::ResetPanel)
357+
.on_press(Message::ConfirmResetPanel)
351358
.into()
352359
}
353360
.map(msg_map)
@@ -432,6 +439,8 @@ pub enum Message {
432439
OutputRemoved(WlOutput),
433440
PanelConfig(Box<CosmicPanelConfig>),
434441
ResetPanel,
442+
ConfirmResetPanel,
443+
CloseDialog,
435444
FullReset,
436445
Surface(surface::Action),
437446
}
@@ -673,7 +682,13 @@ impl PageInner {
673682
self.panel_config = Some(*c);
674683
return Task::none();
675684
}
676-
Message::ResetPanel | Message::FullReset => {}
685+
Message::ConfirmResetPanel => {
686+
self.dialog = Some(PanelInnerDialog::ResetPanelConfirmation);
687+
}
688+
Message::CloseDialog | Message::ResetPanel => {
689+
self.dialog = None;
690+
}
691+
Message::FullReset => {}
677692
Message::Surface(_) => {
678693
unimplemented!()
679694
}

cosmic-settings/src/pages/desktop/panel/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::collections::HashMap;
22

3-
use cosmic::{Task, cosmic_config::CosmicConfigEntry};
3+
use cosmic::{
4+
Apply, Element, Task,
5+
cosmic_config::CosmicConfigEntry,
6+
widget::{self, icon},
7+
};
48
use cosmic_panel_config::{CosmicPanelConfig, CosmicPanelContainerConfig};
59
use cosmic_settings_page::{self as page, Section, section};
610
use slotmap::SlotMap;
@@ -145,4 +149,25 @@ impl page::Page<crate::pages::Message> for Page {
145149

146150
Task::none()
147151
}
152+
153+
fn dialog(&'_ self) -> Option<Element<'_, crate::pages::Message>> {
154+
self.inner.dialog.as_ref().map(|dialog| match dialog {
155+
inner::PanelInnerDialog::ResetPanelConfirmation => {
156+
let primary_action = widget::button::destructive(fl!("confirm"))
157+
.on_press(inner::Message::ResetPanel);
158+
159+
let secondary_action =
160+
widget::button::standard(fl!("cancel")).on_press(inner::Message::CloseDialog);
161+
162+
widget::dialog()
163+
.title(fl!("panel-reset-dialog"))
164+
.icon(icon::from_name("dialog-warning").size(64))
165+
.body(fl!("panel-reset-dialog", "desc"))
166+
.primary_action(primary_action)
167+
.secondary_action(secondary_action)
168+
.apply(Element::from)
169+
.map(|m| crate::pages::Message::Panel(Message(m)))
170+
}
171+
})
172+
}
148173
}

i18n/en/cosmic_settings.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ panel-applets = Configuration
460460
.dock-desc = Configure dock applets
461461
.desc = Configure panel applets
462462
463+
panel-reset-dialog = Reset panel settings
464+
.desc = This action will reset all panel settings, including configured applets. This action cannot be undone.
465+
463466
panel-missing = Panel configuration is missing
464467
.desc = The panel configuration file is missing due to use of a custom configuration or it is corrupted.
465468
.fix = Reset to default

0 commit comments

Comments
 (0)