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

Andrea Weikert elubie at gmx.net
Sat May 8 23:02:22 CEST 2010


Revision: 28675
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28675
Author:   elubie
Date:     2010-05-08 23:02:22 +0200 (Sat, 08 May 2010)

Log Message:
-----------
== filebrowser ==
- smooth scrolling to editable button after new directory is created
(for now scrolling starts as soon as the mouse moves back to the file list area, for Matt to check if immediate scrolling is possible)

- fix for autocomplete directory, show first matching part if directory doesn't exist, otherwise won't work for directories starting with the same prefix like textures_walls and textures_grass for example.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/editors/space_file/file_intern.h
    trunk/blender/source/blender/editors/space_file/file_ops.c
    trunk/blender/source/blender/editors/space_file/filesel.c
    trunk/blender/source/blender/editors/space_file/space_file.c
    trunk/blender/source/blender/makesdna/DNA_space_types.h

Modified: trunk/blender/source/blender/editors/space_file/file_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_draw.c	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/editors/space_file/file_draw.c	2010-05-08 21:02:22 UTC (rev 28675)
@@ -514,6 +514,13 @@
 
 	numfiles_layout = ED_fileselect_layout_numfiles(layout, ar);
 
+	/* adjust, so the next row is already drawn when scrolling */
+	if (layout->flag & FILE_LAYOUT_HOR) {
+		numfiles_layout += layout->rows;
+	} else {
+		numfiles_layout += layout->columns;
+	}
+
 	for (i=offset; (i < numfiles) && (i<offset+numfiles_layout); ++i)
 	{
 		ED_fileselect_layout_tilepos(layout, i, &sx, &sy);

Modified: trunk/blender/source/blender/editors/space_file/file_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_intern.h	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/editors/space_file/file_intern.h	2010-05-08 21:02:22 UTC (rev 28675)
@@ -70,6 +70,7 @@
 void FILE_OT_filenum(struct wmOperatorType *ot);
 void FILE_OT_delete(struct wmOperatorType *ot);
 void FILE_OT_rename(struct wmOperatorType *ot);
+void FILE_OT_smoothscroll(struct wmOperatorType *ot);
 
 int file_exec(bContext *C, struct wmOperator *exec_op);
 int file_cancel_exec(bContext *C, struct wmOperator *unused);

Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c	2010-05-08 21:02:22 UTC (rev 28675)
@@ -745,6 +745,107 @@
 	return OPERATOR_FINISHED;
 }
 
+
+/* only meant for timer usage */
+static int file_smoothscroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	SpaceFile *sfile= CTX_wm_space_file(C);
+	ARegion *ar= CTX_wm_region(C);
+	int numfiles, offset;
+	int edit_idx = 0;
+	int numfiles_layout;
+	int i;
+
+	/* escape if not our timer */
+	if(sfile->smoothscroll_timer==NULL || sfile->smoothscroll_timer!=event->customdata)
+		return OPERATOR_PASS_THROUGH;
+	
+	numfiles = filelist_numfiles(sfile->files);
+
+	/* check if we are editing a name */
+	for (i=0; i < numfiles; ++i)
+	{
+		struct direntry *file = filelist_file(sfile->files, i);	
+		if (file->flags & EDITING) {
+			edit_idx=i;
+			break;
+		}
+	}
+
+	/* if we are not editing, we are done */
+	if (0==edit_idx) {
+		WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
+		sfile->smoothscroll_timer=NULL;
+		return OPERATOR_PASS_THROUGH;
+	}
+
+	/* we need the correct area for scrolling */
+	if (!ar || ar->regiontype != RGN_TYPE_WINDOW) {
+		WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
+		sfile->smoothscroll_timer=NULL;
+		return OPERATOR_PASS_THROUGH;
+	}
+
+	offset = ED_fileselect_layout_offset(sfile->layout, 0, ar->v2d.cur.xmin, -ar->v2d.cur.ymax);
+	if (offset<0) offset=0;
+
+	/* scroll offset is the first file in the row/column we are editing in */
+	if (sfile->scroll_offset == 0) {
+		if (sfile->layout->flag & FILE_LAYOUT_HOR) {
+			sfile->scroll_offset = (edit_idx/sfile->layout->rows)*sfile->layout->rows;
+			if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->rows;
+		} else {
+			sfile->scroll_offset = (edit_idx/sfile->layout->columns)*sfile->layout->columns;
+			if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->columns;
+		}
+	}
+	
+	numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, ar);
+	
+	/* check if we have reached our final scroll position */
+	if ( (sfile->scroll_offset >= offset) && (sfile->scroll_offset < offset + numfiles_layout) ) {
+		WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
+		sfile->smoothscroll_timer=NULL;
+		return OPERATOR_FINISHED;
+	}
+
+	/* scroll one step in the desired direction */
+	if (sfile->scroll_offset < offset) {
+		if (sfile->layout->flag & FILE_LAYOUT_HOR) {
+			WM_operator_name_call(C, "VIEW2D_OT_scroll_left", 0, NULL);
+		} else {
+			WM_operator_name_call(C, "VIEW2D_OT_scroll_up", 0, NULL);
+		}
+		
+	} else {
+		if (sfile->layout->flag & FILE_LAYOUT_HOR) {
+			WM_operator_name_call(C, "VIEW2D_OT_scroll_right", 0, NULL);
+		} else {
+			WM_operator_name_call(C, "VIEW2D_OT_scroll_down", 0, NULL);
+		}
+	}
+	
+	ED_region_tag_redraw(CTX_wm_region(C));
+	
+	return OPERATOR_FINISHED;
+}
+
+
+void FILE_OT_smoothscroll(wmOperatorType *ot)
+{
+	
+	/* identifiers */
+	ot->name= "Smooth Scroll";
+	ot->idname= "FILE_OT_smoothscroll";
+	ot->description="Smooth scroll to make editable file visible.";
+	
+	/* api callbacks */
+	ot->invoke= file_smoothscroll_invoke;
+	
+	ot->poll= ED_operator_file_active;
+}
+
+
 /* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created.
    The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
 */
@@ -794,6 +895,12 @@
 
 	/* now remember file to jump into editing */
 	BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
+
+	/* set timer to smoothly view newly generated file */
+	sfile->smoothscroll_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/1000.0);	/* max 30 frs/sec */
+	sfile->scroll_offset=0;
+
+	/* reload dir to make sure we're seeing what's in the directory */
 	ED_fileselect_clear(C, sfile);
 	WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
 

Modified: trunk/blender/source/blender/editors/space_file/filesel.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filesel.c	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/editors/space_file/filesel.c	2010-05-08 21:02:22 UTC (rev 28675)
@@ -213,11 +213,11 @@
 
 	if (layout->flag & FILE_LAYOUT_HOR) {
 		int width = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*layout->tile_border_x;
-		numfiles = width/layout->tile_w + 1;
+		numfiles = (float)width/(float)layout->tile_w+0.5;
 		return numfiles*layout->rows;
 	} else {
 		int height = ar->v2d.cur.ymax - ar->v2d.cur.ymin - 2*layout->tile_border_y;
-		numfiles = height/layout->tile_h + 1;
+		numfiles = (float)height/(float)layout->tile_h+0.5;
 		return numfiles*layout->columns;
 	}
 }
@@ -482,12 +482,42 @@
 			if (BLI_exists(str)) {
 				BLI_add_slash(str);
 			} else {
-				BLI_make_exist(str);
+				BLI_strncpy(sfile->params->dir, str, sizeof(sfile->params->dir));
 			}
 		}
 	}
 }
+#if 0
+void autocomplete_directory(struct bContext *C, char *str, void *arg_v)
+{
+		char tmp[FILE_MAX];
+	SpaceFile *sfile= CTX_wm_space_file(C);
 
+	/* search if str matches the beginning of name */
+	if(str[0] && sfile->files) {
+		AutoComplete *autocpl= autocomplete_begin(str, FILE_MAX);
+		int nentries = filelist_numfiles(sfile->files);
+		int i;
+
+		for(i= 0; i<nentries; ++i) {
+			struct direntry* file = filelist_file(sfile->files, i);
+			const char* dir = filelist_dir(sfile->files);
+			if (file && S_ISDIR(file->type))	{
+				// BLI_make_file_string(G.sce, tmp, dir, file->relname);
+				BLI_join_dirfile(tmp, dir, file->relname);
+				autocomplete_do_name(autocpl,tmp);
+			}
+		}
+		autocomplete_end(autocpl, str);
+		if (BLI_exists(str)) {
+			BLI_add_slash(str);
+		} else {
+			BLI_strncpy(sfile->params->dir, str, sizeof(sfile->params->dir));
+		}
+	}
+}
+#endif
+
 void autocomplete_file(struct bContext *C, char *str, void *arg_v)
 {
 	SpaceFile *sfile= CTX_wm_space_file(C);

Modified: trunk/blender/source/blender/editors/space_file/space_file.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/space_file.c	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/editors/space_file/space_file.c	2010-05-08 21:02:22 UTC (rev 28675)
@@ -364,6 +364,7 @@
 	WM_operatortype_append(FILE_OT_directory_new);
 	WM_operatortype_append(FILE_OT_delete);
 	WM_operatortype_append(FILE_OT_rename);
+	WM_operatortype_append(FILE_OT_smoothscroll);
 }
 
 /* NOTE: do not add .blend file reading on this level */
@@ -408,6 +409,7 @@
 	RNA_int_set(kmi->ptr, "increment", -10);
 	kmi = WM_keymap_add_item(keymap, "FILE_OT_filenum", PADMINUS, KM_PRESS, KM_CTRL, 0);
 	RNA_int_set(kmi->ptr, "increment",-100);
+	WM_keymap_verify_item(keymap, "FILE_OT_smoothscroll", TIMER1, KM_ANY, KM_ANY, 0);
 	
 	/* keys for button area (top) */
 	keymap= WM_keymap_find(keyconf, "File Browser Buttons", SPACE_FILE, 0);

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2010-05-08 20:57:09 UTC (rev 28674)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2010-05-08 21:02:22 UTC (rev 28675)
@@ -187,7 +187,7 @@
 	SpaceLink *next, *prev;
 	ListBase regionbase;		/* storage of regions for inactive spaces */
 	int spacetype;
-	int pad;
+	int scroll_offset;
 
 	struct FileSelectParams *params; /* config and input for file select */
 	
@@ -203,7 +203,7 @@
 	*/
 	struct wmOperator *op; 
 
-	struct wmTimer *loadimage_timer;
+	struct wmTimer *smoothscroll_timer;
 
 	struct FileLayout *layout;
 	





More information about the Bf-blender-cvs mailing list