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...
This commit is contained in:
@@ -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'
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user