file operator cleanup
authorAndrea Weikert <elubie@gmx.net>
Sat, 26 Jun 2010 08:53:29 +0000 (08:53 +0000)
committerAndrea Weikert <elubie@gmx.net>
Sat, 26 Jun 2010 08:53:29 +0000 (08:53 +0000)
* the default properties of the file operator now only contain the "filepath", which means only the complete path to a file is returned.
* "filename" and "directory" has been added to the link/append operator - the only place it was used.
* sequence operators still work on the "files", which was custom property passed to the file operator anyway.
* have tested sequence loading, image loading and append/link - please report if there are any issues

source/blender/editors/space_file/file_ops.c
source/blender/windowmanager/intern/wm_operators.c

index 9028e5f15c60645d61320a93b709947b1ac32620..7c2a2f436cc08b6fb5e865a395a3704a93cc4ed6 100644 (file)
@@ -545,7 +545,7 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
 int file_exec(bContext *C, wmOperator *exec_op)
 {
        SpaceFile *sfile= CTX_wm_space_file(C);
-       char name[FILE_MAX];
+       char filepath[FILE_MAX];
        
        if(sfile->op) {
                wmOperator *op= sfile->op;
@@ -567,16 +567,23 @@ int file_exec(bContext *C, wmOperator *exec_op)
                }
                
                sfile->op = NULL;
-               RNA_string_set(op->ptr, "filename", sfile->params->file);
-               BLI_strncpy(name, sfile->params->dir, sizeof(name));
-               RNA_string_set(op->ptr, "directory", name);
-               strcat(name, sfile->params->file); // XXX unsafe
 
-               if(RNA_struct_find_property(op->ptr, "relative_path"))
-                       if(RNA_boolean_get(op->ptr, "relative_path"))
-                               BLI_path_rel(name, G.sce);
+               BLI_join_dirfile(filepath, sfile->params->dir, sfile->params->file);
+               if(RNA_struct_find_property(op->ptr, "relative_path")) {
+                       if(RNA_boolean_get(op->ptr, "relative_path")) {
+                               BLI_path_rel(filepath, G.sce);
+                       }
+               }
 
-               RNA_string_set(op->ptr, "filepath", name);
+               if(RNA_struct_find_property(op->ptr, "filename")) {
+                       RNA_string_set(op->ptr, "filename", sfile->params->file);
+               }
+               if(RNA_struct_find_property(op->ptr, "directory")) {
+                       RNA_string_set(op->ptr, "directory", sfile->params->dir);
+               }
+               if(RNA_struct_find_property(op->ptr, "filepath")) {
+                       RNA_string_set(op->ptr, "filepath", filepath);
+               }
                
                /* some ops have multiple files to select */
                {
@@ -612,8 +619,8 @@ int file_exec(bContext *C, wmOperator *exec_op)
                folderlist_free(sfile->folders_next);
 
                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);
+               BLI_make_file_string(G.sce, filepath, BLI_gethome(), ".Bfs");
+               fsmenu_write_file(fsmenu_get(), filepath);
                WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
 
                ED_fileselect_clear(C, sfile);
index c38ba67a64880835f37753587c9ba2d2958b6741..058c39749a6db9b6cf332285791c76c0650cdf33 100644 (file)
@@ -789,8 +789,6 @@ void WM_operator_properties_filesel(wmOperatorType *ot, int filter, short type,
        PropertyRNA *prop;
 
        RNA_def_string_file_path(ot->srna, "filepath", "", FILE_MAX, "File Path", "Path to file");
-       RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file");
-       RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file");
 
        if (action == FILE_SAVE) {
                prop= RNA_def_boolean(ot->srna, "check_existing", 1, "Check Existing", "Check and warn on overwriting existing files");
@@ -1653,6 +1651,9 @@ static void WM_OT_link_append(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "active_layer", 1, "Active Layer", "Put the linked objects on the active layer");
        RNA_def_boolean(ot->srna, "instance_groups", 1, "Instance Groups", "Create instances for each group as a DupliGroup");
 
+       RNA_def_string_file_name(ot->srna, "filename", "", FILE_MAX, "File Name", "Name of the file");
+       RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Directory of the file");
+
        RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
 }