[Bf-blender-cvs] [ab9126b] id-remap: Move most of (currently NoP) relocate code to WM area.
Bastien Montagne
noreply at git.blender.org
Thu Sep 17 21:01:12 CEST 2015
Commit: ab9126b7b5830d0391048969449d4da7036ba9bb
Author: Bastien Montagne
Date: Wed Sep 16 12:06:40 2015 +0200
Branches: id-remap
https://developer.blender.org/rBab9126b7b5830d0391048969449d4da7036ba9bb
Move most of (currently NoP) relocate code to WM area.
===================================================================
M source/blender/editors/space_outliner/outliner_edit.c
M source/blender/editors/space_outliner/outliner_tools.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 7bd1157..1ccb70c 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -301,12 +301,10 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
/* Library relocate --------------------------------------------------- */
-void item_lib_relocate_cb(
- bContext *C, Scene *UNUSED(scene), TreeElement *te,
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
+static int item_lib_relocate(bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot)
{
- wmOperatorType *ot = user_data;
PointerRNA op_props;
+ int ret = 0;
BLI_assert(te->idcode == ID_LI && tselem->id != NULL);
UNUSED_VARS_NDEBUG(te);
@@ -315,125 +313,70 @@ void item_lib_relocate_cb(
RNA_string_set(&op_props, "library", tselem->id->name);
- WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props);
+ ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props);
WM_operator_properties_free(&op_props);
+
+ return ret;
+}
+
+/* XXX This does work with several items (ot is only called once in the end...). */
+void item_lib_relocate_cb(
+ bContext *C, Scene *UNUSED(scene), TreeElement *te,
+ TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
+{
+ wmOperatorType *ot = user_data;
+
+ item_lib_relocate(C, te, tselem, ot);
}
-static Library *outliner_lib_relocate_invoke_findlib(TreeElement *te, const float mval[2])
+static int outliner_lib_relocate_invoke_do(bContext *C, ReportList *reports, TreeElement *te, const float mval[2])
{
if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
TreeStoreElem *tselem = TREESTORE(te);
if (te->idcode == ID_LI && tselem->id) {
- return (Library *)tselem->id;
+ if (((Library *)tselem->id)->parent) {
+ BKE_reportf(reports, RPT_ERROR_INVALID_INPUT,
+ "Cannot relocate indirectly linked library '%s'", ((Library *)tselem->id)->filepath);
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false);
+
+ return item_lib_relocate(C, te, tselem, ot);
+ }
}
}
else {
for (te = te->subtree.first; te; te = te->next) {
- Library *lib;
- if ((lib = outliner_lib_relocate_invoke_findlib(te, mval))) {
- return lib;
+ int ret;
+ if ((ret = outliner_lib_relocate_invoke_do(C, reports, te, mval)) >= 0) {
+ return ret;
}
}
}
- return NULL;
+ return -1;
}
static int outliner_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- ARegion *ar;
- SpaceOops *soops;
+ ARegion *ar = CTX_wm_region(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
TreeElement *te;
- Library *lib;
- char lib_name[MAX_ID_NAME];
-
- RNA_string_get(op->ptr, "library", lib_name);
- lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
-
- if (!lib && (soops = CTX_wm_space_outliner(C)) && (ar = CTX_wm_region(C))) {
- float fmval[2];
-
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
-
- for (te = soops->tree.first; te; te = te->next) {
- if ((lib = outliner_lib_relocate_invoke_findlib(te, fmval))) {
- RNA_string_set(op->ptr, "library", lib->id.name);
- break;
- }
- }
- }
-
- if (lib) {
- if (lib->parent) {
- BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
- "Cannot relocate indirectly linked library '%s'", lib->filepath);
- return OPERATOR_CANCELLED;
- }
- RNA_string_set(op->ptr, "filepath", lib->filepath);
-
- WM_event_add_fileselect(C, op);
-
- return OPERATOR_RUNNING_MODAL;
- }
-
- return OPERATOR_CANCELLED;
-}
-
-static int outliner_lib_relocate_exec(bContext *C, wmOperator *op)
-{
- Library *lib;
- char lib_name[MAX_ID_NAME];
-
- RNA_string_get(op->ptr, "library", lib_name);
- lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
-
- if (lib) {
- char filepath[FILE_MAXFILE];
-
- if (lib->parent) {
- BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
- "Cannot relocate indirectly linked library '%s'", lib->filepath);
- return OPERATOR_CANCELLED;
- }
-
- RNA_string_get(op->ptr, "filepath", filepath);
-
- if (BLI_path_cmp(lib->filepath, filepath) == 0) {
- /* Reload, not relocate... */
- return OPERATOR_FINISHED;
- }
-
- printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, filepath);
-
- {
- const size_t max_id_path_len = BLO_GROUP_MAX + MAX_NAME;
- BLI_Stack *id_paths_todo = BLI_stack_new(max_id_path_len, __func__);
-
- Main *bmain = CTX_data_main(C);
- ListBase *lbarray[MAX_LIBARRAY];
- int a;
-
- a = set_listbasepointers(bmain, lbarray);
- while (a--) {
- ID *id;
+ float fmval[2];
- for (id = lbarray[a]->first; id; id = id->next) {
- if (id->lib == lib) {
- char *id_path = BLI_stack_push_r(id_paths_todo);
+ BLI_assert(ar && soops);
- BLI_snprintf(id_path, max_id_path_len, "%s/%s", BKE_idcode_to_name(GS(id->name)), id->name + 2);
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
- printf("\t%s will be remapped\n", id_path);
- }
- }
- }
+ for (te = soops->tree.first; te; te = te->next) {
+ int ret;
- BLI_stack_free(id_paths_todo);
+ if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval)) >= 0) {
+ return ret;
}
-
- return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
@@ -446,13 +389,7 @@ void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
ot->description = "Relocate library under cursor";
ot->invoke = outliner_lib_relocate_invoke;
- ot->exec = outliner_lib_relocate_exec;
- /* ot->poll = ED_operator_outliner_active; */ /* Can also be used outside of Outliner context. */
-
- RNA_def_string(ot->srna, "library", NULL, MAX_ID_NAME, "Library", "Library to relocate");
-
- WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER, FILE_BLENDER, FILE_OPENFILE,
- WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+ ot->poll = ED_operator_outliner_active;
}
/* ************************************************************** */
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index 63190a5..40fc6af 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -1299,7 +1299,7 @@ static int outliner_lib_operation_exec(bContext *C, wmOperator *op)
}
case OL_LIB_RELOCATE:
{
- wmOperatorType *ot = WM_operatortype_find("OUTLINER_OT_lib_relocate", false);
+ wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false);
/* rename */
outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_lib_relocate_cb, ot);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index c9dd072..63c5c61 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -63,6 +63,7 @@
#include "BLI_dynstr.h" /*for WM_operator_pystring */
#include "BLI_linklist_stack.h"
#include "BLI_math.h"
+#include "BLI_stack.h"
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
@@ -2857,6 +2858,108 @@ static void WM_OT_append(wmOperatorType *ot)
wm_link_append_properties_common(ot, false);
}
+
+static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ Library *lib;
+ char lib_name[MAX_ID_NAME];
+
+ RNA_string_get(op->ptr, "library", lib_name);
+ lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
+
+ if (lib) {
+ if (lib->parent) {
+ BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
+ "Cannot relocate indirectly linked library '%s'", lib->filepath);
+ return OPERATOR_CANCELLED;
+ }
+ RNA_string_set(op->ptr, "filepath", lib->filepath);
+
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static int wm_lib_relocate_exec(bContext *C, wmOperator *op)
+{
+ Library *lib;
+ char lib_name[MAX_ID_NAME];
+
+ RNA_string_get(op->ptr, "library", lib_name);
+ lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
+
+ if (lib) {
+ char filepath[FILE_MAXFILE];
+
+ if (lib->parent) {
+ BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
+ "Cannot relocate indirectly linked library '%s'", lib->filepath);
+ return OPERATOR_CANCELLED;
+ }
+
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (BLI_path_cmp(lib->filepath, filepath) == 0) {
+ printf("We are supposed to reload '%s' lib...\n", lib->filepath);
+
+ return OPERATOR_FINISHED;
+ }
+
+ printf("We are supposed to relocate '%s' lib to new '%s' one...\n", lib->filepath, filepath);
+
+ {
+ const size_t max_id_path_len = BLO_GROUP_MAX + MAX_NAME;
+ BLI_Stack *id_paths_todo = BLI_stack_new(max_id_path_len, __func__);
+
+ Main *bmain = CTX_data_main(C);
+ ListBase *lbarray[MAX_LIBARRAY];
+ int a;
+
+ a = set_listbasepointers(bmain, lbarray);
+ while (a--) {
+ ID *id;
+
+ for (id = lbarray[a]->first; id; id = id->next) {
+ if (id->lib == lib) {
+ char *id_path = BLI_stack_push_r(id_paths_todo);
+
+ BLI_snprintf(id_path, max_id_path_len, "%s/%s", BKE_idcode_to_name(GS(id->name)), id->name + 2);
+
+ printf("\t%s will be remapped\n", id_path);
+ }
+ }
+ }
+
+ BLI_stack_free(id_paths_todo);
+ }
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void WM_OT_lib_relocate(wmOperatorType *ot)
+{
+ ot->name = "Relocate Library";
+ ot->idname = "WM_OT_lib_relocate";
+ ot->description = "Relocate given library to another one";
+
+ ot->invoke = wm_lib_relocate_invoke;
+ ot->exec = wm_lib_relocate_exec;
+
+ ot->flag |= OPTYPE_UNDO;
+
+ RNA_def_string(ot->srna, "library", NULL, MAX_ID_NAME, "Library", "Library to relocate");
+
+ WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list