diff --git a/i18n/en/cosmic_edit.ftl b/i18n/en/cosmic_edit.ftl index 8b8e1b1..636a727 100644 --- a/i18n/en/cosmic_edit.ftl +++ b/i18n/en/cosmic_edit.ftl @@ -24,7 +24,7 @@ project-search = Project search ## Prompt save changes prompt-save-changes-title = Unsaved changes prompt-unsaved-changes = You have unsaved changes. Save? -cancel = Cancel +discard = Discard changes ## Settings settings = Settings diff --git a/src/main.rs b/src/main.rs index 78cc8a7..48fa853 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1022,7 +1022,7 @@ impl App { let save = widget::text(fl!("save")); let save_button = widget::button(save) .on_press(Message::Save) - .style(theme::Button::Standard) + .style(theme::Button::Suggested) .width(Length::Fill); // Save As is shown if the file has been saved previously @@ -1032,7 +1032,7 @@ impl App { let save_as = widget::text(fl!("save-as")); let save_as_button = widget::button(save_as) .on_press(Message::SaveAsDialog) - .style(theme::Button::Standard) + .style(theme::Button::Suggested) .width(Length::Fill); Some(save_as_button) } @@ -1040,9 +1040,16 @@ impl App { }; // TODO: Maybe a button to show diffs in a split? + // And more info, such as the path if any? // let diff = widget::text(fl!("diff")); // let diff_button = widget::button(diff.into()); + let discard = widget::text(fl!("discard")); + let discard_button = widget::button(discard) + .on_press(Message::TabCloseForce(entity)) + .style(theme::Button::Destructive) + .width(Length::Fill); + widget::column::with_children(vec![ widget::text(fl!("prompt-unsaved-changes")) .style(theme::Text::Color(warning_color.into())) @@ -1051,6 +1058,7 @@ impl App { .push(save_button) .push_maybe(save_as_button) .into(), + discard_button.into(), ]) .spacing(spacing.space_s) .into() @@ -1986,8 +1994,12 @@ impl Application for App { Some(Tab::Editor(tab)) if tab.changed() => { // Don't close the save prompt if `TabClose` is emitted again; only // toggle if no pages are open or a different page is open - if !self.core.window.show_context - || matches!(self.context_page, ContextPage::PromptSaveChanges(_)) + // `PromptSaveChanges` for a different tab other than `entity` counts as + // a different page + // If tab 2 and 3 both have unsaved changes and PromptSaveChanges is + // open for tab 2, closing tab 3 should open the page for tab 3 + if !self.core().window.show_context + || !matches!(self.context_page, ContextPage::PromptSaveChanges(id) if id != entity) { // Focus the tab in case the user is closing an unfocussed tab // Otherwise, closing an unfocussed tab would be very confusing @@ -2023,6 +2035,18 @@ impl Application for App { self.open_tab(None); } + // Close PromptSaveChanges page if open for this entity + if self.core().window.show_context + && matches!(self.context_page, ContextPage::PromptSaveChanges(_)) + { + return Command::batch([ + self.update(Message::ToggleContextPage(ContextPage::PromptSaveChanges( + entity, + ))), + self.update_tab(), + ]); + } + return self.update_tab(); } Message::TabContextAction(entity, action) => {