[Bf-blender-cvs] [242fdf5] asset-experiments: WIP: merge work on local branch about using UILists for bookmarks, be able to rename them, etc.

Bastien Montagne noreply at git.blender.org
Sun Dec 21 16:16:47 CET 2014


Commit: 242fdf5e606f545cab3052fea4e4287118f25668
Author: Bastien Montagne
Date:   Sun Dec 21 16:02:12 2014 +0100
Branches: asset-experiments
https://developer.blender.org/rB242fdf5e606f545cab3052fea4e4287118f25668

WIP: merge work on local branch about using UILists for bookmarks, be able to rename them, etc.

Doing it mostly because I need some update work done here so far to get py uilists/bookmarks working.

This exposes/moves part of bookmark code to ED_ area, so that it becomes available from e.g. RNA.
And adds RNA struct and such to represent a bookmark entry.

Also, Bookmark format is ammended to store optional custom names.

All this is still *very* crappy, should probably take some time soon to cleanup the whole branch!

See also T42777.

===================================================================

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/fsmenu.c
M	source/blender/editors/space_file/fsmenu.h
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 5515baf..0142d9a 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -18,7 +18,7 @@
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Header
+from bpy.types import Header, Panel
 
 
 class FILEBROWSER_HT_header(Header):
@@ -92,5 +92,44 @@ class FILEBROWSER_HT_header(Header):
         layout.template_running_jobs()
 
 
+
+class FILEBROWSER_UL_dir(bpy.types.UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+        direntry = item
+        space = context.space_data
+        icon = 'DISK_DRIVE' if active_propname == "system_folders_active" else 'NONE'
+
+        if (space.params.directory == direntry.path):
+            setattr(active_data, active_propname, index)
+
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            row = layout.row(align=True)
+
+            row.prop(direntry, "name", text="", emboss=False, icon=icon)
+
+            if direntry.use_save:
+                row.label("CaN DeLeTe")
+
+        elif self.layout_type in {'GRID'}:
+            layout.alignment = 'CENTER'
+            layout.prop(direntry, "path", text="")
+
+
+class FILEBROWSER_PT_system_folders(Panel):
+    bl_space_type = 'FILE_BROWSER'
+    bl_region_type = 'CHANNELS'
+    bl_label = "System Folders"
+    #bl_options = {'HIDE_HEADER'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        space = context.space_data
+
+        if space.system_folders:
+            #~ print(space.system_folders_active)
+            layout.template_list("FILEBROWSER_UL_dir", "system_folders", space, "system_folders", space, "system_folders_active", rows=1, maxrows=6)
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index f2a6ce0..171b5c9 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -108,5 +108,42 @@ int ED_file_extension_icon(const char *relname);
 
 void ED_file_read_bookmarks(void);
 
+/* File menu stuff */
+
+typedef enum FSMenuCategory {
+	FS_CATEGORY_SYSTEM,
+	FS_CATEGORY_SYSTEM_BOOKMARKS,
+	FS_CATEGORY_BOOKMARKS,
+	FS_CATEGORY_RECENT
+} FSMenuCategory;
+
+typedef enum FSMenuInsert {
+	FS_INSERT_SORTED = (1 << 0),
+	FS_INSERT_SAVE   = (1 << 1),
+	FS_INSERT_FIRST  = (1 << 2),   /* moves the item to the front of the list when its not already there */
+	FS_APPEND_LAST   = (1 << 3)   /* just append to preseve delivered order */
+} FSMenuInsert;
+
+struct FSMenu;
+struct FSMenuEntry;
+
+struct FSMenu *fsmenu_get(void);
+struct FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category);
+
+/** Returns the number of entries in the Fileselect Menu */
+int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category);
+
+struct FSMenuEntry *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int index);
+
+/** Returns the fsmenu entry (path) at \a index (or NULL if a bad index) or a separator.
+ */
+char *fsmenu_get_entry_path(struct FSMenu *fsmenu, FSMenuCategory category, int index);
+
+/** Returns the fsmenu name at \a index (or NULL if a bad index) or a separator.
+ */
+char *fsmenu_get_entry_name(struct FSMenu *fsmenu, FSMenuCategory category, int index);
+char *fsmenu_entry_get_name(struct FSMenuEntry *fsentry);
+void fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name);
+
 #endif /* __ED_FILESELECT_H__ */
 
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 39e1837..65c341d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -480,7 +480,7 @@ static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
 	if (params->dir[0] != '\0') {
 		char name[FILE_MAX];
 	
-		fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, FS_INSERT_SAVE);
+		fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, NULL, FS_INSERT_SAVE);
 		BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
 		fsmenu_write_file(fsmenu, name);
 	}
@@ -546,7 +546,7 @@ static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
 	char name[FILE_MAX];
 	struct FSMenu *fsmenu = fsmenu_get();
 	
-	while (fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
+	while (fsmenu_get_entry_path(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
 		fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0);
 	}
 	BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
@@ -827,7 +827,7 @@ int file_exec(bContext *C, wmOperator *exec_op)
 		file_sfile_to_operator(op, sfile, filepath);
 
 		if (BLI_exists(sfile->params->dir)) {
-			fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE | FS_INSERT_FIRST);
+			fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, NULL, FS_INSERT_SAVE | FS_INSERT_FIRST);
 		}
 
 		BLI_make_file_string(G.main->name, filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c
index c224da7..42c5d49 100644
--- a/source/blender/editors/space_file/file_panels.c
+++ b/source/blender/editors/space_file/file_panels.c
@@ -44,6 +44,8 @@
 
 #include "RNA_access.h"
 
+#include "ED_fileselect.h"
+
 #include "UI_interface.h"
 #include "UI_resources.h"
 
@@ -90,32 +92,32 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat
 	col = uiLayoutColumn(box, true);
 
 	for (i = 0; i < nentries; ++i) {
-		char dir[FILE_MAX];
-		char temp[FILE_MAX];
 		uiLayout *layout = uiLayoutRow(col, false);
-		char *entry;
+		char *entry_path;
+		char *entry_name;
 		
-		entry = fsmenu_get_entry(fsmenu, category, i);
+		entry_path = fsmenu_get_entry_path(fsmenu, category, i);
+		entry_name = fsmenu_get_entry_name(fsmenu, category, i);
 		
 		/* set this list item as active if we have a match */
 		if (sfile->params) {
-			if (BLI_path_cmp(sfile->params->dir, entry) == 0) {
+			if (BLI_path_cmp(sfile->params->dir, entry_path) == 0) {
 				*nr = i;
 			}
 		}
 
 		/* create nice bookmark name, shows last directory in the full path currently */
-		BLI_strncpy(temp, entry, FILE_MAX);
-		BLI_add_slash(temp);
-		BLI_getlastdir(temp, dir, FILE_MAX);
-		BLI_del_slash(dir);
+		//BLI_strncpy(temp, entry, FILE_MAX);
+		//BLI_add_slash(temp);
+		//BLI_getlastdir(temp, dir, FILE_MAX);
+		//BLI_del_slash(dir);
 
-		if (dir[0] == 0)
-			BLI_strncpy(dir, entry, FILE_MAX);
+		//if (dir[0] == 0)
+			//BLI_strncpy(dir, entry, FILE_MAX);
 
 		/* create list item */
-		but = uiDefIconTextButS(block, UI_BTYPE_LISTROW, 0, icon, dir, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, nr, 0, i, 0, 0, entry);
-		UI_but_func_set(but, file_panel_cb, entry, NULL);
+		but = uiDefIconTextButS(block, UI_BTYPE_LISTROW, 0, icon, entry_name, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, nr, 0, i, 0, 0, entry_path);
+		UI_but_func_set(but, file_panel_cb, entry_path, NULL);
 		UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
 		UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT);
 
@@ -132,8 +134,8 @@ static void file_panel_system(const bContext *C, Panel *pa)
 {
 	SpaceFile *sfile = CTX_wm_space_file(C);
 
-	if (sfile)
-		file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0);
+	//~ if (sfile)
+		//~ file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0);
 }
 
 static int file_panel_system_bookmarks_poll(const bContext *C, PanelType *UNUSED(pt))
diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 4ab9bc6..305030c 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -40,6 +40,10 @@
 #include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
 
+#include "DNA_space_types.h"
+
+#include "ED_fileselect.h"
+
 #ifdef WIN32
 #  include <windows.h> /* need to include windows.h so _WIN32_IE is defined  */
 #  ifndef _WIN32_IE
@@ -63,15 +67,6 @@
 
 /* FSMENU HANDLING */
 
-/* FSMenuEntry's without paths indicate seperators */
-typedef struct _FSMenuEntry FSMenuEntry;
-struct _FSMenuEntry {
-	FSMenuEntry *next;
-
-	char *path;
-	short save;
-};
-
 typedef struct FSMenu {
 	FSMenuEntry *fsmenu_system;
 	FSMenuEntry *fsmenu_system_bookmarks;
@@ -89,7 +84,7 @@ FSMenu *fsmenu_get(void)
 	return g_fsmenu;
 }
 
-static FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category)
+struct FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category)
 {
 	FSMenuEntry *fsm_head = NULL;
 
@@ -140,15 +135,75 @@ int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category)
 	return count;
 }
 
-char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
+FSMenuEntry *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int index)
 {
 	FSMenuEntry *fsm_iter;
 
-	for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) {
-		idx--;
+	for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && index; fsm_iter = fsm_iter->next) {
+		index--;
+	}
+
+	return fsm_iter;
+}
+
+char *fsmenu_get_entry_path(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
+{
+	FSMenuEntry *fsm = fsmenu_get_entry(fsmenu, category, idx);
+
+	return fsm ? fsm->path : NULL;
+}
+
+static void fsmenu_entry_generate_name(struct FSMenuEntry *fsentry, char *name, size_t name_size)
+{
+	char temp[FILE_MAX];
+
+	BLI_strncpy(temp, fsentry->path, FILE_MAX);
+	BLI_add_slash(temp);
+	BLI_getlastdir(temp, name, name_size);
+	BLI_del_slash(name);
+	if (!name[0]) {
+		name[0] = '/';
+		name[1] = '\0';
 	}
+}
 
-	return fsm_iter ? fsm_iter->path : NULL;
+char *fsmenu_entry_get_name(struct FSMenuEntry *fsentry)
+{


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list