diff options
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_types.h | 8 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_undo.h | 0 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm.c | 8 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 89 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 17 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 28 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_keymap.c | 12 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 32 |
9 files changed, 108 insertions, 87 deletions
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 234491a2186..da61a201ef6 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -43,6 +43,7 @@ set(INC ../nodes ../render/extern/include ../../gameengine/BlenderRoutines + ../../../intern/clog ../../../intern/ghost ../../../intern/guardedalloc ../../../intern/glew-mx diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index a09814cf5dd..4bd5bcfc056 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -731,6 +731,14 @@ typedef struct RecentFile { char *filepath; } RecentFile; +/* Logging */ +struct CLG_LogRef; +/* wm_init_exit.c */ +extern struct CLG_LogRef *WM_LOG_OPERATORS; +extern struct CLG_LogRef *WM_LOG_HANDLERS; +extern struct CLG_LogRef *WM_LOG_EVENTS; +extern struct CLG_LogRef *WM_LOG_KEYMAPS; + #ifdef __cplusplus } diff --git a/source/blender/windowmanager/WM_undo.h b/source/blender/windowmanager/WM_undo.h new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/source/blender/windowmanager/WM_undo.h diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 54c2d7a3aef..27107299863 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -63,6 +63,7 @@ #include "wm.h" #include "ED_screen.h" +#include "BKE_undo_system.h" #ifdef WITH_PYTHON #include "BPY_extern.h" @@ -506,7 +507,12 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm) WM_drag_free_list(&wm->drags); wm_reports_free(wm); - + + if (wm->undo_stack) { + BKE_undosys_stack_destroy(wm->undo_stack); + wm->undo_stack = NULL; + } + if (C && CTX_wm_manager(C) == wm) CTX_wm_manager_set(C, NULL); } diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 630f858099f..4a4a993b386 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -43,6 +43,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "GHOST_C-api.h" #include "BLI_blenlib.h" @@ -608,14 +610,6 @@ int WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context) return wm_operator_call_internal(C, ot, NULL, NULL, context, true); } -static void wm_operator_print(bContext *C, wmOperator *op) -{ - /* context is needed for enum function */ - char *buf = WM_operator_pystring(C, op, false, true); - puts(buf); - MEM_freeN(buf); -} - /** * Sets the active region for this space from the context. * @@ -776,10 +770,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, bool ca } if (retval & OPERATOR_FINISHED) { - if (G.debug & G_DEBUG_WM) { - /* todo - this print may double up, might want to check more flags then the FINISHED */ - wm_operator_print(C, op); - } + CLOG_STR_INFO_N(WM_LOG_OPERATORS, 1, WM_operator_pystring(C, op, false, true)); if (caller_owns_reports == false) { BKE_reports_print(op->reports, RPT_DEBUG); /* print out reports to console. */ @@ -1104,9 +1095,7 @@ bool WM_operator_last_properties_init(wmOperator *op) IDProperty *replaceprops = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); PropertyRNA *iterprop; - if (G.debug & G_DEBUG_WM) { - printf("%s: loading previous properties for '%s'\n", __func__, op->type->idname); - } + CLOG_INFO(WM_LOG_OPERATORS, 1, "loading previous properties for '%s'", op->type->idname); iterprop = RNA_struct_iterator_property(op->type->srna); @@ -1151,9 +1140,7 @@ bool WM_operator_last_properties_store(wmOperator *op) } if (op->properties) { - if (G.debug & G_DEBUG_WM) { - printf("%s: storing properties for '%s'\n", __func__, op->type->idname); - } + CLOG_INFO(WM_LOG_OPERATORS, 1, "storing properties for '%s'", op->type->idname); op->type->last_properties = IDP_CopyProperty(op->properties); return true; } @@ -1203,11 +1190,12 @@ static int wm_operator_invoke( WM_operator_last_properties_init(op); } - if ((G.debug & G_DEBUG_HANDLERS) && ((event == NULL) || (event->type != MOUSEMOVE))) { - printf("%s: handle evt %d region %p op %s\n", - __func__, event ? event->type : 0, CTX_wm_screen(C)->active_region, ot->idname); + if ((event == NULL) || (event->type != MOUSEMOVE)) { + CLOG_INFO(WM_LOG_HANDLERS, 2, + "handle evt %d win %p op %s", + event ? event->type : 0, CTX_wm_screen(C)->active_region, ot->idname); } - + if (op->type->invoke && event) { wm_region_mouse_co(C, event); @@ -1232,9 +1220,9 @@ static int wm_operator_invoke( } else { /* debug, important to leave a while, should never happen */ - printf("%s: invalid operator call '%s'\n", __func__, ot->idname); + CLOG_ERROR(WM_LOG_OPERATORS, "invalid operator call '%s'", op->idname); } - + /* Note, if the report is given as an argument then assume the caller will deal with displaying them * currently python only uses this */ if (!(retval & OPERATOR_HANDLED) && (retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED))) { @@ -1509,8 +1497,10 @@ int WM_operator_call_py( if (is_undo && op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) wm->op_undo_depth--; } - else - printf("error \"%s\" operator has no exec function, python cannot call it\n", op->type->name); + else { + CLOG_WARN(WM_LOG_OPERATORS, "\"%s\" operator has no exec function, Python cannot call it", op->type->name); + } + #endif /* not especially nice using undo depth here, its used so py never @@ -1554,8 +1544,9 @@ static void wm_handler_op_context(bContext *C, wmEventHandler *handler, const wm if (sa == NULL) { /* when changing screen layouts with running modal handlers (like render display), this * is not an error to print */ - if (handler->op == NULL) - printf("internal error: handler (%s) has invalid area\n", handler->op->type->idname); + if (handler->op == NULL) { + CLOG_ERROR(WM_LOG_HANDLERS, "internal error: handler (%s) has invalid area", handler->op->type->idname); + } } else { ARegion *ar; @@ -1901,10 +1892,9 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand //retval &= ~OPERATOR_PASS_THROUGH; } } - } else { - printf("%s: error '%s' missing modal\n", __func__, op->idname); + CLOG_ERROR(WM_LOG_HANDLERS, "missing modal '%s'", op->idname); } } else { @@ -2195,19 +2185,15 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers action |= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr); if (action & WM_HANDLER_BREAK) { /* not always_pass here, it denotes removed handler */ - - if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) - printf("%s: handled! '%s'\n", __func__, kmi->idname); - + CLOG_INFO(WM_LOG_HANDLERS, 2, "handled! '%s'", kmi->idname); break; } else { if (action & WM_HANDLER_HANDLED) { - if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) - printf("%s: handled - and pass on! '%s'\n", __func__, kmi->idname); + CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname); } else { - PRINT("%s: un-handled '%s'\n", __func__, kmi->idname); + CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname); } } } @@ -2466,10 +2452,8 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) { event->val = KM_CLICK; - if (G.debug & (G_DEBUG_HANDLERS)) { - printf("%s: handling CLICK\n", __func__); - } - + CLOG_INFO(WM_LOG_HANDLERS, 1, "handling CLICK"); + action |= wm_handlers_do_intern(C, event, handlers); event->val = KM_RELEASE; @@ -2708,8 +2692,8 @@ void wm_event_do_handlers(bContext *C) /* take care of pie event filter */ if (wm_event_pie_filter(win, event)) { - if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { - printf("\n%s: event filtered due to pie button pressed\n", __func__); + if (!ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + CLOG_INFO(WM_LOG_HANDLERS, 1, "event filtered due to pie button pressed"); } BLI_remlink(&win->queue, event); wm_event_free(event); @@ -3058,7 +3042,7 @@ wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap wmEventHandler *handler; if (!keymap) { - printf("%s: called with NULL keymap\n", __func__); + CLOG_WARN(WM_LOG_HANDLERS, "called with NULL keymap"); return NULL; } @@ -3679,8 +3663,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* double click test */ if (wm_event_is_double_click(&event, evt)) { - if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS)) - printf("%s Send double click\n", __func__); + CLOG_INFO(WM_LOG_HANDLERS, 1, "Send double click"); event.val = KM_DBL_CLICK; } if (event.val == KM_PRESS) { @@ -3734,7 +3717,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* ghost should do this already for key up */ if (event.utf8_buf[0]) { - printf("%s: ghost on your platform is misbehaving, utf8 events on key up!\n", __func__); + CLOG_ERROR(WM_LOG_EVENTS, "ghost on your platform is misbehaving, utf8 events on key up!"); } event.utf8_buf[0] = '\0'; } @@ -3747,8 +3730,9 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U if (event.utf8_buf[0]) { if (BLI_str_utf8_size(event.utf8_buf) == -1) { - printf("%s: ghost detected an invalid unicode character '%d'!\n", - __func__, (int)(unsigned char)event.utf8_buf[0]); + CLOG_ERROR(WM_LOG_EVENTS, + "ghost detected an invalid unicode character '%d'", + (int)(unsigned char)event.utf8_buf[0]); event.utf8_buf[0] = '\0'; } } @@ -3797,8 +3781,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* double click test */ /* if previous event was same type, and previous was release, and now it presses... */ if (wm_event_is_double_click(&event, evt)) { - if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS)) - printf("%s Send double click\n", __func__); + CLOG_INFO(WM_LOG_HANDLERS, 1, "Send double click"); evt->val = event.val = KM_DBL_CLICK; } @@ -3868,9 +3851,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U attach_ndof_data(&event, customdata); wm_event_add(win, &event); - if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS)) - printf("%s sending NDOF_MOTION, prev = %d %d\n", __func__, event.x, event.y); - + CLOG_INFO(WM_LOG_HANDLERS, 1, "sending NDOF_MOTION, prev = %d %d", event.x, event.y); break; } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index e673b1d386b..bb9ff0ab8eb 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -87,10 +87,12 @@ #include "BKE_sound.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_undo_system.h" #include "BKE_workspace.h" #include "BLO_readfile.h" #include "BLO_writefile.h" +#include "BLO_undofile.h" /* to save from an undo memfile */ #include "RNA_access.h" #include "RNA_define.h" @@ -534,9 +536,13 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo } if (!G.background) { -// undo_editmode_clear(); - BKE_undo_reset(); - BKE_undo_write(C, "original"); /* save current state */ + if (wm->undo_stack == NULL) { + wm->undo_stack = BKE_undosys_stack_create(); + } + else { + BKE_undosys_stack_clear(wm->undo_stack); + } + BKE_undosys_stack_init_from_main(wm->undo_stack, CTX_data_main(C)); } } @@ -1287,7 +1293,10 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w if (U.uiflag & USER_GLOBALUNDO) { /* fast save of last undobuffer, now with UI */ - BKE_undo_save_file(filepath); + struct MemFile *memfile = ED_undosys_stack_memfile_get_active(wm->undo_stack); + if (memfile) { + BLO_memfile_write_file(memfile, filepath); + } } else { /* save as regular blend file */ diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 03bc1ae0a02..534b20ff22e 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -40,6 +40,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "DNA_genfile.h" #include "DNA_scene_types.h" #include "DNA_userdef_types.h" @@ -53,6 +55,7 @@ #include "BLI_utildefines.h" #include "BLO_writefile.h" +#include "BLO_undofile.h" #include "BKE_blender.h" #include "BKE_blender_undo.h" @@ -132,6 +135,11 @@ # include "BKE_subsurf.h" #endif +CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_OPERATORS, "wm.operator"); +CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_HANDLERS, "wm.handler"); +CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_EVENTS, "wm.event"); +CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_KEYMAPS, "wm.keymap"); + static void wm_init_reports(bContext *C) { ReportList *reports = CTX_wm_reports(C); @@ -147,11 +155,6 @@ static void wm_free_reports(bContext *C) BKE_reports_clear(reports); } -static void wm_undo_kill_callback(bContext *C) -{ - WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C)); -} - bool wm_start_with_console = false; /* used in creator.c */ /* only called once, for startup */ @@ -172,7 +175,7 @@ void WM_init(bContext *C, int argc, const char **argv) wm_manipulatortype_init(); wm_manipulatorgrouptype_init(); - BKE_undo_callback_wm_kill_jobs_set(wm_undo_kill_callback); + ED_undosys_type_init(); BKE_library_callback_free_window_manager_set(wm_close_and_free); /* library.c */ BKE_library_callback_free_notifier_reference_set(WM_main_remove_notifier_reference); /* library.c */ @@ -482,7 +485,8 @@ void WM_exit_ext(bContext *C, const bool do_python) wmWindow *win; if (!G.background) { - if ((U.uiflag2 & USER_KEEP_SESSION) || BKE_undo_is_valid(NULL)) { + struct MemFile *undo_memfile = wm->undo_stack ? ED_undosys_stack_memfile_get_active(wm->undo_stack) : NULL; + if ((U.uiflag2 & USER_KEEP_SESSION) || (undo_memfile != NULL)) { /* save the undo state as quit.blend */ char filename[FILE_MAX]; bool has_edited; @@ -493,7 +497,7 @@ void WM_exit_ext(bContext *C, const bool do_python) has_edited = ED_editors_flush_edits(C, false); if ((has_edited && BLO_write_file(CTX_data_main(C), filename, fileflags, NULL, NULL)) || - BKE_undo_save_file(filename)) + (undo_memfile && BLO_memfile_write_file(undo_memfile, filename))) { printf("Saved session recovery to '%s'\n", filename); } @@ -516,11 +520,13 @@ void WM_exit_ext(bContext *C, const bool do_python) wm_dropbox_free(); WM_menutype_free(); WM_uilisttype_free(); - + /* all non-screen and non-space stuff editors did, like editmode */ if (C) ED_editors_exit(C); + ED_undosys_type_free(); + // XXX // BIF_GlobalReebFree(); // BIF_freeRetarget(); @@ -608,8 +614,6 @@ void WM_exit_ext(bContext *C, const bool do_python) (void)do_python; #endif - BKE_undo_reset(); - ED_file_exit(); /* for fsmenu */ UI_exit(); @@ -634,6 +638,8 @@ void WM_exit_ext(bContext *C, const bool do_python) * see also T50676. */ BKE_sound_exit(); + CLG_exit(); + BKE_blender_atexit(); if (MEM_get_memory_blocks_in_use() != 0) { diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index e86e80dddf6..0db67e0b199 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -1,4 +1,5 @@ /* + * * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -40,6 +41,7 @@ #include "DNA_workspace_types.h" #include "MEM_guardedalloc.h" +#include "CLG_log.h" #include "BLI_blenlib.h" #include "BLI_utildefines.h" @@ -902,11 +904,13 @@ wmKeyMapItem *WM_modalkeymap_find_propvalue(wmKeyMap *km, const int propvalue) void WM_modalkeymap_assign(wmKeyMap *km, const char *opname) { wmOperatorType *ot = WM_operatortype_find(opname, 0); - - if (ot) + + if (ot) { ot->modalkeymap = km; - else - printf("error: modalkeymap_assign, unknown operator %s\n", opname); + } + else { + CLOG_ERROR(WM_LOG_KEYMAPS, "unknown operator '%s'", opname); + } } static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 782d0c502a4..ebe68bc8f35 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -46,6 +46,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "DNA_ID.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" @@ -142,12 +144,12 @@ wmOperatorType *WM_operatortype_find(const char *idname, bool quiet) } if (!quiet) { - printf("search for unknown operator '%s', '%s'\n", idname_bl, idname); + CLOG_INFO(WM_LOG_OPERATORS, 0, "search for unknown operator '%s', '%s'\n", idname_bl, idname); } } else { if (!quiet) { - printf("search for empty operator\n"); + CLOG_INFO(WM_LOG_OPERATORS, 0, "search for empty operator"); } } @@ -180,8 +182,7 @@ static wmOperatorType *wm_operatortype_append__begin(void) static void wm_operatortype_append__end(wmOperatorType *ot) { if (ot->name == NULL) { - fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname); - ot->name = N_("Dummy Name"); + CLOG_ERROR(WM_LOG_OPERATORS, "Operator '%s' has no name property", ot->idname); } /* Allow calling _begin without _end in operatortype creation. */ @@ -269,7 +270,7 @@ static int wm_macro_exec(bContext *C, wmOperator *op) } } else { - printf("%s: '%s' cant exec macro\n", __func__, opm->type->idname); + CLOG_WARN(WM_LOG_OPERATORS, "'%s' cant exec macro", opm->type->idname); } } @@ -314,8 +315,9 @@ static int wm_macro_modal(bContext *C, wmOperator *op, const wmEvent *event) wmOperator *opm = op->opm; int retval = OPERATOR_FINISHED; - if (opm == NULL) - printf("%s: macro error, calling NULL modal()\n", __func__); + if (opm == NULL) { + CLOG_ERROR(WM_LOG_OPERATORS, "macro error, calling NULL modal()"); + } else { retval = opm->type->modal(C, opm, event); OPERATOR_RETVAL_CHECK(retval); @@ -389,7 +391,7 @@ wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *nam const char *i18n_context; if (WM_operatortype_find(idname, true)) { - printf("%s: macro error: operator %s exists\n", __func__, idname); + CLOG_ERROR(WM_LOG_OPERATORS, "operator %s exists, cannot create macro", idname); return NULL; } @@ -1198,11 +1200,14 @@ int WM_menu_invoke_ex(bContext *C, wmOperator *op, int opcontext) uiLayout *layout; if (prop == NULL) { - printf("%s: %s has no enum property set\n", __func__, op->type->idname); + CLOG_ERROR(WM_LOG_OPERATORS, + "'%s' has no enum property set", + op->type->idname); } else if (RNA_property_type(prop) != PROP_ENUM) { - printf("%s: %s \"%s\" is not an enum property\n", - __func__, op->type->idname, RNA_property_identifier(prop)); + CLOG_ERROR(WM_LOG_OPERATORS, + "'%s', '%s' is not an enum property", + op->type->idname, RNA_property_identifier(prop)); } else if (RNA_property_is_set(op->ptr, prop)) { const int retval = op->type->exec(C, op); @@ -1956,8 +1961,9 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar memcpy(ibuf->rect, ibuf_template->rect, ibuf_template->x * ibuf_template->y * sizeof(char[4])); } else { - printf("Splash expected %dx%d found %dx%d, ignoring: %s\n", - x_expect, y_expect, ibuf_template->x, ibuf_template->y, splash_filepath); + CLOG_ERROR(WM_LOG_OPERATORS, + "Splash expected %dx%d found %dx%d, ignoring: %s\n", + x_expect, y_expect, ibuf_template->x, ibuf_template->y, splash_filepath); } IMB_freeImBuf(ibuf_template); } |