From f16e075279aa426e1fc94fe5f7fa934b15382f5d Mon Sep 17 00:00:00 2001 From: barsoosayque Date: Sun, 27 Oct 2024 15:14:34 +0700 Subject: [PATCH] New pack menu button --- crates/opensi-editor/Cargo.toml | 1 + crates/opensi-editor/src/app.rs | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/crates/opensi-editor/Cargo.toml b/crates/opensi-editor/Cargo.toml index 39f24fb..a4e274f 100644 --- a/crates/opensi-editor/Cargo.toml +++ b/crates/opensi-editor/Cargo.toml @@ -21,6 +21,7 @@ thiserror = "1.0.64" serde = { version = "1", features = ["derive"] } egui_extras = "0.29.0" itertools = "0.13.0" +egui-modal = "0.5.0" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/opensi-editor/src/app.rs b/crates/opensi-editor/src/app.rs index 4654b32..a845929 100644 --- a/crates/opensi-editor/src/app.rs +++ b/crates/opensi-editor/src/app.rs @@ -55,11 +55,47 @@ impl eframe::App for EditorApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { self.package_state.update(); + let new_pack_modal = + egui_modal::Modal::new(ctx, "new-pack-modal").with_close_on_outside_click(true); + new_pack_modal.show(|ui| { + new_pack_modal.title(ui, "Перезаписать текущий пак ?"); + new_pack_modal.frame(ui, |ui| { + new_pack_modal + .body(ui, "Создание нового пака перезапишет текущий пак. Вы уверены ?"); + }); + new_pack_modal.buttons(ui, |ui| { + if new_pack_modal.caution_button(ui, "Отмена").clicked() { + new_pack_modal.close(); + }; + if new_pack_modal.suggested_button(ui, "Перезаписать").clicked() { + self.package_state = PackageState::Active { + package: opensi_core::Package::default(), + selected: None, + }; + }; + }); + }); + egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { egui::menu::bar(ui, |ui| { egui::widgets::global_theme_preference_switch(ui); ui.add_space(16.0); ui.menu_button("Файл", |ui| { + if ui.button("➕ Новый пак").clicked() { + match self.package_state { + PackageState::Active { .. } => { + new_pack_modal.open(); + }, + _ => { + self.package_state = PackageState::Active { + package: opensi_core::Package::default(), + selected: None, + }; + }, + } + ui.close_menu(); + } + ui.separator(); if ui.button("⮩ Импорт").clicked() { let package_receiver = file_dialogs::import_dialog(); self.package_state = PackageState::Loading(package_receiver);