Discard button for unsaved changes prompt
This commit is contained in:
parent
95423d6375
commit
b277699cca
2 changed files with 29 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
32
src/main.rs
32
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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue