Skip to content

Commit

Permalink
Improved exit logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Dec 9, 2023
1 parent 0729255 commit 7bd433e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 7 additions & 11 deletions pubsubman/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,18 @@ impl App {
};
}

fn render_close_dialog(&mut self, ctx: &egui::Context) {
fn handle_exit(&mut self, ctx: &egui::Context) {
if ctx.input(|i| i.viewport().close_requested()) && !self.exit_state.can_exit {
self.exit_state.show_exit_dialogue = true;
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
}

let sub_names = self.memory.subscriptions.values().cloned().collect();
let cleanup_subscriptions = |sub_names: Vec<SubscriptionName>| {
delete_subscriptions(&self.front_tx, sub_names);
};
self.exit_state.show(ctx, sub_names, cleanup_subscriptions)
}

fn handle_exit(&mut self, ctx: &egui::Context) {
if ctx.input(|i| i.viewport().close_requested()) && !self.exit_state.show_exit_dialogue {
self.exit_state.show_exit_dialogue = true;
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
}
self.exit_state.show(ctx, sub_names, cleanup_subscriptions);

if self.exit_state.can_exit {
for view in self.messages_views.values_mut() {
Expand All @@ -319,8 +318,6 @@ impl App {
// Clear superficial widget state, e.g. reset all collapsing headers.
ctx.data_mut(|d| d.clear());
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
} else {
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
}
}
}
Expand All @@ -329,7 +326,6 @@ impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
ctx.request_repaint();
self.handle_backend_message();
self.render_close_dialog(ctx);
self.render_top_panel(ctx);
self.render_topics_panel(ctx);
self.render_central_panel(ctx);
Expand Down
2 changes: 0 additions & 2 deletions pubsubman/src/exit_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ impl ExitState {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Cancel").clicked() {
self.show_exit_dialogue = false;
ui.ctx()
.send_viewport_cmd(egui::ViewportCommand::CancelClose);
}
});
});
Expand Down

0 comments on commit 7bd433e

Please sign in to comment.