Cleanup: Rename callback flags from library_query to `IDWALK_CB_...`
[blender-staging.git] / source / blender / windowmanager / intern / wm_operators.c
index e4ba3969824473680a6f877a7724cb394d110bee..a3f403e0bb34690e9b6b55bc9521127a4dc93759 100644 (file)
@@ -1068,7 +1068,7 @@ int WM_operator_smooth_viewtx_get(const wmOperator *op)
 }
 
 /* invoke callback, uses enum property named "type" */
-int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+int WM_menu_invoke_ex(bContext *C, wmOperator *op, int opcontext)
 {
        PropertyRNA *prop = op->type->prop;
        uiPopupMenu *pup;
@@ -1090,8 +1090,8 @@ int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
                pup = UI_popup_menu_begin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE);
                layout = UI_popup_menu_layout(pup);
                /* set this so the default execution context is the same as submenus */
-               uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
-               uiItemsFullEnumO(layout, op->type->idname, RNA_property_identifier(prop), op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
+               uiLayoutSetOperatorContext(layout, opcontext);
+               uiItemsFullEnumO(layout, op->type->idname, RNA_property_identifier(prop), op->ptr->data, opcontext, 0);
                UI_popup_menu_end(C, pup);
                return OPERATOR_INTERFACE;
        }
@@ -1099,6 +1099,11 @@ int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
        return OPERATOR_CANCELLED;
 }
 
+int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+       return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_REGION_WIN);
+}
+
 
 /* generic enum search invoke popup */
 static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg_op)
@@ -1364,12 +1369,13 @@ typedef struct wmOpPopUp {
 /* Only invoked by OK button in popups created with wm_block_dialog_create() */
 static void dialog_exec_cb(bContext *C, void *arg1, void *arg2)
 {
-       wmWindowManager *wm = CTX_wm_manager(C);
-       wmWindow *win = CTX_wm_window(C);
-
        wmOpPopUp *data = arg1;
        uiBlock *block = arg2;
 
+       /* Explicitly set UI_RETURN_OK flag, otherwise the menu might be cancelled
+        * in case WM_operator_call_ex exits/reloads the current file (T49199). */
+       UI_popup_menu_retval_set(block, UI_RETURN_OK, true);
+
        WM_operator_call_ex(C, data->op, true);
 
        /* let execute handle freeing it */
@@ -1379,14 +1385,24 @@ static void dialog_exec_cb(bContext *C, void *arg1, void *arg2)
        /* in this case, wm_operator_ui_popup_cancel wont run */
        MEM_freeN(data);
 
+       /* get context data *after* WM_operator_call_ex which might have closed the current file and changed context */
+       wmWindowManager *wm = CTX_wm_manager(C);
+       wmWindow *win = CTX_wm_window(C);
+
        /* check window before 'block->handle' incase the
-        * popup execution closed the window and freed the block. see T44688. */
+        * popup execution closed the window and freed the block. see T44688.
+        */
+       /* Post 2.78 TODO: Check if this fix and others related to T44688 are still
+        * needed or can be improved now that requesting context data has been corrected
+        * (see above). We're close to release so not a good time for experiments.
+        * -- Julian
+        */
        if (BLI_findindex(&wm->windows, win) != -1) {
                UI_popup_block_close(C, win, block);
        }
 }
 
-static void dialog_check_cb(bContext *C, void *op_ptr, void *UNUSED(arg))
+static void popup_check_cb(bContext *C, void *op_ptr, void *UNUSED(arg))
 {
        wmOperator *op = op_ptr;
        if (op->type->check) {
@@ -1418,7 +1434,7 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *ar, void *userData)
 
        layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style);
        
-       UI_block_func_set(block, dialog_check_cb, op, NULL);
+       UI_block_func_set(block, popup_check_cb, op, NULL);
 
        uiLayoutOperatorButs(C, layout, op, NULL, 'H', UI_LAYOUT_OP_SHOW_TITLE);
        
@@ -1458,9 +1474,13 @@ static uiBlock *wm_operator_ui_create(bContext *C, ARegion *ar, void *userData)
 
        layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style);
 
+       UI_block_func_set(block, popup_check_cb, op, NULL);
+
        /* since ui is defined the auto-layout args are not used */
        uiLayoutOperatorButs(C, layout, op, NULL, 'V', 0);
 
+       UI_block_func_set(block, NULL, NULL, NULL);
+
        UI_block_bounds_set_popup(block, 4, 0, 0);
 
        return block;
@@ -1826,7 +1846,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
                     BLENDER_VERSION / 100, BLENDER_VERSION % 100);
        uiItemStringO(col, IFACE_("Release Log"), ICON_URL, "WM_OT_url_open", "url", url);
        uiItemStringO(col, IFACE_("Manual"), ICON_URL, "WM_OT_url_open", "url",
-                     "http://www.blender.org/manual");
+                     "https://docs.blender.org/manual/en/dev/");
        uiItemStringO(col, IFACE_("Blender Website"), ICON_URL, "WM_OT_url_open", "url", "http://www.blender.org");
        if (STREQ(STRINGIFY(BLENDER_VERSION_CYCLE), "release")) {
                BLI_snprintf(url, sizeof(url), "http://www.blender.org/documentation/blender_python_api_%d_%d"
@@ -2279,6 +2299,11 @@ int WM_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
                }
 
        }
+#ifdef WITH_INPUT_NDOF
+       else if (event->type == NDOF_MOTION) {
+               return OPERATOR_PASS_THROUGH;
+       }
+#endif
 //     /* Allow view navigation??? */
 //     else {
 //             return OPERATOR_PASS_THROUGH;
@@ -2393,6 +2418,11 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
                                return OPERATOR_FINISHED; /* use finish or we don't get an undo */
                }
        }
+#ifdef WITH_INPUT_NDOF
+       else if (event->type == NDOF_MOTION) {
+               return OPERATOR_PASS_THROUGH;
+       }
+#endif
        /* Allow view navigation??? */
        /* note, this gives issues: 1) other modal ops run on top (border select), 2) middlemouse is used now 3) tablet/trackpad? */
 //     else {
@@ -2842,10 +2872,9 @@ void WM_OT_straightline_gesture(wmOperatorType *ot)
 
 /* *********************** radial control ****************** */
 
-#define WM_RADIAL_CONTROL_DISPLAY_SIZE (200 * U.pixelsize)
-#define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE (35 * U.pixelsize)
+#define WM_RADIAL_CONTROL_DISPLAY_SIZE (200 * UI_DPI_FAC)
+#define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE (35 * UI_DPI_FAC)
 #define WM_RADIAL_CONTROL_DISPLAY_WIDTH (WM_RADIAL_CONTROL_DISPLAY_SIZE - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE)
-#define WM_RADIAL_CONTROL_HEADER_LENGTH 180
 #define WM_RADIAL_MAX_STR 10
 
 typedef struct {
@@ -2871,7 +2900,7 @@ typedef struct {
 static void radial_control_update_header(wmOperator *op, bContext *C)
 {
        RadialControl *rc = op->customdata;
-       char msg[WM_RADIAL_CONTROL_HEADER_LENGTH];
+       char msg[UI_MAX_DRAW_STR];
        ScrArea *sa = CTX_wm_area(C);
        Scene *scene = CTX_data_scene(C);
        
@@ -2879,34 +2908,33 @@ static void radial_control_update_header(wmOperator *op, bContext *C)
                if (hasNumInput(&rc->num_input)) {
                        char num_str[NUM_STR_REP_LEN];
                        outputNumInput(&rc->num_input, num_str, &scene->unit);
-                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %s", RNA_property_ui_name(rc->prop), num_str);
-                       ED_area_headerprint(sa, msg);
+                       BLI_snprintf(msg, sizeof(msg), "%s: %s", RNA_property_ui_name(rc->prop), num_str);
                }
                else {
                        const char *ui_name = RNA_property_ui_name(rc->prop);
                        switch (rc->subtype) {
                                case PROP_NONE:
                                case PROP_DISTANCE:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %0.4f", ui_name, rc->current_value);
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %0.4f", ui_name, rc->current_value);
                                        break;
                                case PROP_PIXEL:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %d", ui_name, (int)rc->current_value); /* XXX: round to nearest? */
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %d", ui_name, (int)rc->current_value); /* XXX: round to nearest? */
                                        break;
                                case PROP_PERCENTAGE:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %3.1f%%", ui_name, rc->current_value);
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %3.1f%%", ui_name, rc->current_value);
                                        break;
                                case PROP_FACTOR:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %1.3f", ui_name, rc->current_value);
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %1.3f", ui_name, rc->current_value);
                                        break;
                                case PROP_ANGLE:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value));
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value));
                                        break;
                                default:
-                                       BLI_snprintf(msg, WM_RADIAL_CONTROL_HEADER_LENGTH, "%s", ui_name); /* XXX: No value? */
+                                       BLI_snprintf(msg, sizeof(msg), "%s", ui_name); /* XXX: No value? */
                                        break;
                        }
-                       ED_area_headerprint(sa, msg);
                }
+               ED_area_headerprint(sa, msg);
        }
 }
 
@@ -2922,7 +2950,7 @@ static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *e
                case PROP_NONE:
                case PROP_DISTANCE:
                case PROP_PIXEL:
-                       d[0] = rc->initial_value * U.pixelsize;
+                       d[0] = rc->initial_value;
                        break;
                case PROP_PERCENTAGE:
                        d[0] = (rc->initial_value) / 100.0f * WM_RADIAL_CONTROL_DISPLAY_WIDTH + WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE;
@@ -3048,8 +3076,8 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
                case PROP_NONE:
                case PROP_DISTANCE:
                case PROP_PIXEL:
-                       r1 = rc->current_value * U.pixelsize;
-                       r2 = rc->initial_value * U.pixelsize;
+                       r1 = rc->current_value;
+                       r2 = rc->initial_value;
                        tex_radius = r1;
                        alpha = 0.75;
                        break;
@@ -3122,7 +3150,7 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
        if (rmin > 0.0f)
                glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), rmin, 40);
 
-       BLF_size(fontid, 1.5 * fstyle_points, 1.0f / U.dpi);
+       BLF_size(fontid, 1.5 * fstyle_points * U.pixelsize, U.dpi);
        BLF_enable(fontid, BLF_SHADOW);
        BLF_shadow(fontid, 3, (const float[4]){0.0f, 0.0f, 0.0f, 0.5f});
        BLF_shadow_offset(fontid, 1, -1);
@@ -3531,7 +3559,6 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
                                                case PROP_PIXEL:
                                                        new_value = dist;
                                                        if (snap) new_value = ((int)new_value + 5) / 10 * 10;
-                                                       new_value /= U.pixelsize;
                                                        break;
                                                case PROP_PERCENTAGE:
                                                        new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) / WM_RADIAL_CONTROL_DISPLAY_WIDTH) * 100.0f;
@@ -3877,14 +3904,18 @@ static void previews_id_ensure(bContext *C, Scene *scene, ID *id)
 
        /* Only preview non-library datablocks, lib ones do not pertain to this .blend file!
         * Same goes for ID with no user. */
-       if (!id->lib && (id->us != 0)) {
+       if (!ID_IS_LINKED_DATABLOCK(id) && (id->us != 0)) {
                UI_id_icon_render(C, scene, id, false, false);
                UI_id_icon_render(C, scene, id, true, false);
        }
 }
 
-static int previews_id_ensure_callback(void *userdata, ID *UNUSED(self_id), ID **idptr, int UNUSED(cd_flag))
+static int previews_id_ensure_callback(void *userdata, ID *UNUSED(self_id), ID **idptr, int cd_flag)
 {
+       if (cd_flag & IDWALK_CB_PRIVATE) {
+               return IDWALK_RET_NOP;
+       }
+
        PreviewsIDEnsureData *data = userdata;
        ID *id = *idptr;
 
@@ -3917,7 +3948,7 @@ static int previews_ensure_exec(bContext *C, wmOperator *UNUSED(op))
                preview_id_data.scene = scene;
                id = (ID *)scene;
 
-               BKE_library_foreach_ID_link(id, previews_id_ensure_callback, &preview_id_data, IDWALK_RECURSE);
+               BKE_library_foreach_ID_link(NULL, id, previews_id_ensure_callback, &preview_id_data, IDWALK_RECURSE);
        }
 
        /* Check a last time for ID not used (fake users only, in theory), and
@@ -3936,9 +3967,9 @@ static int previews_ensure_exec(bContext *C, wmOperator *UNUSED(op))
 
 static void WM_OT_previews_ensure(wmOperatorType *ot)
 {
-       ot->name = "Refresh DataBlock Previews";
+       ot->name = "Refresh Data-Block Previews";
        ot->idname = "WM_OT_previews_ensure";
-       ot->description = "Ensure datablock previews are available and up-to-date "
+       ot->description = "Ensure data-block previews are available and up-to-date "
                          "(to be saved in .blend file, only for some types like materials, textures, etc.)";
 
        ot->exec = previews_ensure_exec;
@@ -3995,9 +4026,9 @@ static int previews_clear_exec(bContext *C, wmOperator *op)
 
 static void WM_OT_previews_clear(wmOperatorType *ot)
 {
-       ot->name = "Clear DataBlock Previews";
+       ot->name = "Clear Data-Block Previews";
        ot->idname = "WM_OT_previews_clear";
-       ot->description = "Clear datablock previews (only for some types like objects, materials, textures, etc.)";
+       ot->description = "Clear data-block previews (only for some types like objects, materials, textures, etc.)";
 
        ot->exec = previews_clear_exec;
        ot->invoke = WM_menu_invoke;
@@ -4005,7 +4036,7 @@ static void WM_OT_previews_clear(wmOperatorType *ot)
        ot->prop = RNA_def_enum_flag(ot->srna, "id_type", preview_id_type_items,
                                     FILTER_ID_SCE | FILTER_ID_OB | FILTER_ID_GR |
                                     FILTER_ID_MA | FILTER_ID_LA | FILTER_ID_WO | FILTER_ID_TE | FILTER_ID_IM,
-                                    "DataBlock Type", "Which datablock previews to clear");
+                                    "Data-Block Type", "Which data-block previews to clear");
 }
 
 /* *************************** Doc from UI ************* */
@@ -4120,6 +4151,8 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_revert_mainfile);
        WM_operatortype_append(WM_OT_link);
        WM_operatortype_append(WM_OT_append);
+       WM_operatortype_append(WM_OT_lib_relocate);
+       WM_operatortype_append(WM_OT_lib_reload);
        WM_operatortype_append(WM_OT_recover_last_session);
        WM_operatortype_append(WM_OT_recover_auto_save);
        WM_operatortype_append(WM_OT_save_as_mainfile);
@@ -4199,7 +4232,8 @@ static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
        WM_modalkeymap_assign(keymap, "MASK_OT_select_circle");
        WM_modalkeymap_assign(keymap, "NODE_OT_select_circle");
        WM_modalkeymap_assign(keymap, "GPENCIL_OT_select_circle");
-       WM_modalkeymap_assign(keymap, "GRAPH_OT_select_circle");        
+       WM_modalkeymap_assign(keymap, "GRAPH_OT_select_circle");
+       WM_modalkeymap_assign(keymap, "ACTION_OT_select_circle");
 
 }
 
@@ -4296,6 +4330,7 @@ static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_border");
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border"); /* XXX TODO: zoom border should perhaps map rightmouse to zoom out instead of in+cancel */
        WM_modalkeymap_assign(keymap, "IMAGE_OT_render_border");
+       WM_modalkeymap_assign(keymap, "IMAGE_OT_view_zoom_border");
        WM_modalkeymap_assign(keymap, "GPENCIL_OT_select_border");
 }
 
@@ -4330,6 +4365,7 @@ static void gesture_zoom_border_modal_keymap(wmKeyConfig *keyconf)
        /* assign map to operators */
        WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
        WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border");
+       WM_modalkeymap_assign(keymap, "IMAGE_OT_view_zoom_border");
 }
 
 /* default keymap for windows and screens, only call once per WM */
@@ -4337,7 +4373,6 @@ void wm_window_keymap(wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap = WM_keymap_find(keyconf, "Window", 0, 0);
        wmKeyMapItem *kmi;
-       const char *data_path;
        
        /* note, this doesn't replace existing keymap items */
        WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
@@ -4375,7 +4410,9 @@ void wm_window_keymap(wmKeyConfig *keyconf)
 
        /* menus that can be accessed anywhere in blender */
        WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
+#ifdef WITH_INPUT_NDOF
        WM_keymap_add_menu(keymap, "USERPREF_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0);
+#endif
 
        /* Space switching */
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
@@ -4422,8 +4459,9 @@ void wm_window_keymap(wmKeyConfig *keyconf)
        RNA_string_set(kmi->ptr, "data_path", "area.type");
        RNA_string_set(kmi->ptr, "value", "DOPESHEET_EDITOR");
        
+#ifdef WITH_INPUT_NDOF
        /* ndof speed */
-       data_path = "user_preferences.inputs.ndof_sensitivity";
+       const char *data_path = "user_preferences.inputs.ndof_sensitivity";
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_scale_float", NDOF_BUTTON_PLUS, KM_PRESS, 0, 0);
        RNA_string_set(kmi->ptr, "data_path", data_path);
        RNA_float_set(kmi->ptr, "value", 1.1f);
@@ -4439,9 +4477,7 @@ void wm_window_keymap(wmKeyConfig *keyconf)
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_scale_float", NDOF_BUTTON_MINUS, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(kmi->ptr, "data_path", data_path);
        RNA_float_set(kmi->ptr, "value", 1.0f / 1.5f);
-       data_path = NULL;
-       (void)data_path;
-
+#endif /* WITH_INPUT_NDOF */
 
        gesture_circle_modal_keymap(keyconf);
        gesture_border_modal_keymap(keyconf);
@@ -4457,7 +4493,7 @@ static EnumPropertyItem *rna_id_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(pt
        int i = 0;
 
        for (; id; id = id->next) {
-               if (local == false || id->lib == NULL) {
+               if (local == false || !ID_IS_LINKED_DATABLOCK(id)) {
                        item_tmp.identifier = item_tmp.name = id->name + 2;
                        item_tmp.value = i++;
                        RNA_enum_item_add(&item, &totitem, &item_tmp);
@@ -4526,4 +4562,3 @@ EnumPropertyItem *RNA_mask_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA
 {
        return rna_id_itemf(C, ptr, r_free, C ? (ID *)CTX_data_main(C)->mask.first : NULL, true);
 }
-