[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35543] trunk/blender/source/blender/ editors: == filebrowser ==

Andrea Weikert elubie at gmx.net
Mon Mar 14 20:56:13 CET 2011


Revision: 35543
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35543
Author:   elubie
Date:     2011-03-14 19:56:13 +0000 (Mon, 14 Mar 2011)
Log Message:
-----------
== filebrowser ==
Cleanup of selection code.
Also fixed bug where selection outside the tiles was clamped and file in last column was selected.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_fileselect.h
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/editors/space_file/file_ops.c
    trunk/blender/source/blender/editors/space_file/filelist.c
    trunk/blender/source/blender/editors/space_file/filelist.h
    trunk/blender/source/blender/editors/space_file/filesel.c

Modified: trunk/blender/source/blender/editors/include/ED_fileselect.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_fileselect.h	2011-03-14 17:37:51 UTC (rev 35542)
+++ trunk/blender/source/blender/editors/include/ED_fileselect.h	2011-03-14 19:56:13 UTC (rev 35543)
@@ -75,6 +75,13 @@
 	float column_widths[MAX_FILE_COLUMN];
 } FileLayout;
 
+typedef struct FileSelection {
+	int first;
+	int last;
+} FileSelection;
+
+struct rcti;
+
 struct FileSelectParams* ED_fileselect_get_params(struct SpaceFile *sfile);
 
 short ED_fileselect_set_params(struct SpaceFile *sfile);
@@ -88,7 +95,8 @@
 FileLayout* ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar);
 
 int ED_fileselect_layout_numfiles(FileLayout* layout, struct ARegion *ar);
-int ED_fileselect_layout_offset(FileLayout* layout, int clamp_bounds, int x, int y);
+int ED_fileselect_layout_offset(FileLayout* layout, int x, int y);
+FileSelection ED_fileselect_layout_offset_rect(FileLayout* layout, const struct rcti* rect);
 
 void ED_fileselect_layout_tilepos(FileLayout* layout, int tile, int *x, int *y);
 

Modified: trunk/blender/source/blender/editors/space_file/file_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_draw.c	2011-03-14 17:37:51 UTC (rev 35542)
+++ trunk/blender/source/blender/editors/space_file/file_draw.c	2011-03-14 19:56:13 UTC (rev 35543)
@@ -487,7 +487,7 @@
 		draw_dividers(layout, v2d);
 	}
 
-	offset = ED_fileselect_layout_offset(layout, 0, ar->v2d.cur.xmin, -ar->v2d.cur.ymax);
+	offset = ED_fileselect_layout_offset(layout, ar->v2d.cur.xmin, -ar->v2d.cur.ymax);
 	if (offset<0) offset=0;
 
 	numfiles_layout = ED_fileselect_layout_numfiles(layout, ar);

Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c	2011-03-14 17:37:51 UTC (rev 35542)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c	2011-03-14 19:56:13 UTC (rev 35543)
@@ -71,85 +71,84 @@
 #define INACTIVATE			2
 
 /* ---------- FILE SELECTION ------------ */
-
-static int find_file_mouse(SpaceFile *sfile, struct ARegion* ar, int clamp_bounds, int x, int y)
+static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion* ar, const rcti* rect)
 {
-	float fx,fy;
-	int active_file = -1;
+	FileSelection sel;
+	float fxmin,fymin,fxmax, fymax;
+	
 	View2D* v2d = &ar->v2d;
+	rcti rect_view;
 
-	UI_view2d_region_to_view(v2d, x, y, &fx, &fy);
+	UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin);
+	UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax);
 
-	active_file = ED_fileselect_layout_offset(sfile->layout, clamp_bounds, v2d->tot.xmin + fx, v2d->tot.ymax - fy);
+	BLI_init_rcti(&rect_view, v2d->tot.xmin + fxmin, v2d->tot.xmin + fxmax, v2d->tot.ymax - fymin, v2d->tot.ymax - fymax);
+
+	sel  = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
 	
-	return active_file;
+	return sel;
 }
 
-
-static void file_deselect_all(SpaceFile* sfile)
+static void file_deselect_all(SpaceFile* sfile, unsigned int flag)
 {
 	int numfiles = filelist_numfiles(sfile->files);
 	int i;
 
 	for ( i=0; i < numfiles; ++i) {
 		struct direntry* file = filelist_file(sfile->files, i);
-		if (file && (file->flags & ACTIVEFILE)) {
-			file->flags &= ~ACTIVEFILE;
+		if (file && (file->flags & flag)) {
+			file->flags &= ~flag;
 		}
 	}
 }
 
-typedef enum FileSelect { FILE_SELECT_DIR = 1, 
-  FILE_SELECT_FILE = 2 } FileSelect;
+typedef enum FileSelect { 
+	FILE_SELECT_NOTHING = 0,
+	FILE_SELECT_DIR = 1, 
+	FILE_SELECT_FILE = 2 
+} FileSelect;
 
-
-static void clamp_to_filelist(int numfiles, int *first_file, int *last_file)
+static void clamp_to_filelist(int numfiles, FileSelection* sel)
 {
 	/* border select before the first file */
-	if ( (*first_file < 0) && (*last_file >=0 ) ) {
-		*first_file = 0;
+	if ( (sel->first < 0) && (sel->last >=0 ) ) {
+		sel->first = 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;
+	if ( (sel->first >= numfiles) && ((sel->last < 0) || (sel->last >= numfiles)) ) {
+		sel->first = -1;
+		sel->last = -1;
 	}
 	
 	/* fix if last file invalid */
-	if ( (*first_file > 0) && (*last_file < 0) )
-		*last_file = numfiles-1;
+	if ( (sel->first > 0) && (sel->last < 0) )
+		sel->last = numfiles-1;
 
 	/* clamp */
-	if ( (*first_file >= numfiles) ) {
-		*first_file = numfiles-1;
+	if ( (sel->first >= numfiles) ) {
+		sel->first = numfiles-1;
 	}
-	if ( (*last_file >= numfiles) ) {
-		*last_file = numfiles-1;
+	if ( (sel->last >= numfiles) ) {
+		sel->last = numfiles-1;
 	}
 }
 
-static FileSelect file_select(bContext* C, const rcti* rect, short selecting, short toggle_one, short fill)
+static FileSelection file_selection_get(bContext* C, const rcti* rect, short fill)
 {
 	ARegion *ar= CTX_wm_region(C);
 	SpaceFile *sfile= CTX_wm_space_file(C);
-	int first_file = -1;
-	int last_file = -1;
-	int act_file;
-	FileSelect retval = FILE_SELECT_FILE;
+	int numfiles = filelist_numfiles(sfile->files);
+	FileSelection sel;
 
-	FileSelectParams *params = ED_fileselect_get_params(sfile);
-	// FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
+	sel = find_file_mouse_rect(sfile, ar, rect);
+	if ( !((sel.first == -1) && (sel.last == -1)) ) {
+		clamp_to_filelist(numfiles, &sel);
+	}
 
-	int numfiles = filelist_numfiles(sfile->files);
-	
-	params->selstate = NOTACTIVEFILE;
-	first_file = find_file_mouse(sfile, ar, 1, rect->xmin, rect->ymax);
-	last_file = find_file_mouse(sfile, ar, 1, rect->xmax, rect->ymin);
-	
-	clamp_to_filelist(numfiles, &first_file, &last_file);
 
-	if (fill && (last_file >= 0) && (last_file < numfiles) ) {
-		int f= last_file;
+	/* if desired, fill the selection up from the last selected file to the current one */
+	if (fill && (sel.last >= 0) && (sel.last < numfiles) ) {
+		int f= sel.last;
 		while (f >= 0) {
 			struct direntry* file = filelist_file(sfile->files, f);
 			if (file->flags & ACTIVEFILE)
@@ -157,36 +156,24 @@
 			f--;
 		}
 		if (f >= 0) {
-			first_file = f+1;
+			sel.first = f+1;
 		}
 	}
+	return sel;
+}
 
-	/* 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++) {
-			struct direntry* file = filelist_file(sfile->files, act_file);
-			
-			if (toggle_one) {
-				if (file->flags & ACTIVEFILE) {
-					file->flags &= ~ACTIVEFILE;
-					selecting=0;
-				} else
-					file->flags |= ACTIVEFILE;
-			} else if (selecting) 
-				file->flags |= ACTIVEFILE;
-			else
-				file->flags &= ~ACTIVEFILE;
-		}
-	}
+static FileSelect file_select_do(bContext* C, short select, int selected_idx)
+{
+	FileSelect retval = FILE_SELECT_NOTHING;
+	SpaceFile *sfile= CTX_wm_space_file(C);
+	FileSelectParams *params = ED_fileselect_get_params(sfile);
+	int numfiles = filelist_numfiles(sfile->files);
 
-	/* Don't act on multiple selected files */
-	if (first_file != last_file) selecting= 0;
+	/* make the selected file active */
+	if (select && (selected_idx >= 0) && (selected_idx < numfiles)) {
+		struct direntry* file = filelist_file(sfile->files, selected_idx);
+		params->active_file = selected_idx;
 
-	/* make the last file active */
-	if (selecting && (last_file >= 0 && last_file < numfiles)) {
-		struct direntry* file = filelist_file(sfile->files, last_file);
-		params->active_file = last_file;
-
 		if(file && S_ISDIR(file->type)) {
 			/* the path is too long and we are not going up! */
 			if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) 
@@ -211,10 +198,27 @@
 			if (file->relname) {
 				BLI_strncpy(params->file, file->relname, FILE_MAXFILE);
 			}
-			
-		}	
+			retval = FILE_SELECT_FILE;
+		}
 	}
+	return retval;
+}
+
+
+static FileSelect file_select(bContext* C, const rcti* rect, short select, short fill)
+{
+	SpaceFile *sfile= CTX_wm_space_file(C);
+	FileSelect retval = FILE_SELECT_NOTHING;
+	FileSelection sel= file_selection_get(C, rect, fill); /* get the selection */
 	
+	/* flag the files as selected in the filelist */
+	filelist_select(sfile->files, &sel, select, ACTIVEFILE);
+	
+	/* Don't act on multiple selected files */
+	if (sel.first != sel.last) select = 0;
+
+	retval = file_select_do(C, select, sel.last);
+	
 	/* update operator for name change event */
 	file_draw_check_cb(C, NULL, NULL);
 	
@@ -222,24 +226,24 @@
 }
 
 
-
 static int file_border_select_exec(bContext *C, wmOperator *op)
 {
 	ARegion *ar= CTX_wm_region(C);
-	short selecting;
 	rcti rect;
-	
-	selecting= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
+	FileSelect ret;
+
+	short select= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
 	rect.xmin= RNA_int_get(op->ptr, "xmin");
 	rect.ymin= RNA_int_get(op->ptr, "ymin");
 	rect.xmax= RNA_int_get(op->ptr, "xmax");
 	rect.ymax= RNA_int_get(op->ptr, "ymax");
 
 	BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
-	
-	if (FILE_SELECT_DIR == file_select(C, &rect, selecting, 0, 0)) {
+
+	ret = file_select(C, &rect, select, 0);
+	if (FILE_SELECT_DIR == ret) {
 		WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
-	} else {
+	} else if (FILE_SELECT_FILE == ret) {
 		WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
 	}
 	return OPERATOR_FINISHED;
@@ -280,9 +284,9 @@
 		return OPERATOR_CANCELLED;
 
 	/* single select, deselect all selected first */
-	if (!extend) file_deselect_all(sfile);
+	if (!extend) file_deselect_all(sfile, ACTIVEFILE);
 
-	if (FILE_SELECT_DIR == file_select(C, &rect, 1, extend, fill ))
+	if (FILE_SELECT_DIR == file_select(C, &rect, 1, fill))
 		WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 	else
 		WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
@@ -348,10 +352,11 @@
 	
 	/* api callbacks */
 	ot->exec= file_select_all_exec;
+	ot->poll= ED_operator_file_active;
 
 	/* rna */
 
-	ot->poll= ED_operator_file_active;
+	
 }
 
 /* ---------- BOOKMARKS ----------- */
@@ -457,9 +462,10 @@
 
 int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
 {
+	View2D* v2d = &ar->v2d;
 	FileSelectParams* params;
-	int numfiles, actfile, origfile;
-	
+	int numfiles, origfile;	
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list