== filebrowser ==

further fixes for 'RECENT' files panel in filebrowser:
* Also add the recent folder at the head if it is not yet in the list
* since we now insert at the head, we need to remove the skipping of the first entries if there are too many. Now correctly leaving the last elements unwritten.
* Another consequence of inserting at the head is that we don't want to reverse the list in the recent panel anymore - got rid of the corresponding code.
This commit is contained in:
Andrea Weikert
2012-09-17 21:29:30 +00:00
parent f5395107cc
commit dd3636a6d4
2 changed files with 15 additions and 17 deletions

View File

@@ -67,14 +67,14 @@ static void file_panel_cb(bContext *C, void *arg_entry, void *UNUSED(arg_v))
WM_operator_properties_free(&ptr);
}
static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, short *nr, int icon, int allow_delete, int reverse)
static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory category, short *nr, int icon, int allow_delete)
{
SpaceFile *sfile = CTX_wm_space_file(C);
uiBlock *block;
uiBut *but;
uiLayout *box, *col;
struct FSMenu *fsmenu = fsmenu_get();
int i, i_iter, nentries = fsmenu_get_nentries(fsmenu, category);
int i, nentries = fsmenu_get_nentries(fsmenu, category);
/* reset each time */
*nr = -1;
@@ -89,13 +89,11 @@ static void file_panel_category(const bContext *C, Panel *pa, FSMenuCategory cat
box = uiLayoutBox(pa->layout);
col = uiLayoutColumn(box, TRUE);
for (i_iter = 0; i_iter < nentries; ++i_iter) {
for (i = 0; i < nentries; ++i) {
char dir[FILE_MAX];
char temp[FILE_MAX];
uiLayout *layout = uiLayoutRow(col, FALSE);
char *entry;
i = reverse ? nentries - (i_iter + 1) : i_iter;
entry = fsmenu_get_entry(fsmenu, category, i);
@@ -134,7 +132,7 @@ 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, 0);
file_panel_category(C, pa, FS_CATEGORY_SYSTEM, &sfile->systemnr, ICON_DISK_DRIVE, 0);
}
static void file_panel_bookmarks(const bContext *C, Panel *pa)
@@ -147,7 +145,7 @@ static void file_panel_bookmarks(const bContext *C, Panel *pa)
uiItemO(row, IFACE_("Add"), ICON_ZOOMIN, "file.bookmark_add");
uiItemL(row, NULL, ICON_NONE);
file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, &sfile->bookmarknr, ICON_BOOKMARKS, 1, 0);
file_panel_category(C, pa, FS_CATEGORY_BOOKMARKS, &sfile->bookmarknr, ICON_BOOKMARKS, 1);
}
}
@@ -157,7 +155,7 @@ static void file_panel_recent(const bContext *C, Panel *pa)
if (sfile) {
if (!(U.uiflag & USER_HIDE_RECENT) ) {
file_panel_category(C, pa, FS_CATEGORY_RECENT, &sfile->recentnr, ICON_FILE_FOLDER, 0, 1);
file_panel_category(C, pa, FS_CATEGORY_RECENT, &sfile->recentnr, ICON_FILE_FOLDER, 0);
}
}
}

View File

@@ -203,8 +203,13 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const c
fsm_iter->save = (flag & FS_INSERT_SAVE) != 0;
if (fsm_prev) {
fsm_iter->next = fsm_prev->next;
fsm_prev->next = fsm_iter;
if (flag & FS_INSERT_FIRST) {
fsm_iter->next = fsm_head;
fsmenu_set_category(fsmenu, category, fsm_iter);
} else {
fsm_iter->next = fsm_prev->next;
fsm_prev->next = fsm_iter;
}
}
else {
fsm_iter->next = fsm_head;
@@ -247,7 +252,7 @@ void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx
void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename)
{
FSMenuEntry *fsm_iter = NULL;
int nskip = 0;
int nwritten = 0;
FILE *fp = BLI_fopen(filename, "w");
if (!fp) return;
@@ -259,12 +264,7 @@ void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename)
}
}
fprintf(fp, "[Recent]\n");
nskip = fsmenu_get_nentries(fsmenu, FS_CATEGORY_RECENT) - FSMENU_RECENT_MAX;
/* skip first entries if list too long */
for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsm_iter && (nskip > 0); fsm_iter = fsm_iter->next, --nskip) {
/* pass */
}
for (; fsm_iter; fsm_iter = fsm_iter->next) {
for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsm_iter && (nwritten < FSMENU_RECENT_MAX); fsm_iter = fsm_iter->next, ++nwritten) {
if (fsm_iter->path && fsm_iter->save) {
fprintf(fp, "%s\n", fsm_iter->path);
}