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.c125
1 files changed, 97 insertions, 28 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index e1a6e346ce2..75230813a41 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -68,25 +68,15 @@
/* ---------- FILE SELECTION ------------ */
-static int find_file_mouse(SpaceFile *sfile, struct ARegion* ar, short x, short y, short clamp)
+static int find_file_mouse(SpaceFile *sfile, struct ARegion* ar, int x, int y)
{
float fx,fy;
int active_file = -1;
- int numfiles = filelist_numfiles(sfile->files);
View2D* v2d = &ar->v2d;
UI_view2d_region_to_view(v2d, x, y, &fx, &fy);
active_file = ED_fileselect_layout_offset(sfile->layout, v2d->tot.xmin + fx, v2d->tot.ymax - fy);
-
- if(active_file < 0) {
- if(clamp) active_file= 0;
- else active_file= -1;
- }
- else if(active_file >= numfiles) {
- if(clamp) active_file= numfiles-1;
- else active_file= -1;
- }
return active_file;
}
@@ -109,6 +99,31 @@ typedef enum FileSelect { FILE_SELECT_DIR = 1,
FILE_SELECT_FILE = 2 } FileSelect;
+static void clamp_to_filelist(int numfiles, int *first_file, int *last_file)
+{
+ /* border select before the first file */
+ if ( (*first_file < 0) && (*last_file >=0 ) ) {
+ *first_file = 0;
+ }
+ /* don't select if everything is outside filelist */
+ if ( (*first_file >= numfiles) && ((*last_file < 0) || (*last_file >= numfiles)) ) {
+ *first_file = -1;
+ *last_file = -1;
+ }
+
+ /* fix if last file invalid */
+ if ( (*first_file > 0) && (*last_file < 0) )
+ *last_file = numfiles-1;
+
+ /* clamp */
+ if ( (*first_file >= numfiles) ) {
+ *first_file = numfiles-1;
+ }
+ if ( (*last_file >= numfiles) ) {
+ *last_file = numfiles-1;
+ }
+}
+
static FileSelect file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, short val)
{
int first_file = -1;
@@ -123,9 +138,11 @@ static FileSelect file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, s
int numfiles = filelist_numfiles(sfile->files);
params->selstate = NOTACTIVE;
- first_file = find_file_mouse(sfile, ar, rect->xmin, rect->ymax, 1);
- last_file = find_file_mouse(sfile, ar, rect->xmax, rect->ymin, 1);
+ first_file = find_file_mouse(sfile, ar, rect->xmin, rect->ymax);
+ last_file = find_file_mouse(sfile, ar, rect->xmax, rect->ymin);
+ clamp_to_filelist(numfiles, &first_file, &last_file);
+
/* select all valid files between first and last indicated */
if ( (first_file >= 0) && (first_file < numfiles) && (last_file >= 0) && (last_file < numfiles) ) {
for (act_file = first_file; act_file <= last_file; act_file++) {
@@ -137,6 +154,9 @@ static FileSelect file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, s
}
}
+ /* Don't act on multiple selected files */
+ if (first_file != last_file) selecting= 0;
+
/* make the last file active */
if (selecting && (last_file >= 0 && last_file < numfiles)) {
struct direntry* file = filelist_file(sfile->files, last_file);
@@ -168,7 +188,7 @@ static FileSelect file_select(SpaceFile* sfile, ARegion* ar, const rcti* rect, s
}
}
- }
+ }
return retval;
}
@@ -449,7 +469,7 @@ int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
my -= ar->winrct.ymin;
if(BLI_in_rcti(&ar->v2d.mask, mx, my)) {
- actfile = find_file_mouse(sfile, ar, mx , my, 0);
+ actfile = find_file_mouse(sfile, ar, mx , my);
if((actfile >= 0) && (actfile < numfiles))
params->active_file=actfile;
@@ -496,9 +516,26 @@ int file_cancel_exec(bContext *C, wmOperator *unused)
WM_event_fileselect_event(C, sfile->op, EVT_FILESELECT_CANCEL);
sfile->op = NULL;
+ if (sfile->files) {
+ filelist_freelib(sfile->files);
+ filelist_free(sfile->files);
+ MEM_freeN(sfile->files);
+ sfile->files= NULL;
+ }
+
return OPERATOR_FINISHED;
}
+int file_operator_poll(bContext *C)
+{
+ int poll = ED_operator_file_active(C);
+ SpaceFile *sfile= CTX_wm_space_file(C);
+
+ if (!sfile || !sfile->op) poll= 0;
+
+ return poll;
+}
+
void FILE_OT_cancel(struct wmOperatorType *ot)
{
/* identifiers */
@@ -507,7 +544,7 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
/* api callbacks */
ot->exec= file_cancel_exec;
- ot->poll= ED_operator_file_active;
+ ot->poll= file_operator_poll;
}
/* sends events now, so things get handled on windowqueue level */
@@ -520,9 +557,16 @@ int file_exec(bContext *C, wmOperator *unused)
wmOperator *op= sfile->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);
- RNA_string_set(op->ptr, "filename", name);
+
+ if(RNA_struct_find_property(op->ptr, "relative_paths"))
+ if(RNA_boolean_get(op->ptr, "relative_paths"))
+ BLI_makestringcode(G.sce, name);
+
+ RNA_string_set(op->ptr, "path", name);
/* some ops have multiple files to select */
{
@@ -561,6 +605,11 @@ int file_exec(bContext *C, wmOperator *unused)
BLI_make_file_string(G.sce, name, BLI_gethome(), ".Bfs");
fsmenu_write_file(fsmenu_get(), name);
WM_event_fileselect_event(C, op, EVT_FILESELECT_EXEC);
+
+ filelist_freelib(sfile->files);
+ filelist_free(sfile->files);
+ MEM_freeN(sfile->files);
+ sfile->files= NULL;
}
return OPERATOR_FINISHED;
@@ -574,7 +623,7 @@ void FILE_OT_execute(struct wmOperatorType *ot)
/* api callbacks */
ot->exec= file_exec;
- ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
+ ot->poll= file_operator_poll;
}
@@ -699,7 +748,9 @@ int file_directory_new_exec(bContext *C, wmOperator *unused)
BLI_join_dirfile(tmpstr, tmpstr, tmpdir);
}
BLI_recurdir_fileops(tmpstr);
- if (!BLI_exists(tmpstr)) {
+ if (BLI_exists(tmpstr)) {
+ BLI_strncpy(sfile->params->renamefile, tmpdir, FILE_MAXFILE);
+ } else {
filelist_free(sfile->files);
filelist_parent(sfile->files);
BLI_strncpy(sfile->params->dir, filelist_dir(sfile->files), FILE_MAX);
@@ -847,13 +898,9 @@ int file_bookmark_toggle_exec(bContext *C, wmOperator *unused)
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= file_buttons_region(sa);
- if(ar) {
- ar->flag ^= RGN_FLAG_HIDDEN;
- ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
-
- ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
- ED_area_tag_redraw(sa);
- }
+ if(ar)
+ ED_region_toggle_hidden(C, ar);
+
return OPERATOR_FINISHED;
}
@@ -872,11 +919,13 @@ void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
int file_filenum_exec(bContext *C, wmOperator *op)
{
SpaceFile *sfile= CTX_wm_space_file(C);
+ ScrArea *sa= CTX_wm_area(C);
int inc = RNA_int_get(op->ptr, "increment");
if(sfile->params && (inc != 0)) {
BLI_newname(sfile->params->file, inc);
- WM_event_add_notifier(C, NC_WINDOW, NULL);
+ ED_area_tag_redraw(sa);
+ // WM_event_add_notifier(C, NC_WINDOW, NULL);
}
return OPERATOR_FINISHED;
@@ -916,6 +965,24 @@ int file_rename_exec(bContext *C, wmOperator *op)
}
+int file_rename_poll(bContext *C)
+{
+ int poll = ED_operator_file_active(C);
+ SpaceFile *sfile= CTX_wm_space_file(C);
+
+ if (sfile && sfile->params) {
+ if (sfile->params->active_file < 0) {
+ poll= 0;
+ } else {
+ char dir[FILE_MAX], group[FILE_MAX];
+ if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
+ }
+ }
+ else
+ poll= 0;
+ return poll;
+}
+
void FILE_OT_rename(struct wmOperatorType *ot)
{
/* identifiers */
@@ -924,7 +991,7 @@ void FILE_OT_rename(struct wmOperatorType *ot)
/* api callbacks */
ot->exec= file_rename_exec;
- ot->poll= ED_operator_file_active; /* <- important, handler is on window level */
+ ot->poll= file_rename_poll;
}
@@ -938,6 +1005,8 @@ int file_delete_poll(bContext *C)
if (sfile->params->active_file < 0) {
poll= 0;
} else {
+ char dir[FILE_MAX], group[FILE_MAX];
+ if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
file = filelist_file(sfile->files, sfile->params->active_file);
if (file && S_ISDIR(file->type)) poll= 0;
}