Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Tue, 3 Jul 2018 05:23:15 +0000 (07:23 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 3 Jul 2018 05:23:15 +0000 (07:23 +0200)
1  2 
source/blender/editors/interface/interface_ops.c

index 3457d2e2eebf8aa10be7867a829a499775648cc2,9a4ea41141a333673466d48a50bd69459bbddeb4..96128aa29f0b5a15a35caaeaf3523831d87f23bd
  #include "BLT_lang.h"
  
  #include "BKE_context.h"
 +#include "BKE_idprop.h"
 +#include "BKE_layer.h"
  #include "BKE_screen.h"
  #include "BKE_global.h"
 +#include "BKE_library_override.h"
  #include "BKE_node.h"
  #include "BKE_text.h" /* for UI_OT_reports_to_text */
  #include "BKE_report.h"
  
 +#include "DEG_depsgraph.h"
 +
  #include "RNA_access.h"
  #include "RNA_define.h"
 +#include "RNA_types.h"
  
  #include "UI_interface.h"
  
@@@ -334,217 -328,6 +334,217 @@@ static void UI_OT_unset_property_button
        ot->flag = OPTYPE_UNDO;
  }
  
 +
 +/* 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",
 +       "'No-Operation', place holder preventing automatic override to ever affect the property"},
 +      {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)"},
 +      {0, NULL, 0, NULL, NULL}
 +};
 +
 +
 +static bool override_type_set_button_poll(bContext *C)
 +{
 +      PointerRNA ptr;
 +      PropertyRNA *prop;
 +      int index;
 +
 +      UI_context_active_but_prop_get(C, &ptr, &prop, &index);
 +
 +      const int override_status = RNA_property_static_override_status(&ptr, prop, index);
 +
 +      return (ptr.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDABLE));
 +}
 +
 +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;
 +
 +      switch (op_type) {
 +              case UIOverride_Type_NOOP:
 +                      operation = IDOVERRIDESTATIC_OP_NOOP;
 +                      break;
 +              case UIOverride_Type_Replace:
 +                      operation = IDOVERRIDESTATIC_OP_REPLACE;
 +                      break;
 +              case UIOverride_Type_Difference:
 +                      operation = IDOVERRIDESTATIC_OP_ADD;  /* override code will automatically switch to subtract if needed. */
 +                      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(
 +              &ptr, prop, operation, index, true, NULL, &created);
 +      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))
 +{
 +#if 0  /* Disabled for now */
 +      return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_DEFAULT);
 +#else
 +      RNA_enum_set(op->ptr, "type", IDOVERRIDESTATIC_OP_REPLACE);
 +      return override_type_set_button_exec(C, op);
 +#endif
 +}
 +
 +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");
 +      ot->prop = RNA_def_enum(
 +              ot->srna, "type", override_type_items, UIOverride_Type_Replace,
 +              "Type", "Type of override operation");
 +      /* TODO: add itemf callback, not all options are available for all data types... */
 +}
 +
 +
 +static bool override_remove_button_poll(bContext *C)
 +{
 +      PointerRNA ptr;
 +      PropertyRNA *prop;
 +      int index;
 +
 +      UI_context_active_but_prop_get(C, &ptr, &prop, &index);
 +
 +      const int override_status = RNA_property_static_override_status(&ptr, prop, index);
 +
 +      return (ptr.data && ptr.id.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN));
 +}
 +
 +static int override_remove_button_exec(bContext *C, wmOperator *op)
 +{
 +      Main *bmain = CTX_data_main(C);
 +      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;
 +              /* Remove override operation for given item, add singular operations for the other items as needed. */
 +              IDOverrideStaticPropertyOperation *opop = BKE_override_static_property_operation_find(
 +                      oprop, NULL, NULL, index, index, false, &is_strict_find);
 +              BLI_assert(opop != NULL);
 +              if (!is_strict_find) {
 +                      /* No specific override operation, we have to get generic one,
 +                       * and create item-specific override operations for all but given index, before removing generic one. */
 +                      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) {
 +                      RNA_property_copy(bmain, &ptr, &src, prop, index);
 +              }
 +              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) {
 +                      RNA_property_copy(bmain, &ptr, &src, prop, -1);
 +              }
 +      }
 +
 +      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");
 +}
 +
 +
 +
 +
  /* Copy To Selected Operator ------------------------ */
  
  bool UI_context_copy_to_selected_list(
   */
  static bool copy_to_selected_button(bContext *C, bool all, bool poll)
  {
 +      Main *bmain = CTX_data_main(C);
        PointerRNA ptr, lptr, idptr;
        PropertyRNA *prop, *lprop;
        bool success = false;
                                                                break;
                                                        }
                                                        else {
 -                                                              if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
 +                                                              if (RNA_property_copy(bmain, &lptr, &ptr, prop, (all) ? -1 : index)) {
                                                                        RNA_property_update(C, &lptr, prop);
                                                                        success = true;
                                                                }
@@@ -948,11 -730,14 +948,14 @@@ void UI_editsource_active_but_test(uiBu
  
  static int editsource_text_edit(
          bContext *C, wmOperator *op,
-         char filepath[FILE_MAX], int line)
+         const char filepath[FILE_MAX], const int line)
  {
        struct Main *bmain = CTX_data_main(C);
        Text *text;
  
+       /* Developers may wish to copy-paste to an external editor. */
+       printf("%s:%d\n", filepath, line);
        for (text = bmain->text.first; text; text = text->id.next) {
                if (text->name && BLI_path_cmp(text->name, filepath) == 0) {
                        break;
@@@ -1007,7 -792,6 +1010,7 @@@ static int editsource_exec(bContext *C
                ui_editsource_active_but_set(but);
  
                /* redraw and get active button python info */
 +              ED_region_do_layout(C, ar);
                ED_region_do_draw(C, ar);
                ar->do_draw = false;
  
@@@ -1343,8 -1127,6 +1346,8 @@@ void ED_operatortypes_ui(void
        WM_operatortype_append(UI_OT_copy_python_command_button);
        WM_operatortype_append(UI_OT_reset_default_button);
        WM_operatortype_append(UI_OT_unset_property_button);
 +      WM_operatortype_append(UI_OT_override_type_set_button);
 +      WM_operatortype_append(UI_OT_override_remove_button);
        WM_operatortype_append(UI_OT_copy_to_selected_button);
        WM_operatortype_append(UI_OT_reports_to_textblock);  /* XXX: temp? */
        WM_operatortype_append(UI_OT_drop_color);