UI: Simple confirm dialog when loading new file

I also had to make the "New" operator a submenu in the
`File Context Menu`, so that you can still select the template.

This partially solves T61599. Currently the confirm dialog
is not shown when an already existing file is opened.
Implementing that requires a bit more work and will be
done in a separate patch.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4732
This commit is contained in:
Jacques Lucke 2019-04-24 17:45:34 +02:00
parent ea80264381
commit ca41548626
2 changed files with 14 additions and 2 deletions

View File

@ -262,7 +262,7 @@ class TOPBAR_MT_file_new(Menu):
@staticmethod
def draw_ex(layout, _context, *, use_splash=False, use_more=False):
layout.operator_context = 'EXEC_DEFAULT'
layout.operator_context = 'INVOKE_DEFAULT'
# Limit number of templates in splash screen, spill over into more menu.
paths = TOPBAR_MT_file_new.app_template_paths()
@ -557,7 +557,7 @@ class TOPBAR_MT_file_context_menu(Menu):
layout = self.layout
layout.operator_context = 'INVOKE_AREA'
layout.operator("wm.read_homefile", text="New", icon='FILE_NEW')
layout.menu("TOPBAR_MT_file_new", text="New", icon='FILE_NEW')
layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
layout.separator()

View File

@ -1846,6 +1846,17 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
wmWindowManager *wm = CTX_wm_manager(C);
if (U.uiflag & USER_SAVE_PROMPT && !wm->file_saved) {
return WM_operator_confirm_message(C, op, "Changes in current file will be lost. Continue?");
}
else {
return wm_homefile_read_exec(C, op);
}
}
void WM_OT_read_homefile(wmOperatorType *ot)
{
PropertyRNA *prop;
@ -1853,6 +1864,7 @@ void WM_OT_read_homefile(wmOperatorType *ot)
ot->idname = "WM_OT_read_homefile";
ot->description = "Open the default file (doesn't save the current file)";
ot->invoke = wm_homefile_read_invoke;
ot->exec = wm_homefile_read_exec;
prop = RNA_def_string_file_path(