From 008c53962393416d7bbac2e44ea6c26e5089bdd9 Mon Sep 17 00:00:00 2001
From: Dane Johnson <daneallenjohnson@protonmail.com>
Date: Tue, 3 May 2022 15:50:09 -0500
Subject: [PATCH] Use new window for node placement

---
 src/main.rs | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 801af48..66c5295 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -108,7 +108,7 @@ impl Board {
 }
 
 //////////////////// Node Create/Edit Dialogs ////////////////////
-fn node_create_dialog(state: &mut AppState, pos_x: f32, pos_y: f32) {
+fn node_create_dialog(pos_x: f32, pos_y: f32) {
     let mut win = window::Window::default()
 	.with_size(100, 100)
 	.with_pos(app::event_x_root(), app::event_y_root());
@@ -125,6 +125,14 @@ fn node_create_dialog(state: &mut AppState, pos_x: f32, pos_y: f32) {
     win.make_resizable(true);
     win.make_modal(true);
     win.show();
+    btn.set_callback({
+	let mut win = win.clone();
+	move |_| {
+	    let mut state = STATE.get().lock().unwrap();
+	    state.board.add_node(pos_x, pos_y, name.value().to_string());
+	    win.hide();
+	}
+    });
     while win.shown() {
 	app::wait();
     }
@@ -138,11 +146,7 @@ mod dispatch {
     pub(super) fn node_press(coords: Coords) {
 	let (pos_x, pos_y) = coords;
 	if app::event_button() == 1 {
-	    let name = dialog::input_default("Node", "");
-	    if let Some(name) = name {
-		let mut state = STATE.get().lock().unwrap();
-		state.board.add_node(pos_x, pos_y, name);
-	    }
+	    node_create_dialog(pos_x, pos_y);
 	} else if app::event_button() == 3 {
 	    let mut state = STATE.get().lock().unwrap();
 	    let id = state.board.nearest_node(pos_x, pos_y);
@@ -314,7 +318,7 @@ fn main() {
 	let file = File::create(fc.filename()).unwrap();
 	let mut ar = zip::ZipWriter::new(file);
 	let options = zip::write::FileOptions::default();
-	let mut state = STATE.get().lock().unwrap();
+	let state = STATE.get().lock().unwrap();
 
 	ar.start_file("graph.json", options).ok();
 	ar.write(&serde_json::to_vec(&state.board).unwrap()).ok();