[Bf-blender-cvs] [b9ffd70] master: FileBrowser Bookmarks: fix issue with invalid bookmarks.

Bastien Montagne noreply at git.blender.org
Wed Feb 11 17:23:04 CET 2015


Commit: b9ffd70960c5047a003fadf2363bfed50095d79b
Author: Bastien Montagne
Date:   Wed Feb 11 17:07:52 2015 +0100
Branches: master
https://developer.blender.org/rBb9ffd70960c5047a003fadf2363bfed50095d79b

FileBrowser Bookmarks: fix issue with invalid bookmarks.

Reported by maxon through IRC, thanks.

Invalid (inexistant) bookmarks would not be selectable, hence not removable.

First, made invalid bookmarks grayed out in lists, so that user knows when there are some.

Then, added a new 'cleanup' operator that removes all invalid bookmarks.

This solution may not be completely satisfaying, but should do the work for now.
I do not want to add back those ugly 'X' delete buttons for each entry in list,
so better solution would be to make UIList able to select several items at once...

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

M	release/scripts/startup/bl_ui/space_filebrowser.py
M	source/blender/editors/space_file/file_intern.h
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index cda3dfe..ded307e 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -98,7 +98,12 @@ class FILEBROWSER_UL_dir(bpy.types.UIList):
 
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             row = layout.row(align=True)
-            row.prop(direntry, "name", text="", emboss=False, icon=icon)
+            row.enabled = direntry.is_valid
+            # Non-editable entries would show grayed-out, which is bad in this specific case, so switch to mere label.
+            if direntry.is_property_readonly('name'):
+                row.label(text=direntry.name, icon=icon)
+            else:
+                row.prop(direntry, "name", text="", emboss=False, icon=icon)
 
         elif self.layout_type in {'GRID'}:
             layout.alignment = 'CENTER'
@@ -146,7 +151,9 @@ class FILEBROWSER_MT_bookmarks_specials(Menu):
 
     def draw(self, context):
         layout = self.layout
+        layout.operator("file.bookmark_cleanup", icon='X', text="Cleanup")
 
+        layout.separator()
         layout.operator("file.bookmark_move", icon='TRIA_UP_BAR', text="Move To Top").direction = 'TOP'
         layout.operator("file.bookmark_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").direction = 'BOTTOM'
 
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 31d479b..7425f2e 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -66,6 +66,7 @@ void FILE_OT_select_border(struct wmOperatorType *ot);
 void FILE_OT_select_bookmark(struct wmOperatorType *ot);
 void FILE_OT_bookmark_add(struct wmOperatorType *ot);
 void FILE_OT_bookmark_delete(struct wmOperatorType *ot);
+void FILE_OT_bookmark_cleanup(struct wmOperatorType *ot);
 void FILE_OT_bookmark_move(struct wmOperatorType *ot);
 void FILE_OT_reset_recent(wmOperatorType *ot);
 void FILE_OT_hidedot(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index a0e312e..ddf9545 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -573,6 +573,52 @@ void FILE_OT_bookmark_delete(wmOperatorType *ot)
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
+static int bookmark_cleanup_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	ScrArea *sa = CTX_wm_area(C);
+	struct FSMenu *fsmenu = ED_fsmenu_get();
+	struct FSMenuEntry *fsme_next, *fsme = ED_fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS);
+	int index;
+	bool changed = false;
+
+	for (index = 0; fsme; fsme = fsme_next) {
+		fsme_next = fsme->next;
+
+		if (!BLI_is_dir(fsme->path)) {
+			fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
+			changed = true;
+		}
+		else {
+			index++;
+		}
+	}
+
+	if (changed) {
+		char name[FILE_MAX];
+
+		BLI_make_file_string("/", name, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
+		fsmenu_write_file(fsmenu, name);
+		ED_area_tag_refresh(sa);
+		ED_area_tag_redraw(sa);
+	}
+
+	return OPERATOR_FINISHED;
+}
+
+void FILE_OT_bookmark_cleanup(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Cleanup Bookmarks";
+	ot->description = "Delete all invalid bookmarks";
+	ot->idname = "FILE_OT_bookmark_cleanup";
+
+	/* api callbacks */
+	ot->exec = bookmark_cleanup_exec;
+	ot->poll = ED_operator_file_active;
+
+	/* properties */
+}
+
 enum {
 	FILE_BOOKMARK_MOVE_TOP = -2,
 	FILE_BOOKMARK_MOVE_UP = -1,
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 3c60233..fe861fa 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -404,6 +404,7 @@ static void file_operatortypes(void)
 	WM_operatortype_append(FILE_OT_bookmark_toggle);
 	WM_operatortype_append(FILE_OT_bookmark_add);
 	WM_operatortype_append(FILE_OT_bookmark_delete);
+	WM_operatortype_append(FILE_OT_bookmark_cleanup);
 	WM_operatortype_append(FILE_OT_bookmark_move);
 	WM_operatortype_append(FILE_OT_reset_recent);
 	WM_operatortype_append(FILE_OT_hidedot);
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index fc2b2d7..70b9f18 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -1422,6 +1422,13 @@ static int rna_FileBrowser_FSMenuEntry_name_get_editable(PointerRNA *ptr)
 	return fsm->save;
 }
 
+static int rna_FileBrowser_FSMenuEntry_is_valid_get(PointerRNA *ptr)
+{
+	char *path = ED_fsmenu_entry_get_path(ptr->data);
+
+	return path ? BLI_is_dir(path) : false;  /* For now, no path = invalid. */
+}
+
 static void rna_FileBrowser_FSMenu_next(CollectionPropertyIterator *iter)
 {
 	ListBaseIterator *internal = &iter->internal.listbase;
@@ -3629,6 +3636,11 @@ static void rna_def_filemenu_entry(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "save", 1);
 	RNA_def_property_ui_text(prop, "Save", "Whether this path is saved in bookmarks, or generated from OS");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+	prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_funcs(prop, "rna_FileBrowser_FSMenuEntry_is_valid_get", NULL);
+	RNA_def_property_ui_text(prop, "Save", "Whether this path is saved in bookmarks, or generated from OS");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 }
 
 static void rna_def_space_filebrowser(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list