Revision: 21988
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21988
Author:   blendix
Date:     2009-07-28 20:51:06 +0200 (Tue, 28 Jul 2009)

Log Message:
-----------
2.5: File browse button in ui layouts now works, e.g. for render
output path or fluidsim path.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
    
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
    
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c
    
branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c

Modified: 
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-07-28 18:42:26 UTC (rev 21987)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-07-28 18:51:06 UTC (rev 21988)
@@ -142,6 +142,7 @@
 #define UI_BUT_ANIMATED_KEY    (1<<21)
 #define UI_BUT_DRIVEN          (1<<22)
 #define UI_BUT_INACTIVE                (1<<23)
+#define UI_BUT_LAST_ACTIVE     (1<<24)
 
 #define UI_PANEL_WIDTH                 340
 #define UI_COMPACT_PANEL_WIDTH 160
@@ -674,9 +675,9 @@
 void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, 
char *propname);
 void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA 
*ptr, char *propname);
 
-/* Animation */
-
+/* Helpers for Operators */
 void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, 
struct PropertyRNA **prop, int *index);
+void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA 
*ptr, struct PropertyRNA **prop);
 
 /* Styled text draw */
 void uiStyleFontSet(struct uiFontStyle *fs);

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c   
    2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c   
    2009-07-28 18:51:06 UTC (rev 21988)
@@ -165,6 +165,10 @@
        uiBlock *block;
        uiBut *but;
 
+       memset(ptr, 0, sizeof(*ptr));
+       *prop= NULL;
+       *index= 0;
+
        if(ar) {
                for(block=ar->uiblocks.first; block; block=block->next) {
                        for(but=block->buttons.first; but; but= but->next) {

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
   2009-07-28 18:51:06 UTC (rev 21988)
@@ -3687,6 +3687,7 @@
 static void button_activate_exit(bContext *C, uiHandleButtonData *data, uiBut 
*but, int mousemove)
 {
        uiBlock *block= but->block;
+       uiBut *bt;
 
        /* ensure we are in the exit state */
        if(data->state != BUTTON_STATE_EXIT)
@@ -3712,7 +3713,14 @@
        if(!data->cancel)
                ui_apply_autokey_undo(C, but);
 
-       /* disable tooltips until mousemove */
+       /* disable tooltips until mousemove + last active flag */
+       for(block=data->region->uiblocks.first; block; block=block->next) {
+               for(bt=block->buttons.first; bt; bt=bt->next)
+                       bt->flag &= ~UI_BUT_LAST_ACTIVE;
+
+               block->tooltipdisabled= 1;
+       }
+
        ui_blocks_set_tooltips(data->region, 0);
 
        /* clean up */
@@ -3728,6 +3736,7 @@
        MEM_freeN(but->active);
        but->active= NULL;
        but->flag &= ~(UI_ACTIVE|UI_SELECT);
+       but->flag |= UI_BUT_LAST_ACTIVE;
        ui_check_but(but);
 
        /* adds empty mousemove in queue for re-init handler, in case mouse is

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c 
    2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c 
    2009-07-28 18:51:06 UTC (rev 21988)
@@ -486,7 +486,9 @@
        if(subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
                uiBlockSetCurLayout(block, uiLayoutRow(sub, 1));
                uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, 
w-UI_UNIT_X, h);
-               but= uiDefIconBut(block, BUT, 0, ICON_FILESEL, x, y, UI_UNIT_X, 
h, NULL, 0.0f, 0.0f, 0.0f, 0.0f, "DUMMY file select button"); /* XXX */
+
+               /* BUTTONS_OT_file_browse calls uiFileBrowseContextProperty */
+               but= uiDefIconButO(block, BUT, "BUTTONS_OT_file_browse", 
WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, "Browse for file or 
directory.");
        }
        else
                but= uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w, 
h);
@@ -495,6 +497,34 @@
        return but;
 }
 
+void uiFileBrowseContextProperty(const bContext *C, PointerRNA *ptr, 
PropertyRNA **prop)
+{
+       ARegion *ar= CTX_wm_region(C);
+       uiBlock *block;
+       uiBut *but, *prevbut;
+
+       memset(ptr, 0, sizeof(*ptr));
+       *prop= NULL;
+
+       if(!ar)
+               return;
+
+       for(block=ar->uiblocks.first; block; block=block->next) {
+               for(but=block->buttons.first; but; but= but->next) {
+                       prevbut= but->prev;
+
+                       /* find the button before the active one */
+                       if((but->flag & UI_BUT_LAST_ACTIVE) && prevbut && 
prevbut->rnapoin.id.data) {
+                               if(RNA_property_type(prevbut->rnaprop) == 
PROP_STRING) {
+                                       *ptr= prevbut->rnapoin;
+                                       *prop= prevbut->rnaprop;
+                                       return;
+                               }
+                       }
+               }
+       }
+}
+
 /********************* Button Items *************************/
 
 /* disabled item */

Modified: 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
   2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
   2009-07-28 18:51:06 UTC (rev 21988)
@@ -89,6 +89,7 @@
 void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
 void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
 
+void BUTTONS_OT_file_browse(struct wmOperatorType *ot);
 void BUTTONS_OT_toolbox(struct wmOperatorType *ot);
 
 #endif /* ED_BUTTONS_INTERN_H */

Modified: 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c  
    2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c  
    2009-07-28 18:51:06 UTC (rev 21988)
@@ -72,6 +72,7 @@
 #include "RNA_define.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "buttons_intern.h"    // own include
 
@@ -935,3 +936,73 @@
        ot->invoke= toolbox_invoke;
 }
 
+/********************** filebrowse operator *********************/
+
+typedef struct FileBrowseOp {
+       PointerRNA ptr;
+       PropertyRNA *prop;
+} FileBrowseOp;
+
+static int file_browse_exec(bContext *C, wmOperator *op)
+{
+       FileBrowseOp *fbo= op->customdata;
+       char *str;
+       
+       str= RNA_string_get_alloc(op->ptr, "filename", 0, 0);
+       RNA_property_string_set(&fbo->ptr, fbo->prop, str);
+       RNA_property_update(C, &fbo->ptr, fbo->prop);
+       MEM_freeN(str);
+
+       MEM_freeN(op->customdata);
+       return OPERATOR_FINISHED;
+}
+
+static int file_browse_cancel(bContext *C, wmOperator *op)
+{
+       MEM_freeN(op->customdata);
+       op->customdata= NULL;
+
+       return OPERATOR_CANCELLED;
+}
+
+static int file_browse_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       PointerRNA ptr;
+       PropertyRNA *prop;
+       FileBrowseOp *fbo;
+       char *str;
+
+       uiFileBrowseContextProperty(C, &ptr, &prop);
+
+       if(!prop)
+               return OPERATOR_CANCELLED;
+       
+       fbo= MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
+       fbo->ptr= ptr;
+       fbo->prop= prop;
+       op->customdata= fbo;
+
+       str= RNA_property_string_get_alloc(&ptr, prop, 0, 0);
+       RNA_string_set(op->ptr, "filename", str);
+       MEM_freeN(str);
+
+       WM_event_add_fileselect(C, op); 
+       
+       return OPERATOR_RUNNING_MODAL;
+}
+
+void BUTTONS_OT_file_browse(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "File Browse";
+       ot->idname= "BUTTONS_OT_file_browse";
+       
+       /* api callbacks */
+       ot->invoke= file_browse_invoke;
+       ot->exec= file_browse_exec;
+       ot->cancel= file_browse_cancel;
+
+       /* properties */
+       WM_operator_properties_filesel(ot, 0);
+}
+

Modified: 
branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
    2009-07-28 18:42:26 UTC (rev 21987)
+++ 
branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
    2009-07-28 18:51:06 UTC (rev 21988)
@@ -209,6 +209,7 @@
        WM_operatortype_append(SCENE_OT_render_layer_remove);
 
        WM_operatortype_append(BUTTONS_OT_toolbox);
+       WM_operatortype_append(BUTTONS_OT_file_browse);
 }
 
 void buttons_keymap(struct wmWindowManager *wm)


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to