As nobody else ever felt like doing it, and I work too much with official

CVS these days in order not to be terribly annoyed by its absence, here it
is: instinctive-blender's "Recent files list".

It's in the CTRL-O menu. No UI / muscle memory changes -- the first entry is
the same as the only entry that used to be in the former popup.
.
This commit is contained in:
Alexander Ewering 2006-05-14 19:42:48 +00:00
parent fd8e5895c8
commit ab30cf7489
3 changed files with 52 additions and 13 deletions

@ -87,6 +87,8 @@ typedef struct Global {
/* strings: lastsaved */ /* strings: lastsaved */
char ima[160], sce[160], lib[160]; char ima[160], sce[160], lib[160];
char recent[10][160];
/* totals */ /* totals */
short totobj, totlamp, totobjsel, totcurve, totmesh; short totobj, totlamp, totobjsel, totcurve, totmesh;

@ -352,6 +352,32 @@ int untitled(char * name)
return(FALSE); return(FALSE);
} }
char *recent_filelist(void)
{
int event, i, ofs;
char pup[2048], *p;
p= pup + sprintf(pup, "Open recent%%t");
if (G.sce[0]) {
p+= sprintf(p, "|%s %%x%d", G.sce, 1);
ofs = 1;
} else ofs = 0;
for (i=0; i<10 && (G.recent[i][0]); i++) {
if (strcmp(G.recent[i], G.sce)) {
p+= sprintf(p, "|%s %%x%d", G.recent[i], i+ofs+1);
}
}
event= pupmenu(pup);
if(event>0) {
if (ofs && (event==1))
return(G.sce);
else
return(G.recent[event-1-ofs]);
}
else
return(NULL);
}
int blenderqread(unsigned short event, short val) int blenderqread(unsigned short event, short val)
{ {
@ -365,6 +391,7 @@ int blenderqread(unsigned short event, short val)
/* Changed str and dir size to 160, to make sure there is enough /* Changed str and dir size to 160, to make sure there is enough
* space for filenames. */ * space for filenames. */
char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2]; char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
char *recentfile;
if(val==0) return 1; if(val==0) return 1;
if(event==MOUSEY || event==MOUSEX) return 1; if(event==MOUSEY || event==MOUSEX) return 1;
@ -720,14 +747,9 @@ int blenderqread(unsigned short event, short val)
case OKEY: case OKEY:
if(textediting==0) { if(textediting==0) {
if(G.qual==LR_CTRLKEY) { if(G.qual==LR_CTRLKEY) {
/* There seem to be crashes here sometimes.... String recentfile = recent_filelist();
* bound overwrites? I changed dir and str sizes, if(recentfile) {
* let's see if this reoccurs. */ BIF_read_file(recentfile);
sprintf(str, "Open file: %s", G.sce);
if(okee(str)) {
strcpy(dir, G.sce);
BIF_read_file(dir);
} }
return 0; return 0;
} }

@ -461,14 +461,22 @@ static void readBlog(void)
{ {
char name[FILE_MAXDIR+FILE_MAXFILE], filename[FILE_MAXFILE]; char name[FILE_MAXDIR+FILE_MAXFILE], filename[FILE_MAXFILE];
LinkNode *l, *lines; LinkNode *l, *lines;
char *line;
int num;
BLI_make_file_string("/", name, BLI_gethome(), ".Blog"); BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
lines= BLI_read_file_as_lines(name); lines= BLI_read_file_as_lines(name);
if (lines && !BLI_streq(lines->link, "")) { for (num= 0; num<10; num++) G.recent[num][0]=0;
strcpy(G.sce, lines->link); for (l= lines, num= 0; l && (num<10); l= l->next, num++) {
} else { line = l->link;
BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend"); if (!BLI_streq(line, "")) {
if (num==0) strcpy(G.sce, line);
strcpy(G.recent[num], line);
} else {
// BLI_make_file_string("/", G.sce, BLI_gethome(), "untitled.blend");
G.sce[0] = 0;
}
} }
BLI_free_file_lines(lines); BLI_free_file_lines(lines);
@ -531,12 +539,19 @@ static void writeBlog(void)
{ {
char name[FILE_MAXDIR+FILE_MAXFILE]; char name[FILE_MAXDIR+FILE_MAXFILE];
FILE *fp; FILE *fp;
int i, num;
BLI_make_file_string("/", name, BLI_gethome(), ".Blog"); BLI_make_file_string("/", name, BLI_gethome(), ".Blog");
fp= fopen(name, "w"); fp= fopen(name, "w");
if (fp) { if (fp) {
fprintf(fp, G.sce); for (i=0, num=0; (num<10) && (G.recent[i][0]); i++, num++) {
if (i==0) {
fprintf(fp, "%s\n", G.sce);
num++;
}
if (strcmp(G.recent[i], G.sce)) fprintf(fp, "%s\n", G.recent[i]);
}
fclose(fp); fclose(fp);
} }
} }