Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r--source/blender/editors/space_file/file_ops.c332
1 files changed, 230 insertions, 102 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 2a50b505c57..100931e02eb 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1,4 +1,4 @@
-/**
+/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
@@ -30,8 +30,10 @@
#include "BKE_screen.h"
#include "BKE_global.h"
#include "BKE_report.h"
+#include "BKE_main.h"
#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
#include "BLI_storage_types.h"
#ifdef WIN32
#include "BLI_winstuff.h"
@@ -190,7 +192,7 @@ static FileSelect file_select(bContext* C, const rcti* rect, short selecting, sh
/* avoids /../../ */
BLI_parent_dir(params->dir);
} else {
- BLI_cleanup_dir(G.sce, params->dir);
+ BLI_cleanup_dir(G.main->name, params->dir);
strcat(params->dir, file->relname);
BLI_add_slash(params->dir);
}
@@ -206,7 +208,11 @@ static FileSelect file_select(bContext* C, const rcti* rect, short selecting, sh
}
}
- }
+ }
+
+ /* update operator for name change event */
+ file_draw_check_cb(C, NULL, NULL);
+
return retval;
}
@@ -255,7 +261,6 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
SpaceFile *sfile= CTX_wm_space_file(C);
- short val;
rcti rect;
int extend = RNA_boolean_get(op->ptr, "extend");
int fill = RNA_boolean_get(op->ptr, "fill");
@@ -265,7 +270,6 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
rect.xmin = rect.xmax = event->x - ar->winrct.xmin;
rect.ymin = rect.ymax = event->y - ar->winrct.ymin;
- val = event->val;
if(!BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin))
return OPERATOR_CANCELLED;
@@ -300,7 +304,7 @@ void FILE_OT_select(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "fill", 0, "Fill", "Select everything beginning with the last selection.");
}
-static int file_select_all_exec(bContext *C, wmOperator *op)
+static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *sa= CTX_wm_area(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -357,7 +361,7 @@ static int bookmark_select_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "dir", entry);
BLI_strncpy(params->dir, entry, sizeof(params->dir));
- BLI_cleanup_dir(G.sce, params->dir);
+ BLI_cleanup_dir(G.main->name, params->dir);
file_change_dir(C, 1);
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
@@ -380,7 +384,7 @@ void FILE_OT_select_bookmark(wmOperatorType *ot)
RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
}
-static int bookmark_add_exec(bContext *C, wmOperator *op)
+static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *sa= CTX_wm_area(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -475,7 +479,7 @@ int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
return (params->active_file != origfile);
}
-static int file_highlight_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -500,26 +504,19 @@ void FILE_OT_highlight(struct wmOperatorType *ot)
ot->poll= ED_operator_file_active;
}
-int file_cancel_exec(bContext *C, wmOperator *unused)
+int file_cancel_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
-
- folderlist_free(sfile->folders_prev);
- folderlist_free(sfile->folders_next);
-
- WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL);
- sfile->op = NULL;
+ wmOperator *op = sfile->op;
- if (sfile->files) {
- ED_fileselect_clear(C, sfile);
- MEM_freeN(sfile->files);
- sfile->files= NULL;
- }
+ sfile->op = NULL;
+
+ WM_event_fileselect_event(C, op, EVT_FILESELECT_CANCEL);
return OPERATOR_FINISHED;
}
-int file_operator_poll(bContext *C)
+static int file_operator_poll(bContext *C)
{
int poll = ED_operator_file_active(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -541,6 +538,118 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
ot->poll= file_operator_poll;
}
+
+void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
+{
+ BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */
+ if(RNA_struct_find_property(op->ptr, "relative_path")) {
+ if(RNA_boolean_get(op->ptr, "relative_path")) {
+ BLI_path_rel(filepath, G.main->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 */
+ {
+ 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 & ACTIVEFILE) {
+ 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 & ACTIVEFILE) {
+ if ((file->type & S_IFDIR)) {
+ RNA_collection_add(op->ptr, "dirs", &itemptr);
+ RNA_string_set(&itemptr, "name", file->relname);
+ }
+ }
+ }
+ }
+ }
+}
+
+void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op)
+{
+ int change= FALSE;
+ if(RNA_struct_find_property(op->ptr, "filename")) {
+ RNA_string_get(op->ptr, "filename", sfile->params->file);
+ change= TRUE;
+ }
+ if(RNA_struct_find_property(op->ptr, "directory")) {
+ RNA_string_get(op->ptr, "directory", sfile->params->dir);
+ change= TRUE;
+ }
+
+ /* If neither of the above are set, split the filepath back */
+ if(RNA_struct_find_property(op->ptr, "filepath")) {
+ if(change==FALSE) {
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+ BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file);
+ }
+ }
+
+ /* XXX, files and dirs updates missing, not really so important though */
+}
+
+void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
+{
+ SpaceFile *sfile= CTX_wm_space_file(C);
+ wmOperator *op= sfile->op;
+ if(op) { /* fail on reload */
+ if(op->type->check) {
+ char filepath[FILE_MAX];
+ file_sfile_to_operator(op, sfile, filepath);
+
+ /* redraw */
+ if(op->type->check(C, op)) {
+ file_operator_to_sfile(sfile, op);
+
+ /* redraw, else the changed settings wont get updated */
+ ED_area_tag_redraw(CTX_wm_area(C));
+ }
+ }
+ }
+}
+
+int file_draw_check_exists(SpaceFile *sfile)
+{
+ if(sfile->op) { /* fails on reload */
+ if(RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
+ if(RNA_boolean_get(sfile->op->ptr, "check_existing")) {
+ char filepath[FILE_MAX];
+ BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
+ if(BLI_exists(filepath) && !BLI_is_dir(filepath)) {
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
/* sends events now, so things get handled on windowqueue level */
int file_exec(bContext *C, wmOperator *exec_op)
{
@@ -568,64 +677,13 @@ int file_exec(bContext *C, wmOperator *exec_op)
sfile->op = NULL;
- 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);
- }
- }
-
- 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 */
- {
- 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 & ACTIVEFILE) {
- 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 & ACTIVEFILE) {
- if ((file->type & S_IFDIR)) {
- RNA_collection_add(op->ptr, "dirs", &itemptr);
- RNA_string_set(&itemptr, "name", file->relname);
- }
- }
- }
- }
- }
-
- folderlist_free(sfile->folders_prev);
- folderlist_free(sfile->folders_next);
+ file_sfile_to_operator(op, sfile, filepath);
fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir,0, 1);
- BLI_make_file_string(G.sce, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
+ BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
fsmenu_write_file(fsmenu_get(), filepath);
WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
- ED_fileselect_clear(C, sfile);
- MEM_freeN(sfile->files);
- sfile->files= NULL;
}
return OPERATOR_FINISHED;
@@ -646,14 +704,14 @@ void FILE_OT_execute(struct wmOperatorType *ot)
}
-int file_parent_exec(bContext *C, wmOperator *unused)
+int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
if(sfile->params) {
if (BLI_has_parent(sfile->params->dir)) {
BLI_parent_dir(sfile->params->dir);
- BLI_cleanup_dir(G.sce, sfile->params->dir);
+ BLI_cleanup_dir(G.main->name, sfile->params->dir);
file_change_dir(C, 0);
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
}
@@ -677,7 +735,7 @@ void FILE_OT_parent(struct wmOperatorType *ot)
}
-int file_refresh_exec(bContext *C, wmOperator *unused)
+static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -701,7 +759,7 @@ void FILE_OT_previous(struct wmOperatorType *ot)
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
}
-int file_previous_exec(bContext *C, wmOperator *unused)
+int file_previous_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -732,7 +790,7 @@ void FILE_OT_next(struct wmOperatorType *ot)
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
}
-int file_next_exec(bContext *C, wmOperator *unused)
+int file_next_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
if(sfile->params) {
@@ -754,7 +812,7 @@ int file_next_exec(bContext *C, wmOperator *unused)
/* only meant for timer usage */
-static int file_smoothscroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
ScrArea *sa = CTX_wm_area(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -871,13 +929,13 @@ static int new_folder_path(const char* parent, char *folder, char *name)
int len = 0;
BLI_strncpy(name, "New Folder", FILE_MAXFILE);
- BLI_join_dirfile(folder, parent, name);
+ BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
/* check whether folder with the name already exists, in this case
add number to the name. Check length of generated name to avoid
crazy case of huge number of folders each named 'New Folder (x)' */
while (BLI_exists(folder) && (len<FILE_MAXFILE)) {
len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
- BLI_join_dirfile(folder, parent, name);
+ BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
i++;
}
@@ -888,6 +946,8 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
{
char name[FILE_MAXFILE];
char path[FILE_MAX];
+ int generate_name= 1;
+
SpaceFile *sfile= CTX_wm_space_file(C);
if(!sfile->params) {
@@ -895,13 +955,22 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- /* create a new, non-existing folder name */
- if (!new_folder_path(sfile->params->dir, path, name)) {
- BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name.");
- return OPERATOR_CANCELLED;
+ path[0] = '\0';
+
+ if(RNA_struct_find_property(op->ptr, "directory")) {
+ RNA_string_get(op->ptr, "directory", path);
+ if (path[0] != '\0') generate_name= 0;
}
-
- /* rename the file */
+
+ if (generate_name) {
+ /* create a new, non-existing folder name */
+ if (!new_folder_path(sfile->params->dir, path, name)) {
+ BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name.");
+ return OPERATOR_CANCELLED;
+ }
+ }
+
+ /* create the file */
BLI_recurdir_fileops(path);
if (!BLI_exists(path)) {
@@ -935,24 +1004,68 @@ void FILE_OT_directory_new(struct wmOperatorType *ot)
ot->invoke= WM_operator_confirm;
ot->exec= file_directory_new_exec;
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
+
+ RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory");
+
}
-int file_directory_exec(bContext *C, wmOperator *unused)
+
+static void file_expand_directory(bContext *C)
{
SpaceFile *sfile= CTX_wm_space_file(C);
if(sfile->params) {
if ( sfile->params->dir[0] == '~' ) {
char tmpstr[sizeof(sfile->params->dir)-1];
- strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
- BLI_join_dirfile(sfile->params->dir, BLI_getDefaultDocumentFolder(), tmpstr);
+ BLI_strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
+ BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BLI_getDefaultDocumentFolder(), tmpstr);
}
#ifdef WIN32
if (sfile->params->dir[0] == '\0')
get_default_root(sfile->params->dir);
#endif
- BLI_cleanup_dir(G.sce, sfile->params->dir);
+ }
+}
+
+static int file_directory_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+ SpaceFile *sfile= CTX_wm_space_file(C);
+
+ if(sfile->params) {
+ file_expand_directory(C);
+
+ if (!BLI_exists(sfile->params->dir)) {
+ return WM_operator_confirm_message(C, op, "Create new directory?");
+ }
+
+ return file_directory_exec(C, op);
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+
+
+int file_directory_exec(bContext *C, wmOperator *UNUSED(unused))
+{
+ SpaceFile *sfile= CTX_wm_space_file(C);
+
+ if(sfile->params) {
+ file_expand_directory(C);
+
+ if (!BLI_exists(sfile->params->dir)) {
+ BLI_recurdir_fileops(sfile->params->dir);
+ }
+
+ /* special case, user may have pasted a fulepath into the directory */
+ if(BLI_exists(sfile->params->dir) && BLI_is_dir(sfile->params->dir) == 0) {
+ char path[sizeof(sfile->params->dir)];
+ BLI_strncpy(path, sfile->params->dir, sizeof(path));
+ BLI_split_dirfile(path, sfile->params->dir, sfile->params->file);
+ }
+
+ BLI_cleanup_dir(G.main->name, sfile->params->dir);
BLI_add_slash(sfile->params->dir);
file_change_dir(C, 1);
@@ -963,7 +1076,7 @@ int file_directory_exec(bContext *C, wmOperator *unused)
return OPERATOR_FINISHED;
}
-int file_filename_exec(bContext *C, wmOperator *unused)
+int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -978,6 +1091,18 @@ int file_filename_exec(bContext *C, wmOperator *unused)
return OPERATOR_FINISHED;
}
+void FILE_OT_directory(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Enter Directory Name";
+ ot->description= "Enter a directory name";
+ ot->idname= "FILE_OT_directory";
+
+ /* api callbacks */
+ ot->invoke= file_directory_invoke;
+ ot->exec= file_directory_exec;
+ ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
+}
void FILE_OT_refresh(struct wmOperatorType *ot)
{
@@ -991,7 +1116,7 @@ void FILE_OT_refresh(struct wmOperatorType *ot)
ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
}
-int file_hidedot_exec(bContext *C, wmOperator *unused)
+static int file_hidedot_exec(bContext *C, wmOperator *UNUSED(unused))
{
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -1044,7 +1169,7 @@ struct ARegion *file_buttons_region(struct ScrArea *sa)
return arnew;
}
-int file_bookmark_toggle_exec(bContext *C, wmOperator *unused)
+static int file_bookmark_toggle_exec(bContext *C, wmOperator *UNUSED(unused))
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= file_buttons_region(sa);
@@ -1068,7 +1193,7 @@ void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
}
-int file_filenum_exec(bContext *C, wmOperator *op)
+static int file_filenum_exec(bContext *C, wmOperator *op)
{
SpaceFile *sfile= CTX_wm_space_file(C);
ScrArea *sa= CTX_wm_area(C);
@@ -1077,6 +1202,7 @@ int file_filenum_exec(bContext *C, wmOperator *op)
if(sfile->params && (inc != 0)) {
BLI_newname(sfile->params->file, inc);
ED_area_tag_redraw(sa);
+ file_draw_check_cb(C, NULL, NULL);
// WM_event_add_notifier(C, NC_WINDOW, NULL);
}
@@ -1099,7 +1225,7 @@ void FILE_OT_filenum(struct wmOperatorType *ot)
RNA_def_int(ot->srna, "increment", 1, 0, 100, "Increment", "", 0,100);
}
-int file_rename_exec(bContext *C, wmOperator *op)
+static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *sa= CTX_wm_area(C);
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
@@ -1110,6 +1236,8 @@ int file_rename_exec(bContext *C, wmOperator *op)
if ( (0<=idx) && (idx<numfiles) ) {
struct direntry *file= filelist_file(sfile->files, idx);
file->flags |= EDITING;
+ BLI_strncpy(sfile->params->renameedit, file->relname, FILE_MAXFILE);
+ sfile->params->renamefile[0]= '\0';
}
ED_area_tag_redraw(sa);
}
@@ -1118,7 +1246,7 @@ int file_rename_exec(bContext *C, wmOperator *op)
}
-int file_rename_poll(bContext *C)
+static int file_rename_poll(bContext *C)
{
int poll = ED_operator_file_active(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -1149,7 +1277,7 @@ void FILE_OT_rename(struct wmOperatorType *ot)
}
-int file_delete_poll(bContext *C)
+static int file_delete_poll(bContext *C)
{
int poll = ED_operator_file_active(C);
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -1171,7 +1299,7 @@ int file_delete_poll(bContext *C)
return poll;
}
-int file_delete_exec(bContext *C, wmOperator *op)
+int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
char str[FILE_MAX];
SpaceFile *sfile= CTX_wm_space_file(C);
@@ -1179,7 +1307,7 @@ int file_delete_exec(bContext *C, wmOperator *op)
file = filelist_file(sfile->files, sfile->params->active_file);
- BLI_make_file_string(G.sce, str, sfile->params->dir, file->relname);
+ BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relname);
BLI_delete(str, 0, 0);
ED_fileselect_clear(C, sfile);
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);