Cleanup: Rename callback flags from library_query to `IDWALK_CB_...`
[blender-staging.git] / source / blender / windowmanager / intern / wm_operators.c
index 516164b540a87f9baea7c8448455a43d5e3b87d8..a3f403e0bb34690e9b6b55bc9521127a4dc93759 100644 (file)
@@ -52,7 +52,6 @@
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 #include "DNA_windowmanager_types.h"
-#include "DNA_mesh_types.h" /* only for USE_BMESH_SAVE_AS_COMPAT */
 
 #include "BLT_translation.h"
 
@@ -61,7 +60,6 @@
 #include "BLI_blenlib.h"
 #include "BLI_dial.h"
 #include "BLI_dynstr.h" /*for WM_operator_pystring */
-#include "BLI_linklist_stack.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
@@ -69,8 +67,7 @@
 #include "BLO_readfile.h"
 
 #include "BKE_appdir.h"
-#include "BKE_autoexec.h"
-#include "BKE_blender.h"
+#include "BKE_blender_version.h"
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
 #include "BKE_unit.h"
-#include "BKE_utildefines.h"
 
 #include "BKE_idcode.h"
 
 #include "BIF_glutil.h" /* for paint cursor */
 #include "BLF_api.h"
 
-#include "IMB_colormanagement.h"
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
 #include "ED_util.h"
 #include "ED_view3d.h"
 
-#include "GPU_material.h"
+#include "GPU_basic_shader.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -1073,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;
@@ -1095,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;
        }
@@ -1104,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)
@@ -1206,196 +1206,6 @@ bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFor
        return false;
 }
 
-/* default properties for fileselect */
-void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type, short action, short flag, short display)
-{
-       PropertyRNA *prop;
-
-       static EnumPropertyItem file_display_items[] = {
-               {FILE_DEFAULTDISPLAY, "FILE_DEFAULTDISPLAY", 0, "Default", "Automatically determine display type for files"},
-               {FILE_SHORTDISPLAY, "FILE_SHORTDISPLAY", ICON_SHORTDISPLAY, "Short List", "Display files as short list"},
-               {FILE_LONGDISPLAY, "FILE_LONGDISPLAY", ICON_LONGDISPLAY, "Long List", "Display files as a detailed list"},
-               {FILE_IMGDISPLAY, "FILE_IMGDISPLAY", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-
-       if (flag & WM_FILESEL_FILEPATH)
-               RNA_def_string_file_path(ot->srna, "filepath", NULL, FILE_MAX, "File Path", "Path to file");
-
-       if (flag & WM_FILESEL_DIRECTORY)
-               RNA_def_string_dir_path(ot->srna, "directory", NULL, FILE_MAX, "Directory", "Directory of the file");
-
-       if (flag & WM_FILESEL_FILENAME)
-               RNA_def_string_file_name(ot->srna, "filename", NULL, FILE_MAX, "File Name", "Name of the file");
-
-       if (flag & WM_FILESEL_FILES)
-               RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
-
-       if (action == FILE_SAVE) {
-               /* note, this is only used to check if we should highlight the filename area red when the
-                * filepath is an existing file. */
-               prop = RNA_def_boolean(ot->srna, "check_existing", true, "Check Existing",
-                                      "Check and warn on overwriting existing files");
-               RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       }
-       
-       prop = RNA_def_boolean(ot->srna, "filter_blender", (filter & FILE_TYPE_BLENDER) != 0, "Filter .blend files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_backup", (filter & FILE_TYPE_BLENDER_BACKUP) != 0, "Filter .blend files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_image", (filter & FILE_TYPE_IMAGE) != 0, "Filter image files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_movie", (filter & FILE_TYPE_MOVIE) != 0, "Filter movie files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_python", (filter & FILE_TYPE_PYSCRIPT) != 0, "Filter python files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_font", (filter & FILE_TYPE_FTFONT) != 0, "Filter font files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_sound", (filter & FILE_TYPE_SOUND) != 0, "Filter sound files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_text", (filter & FILE_TYPE_TEXT) != 0, "Filter text files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_btx", (filter & FILE_TYPE_BTX) != 0, "Filter btx files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_collada", (filter & FILE_TYPE_COLLADA) != 0, "Filter COLLADA files", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_folder", (filter & FILE_TYPE_FOLDER) != 0, "Filter folders", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "filter_blenlib", (filter & FILE_TYPE_BLENDERLIB) != 0, "Filter Blender IDs", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-
-       prop = RNA_def_int(ot->srna, "filemode", type, FILE_LOADLIB, FILE_SPECIAL,
-                          "File Browser Mode", "The setting for the file browser mode to load a .blend file, a library or a special file",
-                          FILE_LOADLIB, FILE_SPECIAL);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-
-       if (flag & WM_FILESEL_RELPATH)
-               RNA_def_boolean(ot->srna, "relative_path", true, "Relative Path", "Select the file relative to the blend file");
-
-       if ((filter & FILE_TYPE_IMAGE) || (filter & FILE_TYPE_MOVIE)) {
-               prop = RNA_def_boolean(ot->srna, "show_multiview", 0, "Enable Multi-View", "");
-               RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-               prop = RNA_def_boolean(ot->srna, "use_multiview", 0, "Use Multi-View", "");
-               RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       }
-
-       prop = RNA_def_enum(ot->srna, "display_type", file_display_items, display, "Display Type", "");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-}
-
-static void wm_operator_properties_select_action_ex(wmOperatorType *ot, int default_action,
-                                                    const EnumPropertyItem *select_actions)
-{
-       RNA_def_enum(ot->srna, "action", select_actions, default_action, "Action", "Selection action to execute");
-}
-
-void WM_operator_properties_select_action(wmOperatorType *ot, int default_action)
-{
-       static EnumPropertyItem select_actions[] = {
-               {SEL_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle selection for all elements"},
-               {SEL_SELECT, "SELECT", 0, "Select", "Select all elements"},
-               {SEL_DESELECT, "DESELECT", 0, "Deselect", "Deselect all elements"},
-               {SEL_INVERT, "INVERT", 0, "Invert", "Invert selection of all elements"},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       wm_operator_properties_select_action_ex(ot, default_action, select_actions);
-}
-
-/**
- * only SELECT/DESELECT
- */
-void WM_operator_properties_select_action_simple(wmOperatorType *ot, int default_action)
-{
-       static EnumPropertyItem select_actions[] = {
-               {SEL_SELECT, "SELECT", 0, "Select", "Select all elements"},
-               {SEL_DESELECT, "DESELECT", 0, "Deselect", "Deselect all elements"},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       wm_operator_properties_select_action_ex(ot, default_action, select_actions);
-}
-
-void WM_operator_properties_select_all(wmOperatorType *ot)
-{
-       WM_operator_properties_select_action(ot, SEL_TOGGLE);
-}
-
-void WM_operator_properties_border(wmOperatorType *ot)
-{
-       PropertyRNA *prop;
-
-       prop = RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-}
-
-void WM_operator_properties_border_to_rcti(struct wmOperator *op, rcti *rect)
-{
-       rect->xmin = RNA_int_get(op->ptr, "xmin");
-       rect->ymin = RNA_int_get(op->ptr, "ymin");
-       rect->xmax = RNA_int_get(op->ptr, "xmax");
-       rect->ymax = RNA_int_get(op->ptr, "ymax");
-}
-
-void WM_operator_properties_border_to_rctf(struct wmOperator *op, rctf *rect)
-{
-       rcti rect_i;
-       WM_operator_properties_border_to_rcti(op, &rect_i);
-       BLI_rctf_rcti_copy(rect, &rect_i);
-}
-
-void WM_operator_properties_gesture_border(wmOperatorType *ot, bool extend)
-{
-       RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX);
-
-       WM_operator_properties_border(ot);
-
-       if (extend) {
-               RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection instead of deselecting everything first");
-       }
-}
-
-void WM_operator_properties_mouse_select(wmOperatorType *ot)
-{
-       PropertyRNA *prop;
-       
-       prop = RNA_def_boolean(ot->srna, "extend", false, "Extend",
-                              "Extend selection instead of deselecting everything first");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Remove from selection");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle Selection", "Toggle the selection");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
-void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
-{
-       PropertyRNA *prop;
-
-       prop = RNA_def_int(ot->srna, "xstart", 0, INT_MIN, INT_MAX, "X Start", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "xend", 0, INT_MIN, INT_MAX, "X End", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "ystart", 0, INT_MIN, INT_MAX, "Y Start", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       prop = RNA_def_int(ot->srna, "yend", 0, INT_MIN, INT_MAX, "Y End", "", INT_MIN, INT_MAX);
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-       
-       if (cursor) {
-               prop = RNA_def_int(ot->srna, "cursor", cursor, 0, INT_MAX,
-                                  "Cursor", "Mouse cursor style to use during the modal operator", 0, INT_MAX);
-               RNA_def_property_flag(prop, PROP_HIDDEN);
-       }
-}
-
-
 /* op->poll */
 int WM_operator_winactive(bContext *C)
 {
@@ -1536,6 +1346,8 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
        if (op->type->flag & OPTYPE_MACRO) {
                for (op = op->macro.first; op; op = op->next) {
                        uiLayoutOperatorButs(C, layout, op, NULL, 'H', UI_LAYOUT_OP_SHOW_TITLE);
+                       if (op->next)
+                               uiItemS(layout);
                }
        }
        else {
@@ -1557,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 */
@@ -1572,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) {
@@ -1611,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);
        
@@ -1651,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;
@@ -2019,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"
@@ -2057,1093 +1884,205 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
                Menu menu = {NULL};
                menu.layout = uiLayoutColumn(layout, false);
                menu.type = mt;
-               mt->draw(C, &menu);
-       }
-
-       UI_block_bounds_set_centered(block, 0);
-       
-       return block;
-}
-
-static int wm_splash_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
-       UI_popup_block_invoke(C, wm_block_create_splash, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-static void WM_OT_splash(wmOperatorType *ot)
-{
-       ot->name = "Splash Screen";
-       ot->idname = "WM_OT_splash";
-       ot->description = "Open the splash screen with release info";
-       
-       ot->invoke = wm_splash_invoke;
-       ot->poll = WM_operator_winactive;
-}
-
-
-/* ***************** Search menu ************************* */
-static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *UNUSED(arg_op))
-{
-       static char search[256] = "";
-       wmEvent event;
-       wmWindow *win = CTX_wm_window(C);
-       uiBlock *block;
-       uiBut *but;
-       
-       block = UI_block_begin(C, ar, "_popup", UI_EMBOSS);
-       UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
-       
-       but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, UI_searchbox_size_x(), UI_UNIT_Y, 0, 0, "");
-       UI_but_func_operator_search(but);
-       
-       /* fake button, it holds space for search items */
-       uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);
-       
-       UI_block_bounds_set_popup(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
-       
-       wm_event_init_from_window(win, &event);
-       event.type = EVT_BUT_OPEN;
-       event.val = KM_PRESS;
-       event.customdata = but;
-       event.customdatafree = false;
-       wm_event_add(win, &event);
-       
-       return block;
-}
-
-static int wm_search_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
-{
-       return OPERATOR_FINISHED;
-}
-
-static int wm_search_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
-       UI_popup_block_invoke(C, wm_block_search_menu, op);
-       
-       return OPERATOR_INTERFACE;
-}
-
-/* op->poll */
-static int wm_search_menu_poll(bContext *C)
-{
-       if (CTX_wm_window(C) == NULL) {
-               return 0;
-       }
-       else {
-               ScrArea *sa = CTX_wm_area(C);
-               if (sa) {
-                       if (sa->spacetype == SPACE_CONSOLE) return 0;  /* XXX - so we can use the shortcut in the console */
-                       if (sa->spacetype == SPACE_TEXT) return 0;     /* XXX - so we can use the spacebar in the text editor */
-               }
-               else {
-                       Object *editob = CTX_data_edit_object(C);
-                       if (editob && editob->type == OB_FONT) return 0;  /* XXX - so we can use the spacebar for entering text */
-               }
-       }
-       return 1;
-}
-
-static void WM_OT_search_menu(wmOperatorType *ot)
-{
-       ot->name = "Search Menu";
-       ot->idname = "WM_OT_search_menu";
-       ot->description = "Pop-up a search menu over all available operators in current context";
-       
-       ot->invoke = wm_search_menu_invoke;
-       ot->exec = wm_search_menu_exec;
-       ot->poll = wm_search_menu_poll;
-}
-
-static int wm_call_menu_exec(bContext *C, wmOperator *op)
-{
-       char idname[BKE_ST_MAXNAME];
-       RNA_string_get(op->ptr, "name", idname);
-
-       return UI_popup_menu_invoke(C, idname, op->reports);
-}
-
-static void WM_OT_call_menu(wmOperatorType *ot)
-{
-       ot->name = "Call Menu";
-       ot->idname = "WM_OT_call_menu";
-       ot->description = "Call (draw) a pre-defined menu";
-
-       ot->exec = wm_call_menu_exec;
-       ot->poll = WM_operator_winactive;
-
-       ot->flag = OPTYPE_INTERNAL;
-
-       RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the menu");
-}
-
-static int wm_call_pie_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
-       char idname[BKE_ST_MAXNAME];
-       RNA_string_get(op->ptr, "name", idname);
-
-       return UI_pie_menu_invoke(C, idname, event);
-}
-
-static int wm_call_pie_menu_exec(bContext *C, wmOperator *op)
-{
-       char idname[BKE_ST_MAXNAME];
-       RNA_string_get(op->ptr, "name", idname);
-
-       return UI_pie_menu_invoke(C, idname, CTX_wm_window(C)->eventstate);
-}
-
-static void WM_OT_call_menu_pie(wmOperatorType *ot)
-{
-       ot->name = "Call Pie Menu";
-       ot->idname = "WM_OT_call_menu_pie";
-       ot->description = "Call (draw) a pre-defined pie menu";
-
-       ot->invoke = wm_call_pie_menu_invoke;
-       ot->exec = wm_call_pie_menu_exec;
-       ot->poll = WM_operator_winactive;
-
-       ot->flag = OPTYPE_INTERNAL;
-
-       RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the pie menu");
-}
-
-/* ************ window / screen operator definitions ************** */
-
-/* this poll functions is needed in place of WM_operator_winactive
- * while it crashes on full screen */
-static int wm_operator_winactive_normal(bContext *C)
-{
-       wmWindow *win = CTX_wm_window(C);
-
-       if (win == NULL || win->screen == NULL || win->screen->state != SCREENNORMAL)
-               return 0;
-
-       return 1;
-}
-
-static void WM_OT_window_duplicate(wmOperatorType *ot)
-{
-       ot->name = "Duplicate Window";
-       ot->idname = "WM_OT_window_duplicate";
-       ot->description = "Duplicate the current Blender window";
-               
-       ot->exec = wm_window_duplicate_exec;
-       ot->poll = wm_operator_winactive_normal;
-}
-
-static void WM_OT_save_homefile(wmOperatorType *ot)
-{
-       ot->name = "Save Startup File";
-       ot->idname = "WM_OT_save_homefile";
-       ot->description = "Make the current file the default .blend file, includes preferences";
-               
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_homefile_write_exec;
-}
-
-static int wm_userpref_autoexec_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
-{
-       bPathCompare *path_cmp = MEM_callocN(sizeof(bPathCompare), "bPathCompare");
-       BLI_addtail(&U.autoexec_paths, path_cmp);
-       return OPERATOR_FINISHED;
-}
-
-static void WM_OT_userpref_autoexec_path_add(wmOperatorType *ot)
-{
-       ot->name = "Add Autoexec Path";
-       ot->idname = "WM_OT_userpref_autoexec_path_add";
-       ot->description = "Add path to exclude from autoexecution";
-
-       ot->exec = wm_userpref_autoexec_add_exec;
-
-       ot->flag = OPTYPE_INTERNAL;
-}
-
-static int wm_userpref_autoexec_remove_exec(bContext *UNUSED(C), wmOperator *op)
-{
-       const int index = RNA_int_get(op->ptr, "index");
-       bPathCompare *path_cmp = BLI_findlink(&U.autoexec_paths, index);
-       if (path_cmp) {
-               BLI_freelinkN(&U.autoexec_paths, path_cmp);
-       }
-       return OPERATOR_FINISHED;
-}
-
-static void WM_OT_userpref_autoexec_path_remove(wmOperatorType *ot)
-{
-       ot->name = "Remove Autoexec Path";
-       ot->idname = "WM_OT_userpref_autoexec_path_remove";
-       ot->description = "Remove path to exclude from autoexecution";
-
-       ot->exec = wm_userpref_autoexec_remove_exec;
-
-       ot->flag = OPTYPE_INTERNAL;
-
-       RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
-}
-
-static void WM_OT_save_userpref(wmOperatorType *ot)
-{
-       ot->name = "Save User Settings";
-       ot->idname = "WM_OT_save_userpref";
-       ot->description = "Save user preferences separately, overrides startup file preferences";
-       
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_userpref_write_exec;
-}
-
-static void WM_OT_read_history(wmOperatorType *ot)
-{
-       ot->name = "Reload History File";
-       ot->idname = "WM_OT_read_history";
-       ot->description = "Reloads history and bookmarks";
-
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_history_file_read_exec;
-
-       /* this operator is only used for loading settings from a previous blender install */
-       ot->flag = OPTYPE_INTERNAL;
-}
-
-static void WM_OT_read_homefile(wmOperatorType *ot)
-{
-       PropertyRNA *prop;
-       ot->name = "Reload Start-Up File";
-       ot->idname = "WM_OT_read_homefile";
-       ot->description = "Open the default file (doesn't save the current file)";
-       
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_homefile_read_exec;
-
-       prop = RNA_def_string_file_path(ot->srna, "filepath", NULL,
-                                       FILE_MAX, "File Path", 
-                                       "Path to an alternative start-up file");
-       RNA_def_property_flag(prop, PROP_HIDDEN);
-
-       /* So scripts can use an alternative start-up file without the UI */
-       prop = RNA_def_boolean(ot->srna, "load_ui", true, "Load UI",
-                              "Load user interface setup from the .blend file");
-       RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-
-       /* omit poll to run in background mode */
-}
-
-static void WM_OT_read_factory_settings(wmOperatorType *ot)
-{
-       ot->name = "Load Factory Settings";
-       ot->idname = "WM_OT_read_factory_settings";
-       ot->description = "Load default file and user preferences";
-       
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_homefile_read_exec;
-       /* omit poll to run in background mode */
-}
-
-/* *************** open file **************** */
-
-/**
- * Wrap #WM_file_read, shared by file reading operators.
- */
-static bool wm_file_read_opwrap(bContext *C, const char *filepath, ReportList *reports,
-                                const bool autoexec_init)
-{
-       bool success;
-
-       /* XXX wm in context is not set correctly after WM_file_read -> crash */
-       /* do it before for now, but is this correct with multiple windows? */
-       WM_event_add_notifier(C, NC_WINDOW, NULL);
-
-       if (autoexec_init) {
-               WM_file_autoexec_init(filepath);
-       }
-
-       success = WM_file_read(C, filepath, reports);
-
-       return success;
-}
-
-/* currently fits in a pointer */
-struct FileRuntime {
-       bool is_untrusted;
-};
-
-static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
-       const char *openname = G.main->name;
-
-       if (CTX_wm_window(C) == NULL) {
-               /* in rare cases this could happen, when trying to invoke in background
-                * mode on load for example. Don't use poll for this because exec()
-                * can still run without a window */
-               BKE_report(op->reports, RPT_ERROR, "Context window not set");
-               return OPERATOR_CANCELLED;
-       }
-
-       /* if possible, get the name of the most recently used .blend file */
-       if (G.recent_files.first) {
-               struct RecentFile *recent = G.recent_files.first;
-               openname = recent->filepath;
-       }
-
-       RNA_string_set(op->ptr, "filepath", openname);
-       wm_open_init_load_ui(op, true);
-       wm_open_init_use_scripts(op, true);
-       op->customdata = NULL;
-
-       WM_event_add_fileselect(C, op);
-
-       return OPERATOR_RUNNING_MODAL;
-}
-
-static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
-{
-       char filepath[FILE_MAX];
-       bool success;
-
-       RNA_string_get(op->ptr, "filepath", filepath);
-
-       /* re-use last loaded setting so we can reload a file without changing */
-       wm_open_init_load_ui(op, false);
-       wm_open_init_use_scripts(op, false);
-
-       if (RNA_boolean_get(op->ptr, "load_ui"))
-               G.fileflags &= ~G_FILE_NO_UI;
-       else
-               G.fileflags |= G_FILE_NO_UI;
-               
-       if (RNA_boolean_get(op->ptr, "use_scripts"))
-               G.f |= G_SCRIPT_AUTOEXEC;
-       else
-               G.f &= ~G_SCRIPT_AUTOEXEC;
-       
-       success = wm_file_read_opwrap(C, filepath, op->reports, !(G.f & G_SCRIPT_AUTOEXEC));
-
-       /* for file open also popup for warnings, not only errors */
-       BKE_report_print_level_set(op->reports, RPT_WARNING);
-
-       if (success) {
-               return OPERATOR_FINISHED;
-       }
-       else {
-               return OPERATOR_CANCELLED;
-       }
-}
-
-static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op)
-{
-       struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata;
-       PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
-       bool is_untrusted = false;
-       char path[FILE_MAX];
-       char *lslash;
-
-       RNA_string_get(op->ptr, "filepath", path);
-
-       /* get the dir */
-       lslash = (char *)BLI_last_slash(path);
-       if (lslash) *(lslash + 1) = '\0';
-
-       if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) {
-               if (BKE_autoexec_match(path) == true) {
-                       RNA_property_boolean_set(op->ptr, prop, false);
-                       is_untrusted = true;
-               }
-       }
-
-       if (file_info) {
-               file_info->is_untrusted = is_untrusted;
-       }
-
-       return is_untrusted;
-}
-
-static void wm_open_mainfile_ui(bContext *UNUSED(C), wmOperator *op)
-{
-       struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata;
-       uiLayout *layout = op->layout;
-       uiLayout *col = op->layout;
-       const char *autoexec_text;
-
-       uiItemR(layout, op->ptr, "load_ui", 0, NULL, ICON_NONE);
-
-       col = uiLayoutColumn(layout, false);
-       if (file_info->is_untrusted) {
-               autoexec_text = IFACE_("Trusted Source [Untrusted Path]");
-               uiLayoutSetActive(col, false);
-               uiLayoutSetEnabled(col, false);
-       }
-       else {
-               autoexec_text = IFACE_("Trusted Source");
-       }
-
-       uiItemR(col, op->ptr, "use_scripts", 0, autoexec_text, ICON_NONE);
-}
-
-static void WM_OT_open_mainfile(wmOperatorType *ot)
-{
-       ot->name = "Open Blender File";
-       ot->idname = "WM_OT_open_mainfile";
-       ot->description = "Open a Blender file";
-
-       ot->invoke = wm_open_mainfile_invoke;
-       ot->exec = wm_open_mainfile_exec;
-       ot->check = wm_open_mainfile_check;
-       ot->ui = wm_open_mainfile_ui;
-       /* omit window poll so this can work in background mode */
-
-       WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER, FILE_BLENDER, FILE_OPENFILE,
-                                      WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
-
-       RNA_def_boolean(ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file");
-       RNA_def_boolean(ot->srna, "use_scripts", true, "Trusted Source",
-                       "Allow .blend file to execute scripts automatically, default available from system preferences");
-}
-
-
-/* *************** revert file **************** */
-
-static int wm_revert_mainfile_exec(bContext *C, wmOperator *op)
-{
-       bool success;
-
-       wm_open_init_use_scripts(op, false);
-
-       if (RNA_boolean_get(op->ptr, "use_scripts"))
-               G.f |= G_SCRIPT_AUTOEXEC;
-       else
-               G.f &= ~G_SCRIPT_AUTOEXEC;
-
-       success = wm_file_read_opwrap(C, G.main->name, op->reports, !(G.f & G_SCRIPT_AUTOEXEC));
-
-       if (success) {
-               return OPERATOR_FINISHED;
-       }
-       else {
-               return OPERATOR_CANCELLED;
-       }
-}
-
-static int wm_revert_mainfile_poll(bContext *UNUSED(C))
-{
-       return G.relbase_valid;
-}
-
-static void WM_OT_revert_mainfile(wmOperatorType *ot)
-{
-       ot->name = "Revert";
-       ot->idname = "WM_OT_revert_mainfile";
-       ot->description = "Reload the saved file";
-       ot->invoke = WM_operator_confirm;
-
-       RNA_def_boolean(ot->srna, "use_scripts", true, "Trusted Source",
-                       "Allow .blend file to execute scripts automatically, default available from system preferences");
-
-       ot->exec = wm_revert_mainfile_exec;
-       ot->poll = wm_revert_mainfile_poll;
-}
-
-/* **************** link/append *************** */
-
-static int wm_link_append_poll(bContext *C)
-{
-       if (WM_operator_winactive(C)) {
-               /* linking changes active object which is pretty useful in general,
-                * but which totally confuses edit mode (i.e. it becoming not so obvious
-                * to leave from edit mode and invalid tools in toolbar might be displayed)
-                * so disable link/append when in edit mode (sergey) */
-               if (CTX_data_edit_object(C))
-                       return 0;
-
-               return 1;
-       }
-
-       return 0;
-}
-
-static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
-       if (RNA_struct_property_is_set(op->ptr, "filepath")) {
-               return WM_operator_call_notest(C, op);
-       }
-       else {
-               /* XXX TODO solve where to get last linked library from */
-               if (G.lib[0] != '\0') {
-                       RNA_string_set(op->ptr, "filepath", G.lib);
-               }
-               else if (G.relbase_valid) {
-                       char path[FILE_MAX];
-                       BLI_strncpy(path, G.main->name, sizeof(G.main->name));
-                       BLI_parent_dir(path);
-                       RNA_string_set(op->ptr, "filepath", path);
-               }
-               WM_event_add_fileselect(C, op);
-               return OPERATOR_RUNNING_MODAL;
-       }
-}
-
-static short wm_link_append_flag(wmOperator *op)
-{
-       short flag = 0;
-
-       if (RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
-       if (RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
-       if (RNA_struct_find_property(op->ptr, "relative_path") && RNA_boolean_get(op->ptr, "relative_path")) flag |= FILE_RELPATH;
-       if (RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
-       if (RNA_boolean_get(op->ptr, "instance_groups")) flag |= FILE_GROUP_INSTANCE;
-
-       return flag;
-}
-
-/* Helper.
- *     if `name` is non-NULL, we assume a single-item link/append.
- *     else if `*todo_libraries` is NULL we assume first-run.
- */
-static void wm_link_append_do_libgroup(
-        bContext *C, wmOperator *op, const char *root, const char *libname, char *group, char *name,
-        const short flag, GSet **todo_libraries)
-{
-       Main *bmain = CTX_data_main(C);
-       Main *mainl;
-       BlendHandle *bh;
-       Library *lib;
-
-       char path[FILE_MAX_LIBEXTRA], relname[FILE_MAX];
-       int idcode;
-       const bool is_first_run = (*todo_libraries == NULL);
-
-       BLI_assert(group);
-       idcode = BKE_idcode_from_name(group);
-
-       bh = BLO_blendhandle_from_file(libname, op->reports);
-
-       if (bh == NULL) {
-               /* unlikely since we just browsed it, but possible
-                * error reports will have been made by BLO_blendhandle_from_file() */
-               return;
-       }
-
-       /* here appending/linking starts */
-       mainl = BLO_library_append_begin(bmain, &bh, libname);
-       lib = mainl->curlib;
-       BLI_assert(lib);
-
-       if (mainl->versionfile < 250) {
-               BKE_reportf(op->reports, RPT_WARNING,
-                           "Linking or appending from a very old .blend file format (%d.%d), no animation conversion will "
-                           "be done! You may want to re-save your lib file with current Blender",
-                           mainl->versionfile, mainl->subversionfile);
-       }
-
-       if (name) {
-               BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
-       }
-       else {
-               if (is_first_run) {
-                       *todo_libraries = BLI_gset_new(BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, __func__);
-               }
-
-               RNA_BEGIN (op->ptr, itemptr, "files")
-               {
-                       char curr_libname[FILE_MAX];
-                       int curr_idcode;
-
-                       RNA_string_get(&itemptr, "name", relname);
-
-                       BLI_join_dirfile(path, sizeof(path), root, relname);
-
-                       if (BLO_library_path_explode(path, curr_libname, &group, &name)) {
-                               if (!group || !name) {
-                                       continue;
-                               }
-
-                               curr_idcode = BKE_idcode_from_name(group);
-
-                               if ((idcode == curr_idcode) && (BLI_path_cmp(curr_libname, libname) == 0)) {
-                                       BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
-                               }
-                               else if (is_first_run) {
-                                       BLI_join_dirfile(path, sizeof(path), curr_libname, group);
-                                       if (!BLI_gset_haskey(*todo_libraries, path)) {
-                                               BLI_gset_insert(*todo_libraries, BLI_strdup(path));
-                                       }
-                               }
-                       }
-               }
-               RNA_END;
-       }
-       BLO_library_append_end(C, mainl, &bh, idcode, flag);
-
-       BLO_blendhandle_close(bh);
-
-       /* mark all library linked objects to be updated */
-       BKE_main_lib_objects_recalc_all(bmain);
-       IMB_colormanagement_check_file_config(bmain);
-
-       /* append, rather than linking */
-       if ((flag & FILE_LINK) == 0) {
-               BLI_assert(BLI_findindex(&bmain->library, lib) != -1);
-               BKE_library_make_local(bmain, lib, true);
-       }
-}
-
-static int wm_link_append_exec(bContext *C, wmOperator *op)
-{
-       Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
-       PropertyRNA *prop;
-       char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX], relname[FILE_MAX];
-       char *group, *name;
-       int totfiles = 0;
-       short flag;
-
-       GSet *todo_libraries = NULL;
-
-       RNA_string_get(op->ptr, "filename", relname);
-       RNA_string_get(op->ptr, "directory", root);
-
-       BLI_join_dirfile(path, sizeof(path), root, relname);
-
-       /* test if we have a valid data */
-       if (!BLO_library_path_explode(path, libname, &group, &name)) {
-               BKE_report(op->reports, RPT_ERROR, "Not a library");
-               return OPERATOR_CANCELLED;
-       }
-       else if (!group) {
-               BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
-               return OPERATOR_CANCELLED;
-       }
-       else if (BLI_path_cmp(bmain->name, libname) == 0) {
-               BKE_report(op->reports, RPT_ERROR, "Cannot use current file as library");
-               return OPERATOR_CANCELLED;
-       }
-
-       /* check if something is indicated for append/link */
-       prop = RNA_struct_find_property(op->ptr, "files");
-       if (prop) {
-               totfiles = RNA_property_collection_length(op->ptr, prop);
-               if (totfiles == 0) {
-                       if (!name) {
-                               BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
-                               return OPERATOR_CANCELLED;
-                       }
-               }
-       }
-       else if (!name) {
-               BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
-               return OPERATOR_CANCELLED;
-       }
-
-       flag = wm_link_append_flag(op);
-
-       /* sanity checks for flag */
-       if (scene->id.lib && (flag & FILE_GROUP_INSTANCE)) {
-               /* TODO, user never gets this message */
-               BKE_reportf(op->reports, RPT_WARNING, "Scene '%s' is linked, group instance disabled", scene->id.name + 2);
-               flag &= ~FILE_GROUP_INSTANCE;
-       }
-
-       /* from here down, no error returns */
-
-       /* now we have or selected, or an indicated file */
-       if (RNA_boolean_get(op->ptr, "autoselect"))
-               BKE_scene_base_deselect_all(scene);
-       
-       /* tag everything, all untagged data can be made local
-        * its also generally useful to know what is new
-        *
-        * take extra care BKE_main_id_flag_all(LIB_LINK_TAG, false) is called after! */
-       BKE_main_id_flag_all(bmain, LIB_PRE_EXISTING, 1);
-
-       if (totfiles != 0) {
-               name = NULL;
-       }
-
-       wm_link_append_do_libgroup(C, op, root, libname, group, name, flag, &todo_libraries);
-
-       if (todo_libraries) {
-               GSetIterator libs_it;
-
-               GSET_ITER(libs_it, todo_libraries) {
-                       char *libpath = (char *)BLI_gsetIterator_getKey(&libs_it);
-
-                       BLO_library_path_explode(libpath, libname, &group, NULL);
-
-                       wm_link_append_do_libgroup(C, op, root, libname, group, NULL, flag, &todo_libraries);
-               }
-
-               BLI_gset_free(todo_libraries, MEM_freeN);
-       }
-
-       /* important we unset, otherwise these object wont
-        * link into other scenes from this blend file */
-       BKE_main_id_flag_all(bmain, LIB_PRE_EXISTING, false);
-
-       /* recreate dependency graph to include new objects */
-       DAG_scene_relations_rebuild(bmain, scene);
-       
-       /* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
-       GPU_materials_free();
-
-       /* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
-       BLI_strncpy(G.lib, root, FILE_MAX);
-
-       WM_event_add_notifier(C, NC_WINDOW, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-static void wm_link_append_properties_common(wmOperatorType *ot, bool is_link)
-{
-       PropertyRNA *prop;
+               mt->draw(C, &menu);
+       }
 
-       /* better not save _any_ settings for this operator */
-       /* properties */
-       prop = RNA_def_boolean(ot->srna, "link", is_link,
-                              "Link", "Link the objects or datablocks rather than appending");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
-       prop = RNA_def_boolean(ot->srna, "autoselect", true,
-                              "Select", "Select new objects");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "active_layer", true,
-                              "Active Layer", "Put new objects on the active layer");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_boolean(ot->srna, "instance_groups", is_link,
-                              "Instance Groups", "Create Dupli-Group instances for each group");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+       UI_block_bounds_set_centered(block, 0);
+       
+       return block;
 }
 
-static void WM_OT_link(wmOperatorType *ot)
+static int wm_splash_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
 {
-       ot->name = "Link from Library";
-       ot->idname = "WM_OT_link";
-       ot->description = "Link from a Library .blend file";
-       
-       ot->invoke = wm_link_append_invoke;
-       ot->exec = wm_link_append_exec;
-       ot->poll = wm_link_append_poll;
-       
-       ot->flag |= OPTYPE_UNDO;
-
-       WM_operator_properties_filesel(
-               ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER | FILE_TYPE_BLENDERLIB, FILE_LOADLIB, FILE_OPENFILE,
-               WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME | WM_FILESEL_RELPATH | WM_FILESEL_FILES,
-               FILE_DEFAULTDISPLAY);
+       UI_popup_block_invoke(C, wm_block_create_splash, NULL);
        
-       wm_link_append_properties_common(ot, true);
+       return OPERATOR_FINISHED;
 }
 
-static void WM_OT_append(wmOperatorType *ot)
+static void WM_OT_splash(wmOperatorType *ot)
 {
-       ot->name = "Append from Library";
-       ot->idname = "WM_OT_append";
-       ot->description = "Append from a Library .blend file";
-
-       ot->invoke = wm_link_append_invoke;
-       ot->exec = wm_link_append_exec;
-       ot->poll = wm_link_append_poll;
-
-       ot->flag |= OPTYPE_UNDO;
+       ot->name = "Splash Screen";
+       ot->idname = "WM_OT_splash";
+       ot->description = "Open the splash screen with release info";
+       
+       ot->invoke = wm_splash_invoke;
+       ot->poll = WM_operator_winactive;
+}
 
-       WM_operator_properties_filesel(
-               ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER | FILE_TYPE_BLENDERLIB, FILE_LOADLIB, FILE_OPENFILE,
-               WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME | WM_FILESEL_FILES,
-               FILE_DEFAULTDISPLAY);
 
-       wm_link_append_properties_common(ot, false);
-}
+/* ***************** Search menu ************************* */
 
-/* *************** recover last session **************** */
+struct SearchPopupInit_Data {
+       int size[2];
+};
 
-void WM_recover_last_session(bContext *C, ReportList *reports)
+static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *userdata)
 {
-       char filepath[FILE_MAX];
+       const struct SearchPopupInit_Data *init_data = userdata;
+       static char search[256] = "";
+       wmEvent event;
+       wmWindow *win = CTX_wm_window(C);
+       uiBlock *block;
+       uiBut *but;
        
-       BLI_make_file_string("/", filepath, BKE_tempdir_base(), BLENDER_QUIT_FILE);
-       /* if reports==NULL, it's called directly without operator, we add a quick check here */
-       if (reports || BLI_exists(filepath)) {
-               G.fileflags |= G_FILE_RECOVER;
-               
-               wm_file_read_opwrap(C, filepath, reports, true);
+       block = UI_block_begin(C, ar, "_popup", UI_EMBOSS);
+       UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
        
-               G.fileflags &= ~G_FILE_RECOVER;
-               
-               /* XXX bad global... fixme */
-               if (G.main->name[0])
-                       G.file_loaded = 1;      /* prevents splash to show */
-               else {
-                       G.relbase_valid = 0;
-                       G.save_over = 0;    /* start with save preference untitled.blend */
-               }
-
-       }
+       but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 10, init_data->size[0], UI_UNIT_Y, 0, 0, "");
+       UI_but_func_operator_search(but);
+       
+       /* fake button, it holds space for search items */
+       uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - init_data->size[1],
+                init_data->size[0], init_data->size[1], NULL, 0, 0, 0, 0, NULL);
+       
+       UI_block_bounds_set_popup(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
+       
+       wm_event_init_from_window(win, &event);
+       event.type = EVT_BUT_OPEN;
+       event.val = KM_PRESS;
+       event.customdata = but;
+       event.customdatafree = false;
+       wm_event_add(win, &event);
+       
+       return block;
 }
 
-static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
+static int wm_search_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
-       WM_recover_last_session(C, op->reports);
        return OPERATOR_FINISHED;
 }
 
-static void WM_OT_recover_last_session(wmOperatorType *ot)
+static int wm_search_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
 {
-       ot->name = "Recover Last Session";
-       ot->idname = "WM_OT_recover_last_session";
-       ot->description = "Open the last closed file (\"" BLENDER_QUIT_FILE "\")";
-       ot->invoke = WM_operator_confirm;
+       struct SearchPopupInit_Data data = {
+               .size = {
+                   UI_searchbox_size_x() * 2,
+                   UI_searchbox_size_y(),
+               },
+       };
+
+       UI_popup_block_invoke(C, wm_block_search_menu, &data);
        
-       ot->exec = wm_recover_last_session_exec;
+       return OPERATOR_INTERFACE;
 }
 
-/* *************** recover auto save **************** */
-
-static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
+/* op->poll */
+static int wm_search_menu_poll(bContext *C)
 {
-       char filepath[FILE_MAX];
-       bool success;
-
-       RNA_string_get(op->ptr, "filepath", filepath);
-
-       G.fileflags |= G_FILE_RECOVER;
-
-       success = wm_file_read_opwrap(C, filepath, op->reports, true);
-
-       G.fileflags &= ~G_FILE_RECOVER;
-       
-       if (success) {
-               return OPERATOR_FINISHED;
+       if (CTX_wm_window(C) == NULL) {
+               return 0;
        }
        else {
-               return OPERATOR_CANCELLED;
+               ScrArea *sa = CTX_wm_area(C);
+               if (sa) {
+                       if (sa->spacetype == SPACE_CONSOLE) return 0;  /* XXX - so we can use the shortcut in the console */
+                       if (sa->spacetype == SPACE_TEXT) return 0;     /* XXX - so we can use the spacebar in the text editor */
+               }
+               else {
+                       Object *editob = CTX_data_edit_object(C);
+                       if (editob && editob->type == OB_FONT) return 0;  /* XXX - so we can use the spacebar for entering text */
+               }
        }
+       return 1;
 }
 
-static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static void WM_OT_search_menu(wmOperatorType *ot)
 {
-       char filename[FILE_MAX];
-
-       wm_autosave_location(filename);
-       RNA_string_set(op->ptr, "filepath", filename);
-       WM_event_add_fileselect(C, op);
-
-       return OPERATOR_RUNNING_MODAL;
+       ot->name = "Search Menu";
+       ot->idname = "WM_OT_search_menu";
+       ot->description = "Pop-up a search menu over all available operators in current context";
+       
+       ot->invoke = wm_search_menu_invoke;
+       ot->exec = wm_search_menu_exec;
+       ot->poll = wm_search_menu_poll;
 }
 
-static void WM_OT_recover_auto_save(wmOperatorType *ot)
+static int wm_call_menu_exec(bContext *C, wmOperator *op)
 {
-       ot->name = "Recover Auto Save";
-       ot->idname = "WM_OT_recover_auto_save";
-       ot->description = "Open an automatically saved file to recover it";
-       
-       ot->exec = wm_recover_auto_save_exec;
-       ot->invoke = wm_recover_auto_save_invoke;
+       char idname[BKE_ST_MAXNAME];
+       RNA_string_get(op->ptr, "name", idname);
 
-       WM_operator_properties_filesel(ot, FILE_TYPE_BLENDER, FILE_BLENDER, FILE_OPENFILE,
-                                      WM_FILESEL_FILEPATH, FILE_LONGDISPLAY);
+       return UI_popup_menu_invoke(C, idname, op->reports);
 }
 
-/* *************** save file as **************** */
-
-static void wm_filepath_default(char *filepath)
+static void WM_OT_call_menu(wmOperatorType *ot)
 {
-       if (G.save_over == false) {
-               BLI_ensure_filename(filepath, FILE_MAX, "untitled.blend");
-       }
-}
+       ot->name = "Call Menu";
+       ot->idname = "WM_OT_call_menu";
+       ot->description = "Call (draw) a pre-defined menu";
 
-static void save_set_compress(wmOperator *op)
-{
-       PropertyRNA *prop;
+       ot->exec = wm_call_menu_exec;
+       ot->poll = WM_operator_winactive;
 
-       prop = RNA_struct_find_property(op->ptr, "compress");
-       if (!RNA_property_is_set(op->ptr, prop)) {
-               if (G.save_over) {  /* keep flag for existing file */
-                       RNA_property_boolean_set(op->ptr, prop, (G.fileflags & G_FILE_COMPRESS) != 0);
-               }
-               else {  /* use userdef for new file */
-                       RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_FILECOMPRESS) != 0);
-               }
-       }
+       ot->flag = OPTYPE_INTERNAL;
+
+       RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the menu");
 }
 
-static void save_set_filepath(wmOperator *op)
+static int wm_call_pie_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-       PropertyRNA *prop;
-       char name[FILE_MAX];
-
-       prop = RNA_struct_find_property(op->ptr, "filepath");
-       if (!RNA_property_is_set(op->ptr, prop)) {
-               /* if not saved before, get the name of the most recently used .blend file */
-               if (G.main->name[0] == 0 && G.recent_files.first) {
-                       struct RecentFile *recent = G.recent_files.first;
-                       BLI_strncpy(name, recent->filepath, FILE_MAX);
-               }
-               else {
-                       BLI_strncpy(name, G.main->name, FILE_MAX);
-               }
+       char idname[BKE_ST_MAXNAME];
+       RNA_string_get(op->ptr, "name", idname);
 
-               wm_filepath_default(name);
-               RNA_property_string_set(op->ptr, prop, name);
-       }
+       return UI_pie_menu_invoke(C, idname, event);
 }
 
-static int wm_save_as_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int wm_call_pie_menu_exec(bContext *C, wmOperator *op)
 {
+       char idname[BKE_ST_MAXNAME];
+       RNA_string_get(op->ptr, "name", idname);
 
-       save_set_compress(op);
-       save_set_filepath(op);
-       
-       WM_event_add_fileselect(C, op);
-
-       return OPERATOR_RUNNING_MODAL;
+       return UI_pie_menu_invoke(C, idname, CTX_wm_window(C)->eventstate);
 }
 
-/* function used for WM_OT_save_mainfile too */
-static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
+static void WM_OT_call_menu_pie(wmOperatorType *ot)
 {
-       char path[FILE_MAX];
-       int fileflags;
-
-       save_set_compress(op);
-       
-       if (RNA_struct_property_is_set(op->ptr, "filepath")) {
-               RNA_string_get(op->ptr, "filepath", path);
-       }
-       else {
-               BLI_strncpy(path, G.main->name, FILE_MAX);
-               wm_filepath_default(path);
-       }
-       
-       fileflags = G.fileflags & ~G_FILE_USERPREFS;
-
-       /* set compression flag */
-       BKE_BIT_TEST_SET(fileflags, RNA_boolean_get(op->ptr, "compress"),
-                        G_FILE_COMPRESS);
-       BKE_BIT_TEST_SET(fileflags, RNA_boolean_get(op->ptr, "relative_remap"),
-                        G_FILE_RELATIVE_REMAP);
-       BKE_BIT_TEST_SET(fileflags,
-                        (RNA_struct_property_is_set(op->ptr, "copy") &&
-                         RNA_boolean_get(op->ptr, "copy")),
-                        G_FILE_SAVE_COPY);
-
-#ifdef USE_BMESH_SAVE_AS_COMPAT
-       BKE_BIT_TEST_SET(fileflags,
-                        (RNA_struct_find_property(op->ptr, "use_mesh_compat") &&
-                         RNA_boolean_get(op->ptr, "use_mesh_compat")),
-                        G_FILE_MESH_COMPAT);
-#else
-#  error "don't remove by accident"
-#endif
+       ot->name = "Call Pie Menu";
+       ot->idname = "WM_OT_call_menu_pie";
+       ot->description = "Call (draw) a pre-defined pie menu";
 
-       if (wm_file_write(C, path, fileflags, op->reports) != 0)
-               return OPERATOR_CANCELLED;
+       ot->invoke = wm_call_pie_menu_invoke;
+       ot->exec = wm_call_pie_menu_exec;
+       ot->poll = WM_operator_winactive;
 
-       WM_event_add_notifier(C, NC_WM | ND_FILESAVE, NULL);
+       ot->flag = OPTYPE_INTERNAL;
 
-       return OPERATOR_FINISHED;
+       RNA_def_string(ot->srna, "name", NULL, BKE_ST_MAXNAME, "Name", "Name of the pie menu");
 }
 
-/* function used for WM_OT_save_mainfile too */
-static bool blend_save_check(bContext *UNUSED(C), wmOperator *op)
-{
-       char filepath[FILE_MAX];
-       RNA_string_get(op->ptr, "filepath", filepath);
-       if (!BLO_has_bfile_extension(filepath)) {
-               /* some users would prefer BLI_replace_extension(),
-                * we keep getting nitpicking bug reports about this - campbell */
-               BLI_ensure_extension(filepath, FILE_MAX, ".blend");
-               RNA_string_set(op->ptr, "filepath", filepath);
-               return true;
-       }
-       return false;
-}
+/* ************ window / screen operator definitions ************** */
 
-static void WM_OT_save_as_mainfile(wmOperatorType *ot)
+/* this poll functions is needed in place of WM_operator_winactive
+ * while it crashes on full screen */
+static int wm_operator_winactive_normal(bContext *C)
 {
-       PropertyRNA *prop;
+       wmWindow *win = CTX_wm_window(C);
 
-       ot->name = "Save As Blender File";
-       ot->idname = "WM_OT_save_as_mainfile";
-       ot->description = "Save the current file in the desired location";
-       
-       ot->invoke = wm_save_as_mainfile_invoke;
-       ot->exec = wm_save_as_mainfile_exec;
-       ot->check = blend_save_check;
-       /* omit window poll so this can work in background mode */
-
-       WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER, FILE_BLENDER, FILE_SAVE,
-                                      WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
-       RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
-       RNA_def_boolean(ot->srna, "relative_remap", true, "Remap Relative",
-                       "Remap relative paths when saving in a different directory");
-       prop = RNA_def_boolean(ot->srna, "copy", false, "Save Copy",
-                       "Save a copy of the actual working state but does not make saved file active");
-       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-#ifdef USE_BMESH_SAVE_AS_COMPAT
-       RNA_def_boolean(ot->srna, "use_mesh_compat", false, "Legacy Mesh Format",
-                       "Save using legacy mesh format (no ngons) - WARNING: only saves tris and quads, other ngons will "
-                       "be lost (no implicit triangulation)");
-#endif
-}
+       if (win == NULL || win->screen == NULL || win->screen->state != SCREENNORMAL)
+               return 0;
 
-/* *************** save file directly ******** */
+       return 1;
+}
 
-static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+/* included for script-access */
+static void WM_OT_window_close(wmOperatorType *ot)
 {
-       int ret;
-       
-       /* cancel if no active window */
-       if (CTX_wm_window(C) == NULL)
-               return OPERATOR_CANCELLED;
+       ot->name = "Close Window";
+       ot->idname = "WM_OT_window_close";
+       ot->description = "Close the current Blender window";
 
-       save_set_compress(op);
-       save_set_filepath(op);
-
-       /* if we're saving for the first time and prefer relative paths - any existing paths will be absolute,
-        * enable the option to remap paths to avoid confusion [#37240] */
-       if ((G.relbase_valid == false) && (U.flag & USER_RELPATHS)) {
-               PropertyRNA *prop = RNA_struct_find_property(op->ptr, "relative_remap");
-               if (!RNA_property_is_set(op->ptr, prop)) {
-                       RNA_property_boolean_set(op->ptr, prop, true);
-               }
-       }
-
-       if (G.save_over) {
-               char path[FILE_MAX];
-
-               RNA_string_get(op->ptr, "filepath", path);
-               if (BLI_exists(path)) {
-                       ret = WM_operator_confirm_message_ex(C, op, IFACE_("Save Over?"), ICON_QUESTION, path);
-               }
-               else {
-                       ret = wm_save_as_mainfile_exec(C, op);
-               }
-       }
-       else {
-               WM_event_add_fileselect(C, op);
-               ret = OPERATOR_RUNNING_MODAL;
-       }
-       
-       return ret;
+       ot->exec = wm_window_close_exec;
+       ot->poll = WM_operator_winactive;
 }
 
-static void WM_OT_save_mainfile(wmOperatorType *ot)
+static void WM_OT_window_duplicate(wmOperatorType *ot)
 {
-       ot->name = "Save Blender File";
-       ot->idname = "WM_OT_save_mainfile";
-       ot->description = "Save the current Blender file";
-       
-       ot->invoke = wm_save_mainfile_invoke;
-       ot->exec = wm_save_as_mainfile_exec;
-       ot->check = blend_save_check;
-       /* omit window poll so this can work in background mode */
-       
-       WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_BLENDER, FILE_BLENDER, FILE_SAVE,
-                                      WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
-       RNA_def_boolean(ot->srna, "compress", false, "Compress", "Write compressed .blend file");
-       RNA_def_boolean(ot->srna, "relative_remap", false, "Remap Relative",
-                       "Remap relative paths when saving in a different directory");
+       ot->name = "Duplicate Window";
+       ot->idname = "WM_OT_window_duplicate";
+       ot->description = "Duplicate the current Blender window";
+               
+       ot->exec = wm_window_duplicate_exec;
+       ot->poll = wm_operator_winactive_normal;
 }
 
 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -3360,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;
@@ -3474,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 {
@@ -3923,17 +2872,18 @@ 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 {
        PropertyType type;
        PropertySubType subtype;
        PointerRNA ptr, col_ptr, fill_col_ptr, rot_ptr, zoom_ptr, image_id_ptr;
+       PointerRNA fill_col_override_ptr, fill_col_override_test_ptr;
        PropertyRNA *prop, *col_prop, *fill_col_prop, *rot_prop, *zoom_prop;
+       PropertyRNA *fill_col_override_prop, *fill_col_override_test_prop;
        StructRNA *image_id_srna;
        float initial_value, current_value, min_value, max_value;
        int initial_mouse[2];
@@ -3950,14 +2900,40 @@ 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);
-
-       if (sa && 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);
+       
+       if (sa) {
+               if (hasNumInput(&rc->num_input)) {
+                       char num_str[NUM_STR_REP_LEN];
+                       outputNumInput(&rc->num_input, num_str, &scene->unit);
+                       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, sizeof(msg), "%s: %0.4f", ui_name, rc->current_value);
+                                       break;
+                               case PROP_PIXEL:
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %d", ui_name, (int)rc->current_value); /* XXX: round to nearest? */
+                                       break;
+                               case PROP_PERCENTAGE:
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %3.1f%%", ui_name, rc->current_value);
+                                       break;
+                               case PROP_FACTOR:
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %1.3f", ui_name, rc->current_value);
+                                       break;
+                               case PROP_ANGLE:
+                                       BLI_snprintf(msg, sizeof(msg), "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value));
+                                       break;
+                               default:
+                                       BLI_snprintf(msg, sizeof(msg), "%s", ui_name); /* XXX: No value? */
+                                       break;
+                       }
+               }
                ED_area_headerprint(sa, msg);
        }
 }
@@ -3974,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;
@@ -4009,7 +2985,7 @@ static void radial_control_set_tex(RadialControl *rc)
                        if ((ibuf = BKE_brush_gen_radial_control_imbuf(rc->image_id_ptr.data, rc->use_secondary_tex))) {
                                glGenTextures(1, &rc->gltex);
                                glBindTexture(GL_TEXTURE_2D, rc->gltex);
-                               glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, ibuf->x, ibuf->y, 0,
+                               glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, ibuf->x, ibuf->y, 0,
                                             GL_ALPHA, GL_FLOAT, ibuf->rect_float);
                                MEM_freeN(ibuf->rect_float);
                                MEM_freeN(ibuf);
@@ -4026,8 +3002,23 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph
        float rot;
 
        /* set fill color */
-       if (rc->fill_col_prop)
-               RNA_property_float_get_array(&rc->fill_col_ptr, rc->fill_col_prop, col);
+       if (rc->fill_col_prop) {
+               PointerRNA *fill_ptr;
+               PropertyRNA *fill_prop;
+
+               if (rc->fill_col_override_prop &&
+                   RNA_property_boolean_get(&rc->fill_col_override_test_ptr, rc->fill_col_override_test_prop))
+               {
+                       fill_ptr = &rc->fill_col_override_ptr;
+                       fill_prop = rc->fill_col_override_prop;
+               }
+               else {
+                       fill_ptr = &rc->fill_col_ptr;
+                       fill_prop = rc->fill_col_prop;
+               }
+
+               RNA_property_float_get_array(fill_ptr, fill_prop, col);
+       }
        glColor4f(col[0], col[1], col[2], alpha);
 
        if (rc->gltex) {
@@ -4044,7 +3035,7 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph
                }
 
                /* draw textured quad */
-               glEnable(GL_TEXTURE_2D);
+               GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
                glBegin(GL_QUADS);
                glTexCoord2f(0, 0);
                glVertex2f(-radius, -radius);
@@ -4055,7 +3046,7 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph
                glTexCoord2f(0, 1);
                glVertex2f(-radius, radius);
                glEnd();
-               glDisable(GL_TEXTURE_2D);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
                /* undo rotation */
                if (rc->rot_prop)
@@ -4085,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;
@@ -4104,14 +3095,14 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
                        r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
                        rmin = WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE;
                        alpha = rc->current_value / 2.0f + 0.5f;
-                       BLI_snprintf(str, WM_RADIAL_MAX_STR, "%1.2f", rc->current_value);
+                       BLI_snprintf(str, WM_RADIAL_MAX_STR, "%1.3f", rc->current_value);
                        strdrawlen = BLI_strlen_utf8(str);
                        break;
                case PROP_ANGLE:
                        r1 = r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
                        alpha = 0.75;
                        rmin = WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE;
-                       BLI_snprintf(str, WM_RADIAL_MAX_STR, "%3f", RAD2DEGF(rc->current_value));
+                       BLI_snprintf(str, WM_RADIAL_MAX_STR, "%3.2f", RAD2DEGF(rc->current_value));
                        strdrawlen = BLI_strlen_utf8(str);
                        break;
                default:
@@ -4159,13 +3150,13 @@ 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_width_and_height(fontid, str, strdrawlen, &strwidth, &strheight);
+       BLF_size(fontid, 1.5 * fstyle_points * U.pixelsize, U.dpi);
        BLF_enable(fontid, BLF_SHADOW);
-       BLF_shadow(fontid, 3, 0.0f, 0.0f, 0.0f, 0.5f);
+       BLF_shadow(fontid, 3, (const float[4]){0.0f, 0.0f, 0.0f, 0.5f});
        BLF_shadow_offset(fontid, 1, -1);
 
        /* draw value */
+       BLF_width_and_height(fontid, str, strdrawlen, &strwidth, &strheight);
        BLF_position(fontid, -0.5f * strwidth, -0.5f * strheight, 0.0f);
        BLF_draw(fontid, str, strdrawlen);
 
@@ -4291,9 +3282,27 @@ static int radial_control_get_properties(bContext *C, wmOperator *op)
                return 0;
        if (!radial_control_get_path(&ctx_ptr, op, "color_path", &rc->col_ptr, &rc->col_prop, 3, RC_PROP_REQUIRE_FLOAT))
                return 0;
-       if (!radial_control_get_path(&ctx_ptr, op, "fill_color_path", &rc->fill_col_ptr, &rc->fill_col_prop, 3, RC_PROP_REQUIRE_FLOAT))
+
+
+       if (!radial_control_get_path(
+               &ctx_ptr, op, "fill_color_path", &rc->fill_col_ptr, &rc->fill_col_prop, 3, RC_PROP_REQUIRE_FLOAT))
+       {
                return 0;
-       
+       }
+
+       if (!radial_control_get_path(
+               &ctx_ptr, op, "fill_color_override_path",
+               &rc->fill_col_override_ptr, &rc->fill_col_override_prop, 3, RC_PROP_REQUIRE_FLOAT))
+       {
+               return 0;
+       }
+       if (!radial_control_get_path(
+               &ctx_ptr, op, "fill_color_override_test_path",
+               &rc->fill_col_override_test_ptr, &rc->fill_col_override_test_prop, 0, RC_PROP_REQUIRE_BOOL))
+       {
+               return 0;
+       }
+
        /* slightly ugly; allow this property to not resolve
         * correctly. needed because 3d texture paint shares the same
         * keymap as 2d image paint */
@@ -4445,7 +3454,7 @@ static void radial_control_cancel(bContext *C, wmOperator *op)
 static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
        RadialControl *rc = op->customdata;
-       float new_value, dist, zoom[2];
+       float new_value, dist = 0.0f, zoom[2];
        float delta[2], ret = OPERATOR_RUNNING_MODAL;
        bool snap;
        float angle_precision = 0.0f;
@@ -4550,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;
@@ -4632,6 +3640,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
        }
 
        ED_region_tag_redraw(CTX_wm_region(C));
+       radial_control_update_header(op, C);
 
        if (ret != OPERATOR_RUNNING_MODAL)
                radial_control_cancel(C, op);
@@ -4664,6 +3673,9 @@ static void WM_OT_radial_control(wmOperatorType *ot)
 
        RNA_def_string(ot->srna, "fill_color_path", NULL, 0, "Fill Color Path", "Path of property used to set the fill color of the control");
 
+       RNA_def_string(ot->srna, "fill_color_override_path", NULL, 0, "Fill Color Override Path", "");
+       RNA_def_string(ot->srna, "fill_color_override_test_path", NULL, 0, "Fill Color Override Test", "");
+
        RNA_def_string(ot->srna, "zoom_path", NULL, 0, "Zoom Path", "Path of property used to set the zoom level for the control");
 
        RNA_def_string(ot->srna, "image_id", NULL, 0, "Image ID", "Path of ID that is used to generate an image for the control");
@@ -4881,12 +3893,10 @@ static void WM_OT_dependency_relations(wmOperatorType *ot)
 
 /* *************************** Mat/tex/etc. previews generation ************* */
 
-typedef struct PreviewsIDEnsureStack {
+typedef struct PreviewsIDEnsureData {
        bContext *C;
        Scene *scene;
-
-       BLI_LINKSTACK_DECLARE(id_stack, ID *);
-} PreviewsIDEnsureStack;
+} PreviewsIDEnsureData;
 
 static void previews_id_ensure(bContext *C, Scene *scene, ID *id)
 {
@@ -4894,61 +3904,61 @@ 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 bool previews_id_ensure_callback(void *todo_v, ID **idptr, int UNUSED(cd_flag))
+static int previews_id_ensure_callback(void *userdata, ID *UNUSED(self_id), ID **idptr, int cd_flag)
 {
-       PreviewsIDEnsureStack *todo = todo_v;
+       if (cd_flag & IDWALK_CB_PRIVATE) {
+               return IDWALK_RET_NOP;
+       }
+
+       PreviewsIDEnsureData *data = userdata;
        ID *id = *idptr;
 
-       if (id && (id->flag & LIB_DOIT)) {
-               if (ELEM(GS(id->name), ID_MA, ID_TE, ID_IM, ID_WO, ID_LA)) {
-                       previews_id_ensure(todo->C, todo->scene, id);
-               }
-               id->flag &= ~LIB_DOIT;  /* Tag the ID as done in any case. */
-               BLI_LINKSTACK_PUSH(todo->id_stack, id);
+       if (id && (id->tag & LIB_TAG_DOIT)) {
+               BLI_assert(ELEM(GS(id->name), ID_MA, ID_TE, ID_IM, ID_WO, ID_LA));
+               previews_id_ensure(data->C, data->scene, id);
+               id->tag &= ~LIB_TAG_DOIT;
        }
 
-       return true;
+       return IDWALK_RET_NOP;
 }
 
 static int previews_ensure_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Main *bmain = CTX_data_main(C);
        ListBase *lb[] = {&bmain->mat, &bmain->tex, &bmain->image, &bmain->world, &bmain->lamp, NULL};
-       PreviewsIDEnsureStack preview_id_stack;
+       PreviewsIDEnsureData preview_id_data;
        Scene *scene;
        ID *id;
        int i;
 
-       /* We use LIB_DOIT to check whether we have already handled a given ID or not. */
-       BKE_main_id_flag_all(bmain, LIB_DOIT, true);
-
-       BLI_LINKSTACK_INIT(preview_id_stack.id_stack);
+       /* We use LIB_TAG_DOIT to check whether we have already handled a given ID or not. */
+       BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
+       for (i = 0; lb[i]; i++) {
+               BKE_main_id_tag_listbase(lb[i], LIB_TAG_DOIT, true);
+       }
 
+       preview_id_data.C = C;
        for (scene = bmain->scene.first; scene; scene = scene->id.next) {
-               preview_id_stack.scene = scene;
-               preview_id_stack.C = C;
+               preview_id_data.scene = scene;
                id = (ID *)scene;
 
-               do {
-                       /* This will loop over all IDs linked by current one, render icons for them if needed,
-                        * and add them to 'todo' preview_id_stack. */
-                       BKE_library_foreach_ID_link(id, previews_id_ensure_callback, &preview_id_stack, IDWALK_READONLY);
-               } while ((id = BLI_LINKSTACK_POP(preview_id_stack.id_stack)));
+               BKE_library_foreach_ID_link(NULL, id, previews_id_ensure_callback, &preview_id_data, IDWALK_RECURSE);
        }
 
-       BLI_LINKSTACK_FREE(preview_id_stack.id_stack);
-
        /* Check a last time for ID not used (fake users only, in theory), and
         * do our best for those, using current scene... */
        for (i = 0; lb[i]; i++) {
                for (id = lb[i]->first; id; id = id->next) {
-                       previews_id_ensure(C, NULL, id);
+                       if (id->tag & LIB_TAG_DOIT) {
+                               previews_id_ensure(C, NULL, id);
+                               id->tag &= ~LIB_TAG_DOIT;
+                       }
                }
        }
 
@@ -4957,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;
@@ -4971,7 +3981,7 @@ static void WM_OT_previews_ensure(wmOperatorType *ot)
 static EnumPropertyItem preview_id_type_items[] = {
     {FILTER_ID_SCE, "SCENE", 0, "Scenes", ""},
     {FILTER_ID_GR, "GROUP", 0, "Groups", ""},
-       {FILTER_ID_OB, "OBJECT", 0, "Objects", ""},
+    {FILTER_ID_OB, "OBJECT", 0, "Objects", ""},
     {FILTER_ID_MA, "MATERIAL", 0, "Materials", ""},
     {FILTER_ID_LA, "LAMP", 0, "Lamps", ""},
     {FILTER_ID_WO, "WORLD", 0, "Worlds", ""},
@@ -5016,17 +4026,17 @@ 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;
 
        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");
+                                    FILTER_ID_MA | FILTER_ID_LA | FILTER_ID_WO | FILTER_ID_TE | FILTER_ID_IM,
+                                    "Data-Block Type", "Which data-block previews to clear");
 }
 
 /* *************************** Doc from UI ************* */
@@ -5098,11 +4108,11 @@ static void WM_OT_stereo3d_set(wmOperatorType *ot)
        ot->check = wm_stereo3d_set_check;
        ot->cancel = wm_stereo3d_set_cancel;
 
-       prop = RNA_def_enum(ot->srna, "display_mode", stereo3d_display_items, S3D_DISPLAY_ANAGLYPH, "Display Mode", "");
+       prop = RNA_def_enum(ot->srna, "display_mode", rna_enum_stereo3d_display_items, S3D_DISPLAY_ANAGLYPH, "Display Mode", "");
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_enum(ot->srna, "anaglyph_type", stereo3d_anaglyph_type_items, S3D_ANAGLYPH_REDCYAN, "Anaglyph Type", "");
+       prop = RNA_def_enum(ot->srna, "anaglyph_type", rna_enum_stereo3d_anaglyph_type_items, S3D_ANAGLYPH_REDCYAN, "Anaglyph Type", "");
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-       prop = RNA_def_enum(ot->srna, "interlace_type", stereo3d_interlace_type_items, S3D_INTERLACE_ROW, "Interlace Type", "");
+       prop = RNA_def_enum(ot->srna, "interlace_type", rna_enum_stereo3d_interlace_type_items, S3D_INTERLACE_ROW, "Interlace Type", "");
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
        prop = RNA_def_boolean(ot->srna, "use_interlace_swap", false, "Swap Left/Right",
                               "Swap left and right stereo channels");
@@ -5126,6 +4136,7 @@ void wm_operatortype_init(void)
        /* reserve size is set based on blender default setup */
        global_ops_hash = BLI_ghash_str_new_ex("wm_operatortype_init gh", 2048);
 
+       WM_operatortype_append(WM_OT_window_close);
        WM_operatortype_append(WM_OT_window_duplicate);
        WM_operatortype_append(WM_OT_read_history);
        WM_operatortype_append(WM_OT_read_homefile);
@@ -5140,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);
@@ -5219,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");
 
 }
 
@@ -5316,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");
 }
 
@@ -5350,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 */
@@ -5357,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);
@@ -5395,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 */
@@ -5442,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);
@@ -5459,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);
@@ -5477,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);
@@ -5546,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);
 }
-