Blender file selector support for setting multiple selected files/dirs which operator...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 5 Jun 2009 16:11:35 +0000 (16:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 5 Jun 2009 16:11:35 +0000 (16:11 +0000)
This allows the sequencers Add-Image strip to work like it does in 2.4x.

- as well as setting the "filename" operator property, operators can have collections called "files" and "dirs" which are set when available.
- RNA_OperatorFileListElement as new collection type, its a bit redundant since each item only has a "name" property but its needed since we don't have a string array type.
- the file selector now prints operators it runs.

Tested with python, adding a list of images works to the sequencer works.
bpy.ops.SEQUENCER_OT_image_strip_add(name="MyImages", start_frame=54, channel=2, filename="/somedir/", replace_sel=True, files=[{"name":"test1.png"}, {"name":"test2.png"}])

source/blender/editors/space_file/file_ops.c
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/makesrna/RNA_access.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_wm.c
source/blender/python/intern/bpy_interface.c
source/blender/windowmanager/intern/wm_event_system.c

index 94c023207f5628013b4f625c5f37569c01660e08..01f94741f59b4ae2f91386ea2f9686d6d76d6853 100644 (file)
@@ -480,6 +480,36 @@ int file_exec(bContext *C, wmOperator *unused)
                strcat(name, sfile->params->file);
                RNA_string_set(op->ptr, "filename", name);
                
+               /* some ops have multiple files to select */
+               {
+                       PointerRNA itemptr;
+                       int i, numfiles = filelist_numfiles(sfile->files);
+                       struct direntry *file;
+                       if(RNA_struct_find_property(op->ptr, "files")) {
+                               for (i=0; i<numfiles; i++) {
+                                       file = filelist_file(sfile->files, i);
+                                       if(file->flags & ACTIVE) {
+                                               if ((file->type & S_IFDIR)==0) {
+                                                       RNA_collection_add(op->ptr, "files", &itemptr);
+                                                       RNA_string_set(&itemptr, "name", file->relname);
+                                               }
+                                       }
+                               }
+                       }
+                       
+                       if(RNA_struct_find_property(op->ptr, "dirs")) {
+                               for (i=0; i<numfiles; i++) {
+                                       file = filelist_file(sfile->files, i);
+                                       if(file->flags & ACTIVE) {
+                                               if ((file->type & S_IFDIR)) {
+                                                       RNA_collection_add(op->ptr, "dirs", &itemptr);
+                                                       RNA_string_set(&itemptr, "name", file->relname);
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
                fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1);
                BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
                fsmenu_write_file(fsmenu_get(), name);
index 6e38ff053be8935931df824c3c94fbf13b0cba17..8373f588fb23ffa9744e98e9435c81d68ec10635 100644 (file)
@@ -423,9 +423,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Editing *ed= seq_give_editing(scene, TRUE);
 
-
-       int tot_images= 1; //XXX FIXME, we need string arrays!
-       //int a;
+       int tot_images;
 
        char filename[FILE_MAX];
 
@@ -440,26 +438,30 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
        
        RNA_string_get(op->ptr, "filename", filename);
 
-       seq = alloc_sequence(ed->seqbasep, start_frame, channel);
-       
+       seq = alloc_sequence(ed->seqbasep, start_frame, channel);       
        seq->type= SEQ_IMAGE;
        
        /* basic defaults */
        seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
-       strip->len = seq->len = tot_images;     
+       BLI_split_dirfile_basic(filename, strip->dir, NULL);
+       
+       tot_images= RNA_property_collection_length(op->ptr, RNA_struct_find_property(op->ptr, "files"));
+       
+       strip->len = seq->len = tot_images?tot_images:1;
        strip->us= 1;
        
        strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
        
-
-       BLI_split_dirfile_basic(filename, strip->dir, se->name); // XXX se->name assignment should be moved into the loop below
-
-#if 0 // XXX
-       for(a=0; a<seq->len; a++) {
-          strncpy(se->name, name, FILE_MAXFILE-1);
-          se++;
+       if(tot_images) {
+               RNA_BEGIN(op->ptr, itemptr, "files") {
+                       RNA_string_get(&itemptr, "name", se->name);
+                       se++;
+               }
+               RNA_END;
+       }
+       else {
+               BLI_split_dirfile_basic(filename, NULL, se->name);
        }
-#endif
 
        RNA_string_get(op->ptr, "name", seq->name);
        
@@ -507,6 +509,8 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME|SEQPROP_FILENAME);
+       
+       RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
 }
 
 
index 4df5aa6710406ab6604a224a7e029ba2954c8a23..eb355a34f9f460bd39e0bdfb665c5490861f758b 100644 (file)
@@ -196,6 +196,7 @@ extern StructRNA RNA_NorController;
 extern StructRNA RNA_Object;
 extern StructRNA RNA_ObstacleFluidSettings;
 extern StructRNA RNA_Operator;
+extern StructRNA RNA_OperatorFileListElement;
 extern StructRNA RNA_OperatorMousePath;
 extern StructRNA RNA_OperatorProperties;
 extern StructRNA RNA_OperatorStrokeElement;
index 91b46e8e3d7541c26de1f8b4865cbd9495a8f01b..e762d1626f57f347b73d794c7f55d5c0906cb904 100644 (file)
@@ -2214,7 +2214,6 @@ char *RNA_pointer_as_string(PointerRNA *ptr)
                cstring = RNA_property_as_string(&iter.ptr, prop);
                BLI_dynstr_appendf(dynstr, "\"%s\":%s", propname, cstring);
                MEM_freeN(cstring);
-               first_time= 0;
        }
 
        RNA_property_collection_end(&iter);
index a8f63566349e7b52d531a48a21e866128bb49139..b4d2cb35121ee18b70daeae381985abe6b02d0a2 100644 (file)
@@ -133,6 +133,21 @@ static void rna_def_operator_utils(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Time", "Time of mouse location.");
 }
 
+static void rna_def_operator_filelist_element(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       srna= RNA_def_struct(brna, "OperatorFileListElement", "IDPropertyGroup");
+       RNA_def_struct_ui_text(srna, "Operator File List Element", "");
+       
+       
+       prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_IDPROPERTY);
+       RNA_def_property_ui_text(prop, "Name", "the name of a file or directory within a file list");
+}
+
+
 static void rna_def_windowmanager(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -151,6 +166,7 @@ void RNA_def_wm(BlenderRNA *brna)
 {
        rna_def_operator(brna);
        rna_def_operator_utils(brna);
+       rna_def_operator_filelist_element(brna);
        rna_def_windowmanager(brna);
 }
 
index 999f6d8e9cb3083489f04acae1fc4847fe5a4563..7b3a67ebff5a570b410b4ed4071ee2ab74d18c4f 100644 (file)
@@ -19,6 +19,7 @@
 #include "bpy_rna.h"
 #include "bpy_operator.h"
 #include "bpy_ui.h"
+#include "bpy_util.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_space_types.h"
index fc0f1496c6aaa7706b43478b27e39b93dce82045..53f70f6ab8f131b1c6c9f331d69add333df39590 100644 (file)
@@ -826,7 +826,12 @@ static int wm_handler_fileselect_call(bContext *C, ListBase *handlers, wmEventHa
                                                uiPupMenuSaveOver(C, handler->op, path);
                                        }
                                        else {
-                                               handler->op->type->exec(C, handler->op);
+                                               int retval= handler->op->type->exec(C, handler->op);
+                                               
+                                               if (retval & OPERATOR_FINISHED)
+                                                       if(G.f & G_DEBUG)
+                                                               wm_operator_print(handler->op);
+                                               
                                                WM_operator_free(handler->op);
                                        }