Cleanup: use local utility functions for clipboard file-paths
Also rename pose paste `tmp_bmain` to match the name used in copying.
This commit is contained in:
@@ -51,6 +51,17 @@
|
||||
|
||||
#include "armature_intern.h"
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Local Utilities
|
||||
* \{ */
|
||||
|
||||
static void pose_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
|
||||
{
|
||||
BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer_pose.blend");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Apply Pose as Rest Pose
|
||||
* \{ */
|
||||
@@ -789,7 +800,8 @@ static int pose_copy_exec(bContext *C, wmOperator *op)
|
||||
* existing on its own.
|
||||
*/
|
||||
BKE_copybuffer_copy_tag_ID(&ob_copy.id);
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer_pose.blend");
|
||||
|
||||
pose_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
BKE_copybuffer_copy_end(temp_bmain, filepath, op->reports);
|
||||
/* We clear the lists so no datablocks gets freed,
|
||||
* This is required because objects in temp bmain shares same pointers
|
||||
@@ -842,27 +854,27 @@ static int pose_paste_exec(bContext *C, wmOperator *op)
|
||||
|
||||
/* Read copy buffer .blend file. */
|
||||
char filepath[FILE_MAX];
|
||||
Main *tmp_bmain = BKE_main_new();
|
||||
STRNCPY(tmp_bmain->filepath, BKE_main_blendfile_path_from_global());
|
||||
Main *temp_bmain = BKE_main_new();
|
||||
STRNCPY(temp_bmain->filepath, BKE_main_blendfile_path_from_global());
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer_pose.blend");
|
||||
if (!BKE_copybuffer_read(tmp_bmain, filepath, op->reports, FILTER_ID_OB)) {
|
||||
pose_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
if (!BKE_copybuffer_read(temp_bmain, filepath, op->reports, FILTER_ID_OB)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Internal clipboard is empty");
|
||||
BKE_main_free(tmp_bmain);
|
||||
BKE_main_free(temp_bmain);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* Make sure data from this file is usable for pose paste. */
|
||||
if (BLI_listbase_count_at_most(&tmp_bmain->objects, 2) != 1) {
|
||||
if (BLI_listbase_count_at_most(&temp_bmain->objects, 2) != 1) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Internal clipboard is not from pose mode");
|
||||
BKE_main_free(tmp_bmain);
|
||||
BKE_main_free(temp_bmain);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
Object *object_from = tmp_bmain->objects.first;
|
||||
Object *object_from = temp_bmain->objects.first;
|
||||
bPose *pose_from = object_from->pose;
|
||||
if (pose_from == NULL) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Internal clipboard has no pose");
|
||||
BKE_main_free(tmp_bmain);
|
||||
BKE_main_free(temp_bmain);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
@@ -889,7 +901,7 @@ static int pose_paste_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
}
|
||||
BKE_main_free(tmp_bmain);
|
||||
BKE_main_free(temp_bmain);
|
||||
|
||||
/* Update event for pose and deformation children. */
|
||||
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
||||
|
||||
@@ -101,6 +101,11 @@ static bool object_materials_supported_poll_ex(bContext *C, const Object *ob);
|
||||
/** \name Local Utilities
|
||||
* \{ */
|
||||
|
||||
static void material_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
|
||||
{
|
||||
BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer_material.blend");
|
||||
}
|
||||
|
||||
static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob, void *user_data)
|
||||
{
|
||||
bContext *C = static_cast<bContext *>(user_data);
|
||||
@@ -2754,7 +2759,7 @@ static int copy_material_exec(bContext *C, wmOperator *op)
|
||||
|
||||
BKE_copybuffer_copy_tag_ID(&ma->id);
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer_material.blend");
|
||||
material_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
BKE_copybuffer_copy_end(bmain, filepath, op->reports);
|
||||
|
||||
/* We are all done! */
|
||||
@@ -2838,7 +2843,8 @@ static int paste_material_exec(bContext *C, wmOperator *op)
|
||||
Main *temp_bmain = BKE_main_new();
|
||||
|
||||
STRNCPY(temp_bmain->filepath, BKE_main_blendfile_path_from_global());
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer_material.blend");
|
||||
|
||||
material_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
|
||||
/* NOTE(@ideasman42) The node tree might reference different kinds of ID types.
|
||||
* It's not clear-cut which ID types should be included, although it's unlikely
|
||||
|
||||
@@ -74,6 +74,18 @@ static void outliner_show_active(SpaceOutliner *space_outliner,
|
||||
TreeElement *te,
|
||||
ID *id);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Local Utilities
|
||||
* \{ */
|
||||
|
||||
static void outliner_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
|
||||
{
|
||||
/* NOTE: this uses the same path as the 3D viewport. */
|
||||
BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer.blend");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Highlight on Cursor Motion Operator
|
||||
* \{ */
|
||||
@@ -817,7 +829,7 @@ static int outliner_id_copy_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer.blend");
|
||||
outliner_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
BKE_copybuffer_copy_end(bmain, filepath, op->reports);
|
||||
|
||||
BKE_reportf(op->reports, RPT_INFO, "Copied %d selected data-block(s)", num_ids);
|
||||
@@ -851,7 +863,7 @@ static int outliner_id_paste_exec(bContext *C, wmOperator *op)
|
||||
char filepath[FILE_MAX];
|
||||
const short flag = FILE_AUTOSELECT | FILE_ACTIVE_COLLECTION;
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer.blend");
|
||||
outliner_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
|
||||
const int num_pasted = BKE_copybuffer_paste(C, filepath, flag, op->reports, 0);
|
||||
if (num_pasted == 0) {
|
||||
|
||||
@@ -41,6 +41,17 @@
|
||||
# include "BLI_math_base.h" /* M_PI */
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Local Utilities
|
||||
* \{ */
|
||||
|
||||
static void view3d_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
|
||||
{
|
||||
BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer.blend");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* ************************** copy paste ***************************** */
|
||||
|
||||
static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
|
||||
@@ -60,7 +71,7 @@ static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer.blend");
|
||||
view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
BKE_copybuffer_copy_end(bmain, filepath, op->reports);
|
||||
|
||||
BKE_reportf(op->reports, RPT_INFO, "Copied %d selected object(s)", num_copied);
|
||||
@@ -92,7 +103,7 @@ static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
|
||||
flag |= FILE_ACTIVE_COLLECTION;
|
||||
}
|
||||
|
||||
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_base(), "copybuffer.blend");
|
||||
view3d_copybuffer_filepath_get(filepath, sizeof(filepath));
|
||||
|
||||
const int num_pasted = BKE_copybuffer_paste(C, filepath, flag, op->reports, FILTER_ID_OB);
|
||||
if (num_pasted == 0) {
|
||||
|
||||
Reference in New Issue
Block a user