2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-12-17 10:47:55 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-05-23 10:47:12 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2009-12-17 10:47:55 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-12-17 10:47:55 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edinterface
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2018-11-20 17:34:56 +11:00
|
|
|
#include "DNA_armature_types.h"
|
2010-03-30 04:27:13 +00:00
|
|
|
#include "DNA_screen_types.h"
|
2010-11-17 12:02:36 +00:00
|
|
|
#include "DNA_text_types.h" /* for UI_OT_reports_to_text */
|
2015-05-13 07:23:03 +10:00
|
|
|
#include "DNA_object_types.h" /* for OB_DATA_SUPPORT_ID */
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "BLI_math_color.h"
|
2009-12-17 10:47:55 +00:00
|
|
|
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
#include "BLF_api.h"
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_lang.h"
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
#include "BKE_context.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_global.h"
|
2017-03-30 17:01:23 +02:00
|
|
|
#include "BKE_idprop.h"
|
|
|
|
#include "BKE_layer.h"
|
2018-11-07 15:37:31 +01:00
|
|
|
#include "BKE_library.h"
|
2017-11-29 17:03:52 +01:00
|
|
|
#include "BKE_library_override.h"
|
2015-05-14 06:23:41 +10:00
|
|
|
#include "BKE_node.h"
|
2010-11-17 12:02:36 +00:00
|
|
|
#include "BKE_report.h"
|
2018-11-07 18:00:24 +01:00
|
|
|
#include "BKE_screen.h"
|
|
|
|
#include "BKE_text.h" /* for UI_OT_reports_to_text */
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2018-12-13 18:28:41 +01:00
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2017-03-30 17:01:23 +02:00
|
|
|
#include "RNA_types.h"
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2010-03-30 04:27:13 +00:00
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "interface_intern.h"
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2018-11-20 17:34:56 +11:00
|
|
|
#include "ED_object.h"
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "ED_paint.h"
|
|
|
|
|
2011-10-23 04:13:56 +00:00
|
|
|
/* only for UI_OT_editsource */
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BLI_ghash.h"
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy Data Path Operator
|
|
|
|
* \{ */
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool copy_data_path_button_poll(bContext *C)
|
2012-05-09 15:54:25 +00:00
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
char *path;
|
|
|
|
int index;
|
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2012-05-09 15:54:25 +00:00
|
|
|
|
|
|
|
if (ptr.id.data && ptr.data && prop) {
|
|
|
|
path = RNA_path_from_ID_to_property(&ptr, prop);
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2012-05-09 15:54:25 +00:00
|
|
|
if (path) {
|
|
|
|
MEM_freeN(path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-20 00:27:14 +02:00
|
|
|
static int copy_data_path_button_exec(bContext *C, wmOperator *op)
|
2009-12-17 10:47:55 +00:00
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
2009-12-17 17:15:38 +00:00
|
|
|
PropertyRNA *prop;
|
2009-12-17 10:47:55 +00:00
|
|
|
char *path;
|
|
|
|
int index;
|
|
|
|
|
2016-10-20 00:27:14 +02:00
|
|
|
const bool full_path = RNA_boolean_get(op->ptr, "full_path");
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
/* try to create driver using property retrieved from UI */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2016-10-20 00:27:14 +02:00
|
|
|
if (ptr.id.data != NULL) {
|
|
|
|
|
|
|
|
if (full_path) {
|
|
|
|
|
|
|
|
if (prop) {
|
|
|
|
path = RNA_path_full_property_py_ex(&ptr, prop, index, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path = RNA_path_full_struct_py(&ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path = RNA_path_from_ID_to_property(&ptr, prop);
|
|
|
|
}
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
if (path) {
|
2014-01-04 17:16:19 +11:00
|
|
|
WM_clipboard_text_set(path, false);
|
2009-12-17 10:47:55 +00:00
|
|
|
MEM_freeN(path);
|
2012-05-09 15:54:25 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 15:54:25 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static void UI_OT_copy_data_path_button(wmOperatorType *ot)
|
2009-12-17 10:47:55 +00:00
|
|
|
{
|
2016-10-20 00:27:14 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy Data Path";
|
|
|
|
ot->idname = "UI_OT_copy_data_path_button";
|
|
|
|
ot->description = "Copy the RNA data path for this property to the clipboard";
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = copy_data_path_button_exec;
|
2012-05-09 15:54:25 +00:00
|
|
|
ot->poll = copy_data_path_button_poll;
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER;
|
2016-10-20 00:27:14 +02:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
prop = RNA_def_boolean(ot->srna, "full_path", false, "full_path", "Copy full data path");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool copy_python_command_button_poll(bContext *C)
|
2016-02-26 11:57:35 +11:00
|
|
|
{
|
|
|
|
uiBut *but = UI_context_active_but_get(C);
|
|
|
|
|
|
|
|
if (but && (but->optype != NULL)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy Python Command Operator
|
|
|
|
* \{ */
|
|
|
|
|
2016-02-26 11:57:35 +11:00
|
|
|
static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
uiBut *but = UI_context_active_but_get(C);
|
|
|
|
|
|
|
|
if (but && (but->optype != NULL)) {
|
|
|
|
PointerRNA *opptr;
|
|
|
|
char *str;
|
|
|
|
opptr = UI_but_operator_ptr_get(but); /* allocated when needed, the button owns it */
|
|
|
|
|
|
|
|
str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr);
|
|
|
|
|
|
|
|
WM_clipboard_text_set(str, 0);
|
|
|
|
|
|
|
|
MEM_freeN(str);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_copy_python_command_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Copy Python Command";
|
|
|
|
ot->idname = "UI_OT_copy_python_command_button";
|
|
|
|
ot->description = "Copy the Python command matching this button";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = copy_python_command_button_exec;
|
|
|
|
ot->poll = copy_python_command_button_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER;
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Reset to Default Values Button Operator
|
|
|
|
* \{ */
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2013-09-20 09:10:17 +00:00
|
|
|
static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
|
|
|
|
{
|
|
|
|
ID *id = ptr->id.data;
|
|
|
|
|
|
|
|
/* perform updates required for this property */
|
|
|
|
RNA_property_update(C, ptr, prop);
|
|
|
|
|
|
|
|
/* as if we pressed the button */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_handle(C);
|
2013-09-20 09:10:17 +00:00
|
|
|
|
|
|
|
/* Since we don't want to undo _all_ edits to settings, eg window
|
|
|
|
* edits on the screen or on operator settings.
|
|
|
|
* it might be better to move undo's inline - campbell */
|
|
|
|
if (id && ID_CHECK_UNDO(id)) {
|
|
|
|
/* do nothing, go ahead with undo */
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool reset_default_button_poll(bContext *C)
|
2009-12-17 17:15:38 +00:00
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2009-12-17 17:15:38 +00:00
|
|
|
return (ptr.data && prop && RNA_property_editable(&ptr, prop));
|
|
|
|
}
|
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
static int reset_default_button_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
2009-12-17 17:15:38 +00:00
|
|
|
PropertyRNA *prop;
|
2014-02-03 18:55:59 +11:00
|
|
|
int index;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
/* try to reset the nominated setting to its default value */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
/* if there is a valid property that is editable... */
|
|
|
|
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
|
2019-03-25 10:15:20 +11:00
|
|
|
if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) {
|
2013-09-20 09:10:17 +00:00
|
|
|
return operator_button_property_finish(C, &ptr, prop);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2011-09-28 18:45:17 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 09:10:17 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static void UI_OT_reset_default_button(wmOperatorType *ot)
|
2009-12-17 10:47:55 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Reset to Default Value";
|
|
|
|
ot->idname = "UI_OT_reset_default_button";
|
|
|
|
ot->description = "Reset this property's value to its default value";
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = reset_default_button_poll;
|
|
|
|
ot->exec = reset_default_button_exec;
|
2009-12-17 10:47:55 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_UNDO;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2009-12-17 17:15:38 +00:00
|
|
|
/* properties */
|
2011-09-19 12:26:20 +00:00
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
|
2009-12-17 17:15:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Assign Value as Default Button Operator
|
|
|
|
* \{ */
|
2018-12-15 22:37:12 +03:00
|
|
|
|
|
|
|
static bool assign_default_button_poll(bContext *C)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
|
|
|
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
|
|
|
|
PropertyType type = RNA_property_type(prop);
|
|
|
|
|
|
|
|
return RNA_property_is_idprop(prop) && !RNA_property_array_check(prop) && ELEM(type, PROP_INT, PROP_FLOAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int assign_default_button_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
/* try to reset the nominated setting to its default value */
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
|
|
|
/* if there is a valid property that is editable... */
|
|
|
|
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
|
2019-03-25 10:15:20 +11:00
|
|
|
if (RNA_property_assign_default(&ptr, prop)) {
|
2018-12-15 22:37:12 +03:00
|
|
|
return operator_button_property_finish(C, &ptr, prop);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2018-12-15 22:37:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_assign_default_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Assign Value as Default";
|
|
|
|
ot->idname = "UI_OT_assign_default_button";
|
|
|
|
ot->description = "Set this property's current value as the new default";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->poll = assign_default_button_poll;
|
|
|
|
ot->exec = assign_default_button_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Unset Property Button Operator
|
|
|
|
* \{ */
|
2013-09-20 09:10:17 +00:00
|
|
|
|
|
|
|
static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
/* try to unset the nominated property */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2013-09-20 09:10:17 +00:00
|
|
|
|
|
|
|
/* if there is a valid property that is editable... */
|
2014-02-28 11:04:15 +11:00
|
|
|
if (ptr.data && prop && RNA_property_editable(&ptr, prop) &&
|
|
|
|
/* RNA_property_is_idprop(prop) && */
|
|
|
|
RNA_property_is_set(&ptr, prop))
|
2013-09-20 09:10:17 +00:00
|
|
|
{
|
|
|
|
RNA_property_unset(&ptr, prop);
|
|
|
|
return operator_button_property_finish(C, &ptr, prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_unset_property_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Unset property";
|
|
|
|
ot->idname = "UI_OT_unset_property_button";
|
|
|
|
ot->description = "Clear the property and use default or generated value in operators";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->poll = ED_operator_regionactive;
|
|
|
|
ot->exec = unset_property_button_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Define Override Type Operator
|
|
|
|
* \{ */
|
2017-11-29 17:03:52 +01:00
|
|
|
|
|
|
|
/* Note that we use different values for UI/UX than 'real' override operations, user does not care
|
|
|
|
* whether it's added or removed for the differential operation e.g. */
|
|
|
|
enum {
|
|
|
|
UIOverride_Type_NOOP = 0,
|
|
|
|
UIOverride_Type_Replace = 1,
|
|
|
|
UIOverride_Type_Difference = 2, /* Add/subtract */
|
|
|
|
UIOverride_Type_Factor = 3, /* Multiply */
|
|
|
|
/* TODO: should/can we expose insert/remove ones for collections? Doubt it... */
|
|
|
|
};
|
|
|
|
|
|
|
|
static EnumPropertyItem override_type_items[] = {
|
|
|
|
{UIOverride_Type_NOOP, "NOOP", 0, "NoOp",
|
2018-07-01 20:15:21 +02:00
|
|
|
"'No-Operation', place holder preventing automatic override to ever affect the property"},
|
2017-11-29 17:03:52 +01:00
|
|
|
{UIOverride_Type_Replace, "REPLACE", 0, "Replace", "Completely replace value from linked data by local one"},
|
|
|
|
{UIOverride_Type_Difference, "DIFFERENCE", 0, "Difference", "Store difference to linked data value"},
|
|
|
|
{UIOverride_Type_Factor, "FACTOR", 0, "Factor", "Store factor to linked data value (useful e.g. for scale)"},
|
2019-02-03 14:01:45 +11:00
|
|
|
{0, NULL, 0, NULL, NULL},
|
2017-11-29 17:03:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-07-02 12:03:56 +02:00
|
|
|
static bool override_type_set_button_poll(bContext *C)
|
2017-11-29 17:03:52 +01:00
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
2018-05-09 16:17:15 +02:00
|
|
|
const int override_status = RNA_property_static_override_status(&ptr, prop, index);
|
2017-11-29 17:03:52 +01:00
|
|
|
|
2018-03-14 11:47:35 +01:00
|
|
|
return (ptr.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDABLE));
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int override_type_set_button_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
bool created;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
const int op_type = RNA_enum_get(op->ptr, "type");
|
|
|
|
|
|
|
|
short operation;
|
|
|
|
|
2017-12-04 17:19:34 +11:00
|
|
|
switch (op_type) {
|
2017-11-29 17:03:52 +01:00
|
|
|
case UIOverride_Type_NOOP:
|
|
|
|
operation = IDOVERRIDESTATIC_OP_NOOP;
|
|
|
|
break;
|
|
|
|
case UIOverride_Type_Replace:
|
|
|
|
operation = IDOVERRIDESTATIC_OP_REPLACE;
|
|
|
|
break;
|
|
|
|
case UIOverride_Type_Difference:
|
2019-01-15 23:24:20 +11:00
|
|
|
/* override code will automatically switch to subtract if needed. */
|
|
|
|
operation = IDOVERRIDESTATIC_OP_ADD;
|
2017-11-29 17:03:52 +01:00
|
|
|
break;
|
|
|
|
case UIOverride_Type_Factor:
|
|
|
|
operation = IDOVERRIDESTATIC_OP_MULTIPLY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
operation = IDOVERRIDESTATIC_OP_REPLACE;
|
|
|
|
BLI_assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to reset the nominated setting to its default value */
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
|
|
|
BLI_assert(ptr.id.data != NULL);
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDOverrideStaticPropertyOperation *opop = RNA_property_override_property_operation_get(
|
2018-07-01 20:15:21 +02:00
|
|
|
&ptr, prop, operation, index, true, NULL, &created);
|
2017-11-29 17:03:52 +01:00
|
|
|
if (!created) {
|
|
|
|
opop->operation = operation;
|
|
|
|
}
|
|
|
|
|
|
|
|
return operator_button_property_finish(C, &ptr, prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int override_type_set_button_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
2018-04-23 15:14:51 +02:00
|
|
|
#if 0 /* Disabled for now */
|
2017-11-29 17:03:52 +01:00
|
|
|
return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_DEFAULT);
|
2018-04-23 15:14:51 +02:00
|
|
|
#else
|
|
|
|
RNA_enum_set(op->ptr, "type", IDOVERRIDESTATIC_OP_REPLACE);
|
|
|
|
return override_type_set_button_exec(C, op);
|
|
|
|
#endif
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_override_type_set_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Define Override Type";
|
|
|
|
ot->idname = "UI_OT_override_type_set_button";
|
|
|
|
ot->description = "Create an override operation, or set the type of an existing one";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->poll = override_type_set_button_poll;
|
|
|
|
ot->exec = override_type_set_button_exec;
|
|
|
|
ot->invoke = override_type_set_button_invoke;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
|
2018-07-01 20:15:21 +02:00
|
|
|
ot->prop = RNA_def_enum(
|
|
|
|
ot->srna, "type", override_type_items, UIOverride_Type_Replace,
|
|
|
|
"Type", "Type of override operation");
|
2018-04-23 15:14:51 +02:00
|
|
|
/* TODO: add itemf callback, not all options are available for all data types... */
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-02 12:03:56 +02:00
|
|
|
static bool override_remove_button_poll(bContext *C)
|
2017-11-29 17:03:52 +01:00
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
2018-05-09 16:17:15 +02:00
|
|
|
const int override_status = RNA_property_static_override_status(&ptr, prop, index);
|
2017-11-29 17:03:52 +01:00
|
|
|
|
2018-03-14 11:47:35 +01:00
|
|
|
return (ptr.data && ptr.id.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN));
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int override_remove_button_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-06-29 12:46:54 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2017-11-29 17:03:52 +01:00
|
|
|
PointerRNA ptr, id_refptr, src;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
|
|
|
|
|
|
|
/* try to reset the nominated setting to its default value */
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
|
|
|
ID *id = ptr.id.data;
|
|
|
|
IDOverrideStaticProperty *oprop = RNA_property_override_property_find(&ptr, prop);
|
|
|
|
BLI_assert(oprop != NULL);
|
|
|
|
BLI_assert(id != NULL && id->override_static != NULL);
|
|
|
|
|
|
|
|
const bool is_template = (id->override_static->reference == NULL);
|
|
|
|
|
|
|
|
/* We need source (i.e. linked data) to restore values of deleted overrides...
|
|
|
|
* If this is an override template, we obviously do not need to restore anything. */
|
|
|
|
if (!is_template) {
|
|
|
|
RNA_id_pointer_create(id->override_static->reference, &id_refptr);
|
|
|
|
if (!RNA_path_resolve(&id_refptr, oprop->rna_path, &src, NULL)) {
|
|
|
|
BLI_assert(0 && "Failed to create matching source (linked data) RNA pointer");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!all && index != -1) {
|
|
|
|
bool is_strict_find;
|
2019-01-15 23:24:20 +11:00
|
|
|
/* Remove override operation for given item,
|
|
|
|
* add singular operations for the other items as needed. */
|
2017-11-29 17:03:52 +01:00
|
|
|
IDOverrideStaticPropertyOperation *opop = BKE_override_static_property_operation_find(
|
2018-07-01 20:15:21 +02:00
|
|
|
oprop, NULL, NULL, index, index, false, &is_strict_find);
|
2017-11-29 17:03:52 +01:00
|
|
|
BLI_assert(opop != NULL);
|
|
|
|
if (!is_strict_find) {
|
|
|
|
/* No specific override operation, we have to get generic one,
|
2019-01-15 23:24:20 +11:00
|
|
|
* and create item-specific override operations for all but given index,
|
|
|
|
* before removing generic one. */
|
2017-11-29 17:03:52 +01:00
|
|
|
for (int idx = RNA_property_array_length(&ptr, prop); idx--; ) {
|
|
|
|
if (idx != index) {
|
|
|
|
BKE_override_static_property_operation_get(oprop, opop->operation, NULL, NULL, idx, idx, true, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BKE_override_static_property_operation_delete(oprop, opop);
|
|
|
|
if (!is_template) {
|
2018-06-29 12:46:54 +02:00
|
|
|
RNA_property_copy(bmain, &ptr, &src, prop, index);
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
if (BLI_listbase_is_empty(&oprop->operations)) {
|
|
|
|
BKE_override_static_property_delete(id->override_static, oprop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Just remove whole generic override operation of this property. */
|
|
|
|
BKE_override_static_property_delete(id->override_static, oprop);
|
|
|
|
if (!is_template) {
|
2018-06-29 12:46:54 +02:00
|
|
|
RNA_property_copy(bmain, &ptr, &src, prop, -1);
|
2017-11-29 17:03:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return operator_button_property_finish(C, &ptr, prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_override_remove_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Override";
|
|
|
|
ot->idname = "UI_OT_override_remove_button";
|
|
|
|
ot->description = "Remove an override operation";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->poll = override_remove_button_poll;
|
|
|
|
ot->exec = override_remove_button_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
2017-11-29 17:03:52 +01:00
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Copy To Selected Operator
|
|
|
|
* \{ */
|
2009-12-17 17:15:38 +00:00
|
|
|
|
2015-05-11 15:32:43 +10:00
|
|
|
bool UI_context_copy_to_selected_list(
|
2014-08-05 18:59:02 +02:00
|
|
|
bContext *C, PointerRNA *ptr, PropertyRNA *prop,
|
|
|
|
ListBase *r_lb, bool *r_use_path_from_id, char **r_path)
|
2009-12-17 17:15:38 +00:00
|
|
|
{
|
2014-08-05 18:59:02 +02:00
|
|
|
*r_use_path_from_id = false;
|
|
|
|
*r_path = NULL;
|
|
|
|
|
|
|
|
if (RNA_struct_is_a(ptr->type, &RNA_EditBone)) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_editable_bones");
|
|
|
|
}
|
|
|
|
else if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_pose_bones");
|
|
|
|
}
|
2015-07-21 15:08:06 +10:00
|
|
|
else if (RNA_struct_is_a(ptr->type, &RNA_Bone)) {
|
|
|
|
ListBase lb;
|
|
|
|
lb = CTX_data_collection_get(C, "selected_pose_bones");
|
|
|
|
|
|
|
|
if (!BLI_listbase_is_empty(&lb)) {
|
|
|
|
CollectionPointerLink *link;
|
|
|
|
for (link = lb.first; link; link = link->next) {
|
|
|
|
bPoseChannel *pchan = link->ptr.data;
|
|
|
|
RNA_pointer_create(link->ptr.id.data, &RNA_Bone, pchan->bone, &link->ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_lb = lb;
|
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
else if (RNA_struct_is_a(ptr->type, &RNA_Sequence)) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_editable_sequences");
|
|
|
|
}
|
2017-08-19 19:58:39 +03:00
|
|
|
else if (RNA_struct_is_a(ptr->type, &RNA_FCurve)) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_editable_fcurves");
|
|
|
|
}
|
2015-05-14 06:23:41 +10:00
|
|
|
else if (RNA_struct_is_a(ptr->type, &RNA_Node) ||
|
|
|
|
RNA_struct_is_a(ptr->type, &RNA_NodeSocket))
|
|
|
|
{
|
|
|
|
ListBase lb = {NULL, NULL};
|
|
|
|
char *path = NULL;
|
|
|
|
bNode *node = NULL;
|
|
|
|
|
|
|
|
/* Get the node we're editing */
|
|
|
|
if (RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
|
|
|
|
bNodeTree *ntree = ptr->id.data;
|
|
|
|
bNodeSocket *sock = ptr->data;
|
|
|
|
if (nodeFindNode(ntree, sock, &node, NULL)) {
|
|
|
|
if ((path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Node)) != NULL) {
|
|
|
|
/* we're good! */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node = ptr->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now filter by type */
|
|
|
|
if (node) {
|
|
|
|
CollectionPointerLink *link, *link_next;
|
|
|
|
lb = CTX_data_collection_get(C, "selected_nodes");
|
|
|
|
|
|
|
|
for (link = lb.first; link; link = link_next) {
|
|
|
|
bNode *node_data = link->ptr.data;
|
|
|
|
link_next = link->next;
|
|
|
|
|
|
|
|
if (node_data->type != node->type) {
|
|
|
|
BLI_remlink(&lb, link);
|
|
|
|
MEM_freeN(link);
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 09:22:42 +10:00
|
|
|
}
|
2015-05-14 06:23:41 +10:00
|
|
|
|
|
|
|
*r_lb = lb;
|
|
|
|
*r_path = path;
|
2015-05-13 09:22:42 +10:00
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
else if (ptr->id.data) {
|
2012-04-10 15:49:41 +00:00
|
|
|
ID *id = ptr->id.data;
|
|
|
|
|
2014-08-05 18:59:02 +02:00
|
|
|
if (GS(id->name) == ID_OB) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_editable_objects");
|
|
|
|
*r_use_path_from_id = true;
|
|
|
|
*r_path = RNA_path_from_ID_to_property(ptr, prop);
|
2014-01-04 17:16:19 +11:00
|
|
|
}
|
2015-05-13 07:23:03 +10:00
|
|
|
else if (OB_DATA_SUPPORT_ID(GS(id->name))) {
|
|
|
|
/* check we're using the active object */
|
2015-05-13 07:36:43 +10:00
|
|
|
const short id_code = GS(id->name);
|
|
|
|
ListBase lb = CTX_data_collection_get(C, "selected_editable_objects");
|
|
|
|
char *path = RNA_path_from_ID_to_property(ptr, prop);
|
|
|
|
|
|
|
|
/* de-duplicate obdata */
|
|
|
|
if (!BLI_listbase_is_empty(&lb)) {
|
|
|
|
CollectionPointerLink *link, *link_next;
|
|
|
|
|
|
|
|
for (link = lb.first; link; link = link->next) {
|
|
|
|
Object *ob = link->ptr.id.data;
|
|
|
|
if (ob->data) {
|
|
|
|
ID *id_data = ob->data;
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
id_data->tag |= LIB_TAG_DOIT;
|
2015-05-13 07:36:43 +10:00
|
|
|
}
|
2015-05-13 07:23:03 +10:00
|
|
|
}
|
|
|
|
|
2015-05-13 07:36:43 +10:00
|
|
|
for (link = lb.first; link; link = link_next) {
|
|
|
|
Object *ob = link->ptr.id.data;
|
|
|
|
ID *id_data = ob->data;
|
|
|
|
link_next = link->next;
|
|
|
|
|
|
|
|
if ((id_data == NULL) ||
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
(id_data->tag & LIB_TAG_DOIT) == 0 ||
|
2017-11-06 17:17:10 +01:00
|
|
|
ID_IS_LINKED(id_data) ||
|
2015-05-13 07:36:43 +10:00
|
|
|
(GS(id_data->name) != id_code))
|
|
|
|
{
|
|
|
|
BLI_remlink(&lb, link);
|
|
|
|
MEM_freeN(link);
|
2015-05-13 07:23:03 +10:00
|
|
|
}
|
2015-05-13 07:36:43 +10:00
|
|
|
else {
|
|
|
|
/* avoid prepending 'data' to the path */
|
|
|
|
RNA_id_pointer_create(id_data, &link->ptr);
|
2015-05-13 07:23:03 +10:00
|
|
|
}
|
2015-05-27 11:14:39 +10:00
|
|
|
|
|
|
|
if (id_data) {
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
id_data->tag &= ~LIB_TAG_DOIT;
|
2015-05-27 11:14:39 +10:00
|
|
|
}
|
2015-05-13 07:23:03 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 07:36:43 +10:00
|
|
|
*r_lb = lb;
|
|
|
|
*r_path = path;
|
2015-05-13 07:23:03 +10:00
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
else if (GS(id->name) == ID_SCE) {
|
|
|
|
/* Sequencer's ID is scene :/ */
|
2019-01-15 23:24:20 +11:00
|
|
|
/* Try to recursively find an RNA_Sequence ancestor,
|
|
|
|
* to handle situations like T41062... */
|
2014-08-05 18:59:02 +02:00
|
|
|
if ((*r_path = RNA_path_resolve_from_type_to_property(ptr, prop, &RNA_Sequence)) != NULL) {
|
|
|
|
*r_lb = CTX_data_collection_get(C, "selected_editable_sequences");
|
|
|
|
}
|
2012-04-19 10:49:45 +00:00
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
return (*r_path != NULL);
|
2012-04-10 15:49:41 +00:00
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:16:19 +11:00
|
|
|
return true;
|
2009-12-17 17:15:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
/**
|
|
|
|
* called from both exec & poll
|
|
|
|
*
|
|
|
|
* \note: normally we wouldn't call a loop from within a poll function,
|
|
|
|
* However this is a special case, and for regular poll calls, getting
|
|
|
|
* the context from the button will fail early.
|
|
|
|
*/
|
|
|
|
static bool copy_to_selected_button(bContext *C, bool all, bool poll)
|
2009-12-17 17:15:38 +00:00
|
|
|
{
|
2018-06-29 12:46:54 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-04-10 15:49:41 +00:00
|
|
|
PointerRNA ptr, lptr, idptr;
|
|
|
|
PropertyRNA *prop, *lprop;
|
2014-04-11 08:33:54 +10:00
|
|
|
bool success = false;
|
|
|
|
int index;
|
2009-12-17 17:15:38 +00:00
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
/* try to reset the nominated setting to its default value */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
2009-12-17 17:15:38 +00:00
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
/* if there is a valid property that is editable... */
|
2009-12-17 17:15:38 +00:00
|
|
|
if (ptr.data && prop) {
|
2012-04-19 10:49:45 +00:00
|
|
|
char *path = NULL;
|
2014-08-05 18:59:02 +02:00
|
|
|
bool use_path_from_id;
|
2009-12-17 17:15:38 +00:00
|
|
|
CollectionPointerLink *link;
|
2017-09-07 22:13:28 +10:00
|
|
|
ListBase lb = {NULL};
|
2012-04-19 10:49:45 +00:00
|
|
|
|
2017-09-07 22:53:46 +10:00
|
|
|
if (UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path) &&
|
|
|
|
!BLI_listbase_is_empty(&lb))
|
|
|
|
{
|
|
|
|
for (link = lb.first; link; link = link->next) {
|
|
|
|
if (link->ptr.data != ptr.data) {
|
|
|
|
if (use_path_from_id) {
|
|
|
|
/* Path relative to ID. */
|
|
|
|
lprop = NULL;
|
|
|
|
RNA_id_pointer_create(link->ptr.id.data, &idptr);
|
|
|
|
RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
|
|
|
|
}
|
|
|
|
else if (path) {
|
|
|
|
/* Path relative to elements from list. */
|
|
|
|
lprop = NULL;
|
|
|
|
RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lptr = link->ptr;
|
|
|
|
lprop = prop;
|
|
|
|
}
|
2012-04-10 15:49:41 +00:00
|
|
|
|
2017-09-07 22:53:46 +10:00
|
|
|
if (lptr.data == ptr.data) {
|
|
|
|
/* lptr might not be the same as link->ptr! */
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
|
2017-09-07 22:53:46 +10:00
|
|
|
if (lprop == prop) {
|
|
|
|
if (RNA_property_editable(&lptr, lprop)) {
|
|
|
|
if (poll) {
|
2014-04-11 08:33:54 +10:00
|
|
|
success = true;
|
2017-09-07 22:53:46 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2018-06-29 12:46:54 +02:00
|
|
|
if (RNA_property_copy(bmain, &lptr, &ptr, prop, (all) ? -1 : index)) {
|
2017-09-07 22:53:46 +10:00
|
|
|
RNA_property_update(C, &lptr, prop);
|
|
|
|
success = true;
|
|
|
|
}
|
2014-04-11 08:33:54 +10:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 15:49:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-17 17:15:38 +00:00
|
|
|
}
|
2014-08-05 18:59:02 +02:00
|
|
|
MEM_SAFE_FREE(path);
|
2012-04-19 10:49:45 +00:00
|
|
|
BLI_freelistN(&lb);
|
2009-12-17 17:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool copy_to_selected_button_poll(bContext *C)
|
2009-12-17 17:15:38 +00:00
|
|
|
{
|
2014-04-11 08:33:54 +10:00
|
|
|
return copy_to_selected_button(C, false, true);
|
|
|
|
}
|
2012-04-19 10:49:45 +00:00
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
static int copy_to_selected_button_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bool success;
|
2012-04-19 10:49:45 +00:00
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
const bool all = RNA_boolean_get(op->ptr, "all");
|
2009-12-17 17:15:38 +00:00
|
|
|
|
2014-04-11 08:33:54 +10:00
|
|
|
success = copy_to_selected_button(C, all, false);
|
2012-04-10 15:49:41 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2009-12-17 17:15:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static void UI_OT_copy_to_selected_button(wmOperatorType *ot)
|
2009-12-17 17:15:38 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy To Selected";
|
|
|
|
ot->idname = "UI_OT_copy_to_selected_button";
|
|
|
|
ot->description = "Copy property from this object to selected objects or bones";
|
2009-12-17 17:15:38 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = copy_to_selected_button_poll;
|
|
|
|
ot->exec = copy_to_selected_button_exec;
|
2009-12-17 17:15:38 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-30 01:51:25 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-12-17 17:15:38 +00:00
|
|
|
|
2009-12-17 10:47:55 +00:00
|
|
|
/* properties */
|
2016-04-15 15:17:18 +02:00
|
|
|
RNA_def_boolean(ot->srna, "all", true, "All", "Copy to selected all elements of the array");
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
2010-11-17 12:02:36 +00:00
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
2018-11-20 17:34:56 +11:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Jump to Target Operator
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/** Jump to the object or bone referenced by the pointer, or check if it is possible. */
|
|
|
|
static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll)
|
|
|
|
{
|
|
|
|
if (RNA_pointer_is_null(&ptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify pointer type. */
|
|
|
|
char bone_name[MAXBONENAME];
|
|
|
|
const StructRNA *target_type = NULL;
|
|
|
|
|
|
|
|
if (ELEM(ptr.type, &RNA_EditBone, &RNA_PoseBone, &RNA_Bone)) {
|
|
|
|
RNA_string_get(&ptr, "name", bone_name);
|
|
|
|
if (bone_name[0] != '\0') {
|
|
|
|
target_type = &RNA_Bone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (RNA_struct_is_a(ptr.type, &RNA_Object)) {
|
|
|
|
target_type = &RNA_Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target_type == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the containing Object. */
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
Base *base = NULL;
|
|
|
|
const short id_type = GS(((ID *)ptr.id.data)->name);
|
|
|
|
if (id_type == ID_OB) {
|
|
|
|
base = BKE_view_layer_base_find(view_layer, ptr.id.data);
|
|
|
|
}
|
|
|
|
else if (OB_DATA_SUPPORT_ID(id_type)) {
|
|
|
|
base = ED_object_find_first_by_data_id(view_layer, ptr.id.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
if ((base == NULL) ||
|
|
|
|
((target_type == &RNA_Bone) && (base->object->type != OB_ARMATURE)))
|
|
|
|
{
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (poll) {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else {
|
2018-11-21 13:04:03 +11:00
|
|
|
/* Make optional. */
|
|
|
|
const bool reveal_hidden = true;
|
2018-11-20 17:34:56 +11:00
|
|
|
/* Select and activate the target. */
|
|
|
|
if (target_type == &RNA_Bone) {
|
2018-11-21 13:04:03 +11:00
|
|
|
ok = ED_object_jump_to_bone(C, base->object, bone_name, reveal_hidden);
|
2018-11-20 17:34:56 +11:00
|
|
|
}
|
|
|
|
else if (target_type == &RNA_Object) {
|
2018-11-21 13:04:03 +11:00
|
|
|
ok = ED_object_jump_to_object(C, base->object, reveal_hidden);
|
2018-11-20 17:34:56 +11:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Jump to the object or bone referred to by the current UI field value.
|
|
|
|
*
|
|
|
|
* \note quite heavy for a poll callback, but the operator is only
|
|
|
|
* used as a right click menu item for certain UI field types, and
|
|
|
|
* this will fail quickly if the context is completely unsuitable.
|
|
|
|
*/
|
|
|
|
static bool jump_to_target_button(bContext *C, bool poll)
|
|
|
|
{
|
|
|
|
PointerRNA ptr, target_ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
|
|
|
|
|
|
|
|
/* If there is a valid property... */
|
|
|
|
if (ptr.data && prop) {
|
|
|
|
const PropertyType type = RNA_property_type(prop);
|
|
|
|
|
|
|
|
/* For pointer properties, use their value directly. */
|
|
|
|
if (type == PROP_POINTER) {
|
|
|
|
target_ptr = RNA_property_pointer_get(&ptr, prop);
|
|
|
|
|
|
|
|
return jump_to_target_ptr(C, target_ptr, poll);
|
|
|
|
}
|
|
|
|
/* For string properties with prop_search, look up the search collection item. */
|
|
|
|
else if (type == PROP_STRING) {
|
|
|
|
const uiBut *but = UI_context_active_but_get(C);
|
|
|
|
|
|
|
|
if (but->type == UI_BTYPE_SEARCH_MENU && but->search_func == ui_rna_collection_search_cb) {
|
|
|
|
uiRNACollectionSearch *coll_search = but->search_arg;
|
|
|
|
|
|
|
|
char str_buf[MAXBONENAME];
|
|
|
|
char *str_ptr = RNA_property_string_get_alloc(&ptr, prop, str_buf, sizeof(str_buf), NULL);
|
|
|
|
|
|
|
|
int found = RNA_property_collection_lookup_string(&coll_search->search_ptr, coll_search->search_prop, str_ptr, &target_ptr);
|
|
|
|
|
|
|
|
if (str_ptr != str_buf) {
|
|
|
|
MEM_freeN(str_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
return jump_to_target_ptr(C, target_ptr, poll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-15 10:49:26 -03:00
|
|
|
bool ui_jump_to_target_button_poll(bContext *C)
|
2018-11-20 17:34:56 +11:00
|
|
|
{
|
|
|
|
return jump_to_target_button(C, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int jump_to_target_button_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
bool success = jump_to_target_button(C, false);
|
|
|
|
|
|
|
|
return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_jump_to_target_button(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Jump To Target";
|
|
|
|
ot->idname = "UI_OT_jump_to_target_button";
|
|
|
|
ot->description = "Switch to the target object or bone";
|
|
|
|
|
|
|
|
/* callbacks */
|
2019-03-15 10:49:26 -03:00
|
|
|
ot->poll = ui_jump_to_target_button_poll;
|
2018-11-20 17:34:56 +11:00
|
|
|
ot->exec = jump_to_target_button_exec;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Reports to Textblock Operator
|
|
|
|
* \{ */
|
2010-11-17 12:02:36 +00:00
|
|
|
|
2018-05-23 10:47:12 +02:00
|
|
|
/* FIXME: this is just a temporary operator so that we can see all the reports somewhere
|
2010-11-17 12:02:36 +00:00
|
|
|
* when there are too many to display...
|
|
|
|
*/
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool reports_to_text_poll(bContext *C)
|
2010-11-17 12:02:36 +00:00
|
|
|
{
|
|
|
|
return CTX_wm_reports(C) != NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-17 14:36:19 +00:00
|
|
|
static int reports_to_text_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-11-17 12:02:36 +00:00
|
|
|
{
|
|
|
|
ReportList *reports = CTX_wm_reports(C);
|
2013-02-05 12:46:15 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2010-11-17 12:02:36 +00:00
|
|
|
Text *txt;
|
|
|
|
char *str;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* create new text-block to write to */
|
2013-02-05 12:46:15 +00:00
|
|
|
txt = BKE_text_add(bmain, "Recent Reports");
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* convert entire list to a display string, and add this to the text-block
|
2018-11-14 12:53:15 +11:00
|
|
|
* - if commandline debug option enabled, show debug reports too
|
|
|
|
* - otherwise, up to info (which is what users normally see)
|
2010-11-17 12:02:36 +00:00
|
|
|
*/
|
2012-03-31 00:59:17 +00:00
|
|
|
str = BKE_reports_string(reports, (G.debug & G_DEBUG) ? RPT_DEBUG : RPT_INFO);
|
2011-12-12 03:25:10 +00:00
|
|
|
|
|
|
|
if (str) {
|
2018-04-05 15:22:33 +02:00
|
|
|
TextUndoBuf *utxt = NULL; // FIXME
|
|
|
|
BKE_text_write(txt, utxt, str);
|
2011-12-12 03:25:10 +00:00
|
|
|
MEM_freeN(str);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2010-11-17 12:02:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
static void UI_OT_reports_to_textblock(wmOperatorType *ot)
|
2010-11-17 12:02:36 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Reports to Text Block";
|
|
|
|
ot->idname = "UI_OT_reports_to_textblock";
|
|
|
|
ot->description = "Write the reports ";
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2010-11-17 12:02:36 +00:00
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = reports_to_text_poll;
|
|
|
|
ot->exec = reports_to_text_exec;
|
2010-11-17 12:02:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Edit Python Source Operator
|
|
|
|
* \{ */
|
|
|
|
|
2011-11-03 23:20:54 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* EditSource Utility funcs and operator,
|
2012-03-04 04:35:12 +00:00
|
|
|
* note, this includes utility functions and button matching checks */
|
2011-10-23 04:13:56 +00:00
|
|
|
|
2013-08-07 03:44:05 +00:00
|
|
|
typedef struct uiEditSourceStore {
|
2011-10-23 04:13:56 +00:00
|
|
|
uiBut but_orig;
|
|
|
|
GHash *hash;
|
|
|
|
} uiEditSourceStore;
|
|
|
|
|
2013-08-07 03:44:05 +00:00
|
|
|
typedef struct uiEditSourceButStore {
|
2012-01-16 05:52:33 +00:00
|
|
|
char py_dbg_fn[FILE_MAX];
|
2011-10-23 04:13:56 +00:00
|
|
|
int py_dbg_ln;
|
|
|
|
} uiEditSourceButStore;
|
|
|
|
|
|
|
|
/* should only ever be set while the edit source operator is running */
|
2012-03-30 01:51:25 +00:00
|
|
|
static struct uiEditSourceStore *ui_editsource_info = NULL;
|
2011-10-23 04:13:56 +00:00
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
bool UI_editsource_enable_check(void)
|
2011-10-23 04:13:56 +00:00
|
|
|
{
|
|
|
|
return (ui_editsource_info != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_editsource_active_but_set(uiBut *but)
|
|
|
|
{
|
|
|
|
BLI_assert(ui_editsource_info == NULL);
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
ui_editsource_info = MEM_callocN(sizeof(uiEditSourceStore), __func__);
|
2011-10-23 04:13:56 +00:00
|
|
|
memcpy(&ui_editsource_info->but_orig, but, sizeof(uiBut));
|
|
|
|
|
2012-05-16 00:51:36 +00:00
|
|
|
ui_editsource_info->hash = BLI_ghash_ptr_new(__func__);
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_editsource_active_but_clear(void)
|
|
|
|
{
|
2013-05-21 07:37:59 +00:00
|
|
|
BLI_ghash_free(ui_editsource_info->hash, NULL, MEM_freeN);
|
2011-10-23 04:13:56 +00:00
|
|
|
MEM_freeN(ui_editsource_info);
|
2012-03-30 01:51:25 +00:00
|
|
|
ui_editsource_info = NULL;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 17:16:19 +11:00
|
|
|
static bool ui_editsource_uibut_match(uiBut *but_a, uiBut *but_b)
|
2011-10-23 04:13:56 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
printf("matching buttons: '%s' == '%s'\n",
|
|
|
|
but_a->drawstr, but_b->drawstr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* this just needs to be a 'good-enough' comparison so we can know beyond
|
|
|
|
* reasonable doubt that these buttons are the same between redraws.
|
|
|
|
* if this fails it only means edit-source fails - campbell */
|
2012-08-18 18:11:51 +00:00
|
|
|
if (BLI_rctf_compare(&but_a->rect, &but_b->rect, FLT_EPSILON) &&
|
2012-03-30 01:51:25 +00:00
|
|
|
(but_a->type == but_b->type) &&
|
|
|
|
(but_a->rnaprop == but_b->rnaprop) &&
|
|
|
|
(but_a->optype == but_b->optype) &&
|
|
|
|
(but_a->unit_type == but_b->unit_type) &&
|
2015-01-26 16:03:11 +01:00
|
|
|
STREQLEN(but_a->drawstr, but_b->drawstr, UI_MAX_DRAW_STR))
|
2012-03-30 01:51:25 +00:00
|
|
|
{
|
2014-01-04 17:16:19 +11:00
|
|
|
return true;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-01-04 17:16:19 +11:00
|
|
|
return false;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_editsource_active_but_test(uiBut *but)
|
|
|
|
{
|
|
|
|
extern void PyC_FileAndNum_Safe(const char **filename, int *lineno);
|
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
struct uiEditSourceButStore *but_store = MEM_callocN(sizeof(uiEditSourceButStore), __func__);
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
const char *fn;
|
2012-03-30 01:51:25 +00:00
|
|
|
int lineno = -1;
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("comparing buttons: '%s' == '%s'\n",
|
|
|
|
but->drawstr, ui_editsource_info->but_orig.drawstr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PyC_FileAndNum_Safe(&fn, &lineno);
|
|
|
|
|
|
|
|
if (lineno != -1) {
|
|
|
|
BLI_strncpy(but_store->py_dbg_fn, fn,
|
2012-03-30 01:51:25 +00:00
|
|
|
sizeof(but_store->py_dbg_fn));
|
|
|
|
but_store->py_dbg_ln = lineno;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-30 01:51:25 +00:00
|
|
|
but_store->py_dbg_fn[0] = '\0';
|
|
|
|
but_store->py_dbg_ln = -1;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_ghash_insert(ui_editsource_info->hash, but, but_store);
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:13:47 +10:00
|
|
|
static int editsource_text_edit(
|
|
|
|
bContext *C, wmOperator *op,
|
2018-07-03 07:22:26 +02:00
|
|
|
const char filepath[FILE_MAX], const int line)
|
2011-10-23 04:13:56 +00:00
|
|
|
{
|
2012-03-30 01:51:25 +00:00
|
|
|
struct Main *bmain = CTX_data_main(C);
|
2011-10-23 04:13:56 +00:00
|
|
|
Text *text;
|
|
|
|
|
2018-07-03 07:22:26 +02:00
|
|
|
/* Developers may wish to copy-paste to an external editor. */
|
|
|
|
printf("%s:%d\n", filepath, line);
|
|
|
|
|
2019-03-08 09:29:17 +11:00
|
|
|
for (text = bmain->texts.first; text; text = text->id.next) {
|
2011-10-23 04:13:56 +00:00
|
|
|
if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text == NULL) {
|
2018-06-05 15:10:33 +02:00
|
|
|
text = BKE_text_load(bmain, filepath, BKE_main_blendfile_path(bmain));
|
2017-03-10 15:41:14 +01:00
|
|
|
id_us_ensure_real(&text->id);
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (text == NULL) {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_reportf(op->reports, RPT_WARNING, "File '%s' cannot be opened", filepath);
|
2011-10-23 04:13:56 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* naughty!, find text area to set, not good behavior
|
|
|
|
* but since this is a dev tool lets allow it - campbell */
|
2012-03-30 01:51:25 +00:00
|
|
|
ScrArea *sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TEXT, 0);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sa) {
|
2012-03-30 01:51:25 +00:00
|
|
|
SpaceText *st = sa->spacedata.first;
|
|
|
|
st->text = text;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-14 15:29:09 +00:00
|
|
|
BKE_reportf(op->reports, RPT_INFO, "See '%s' in the text editor", text->id.name + 2);
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 17:16:19 +11:00
|
|
|
txt_move_toline(text, line - 1, false);
|
2012-03-30 01:51:25 +00:00
|
|
|
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int editsource_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2014-11-09 21:20:40 +01:00
|
|
|
uiBut *but = UI_context_active_but_get(C);
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
if (but) {
|
|
|
|
GHashIterator ghi;
|
2012-03-30 01:51:25 +00:00
|
|
|
struct uiEditSourceButStore *but_store = NULL;
|
2011-10-23 04:13:56 +00:00
|
|
|
|
2012-03-30 01:51:25 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-10-23 04:13:56 +00:00
|
|
|
int ret;
|
|
|
|
|
2011-10-23 05:08:02 +00:00
|
|
|
/* needed else the active button does not get tested */
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_screen_free_active_but(C, CTX_wm_screen(C));
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
// printf("%s: begin\n", __func__);
|
|
|
|
|
2011-10-23 05:08:02 +00:00
|
|
|
/* take care not to return before calling ui_editsource_active_but_clear */
|
2011-10-23 04:13:56 +00:00
|
|
|
ui_editsource_active_but_set(but);
|
|
|
|
|
|
|
|
/* redraw and get active button python info */
|
2018-06-20 11:13:07 +02:00
|
|
|
ED_region_do_layout(C, ar);
|
2011-10-23 04:13:56 +00:00
|
|
|
ED_region_do_draw(C, ar);
|
2015-04-06 10:40:12 -03:00
|
|
|
ar->do_draw = false;
|
2011-10-23 04:13:56 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (BLI_ghashIterator_init(&ghi, ui_editsource_info->hash);
|
2013-05-08 12:58:11 +00:00
|
|
|
BLI_ghashIterator_done(&ghi) == false;
|
2012-03-30 01:51:25 +00:00
|
|
|
BLI_ghashIterator_step(&ghi))
|
2011-10-23 04:13:56 +00:00
|
|
|
{
|
2012-10-12 14:35:10 +00:00
|
|
|
uiBut *but_key = BLI_ghashIterator_getKey(&ghi);
|
|
|
|
if (but_key && ui_editsource_uibut_match(&ui_editsource_info->but_orig, but_key)) {
|
2012-03-30 01:51:25 +00:00
|
|
|
but_store = BLI_ghashIterator_getValue(&ghi);
|
2011-10-23 04:13:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (but_store) {
|
|
|
|
if (but_store->py_dbg_ln != -1) {
|
2018-07-01 19:57:31 +02:00
|
|
|
ret = editsource_text_edit(
|
|
|
|
C, op,
|
|
|
|
but_store->py_dbg_fn,
|
|
|
|
but_store->py_dbg_ln);
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Active button is not from a script, cannot edit source");
|
2012-03-30 01:51:25 +00:00
|
|
|
ret = OPERATOR_CANCELLED;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-10-26 17:32:50 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Active button match cannot be found");
|
2012-03-30 01:51:25 +00:00
|
|
|
ret = OPERATOR_CANCELLED;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ui_editsource_active_but_clear();
|
|
|
|
|
|
|
|
// printf("%s: end\n", __func__);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Active button not found");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_editsource(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
ot->name = "Edit Source";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "UI_OT_editsource";
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
ot->description = "Edit UI source code of the active button";
|
2011-10-23 04:13:56 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = editsource_exec;
|
2011-10-23 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Edit Translation Operator
|
|
|
|
* \{ */
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
2015-05-31 14:20:03 +10:00
|
|
|
/**
|
|
|
|
* EditTranslation utility funcs and operator,
|
|
|
|
* \note: this includes utility functions and button matching checks.
|
|
|
|
* this only works in conjunction with a py operator!
|
|
|
|
*/
|
2012-09-15 01:52:28 +00:00
|
|
|
static void edittranslation_find_po_file(const char *root, const char *uilng, char *path, const size_t maxlen)
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
{
|
2012-09-05 01:42:52 +00:00
|
|
|
char tstr[32]; /* Should be more than enough! */
|
2012-09-27 14:38:20 +00:00
|
|
|
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
/* First, full lang code. */
|
2012-09-05 01:42:52 +00:00
|
|
|
BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
BLI_join_dirfile(path, maxlen, root, uilng);
|
2013-07-24 21:25:06 +00:00
|
|
|
BLI_path_append(path, maxlen, tstr);
|
2019-03-25 10:15:20 +11:00
|
|
|
if (BLI_is_file(path)) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
return;
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2012-09-27 14:38:20 +00:00
|
|
|
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
/* Now try without the second iso code part (_ES in es_ES). */
|
2012-09-27 14:38:20 +00:00
|
|
|
{
|
2014-04-27 00:22:49 +10:00
|
|
|
const char *tc = NULL;
|
2012-09-27 14:38:20 +00:00
|
|
|
size_t szt = 0;
|
|
|
|
tstr[0] = '\0';
|
|
|
|
|
|
|
|
tc = strchr(uilng, '_');
|
|
|
|
if (tc) {
|
|
|
|
szt = tc - uilng;
|
|
|
|
if (szt < sizeof(tstr)) /* Paranoid, should always be true! */
|
|
|
|
BLI_strncpy(tstr, uilng, szt + 1); /* +1 for '\0' char! */
|
|
|
|
}
|
|
|
|
if (tstr[0]) {
|
|
|
|
/* Because of some codes like sr_SR@latin... */
|
|
|
|
tc = strchr(uilng, '@');
|
2019-03-25 10:15:20 +11:00
|
|
|
if (tc) {
|
2012-09-27 14:38:20 +00:00
|
|
|
BLI_strncpy(tstr + szt, tc, sizeof(tstr) - szt);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2012-09-27 14:38:20 +00:00
|
|
|
|
|
|
|
BLI_join_dirfile(path, maxlen, root, tstr);
|
|
|
|
strcat(tstr, ".po");
|
2013-07-24 21:25:06 +00:00
|
|
|
BLI_path_append(path, maxlen, tstr);
|
2019-03-25 10:15:20 +11:00
|
|
|
if (BLI_is_file(path)) {
|
2012-09-27 14:38:20 +00:00
|
|
|
return;
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2012-09-27 14:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Else no po file! */
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
path[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int edittranslation_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2014-11-09 21:20:40 +01:00
|
|
|
uiBut *but = UI_context_active_but_get(C);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
int ret = OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
if (but) {
|
2014-07-11 15:07:55 +10:00
|
|
|
wmOperatorType *ot;
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
char popath[FILE_MAX];
|
|
|
|
const char *root = U.i18ndir;
|
2015-08-16 17:32:01 +10:00
|
|
|
const char *uilng = BLT_lang_get();
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
|
|
|
uiStringInfo but_label = {BUT_GET_LABEL, NULL};
|
|
|
|
uiStringInfo rna_label = {BUT_GET_RNA_LABEL, NULL};
|
|
|
|
uiStringInfo enum_label = {BUT_GET_RNAENUM_LABEL, NULL};
|
|
|
|
uiStringInfo but_tip = {BUT_GET_TIP, NULL};
|
|
|
|
uiStringInfo rna_tip = {BUT_GET_RNA_TIP, NULL};
|
|
|
|
uiStringInfo enum_tip = {BUT_GET_RNAENUM_TIP, NULL};
|
|
|
|
uiStringInfo rna_struct = {BUT_GET_RNASTRUCT_IDENTIFIER, NULL};
|
|
|
|
uiStringInfo rna_prop = {BUT_GET_RNAPROP_IDENTIFIER, NULL};
|
|
|
|
uiStringInfo rna_enum = {BUT_GET_RNAENUM_IDENTIFIER, NULL};
|
|
|
|
uiStringInfo rna_ctxt = {BUT_GET_RNA_LABEL_CONTEXT, NULL};
|
|
|
|
|
|
|
|
if (!BLI_is_dir(root)) {
|
2018-07-01 19:57:31 +02:00
|
|
|
BKE_report(
|
|
|
|
op->reports, RPT_ERROR,
|
2019-01-04 21:40:16 +01:00
|
|
|
"Please set your Preferences' 'Translation Branches "
|
2018-07-01 19:57:31 +02:00
|
|
|
"Directory' path to a valid directory");
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2014-07-11 15:07:55 +10:00
|
|
|
ot = WM_operatortype_find(EDTSRC_I18N_OP_NAME, 0);
|
|
|
|
if (ot == NULL) {
|
2018-07-01 19:57:31 +02:00
|
|
|
BKE_reportf(
|
|
|
|
op->reports, RPT_ERROR,
|
|
|
|
"Could not find operator '%s'! Please enable ui_translate add-on "
|
|
|
|
"in the User Preferences", EDTSRC_I18N_OP_NAME);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
/* Try to find a valid po file for current language... */
|
|
|
|
edittranslation_find_po_file(root, uilng, popath, FILE_MAX);
|
2018-11-14 12:53:15 +11:00
|
|
|
/* printf("po path: %s\n", popath); */
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
if (popath[0] == '\0') {
|
2012-10-14 15:29:09 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "No valid po found for language '%s' under %s", uilng, root);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:57:31 +02:00
|
|
|
UI_but_string_info_get(
|
|
|
|
C, but, &but_label, &rna_label, &enum_label, &but_tip, &rna_tip, &enum_tip,
|
|
|
|
&rna_struct, &rna_prop, &rna_enum, &rna_ctxt, NULL);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
2014-07-11 15:07:55 +10:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
RNA_string_set(&ptr, "lang", uilng);
|
|
|
|
RNA_string_set(&ptr, "po_file", popath);
|
|
|
|
RNA_string_set(&ptr, "but_label", but_label.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_label", rna_label.strinfo);
|
|
|
|
RNA_string_set(&ptr, "enum_label", enum_label.strinfo);
|
|
|
|
RNA_string_set(&ptr, "but_tip", but_tip.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_tip", rna_tip.strinfo);
|
|
|
|
RNA_string_set(&ptr, "enum_tip", enum_tip.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_struct", rna_struct.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_prop", rna_prop.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_enum", rna_enum.strinfo);
|
|
|
|
RNA_string_set(&ptr, "rna_ctxt", rna_ctxt.strinfo);
|
2014-07-11 15:07:55 +10:00
|
|
|
ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
|
|
|
/* Clean up */
|
2019-03-25 10:15:20 +11:00
|
|
|
if (but_label.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(but_label.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_label.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_label.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (enum_label.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(enum_label.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (but_tip.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(but_tip.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_tip.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_tip.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (enum_tip.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(enum_tip.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_struct.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_struct.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_prop.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_prop.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_enum.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_enum.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
|
|
|
if (rna_ctxt.strinfo) {
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
MEM_freeN(rna_ctxt.strinfo);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Active button not found");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_edittranslation_init(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Edit Translation";
|
|
|
|
ot->idname = "UI_OT_edittranslation_init";
|
|
|
|
ot->description = "Edit i18n in current language for the active button";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = edittranslation_exec;
|
|
|
|
}
|
|
|
|
|
2011-11-03 23:20:54 +00:00
|
|
|
#endif /* WITH_PYTHON */
|
2011-10-23 04:13:56 +00:00
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Reload Translation Operator
|
|
|
|
* \{ */
|
|
|
|
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
static int reloadtranslation_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
|
|
|
|
{
|
2015-08-16 17:32:01 +10:00
|
|
|
BLT_lang_init();
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
BLF_cache_clear();
|
2015-08-16 17:32:01 +10:00
|
|
|
BLT_lang_set(NULL);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
UI_reinit_font();
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_reloadtranslation(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Reload Translation";
|
|
|
|
ot->idname = "UI_OT_reloadtranslation";
|
|
|
|
ot->description = "Force a full reload of UI translation";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = reloadtranslation_exec;
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Prese Button Operator
|
|
|
|
* \{ */
|
2018-10-27 12:21:19 +11:00
|
|
|
|
|
|
|
static ARegion *region_event_inside_for_screen(bContext *C, const int xy[2])
|
|
|
|
{
|
|
|
|
bScreen *sc = CTX_wm_screen(C);
|
|
|
|
if (sc) {
|
|
|
|
for (ARegion *ar = sc->regionbase.first; ar; ar = ar->next) {
|
|
|
|
if (BLI_rcti_isect_pt_v(&ar->winrct, xy)) {
|
|
|
|
return ar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
|
|
|
const bool skip_depressed = RNA_boolean_get(op->ptr, "skip_depressed");
|
|
|
|
ARegion *ar_prev = CTX_wm_region(C);
|
|
|
|
ARegion *ar = region_event_inside_for_screen(C, &event->x);
|
|
|
|
|
|
|
|
if (ar == NULL) {
|
|
|
|
ar = ar_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
CTX_wm_region_set(C, ar);
|
|
|
|
uiBut *but = UI_context_active_but_get(C);
|
|
|
|
CTX_wm_region_set(C, ar_prev);
|
|
|
|
|
|
|
|
if (but == NULL) {
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
if (skip_depressed && (but->flag & (UI_SELECT | UI_SELECT_DRAW))) {
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Weak, this is a workaround for 'UI_but_is_tool', which checks the operator type,
|
|
|
|
* having this avoids a minor drawing glitch. */
|
|
|
|
void *but_optype = but->optype;
|
|
|
|
|
|
|
|
UI_but_execute(C, but);
|
|
|
|
|
|
|
|
but->optype = but_optype;
|
|
|
|
|
|
|
|
WM_event_add_mousemove(C);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UI_OT_button_execute(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Press Button";
|
|
|
|
ot->idname = "UI_OT_button_execute";
|
|
|
|
ot->description = "Presses active button";
|
|
|
|
|
|
|
|
ot->invoke = ui_button_press_invoke;
|
|
|
|
ot->flag = OPTYPE_INTERNAL;
|
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "skip_depressed", 0, "Skip Depressed", "");
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Drop Color Operator
|
|
|
|
* \{ */
|
|
|
|
|
2018-08-07 10:38:20 +02:00
|
|
|
bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
|
|
|
/* should only return true for regions that include buttons, for now
|
|
|
|
* return true always */
|
|
|
|
if (drag->type == WM_DRAG_COLOR) {
|
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
|
2019-03-25 10:15:20 +11:00
|
|
|
if (UI_but_active_drop_color(C)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return 1;
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
if (sima && (sima->mode == SI_MODE_PAINT) &&
|
|
|
|
sima->image && (ar && ar->regiontype == RGN_TYPE_WINDOW))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_drop_color_copy(wmDrag *drag, wmDropBox *drop)
|
|
|
|
{
|
2015-02-06 18:16:46 +11:00
|
|
|
uiDragColorHandle *drag_info = drag->poin;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
RNA_float_set_array(drop->ptr, "color", drag_info->color);
|
|
|
|
RNA_boolean_set(drop->ptr, "gamma", drag_info->gamma_corrected);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
uiBut *but = NULL;
|
2014-08-25 14:31:51 +10:00
|
|
|
float color[4];
|
2014-07-21 12:02:05 +02:00
|
|
|
bool gamma;
|
|
|
|
|
|
|
|
RNA_float_get_array(op->ptr, "color", color);
|
|
|
|
gamma = RNA_boolean_get(op->ptr, "gamma");
|
|
|
|
|
|
|
|
/* find button under mouse, check if it has RNA color property and
|
|
|
|
* if it does copy the data */
|
2019-03-23 00:18:16 +11:00
|
|
|
but = ui_region_find_active_but(ar);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
if (but && but->type == UI_BTYPE_COLOR && but->rnaprop) {
|
2014-08-25 14:31:51 +10:00
|
|
|
const int color_len = RNA_property_array_length(&but->rnapoin, but->rnaprop);
|
|
|
|
BLI_assert(color_len <= 4);
|
|
|
|
|
|
|
|
/* keep alpha channel as-is */
|
|
|
|
if (color_len == 4) {
|
|
|
|
color[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3);
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) {
|
2019-03-25 10:15:20 +11:00
|
|
|
if (!gamma) {
|
2018-12-13 18:28:41 +01:00
|
|
|
IMB_colormanagement_scene_linear_to_srgb_v3(color);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
|
|
|
|
RNA_property_update(C, &but->rnapoin, but->rnaprop);
|
|
|
|
}
|
|
|
|
else if (RNA_property_subtype(but->rnaprop) == PROP_COLOR) {
|
2019-03-25 10:15:20 +11:00
|
|
|
if (gamma) {
|
2018-12-13 18:28:41 +01:00
|
|
|
IMB_colormanagement_srgb_to_scene_linear_v3(color);
|
2019-03-25 10:15:20 +11:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
RNA_property_float_set_array(&but->rnapoin, but->rnaprop, color);
|
|
|
|
RNA_property_update(C, &but->rnapoin, but->rnaprop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (gamma) {
|
|
|
|
srgb_to_linearrgb_v3_v3(color, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_imapaint_bucket_fill(C, color, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void UI_OT_drop_color(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Drop Color";
|
|
|
|
ot->idname = "UI_OT_drop_color";
|
|
|
|
ot->description = "Drop colors to buttons";
|
|
|
|
|
|
|
|
ot->invoke = drop_color_invoke;
|
2015-02-24 14:38:08 +05:00
|
|
|
ot->flag = OPTYPE_INTERNAL;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, FLT_MAX, "Color", "Source color", 0.0, 1.0);
|
|
|
|
RNA_def_boolean(ot->srna, "gamma", 0, "Gamma Corrected", "The source color is gamma corrected ");
|
|
|
|
}
|
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/** \} */
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-03-23 12:07:05 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Operator & Keymap Registration
|
|
|
|
* \{ */
|
2009-12-17 10:47:55 +00:00
|
|
|
|
2016-02-29 17:47:36 +01:00
|
|
|
void ED_operatortypes_ui(void)
|
2009-12-17 10:47:55 +00:00
|
|
|
{
|
2009-12-17 17:15:38 +00:00
|
|
|
WM_operatortype_append(UI_OT_copy_data_path_button);
|
2016-02-26 11:57:35 +11:00
|
|
|
WM_operatortype_append(UI_OT_copy_python_command_button);
|
2009-12-17 10:47:55 +00:00
|
|
|
WM_operatortype_append(UI_OT_reset_default_button);
|
2018-12-15 22:37:12 +03:00
|
|
|
WM_operatortype_append(UI_OT_assign_default_button);
|
2013-09-20 09:10:17 +00:00
|
|
|
WM_operatortype_append(UI_OT_unset_property_button);
|
2017-11-29 17:03:52 +01:00
|
|
|
WM_operatortype_append(UI_OT_override_type_set_button);
|
|
|
|
WM_operatortype_append(UI_OT_override_remove_button);
|
2009-12-17 17:15:38 +00:00
|
|
|
WM_operatortype_append(UI_OT_copy_to_selected_button);
|
2018-11-20 17:34:56 +11:00
|
|
|
WM_operatortype_append(UI_OT_jump_to_target_button);
|
2012-08-19 10:41:27 +00:00
|
|
|
WM_operatortype_append(UI_OT_reports_to_textblock); /* XXX: temp? */
|
2014-07-21 12:02:05 +02:00
|
|
|
WM_operatortype_append(UI_OT_drop_color);
|
2011-11-03 23:20:54 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2011-10-23 04:13:56 +00:00
|
|
|
WM_operatortype_append(UI_OT_editsource);
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
WM_operatortype_append(UI_OT_edittranslation_init);
|
2011-11-03 23:20:54 +00:00
|
|
|
#endif
|
UI translation from inside Blender UI: first part.
This commit reshapes a bit runtime button info getter, by adding a new uiButGetStrInfo() which accepts a variable number of uiStringInfo parameters, and tries to fill them with the requested strings, for the given button (label, tip, context, RNA identifier, keymap, etc.). Currently used mostly by existing ui_tooltip_create(), and new UI_OT_edittranslation_init operator.
It also adds a few getters (to get RNA i18n context, and current language iso code).
Finally, it adds to C operators needed for the py ui_translation addon:
*UI_OT_edittranslation_init, which gathers requested data and launch the py operator.
*UI_OT_reloadtranslation, which forces a full reload of the whole UI translation (including rechecking the directory containing mo files).
For the first operator to work, it also adds a new user preferences path: i18n_branches_directory, to point to the /branch part of a bf-translation checkout.
2012-07-09 14:25:35 +00:00
|
|
|
WM_operatortype_append(UI_OT_reloadtranslation);
|
2018-10-27 12:21:19 +11:00
|
|
|
WM_operatortype_append(UI_OT_button_execute);
|
2013-10-08 15:07:52 +00:00
|
|
|
|
|
|
|
/* external */
|
|
|
|
WM_operatortype_append(UI_OT_eyedropper_color);
|
2019-03-18 18:20:44 +11:00
|
|
|
WM_operatortype_append(UI_OT_eyedropper_colorramp);
|
|
|
|
WM_operatortype_append(UI_OT_eyedropper_colorramp_point);
|
2013-10-08 15:32:54 +00:00
|
|
|
WM_operatortype_append(UI_OT_eyedropper_id);
|
2015-01-14 08:01:40 +11:00
|
|
|
WM_operatortype_append(UI_OT_eyedropper_depth);
|
Driver Setup Workflow Improvement: Property Eyedropper
This commit brings some long requested improvements to the workflow for setting up
drivers, which should make it easier and faster to set up new drivers in a more
interactive fashion.
The new workflow is as follows:
1) Hover over the property (e.g. "Lamp Energy" or "Y Location") or properties ("Rotation")
you wish to add drivers to. We'll refer to this as the "destination"
2) Ctrl-D to active the new "Add Drivers" eyedropper
3) Click on the property you want to use as the source/target. The property under the
mouse will be used to drive the property you invoked Ctrl-D on.
For example, to drive the X, Y, and Z location of the Cube using the Y Location of the Lamp,
hover over any of the X/Y/Z location buttons, hit Ctrl-D, then click on the Y-Location
button of the Lamp object. Drivers will be added to the X, Y, and Z Location properties
of the Cube; each driver will have a single variable, which uses the Y-Location Transform
Channel of the Lamp.
Tips:
- Transform properties will automatically create "Transform Channel" driver variables.
Everything else will use "Single Property" ones
- Due to the way that Blender's UI Context works, you'll need two Properties Panel instances
open (and to have pinned one of the two to show the properties for the unselected
object). It's slightly clunky, but necessary for implementing a workflow like this,
as the UI cannot be manipulated while using eyedroppers to pick data.
- The eyedropper operator implemented here actually has three modes of operation.
1) The "1-N" (one to many) mode is the default used for Ctrl-D, and "Add Driver to All"
in the RMB Menu. This is the behaviour described above.
2) There's also a "1-1" (one to one) mode that is used for the "Add Single Driver" in the
RMB Menu.
3) Finally, there's the "N-N" mode (many to many), which isn't currently exposed.
The point of this is to allow mapping XYZ to XYZ elementwise (i.e. direct copying)
which is useful for things like locations, rotations, scaling, and colours.
Implementation Notes:
- The bulk of the driver adding logic is in editors/animation/drivers.c, where most of
the Driver UI operators and tools are defined
- The property eyedropper code is in interface_eyedropper.c along with all the other
eyedroppers (even though they don't share much actual code in common). However, this
turns out to be necessary, as we can't get access to many of the low-level buttons API's
otherwise.
Todo:
- It may be necessary to restore a way to access the old behaviour (i.e. "manual setup")
in case it is not practical to immediately pick a property.
- Other things to investigate here include extra hotkeys (e.g. Ctrl-Shift-D for Add Single?),
and to expose the N-N mode.
- Other things we could try include interactively applying scaling factors, picking
multiple targets (e.g. for location difference and rotation difference drivers),
and/or other ways of using these property picking methods.
2016-03-26 17:55:42 +13:00
|
|
|
WM_operatortype_append(UI_OT_eyedropper_driver);
|
2009-12-17 10:47:55 +00:00
|
|
|
}
|
2016-02-29 17:40:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief User Interface Keymap
|
|
|
|
*/
|
|
|
|
void ED_keymap_ui(wmKeyConfig *keyconf)
|
|
|
|
{
|
2018-11-08 15:59:51 +11:00
|
|
|
WM_keymap_ensure(keyconf, "User Interface", 0, 0);
|
2016-09-21 20:05:49 +02:00
|
|
|
|
2016-02-29 18:46:20 +01:00
|
|
|
eyedropper_modal_keymap(keyconf);
|
2017-12-12 10:19:55 +11:00
|
|
|
eyedropper_colorband_modal_keymap(keyconf);
|
2016-02-29 17:40:19 +01:00
|
|
|
}
|
2019-03-23 12:07:05 +11:00
|
|
|
|
|
|
|
/** \} */
|