Skip to content

Commit

Permalink
Delete column confirmation
Browse files Browse the repository at this point in the history
closes #549

Signed-off-by: kernelkind <[email protected]>
  • Loading branch information
kernelkind committed Dec 23, 2024
1 parent 6d1d28c commit 348b8b6
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions crates/notedeck_columns/src/ui/column/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ impl<'a> NavTitle<'a> {
ui.add_space(chev_x + item_spacing);
}

let delete_button_resp =
self.title(ui, self.routes.last().unwrap(), back_button_resp.is_some());
let remove_column = self.title(ui, self.routes.last().unwrap(), back_button_resp.is_some());

if delete_button_resp.map_or(false, |r| r.clicked()) {
if remove_column {
Some(RenderNavAction::RemoveColumn)
} else if back_button_resp.map_or(false, |r| r.clicked()) {
Some(RenderNavAction::Back)
Expand Down Expand Up @@ -158,6 +157,35 @@ impl<'a> NavTitle<'a> {
animation_resp
}

fn delete_button_section(&self, ui: &mut egui::Ui) -> bool {
let id = ui.id().with("title");

let delete_button_resp = self.delete_column_button(ui, 32.0);
if delete_button_resp.clicked() {
ui.data_mut(|d| d.insert_temp(id, true));
}

if ui.data_mut(|d| *d.get_temp_mut_or_default(id)) {
let mut confirm_pressed = false;
delete_button_resp.show_tooltip_ui(|ui| {
let confirm_resp = ui.button("Confirm");
if confirm_resp.clicked() {
confirm_pressed = true;
}

if confirm_resp.clicked() || ui.button("Cancel").clicked() {
ui.data_mut(|d| d.insert_temp(id, false));
}
});
if !confirm_pressed && delete_button_resp.clicked_elsewhere() {
ui.data_mut(|d| d.insert_temp(id, false));
}
confirm_pressed
} else {
false
}
}

fn pubkey_pfp<'txn, 'me>(
&'me mut self,
txn: &'txn Transaction,
Expand Down Expand Up @@ -246,12 +274,7 @@ impl<'a> NavTitle<'a> {
};
}

fn title(
&mut self,
ui: &mut egui::Ui,
top: &Route,
navigating: bool,
) -> Option<egui::Response> {
fn title(&mut self, ui: &mut egui::Ui, top: &Route, navigating: bool) -> bool {
if !navigating {
self.title_pfp(ui, top, 32.0);
self.title_label(ui, top);
Expand All @@ -261,9 +284,9 @@ impl<'a> NavTitle<'a> {
if navigating {
self.title_label(ui, top);
self.title_pfp(ui, top, 32.0);
None
false
} else {
Some(self.delete_column_button(ui, 32.0))
self.delete_button_section(ui)
}
})
.inner
Expand Down

0 comments on commit 348b8b6

Please sign in to comment.