summaryrefslogtreecommitdiff
path: root/src/user/raleigh/d/saving_window.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-03-11 22:00:22 -0500
committerBenji Dial <benji6283@gmail.com>2021-03-11 22:00:22 -0500
commit5fcf57739e68a8b5053e03778aaee0eed445babd (patch)
treee7a8bab18668d112e58b1b48190195035c71fa8a /src/user/raleigh/d/saving_window.cpp
parent0f2398d1f622cce37925f52d978d92e6cce1c7a9 (diff)
downloadportland-os-5fcf57739e68a8b5053e03778aaee0eed445babd.tar.gz
settings editor, and lots of changes in service of that
Diffstat (limited to 'src/user/raleigh/d/saving_window.cpp')
-rw-r--r--src/user/raleigh/d/saving_window.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/user/raleigh/d/saving_window.cpp b/src/user/raleigh/d/saving_window.cpp
new file mode 100644
index 0000000..a2d57e4
--- /dev/null
+++ b/src/user/raleigh/d/saving_window.cpp
@@ -0,0 +1,55 @@
+#include <raleigh/d/saving_window.h>
+#include <raleigh/d/dialog.h>
+
+#include <raleigh/w/padding.h>
+#include <raleigh/w/button.h>
+#include <raleigh/w/label.h>
+#include <raleigh/w/hbox.h>
+#include <raleigh/w/vbox.h>
+
+#include <structs/dllist.h>
+
+namespace raleigh {
+ bool on_saving_window_close(window_tag_t tag) {
+ saving_window *const sw = (saving_window *)tag;
+ if (sw->is_saved)
+ return true;
+
+ label text("There is unsaved content in this window.");
+ label text2("Would you like to save before closing it?");
+
+ dllist<widget &> rows;
+ rows.add_back(text);
+ rows.add_back(text2);
+ vbox vb(rows);
+ padding vbp(vb, 2);
+
+ dialog diag(vbp, yes_no_cancel);
+ diag.show_modal();
+
+ switch (diag.result) {
+ case YES:
+ save:
+ if (!sw->save_func(sw->save_tag)) {
+ label text3("Failing saved. Still quit?");
+ dialog diag2(text3, yes_no_retry);
+ diag2.show_modal();
+ switch (diag2.result) {
+ case YES:
+ return true;
+ case RETRY:
+ goto save;
+ default:
+ return false;
+ }
+ }
+ case NO:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ saving_window::saving_window(bool (*save_func)(save_tag_t), save_tag_t save_tag, widget &root, _pixel_t bg_color)
+ : window(root, bg_color, &on_saving_window_close, (window_tag_t)this), is_saved(true), save_func(save_func), save_tag(save_tag) {}
+} \ No newline at end of file