confirm dialogue for new project

gui-branch
an 2019-03-25 22:15:50 -04:00
parent 3b8e285d93
commit 46ad94bdf0
1 changed files with 42 additions and 2 deletions

View File

@ -138,7 +138,7 @@ unsafe fn setup_about_dlg(b: *mut GtkBuilder)
gtk_widget_hide(dlg as _);
}
let dlg: *mut GtkAboutDialog = get_obj(b, c_str!("win-about"));
let dlg: *mut GtkAboutDialog = get_obj(b, c_str!("dlg-about"));
let btn: *mut GtkMenuItem = get_obj(b, c_str!("btn-about"));
let it = env!("CARGO_PKG_AUTHORS").split(';');
@ -181,10 +181,21 @@ unsafe fn setup_win_main(b: *mut GtkBuilder,
let edit = edit as *mut Option<MapEditorState>;
let edit = &mut *edit;
if let Some(_) = *edit {
let titl = c_str!("Confirm");
let text = c_str!("Are you sure you want to create a new project? \
Data may be lost.");
match run_ok_cancel_dlg(titl, text) {
true => {},
false => return,
}
}
*edit = Some(MapEditorState::new());
}
/// Callback to destroy the editor state reference.
/// Callback to finalize the editor state reference.
unsafe extern "C" fn c_new_done(_: *mut GtkWidget, edit: gpointer)
{
Rc::from_raw(edit);
@ -212,6 +223,35 @@ unsafe fn setup_css()
g_object_unref(css as _);
}
/// Runs a modal OK/Cancel dialogue.
unsafe fn run_ok_cancel_dlg(title: ffi::NT, text: ffi::NT) -> bool
{
let flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
let dlg = gtk_dialog_new_with_buttons(title,
ffi::null_mut(),
flags,
c_str!("_OK"),
GTK_RESPONSE_ACCEPT,
c_str!("_Cancel"),
GTK_RESPONSE_REJECT,
ffi::null_mut::<gpointer>());
let area = gtk_dialog_get_content_area(dlg as _);
let labl = gtk_label_new(text);
gtk_container_add(area as _, labl);
gtk_widget_show_all(area as _);
let res = gtk_dialog_run(dlg as _);
gtk_widget_destroy(dlg);
match res {
GTK_RESPONSE_ACCEPT => true,
_ => false,
}
}
/// Connects a handler that hides a toplevel widget when deleted.
unsafe fn connect_hide(wid: *mut GtkWidget)
{