RNA
[blender.git] / source / blender / windowmanager / intern / wm_operators.c
index 34baf672d5e73c2b5fa275ce31d87028459167e9..46e9df10adcf2f790af7db5a458b528be588e773 100644 (file)
@@ -232,7 +232,7 @@ int WM_operator_confirm(bContext *C, wmOperator *op, wmEvent *event)
        uiPopupMenu *pup;
        uiLayout *layout;
 
-       pup= uiPupMenuBegin(C, "OK?", ICON_HELP);
+       pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
        layout= uiPupMenuLayout(pup);
        uiItemO(layout, NULL, 0, op->type->idname);
        uiPupMenuEnd(C, pup);
@@ -276,7 +276,8 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
        wmOperator *op= arg_op;
        PointerRNA ptr;
        uiBlock *block;
-       int height;
+       uiLayout *layout;
+       uiStyle *style= U.uistyles.first;
        
        block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
        uiBlockClearFlag(block, UI_BLOCK_LOOP);
@@ -289,7 +290,8 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
        }
 
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       height= uiDefAutoButsRNA(C, block, &ptr);
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
+       uiDefAutoButsRNA(C, layout, &ptr);
 
        uiPopupBoundsBlock(block, 4.0f, 0, 0);
        uiEndBlock(C, block);
@@ -317,6 +319,151 @@ int WM_operator_redo_popup(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
+/* ***************** Debug menu ************************* */
+
+static uiBlock *wm_block_create_menu(bContext *C, ARegion *ar, void *arg_op)
+{
+       wmOperator *op= arg_op;
+       uiBlock *block;
+       uiLayout *layout;
+       uiStyle *style= U.uistyles.first;
+       
+       block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockClearFlag(block, UI_BLOCK_LOOP);
+       uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
+       
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 300, 20, style);
+       uiDefAutoButsRNA(C, layout, op->ptr);
+       
+       uiPopupBoundsBlock(block, 4.0f, 0, 0);
+       uiEndBlock(C, block);
+       
+       return block;
+}
+
+static int wm_debug_menu_exec(bContext *C, wmOperator *op)
+{
+       G.rt= RNA_int_get(op->ptr, "debugval");
+       ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
+       
+       return OPERATOR_FINISHED;       
+}
+
+static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       
+       RNA_int_set(op->ptr, "debugval", G.rt);
+       
+       /* pass on operator, so return modal */
+       uiPupBlockOperator(C, wm_block_create_menu, op, WM_OP_EXEC_DEFAULT);
+       
+       return OPERATOR_RUNNING_MODAL;
+}
+
+static void WM_OT_debug_menu(wmOperatorType *ot)
+{
+       ot->name= "Debug Menu";
+       ot->idname= "WM_OT_debug_menu";
+       
+       ot->invoke= wm_debug_menu_invoke;
+       ot->exec= wm_debug_menu_exec;
+       ot->poll= WM_operator_winactive;
+       
+       RNA_def_int(ot->srna, "debugval", 0, -10000, 10000, "Debug Value", "", INT_MIN, INT_MAX);
+}
+
+/* ***************** Search menu ************************* */
+static void operator_call_cb(struct bContext *C, void *arg1, void *arg2)
+{
+       wmOperatorType *ot= arg2;
+       
+       if(ot)
+               WM_operator_name_call(C, ot->idname, WM_OP_INVOKE_DEFAULT, NULL);
+}
+
+static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
+{
+       wmOperatorType *ot = WM_operatortype_first();
+       
+       for(; ot; ot= ot->next) {
+               
+               if(BLI_strcasestr(ot->name, str)) {
+                       if(ot->poll==NULL || ot->poll((bContext *)C)) {
+                               char name[256];
+                               int len= strlen(ot->name);
+                               
+                               /* display name for menu, can hold hotkey */
+                               BLI_strncpy(name, ot->name, 256);
+                               
+                               /* check for hotkey */
+                               if(len < 256-6) {
+                                       if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, &name[len+1], 256-len-1))
+                                               name[len]= '|';
+                               }
+                               
+                               if(0==uiSearchItemAdd(items, name, ot))
+                                       break;
+                       }
+               }
+       }
+}
+
+static uiBlock *wm_block_search_menu(bContext *C, ARegion *ar, void *arg_op)
+{
+       static char search[256]= "";
+       wmEvent event;
+       wmWindow *win= CTX_wm_window(C);
+       uiBlock *block;
+       uiBut *but;
+       
+       block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_RET_1);
+       
+       but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 10, 180, 19, "");
+       uiButSetSearchFunc(but, operator_search_cb, NULL, operator_call_cb);
+       
+       /* fake button, it holds space for search items */
+       uiDefBut(block, LABEL, 0, "", 10, 10 - uiSearchBoxhHeight(), 180, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
+       
+       uiPopupBoundsBlock(block, 6.0f, 0, -20); /* move it downwards, mouse over button */
+       uiEndBlock(C, block);
+       
+       event= *(win->eventstate);      /* XXX huh huh? make api call */
+       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 *C, wmOperator *op)
+{
+       
+       return OPERATOR_FINISHED;       
+}
+
+static int wm_search_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       
+       uiPupBlock(C, wm_block_search_menu, op);
+       
+       return OPERATOR_CANCELLED;
+}
+
+static void WM_OT_search_menu(wmOperatorType *ot)
+{
+       ot->name= "Search Menu";
+       ot->idname= "WM_OT_search_menu";
+       
+       ot->invoke= wm_search_menu_invoke;
+       ot->exec= wm_search_menu_exec;
+       ot->poll= WM_operator_winactive;
+}
+
+
 /* ************ window / screen operator definitions ************** */
 
 static void WM_OT_window_duplicate(wmOperatorType *ot)
@@ -1252,10 +1399,10 @@ void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
 void WM_OT_radial_control_partial(wmOperatorType *ot)
 {
        static EnumPropertyItem prop_mode_items[] = {
-               {WM_RADIALCONTROL_SIZE, "SIZE", "Size", ""},
-               {WM_RADIALCONTROL_STRENGTH, "STRENGTH", "Strength", ""},
-               {WM_RADIALCONTROL_ANGLE, "ANGLE", "Angle", ""},
-               {0, NULL, NULL, NULL}};
+               {WM_RADIALCONTROL_SIZE, "SIZE", 0, "Size", ""},
+               {WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
+               {WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
+               {0, NULL, 0, NULL, NULL}};
 
        /* Should be set in custom invoke() */
        RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
@@ -1337,12 +1484,12 @@ static int ten_timer_exec(bContext *C, wmOperator *op)
 static void WM_OT_ten_timer(wmOperatorType *ot)
 {
        static EnumPropertyItem prop_type_items[] = {
-       {0, "DRAW", "Draw Region", ""},
-       {1, "DRAWSWAP", "Draw Region + Swap", ""},
-       {2, "DRAWWINSWAP", "Draw Window + Swap", ""},
-       {3, "ANIMSTEP", "Anim Step", ""},
-       {4, "UNDO", "Undo/Redo", ""},
-       {0, NULL, NULL, NULL}};
+       {0, "DRAW", 0, "Draw Region", ""},
+       {1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
+       {2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
+       {3, "ANIMSTEP", 0, "Anim Step", ""},
+       {4, "UNDO", 0, "Undo/Redo", ""},
+       {0, NULL, 0, NULL, NULL}};
        
        ot->name= "Ten Timer";
        ot->idname= "WM_OT_ten_timer";
@@ -1379,6 +1526,8 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_save_as_mainfile);
        WM_operatortype_append(WM_OT_save_mainfile);
        WM_operatortype_append(WM_OT_ten_timer);
+       WM_operatortype_append(WM_OT_debug_menu);
+       WM_operatortype_append(WM_OT_search_menu);
 }
 
 /* default keymap for windows and screens, only call once per WM */
@@ -1400,6 +1549,10 @@ void wm_window_keymap(wmWindowManager *wm)
        WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, 0, 0);
        WM_keymap_verify_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
 
+       /* debug/testing */
        WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+       WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+       WM_keymap_verify_item(keymap, "WM_OT_search_menu", FKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+       
 }