From ca41548626f5f49a769dc018ab54d7ed06c05489 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 24 Apr 2019 17:45:34 +0200 Subject: [PATCH] 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 --- release/scripts/startup/bl_ui/space_topbar.py | 4 ++-- source/blender/windowmanager/intern/wm_files.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index e75f4d1bb5d..e2bd203f520 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -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() diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index c3642e7f7e7..d75853d623d 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -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(