[Bf-blender-cvs] [bcc4e99a9b2] soc-2020-info-editor: Refactor window manager to use CLOG instead of print
Mateusz GrzeliÅski
noreply at git.blender.org
Tue Jun 30 23:26:06 CEST 2020
Commit: bcc4e99a9b228748f43ceb0c901baa25a840d352
Author: Mateusz Grzeliński
Date: Tue Jun 30 23:25:51 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBbcc4e99a9b228748f43ceb0c901baa25a840d352
Refactor window manager to use CLOG instead of print
===================================================================
M source/blender/blenkernel/BKE_idprop.h
M source/blender/blenkernel/intern/idprop_utils.c
M source/blender/windowmanager/intern/wm_dragdrop.c
M source/blender/windowmanager/intern/wm_files.c
M source/blender/windowmanager/intern/wm_files_link.c
M source/blender/windowmanager/intern/wm_gesture.c
M source/blender/windowmanager/intern/wm_keymap.c
M source/blender/windowmanager/intern/wm_platform_support.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h
index dc01e8ea27b..745c1edabf0 100644
--- a/source/blender/blenkernel/BKE_idprop.h
+++ b/source/blender/blenkernel/BKE_idprop.h
@@ -196,6 +196,7 @@ void IDP_repr_fn(const IDProperty *prop,
void (*str_append_fn)(void *user_data, const char *str, uint str_len),
void *user_data);
void IDP_print(const struct IDProperty *prop);
+char *IDP_print_str(const IDProperty *prop);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/idprop_utils.c b/source/blender/blenkernel/intern/idprop_utils.c
index f8a1113f69b..1ff87b190a5 100644
--- a/source/blender/blenkernel/intern/idprop_utils.c
+++ b/source/blender/blenkernel/intern/idprop_utils.c
@@ -18,6 +18,7 @@
* \ingroup bke
*/
+#include <CLG_log.h>
#include <stdio.h>
#include <string.h>
@@ -240,4 +241,16 @@ void IDP_print(const IDProperty *prop)
MEM_freeN(repr);
}
+char *IDP_print_str(const IDProperty *prop)
+{
+ DynStr *ds = BLI_dynstr_new();
+ char *repr = IDP_reprN(prop, NULL);
+ BLI_dynstr_appendf(ds, "IDProperty(%p): %s", prop, repr);
+ MEM_freeN(repr);
+ char *cstring = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+ return cstring;
+}
+
+
/** \} */
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index ad3fc7a1302..8969a91787f 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -23,6 +23,7 @@
* Our own drag-and-drop, drag state and drop boxes.
*/
+#include <CLG_log.h>
#include <string.h>
#include "DNA_screen_types.h"
@@ -108,7 +109,7 @@ wmDropBox *WM_dropbox_add(ListBase *lb,
if (drop->ot == NULL) {
MEM_freeN(drop);
- printf("Error: dropbox with unknown operator: %s\n", idname);
+ CLOG_ERROR(WM_LOG_OPERATORS, "Dropbox with unknown operator: %s", idname);
return NULL;
}
WM_operator_properties_alloc(&(drop->ptr), &(drop->properties), idname);
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index ebf56f433ed..3d98816b918 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1030,8 +1030,10 @@ void wm_homefile_read(bContext *C,
}
if (BLI_listbase_is_empty(&U.themes)) {
if (G.debug & G_DEBUG) {
- printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n",
- filepath_startup);
+ CLOG_INFO(WM_LOG_SESSION,
+ 0,
+ "Note: No (valid) '%s' found, fall back to built-in default",
+ filepath_startup);
}
success = false;
}
@@ -1409,11 +1411,11 @@ bool write_crash_blend(void)
BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path));
BLI_path_extension_replace(path, sizeof(path), "_crash.blend");
if (BLO_write_file(G_MAIN, path, G.fileflags, &(const struct BlendFileWriteParams){0}, NULL)) {
- printf("written: %s\n", path);
+ CLOG_INFO(WM_LOG_SESSION, 0, "Saving file ok: %s", path);
return 1;
}
else {
- printf("failed: %s\n", path);
+ CLOG_ERROR(WM_LOG_SESSION, "Saving file failed: %s", path);
return 0;
}
}
@@ -1620,7 +1622,8 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt))
if (handler->op) {
wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, 10.0);
if (G.debug) {
- printf("Skipping auto-save, modal operator running, retrying in ten seconds...\n");
+ CLOG_WARN(WM_LOG_SESSION,
+ "Skipping auto-save, modal operator running, retrying in 10 seconds...");
}
return;
}
@@ -1757,8 +1760,6 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_STARTUP_FILE, NULL);
- printf("Writing homefile: '%s' ", filepath);
-
ED_editors_flush_edits(bmain);
/* Force save as regular blend file. */
@@ -1771,11 +1772,11 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
.remap_mode = BLO_WRITE_PATH_REMAP_RELATIVE,
},
op->reports) == 0) {
- printf("fail\n");
+ CLOG_ERROR(WM_LOG_SESSION, "Writing homefile failed: '%s'", filepath);
return OPERATOR_CANCELLED;
}
- printf("ok\n");
+ CLOG_INFO(WM_LOG_SESSION, 0, "Writing homefile ok: '%s'", filepath);
G.save_over = 0;
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index c8574a5a7fb..c00a3230d0a 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -23,6 +23,7 @@
* Functions for dealing with append/link operators and helpers.
*/
+#include <CLG_log.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -302,7 +303,13 @@ static bool wm_link_append_item_poll(ReportList *reports,
short idcode;
if (!group || !name) {
- printf("skipping %s\n", path);
+ /* todo convert to report, but write why can not be linked. Right now it fails silently, not
+ * great UX */
+ CLOG_INFO(WM_LOG_OPERATORS,
+ 0,
+ "Can not be %s, skipping %s",
+ do_append ? "appended" : "linked",
+ path);
return false;
}
@@ -728,9 +735,7 @@ static void lib_relocate_do(Main *bmain,
item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id);
BLI_bitmap_set_all(item->libraries, true, lapp_data->num_libraries);
-#ifdef PRINT_DEBUG
- printf("\tdatablock to seek for: %s\n", id->name);
-#endif
+ CLOG_INFO(WM_LOG_OPERATORS, 2, "\tdatablock to seek for: %s", id->name);
}
}
}
@@ -780,12 +785,12 @@ static void lib_relocate_do(Main *bmain,
BLI_assert(new_id);
}
if (new_id) {
-#ifdef PRINT_DEBUG
- printf("before remap of %s, old_id users: %d, new_id users: %d\n",
- old_id->name,
- old_id->us,
- new_id->us);
-#endif
+ CLOG_INFO(WM_LOG_OPERATORS,
+ 1,
+ "before remap of %s, old_id users: %d, new_id users: %d",
+ old_id->name,
+ old_id->us,
+ new_id->us);
BKE_libblock_remap_locked(bmain, old_id, new_id, remap_flags);
if (old_id->flag & LIB_FAKEUSER) {
@@ -793,12 +798,12 @@ static void lib_relocate_do(Main *bmain,
id_fake_user_set(new_id);
}
-#ifdef PRINT_DEBUG
- printf("after remap of %s, old_id users: %d, new_id users: %d\n",
- old_id->name,
- old_id->us,
- new_id->us);
-#endif
+ CLOG_INFO(WM_LOG_OPERATORS,
+ 1,
+ "after remap of %s, old_id users: %d, new_id users: %d",
+ old_id->name,
+ old_id->us,
+ new_id->us);
/* In some cases, new_id might become direct link, remove parent of library in this case. */
if (new_id->lib->parent && (new_id->tag & LIB_TAG_INDIRECT) == 0) {
@@ -987,9 +992,11 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
}
if (BLI_path_cmp(lib->filepath_abs, path) == 0) {
-#ifdef PRINT_DEBUG
- printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
-#endif
+ CLOG_INFO(WM_LOG_OPERATORS,
+ 0,
+ "We are supposed to reload '%s' lib (%d)...\n",
+ lib->filepath,
+ lib->id.us);
do_reload = true;
@@ -999,9 +1006,11 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
else {
int totfiles = 0;
-#ifdef PRINT_DEBUG
- printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, libname);
-#endif
+ CLOG_INFO(WM_LOG_OPERATORS,
+ 0,
+ "We are supposed to relocate '%s' lib to new '%s' one...\n",
+ lib->filepath,
+ libname);
/* Check if something is indicated for relocate. */
prop = RNA_struct_find_property(op->ptr, "files");
@@ -1027,17 +1036,15 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
continue;
}
-#ifdef PRINT_DEBUG
- printf("\t candidate new lib to reload datablocks from: %s\n", path);
-#endif
+ CLOG_INFO(
+ WM_LOG_OPERATORS, 1, "\t candidate new lib to reload datablocks from: %s\n", path);
wm_link_append_data_library_add(lapp_data, path);
}
RNA_END;
}
else {
-#ifdef PRINT_DEBUG
- printf("\t candidate new lib to reload datablocks from: %s\n", path);
-#endif
+ CLOG_INFO(
+ WM_LOG_OPERATORS, 1, "\t candidate new lib to reload datablocks from: %s\n", path);
wm_link_append_data_library_add(lapp_data, path);
}
}
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index 6b2a74138c9..d2f47140c70 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -27,6 +27,7 @@
#include "DNA_userdef_types.h"
#include "DNA_vec_types.h"
#include "DNA_windowmanager_types.h"
+#include <CLG_log.h>
#include "MEM_guardedalloc.h"
@@ -167,28 +168,28 @@ int wm_gesture_evaluate(wmGesture *gesture, const wmEvent *event)
#if 0
/* debug */
if (val == 1) {
- printf("tweak north\n");
+ CLOG_INFO(WM_LOG_EVENTS, 2, "tweak north");
}
if (val == 2) {
- printf("tweak north-east\n");
+ CLOG_INFO(WM_LOG_EVENTS, 2, "tweak north-east");
}
if (val == 3) {
- printf("tweak east\n");
+ CLOG_INFO(WM_LOG_EVENTS, 2, "tweak east");
}
if (val == 4) {
- printf("tweak south-east\n");
+ CLOG_INFO(WM_LOG_EVENTS, 2, "tweak south-east");
}
if (val == 5) {
- printf("tweak south\n");
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list