2.5 filebrowser
(WIP commit) - added categories SYSTEM, BOOKMARKS and RECENT to left panel (recent files not filled yet) - selection for bookmarks now works by storing draw position, might do that for the file list too - removed fsmenu button and Bookmark button from UI region
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
#include "BMF_Api.h"
|
||||
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_context.h"
|
||||
@@ -88,6 +89,9 @@ enum {
|
||||
B_FS_PARENT,
|
||||
} eFile_ButEvents;
|
||||
|
||||
/* XXX very bad, need to check font code */
|
||||
static gFontsize=12;
|
||||
|
||||
static void do_file_buttons(bContext *C, void *arg, int event)
|
||||
{
|
||||
switch(event) {
|
||||
@@ -114,8 +118,6 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
||||
char *menu;
|
||||
float slen;
|
||||
float button_width = 20.0f;
|
||||
float fsmenubut_width = 0.0f;
|
||||
float bookmarkbut_width = button_width;
|
||||
|
||||
int filebuty1, filebuty2;
|
||||
|
||||
@@ -146,15 +148,8 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
||||
loadbutton= 0;
|
||||
}
|
||||
|
||||
/* XXX to channel region */
|
||||
menu= fsmenu_build_menu();
|
||||
|
||||
if (menu[0]&& (params->type != FILE_MAIN)) {
|
||||
fsmenubut_width = button_width;
|
||||
}
|
||||
|
||||
uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+bookmarkbut_width+2, filebuty1, xmax-xmin-loadbutton-bookmarkbut_width-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
||||
uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+fsmenubut_width+2, filebuty2, xmax-xmin-loadbutton-fsmenubut_width-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
||||
uiDefBut(block, TEX, 0 /* XXX B_FS_FILENAME */,"", xmin+2, filebuty1, xmax-xmin-loadbutton-4, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
||||
uiDefBut(block, TEX, 0 /* XXX B_FS_DIRNAME */,"", xmin+2, filebuty2, xmax-xmin-loadbutton-4, 21, params->dir, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
||||
|
||||
if(loadbutton) {
|
||||
uiSetCurFont(block, UI_HELV);
|
||||
@@ -162,6 +157,7 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
||||
uiDefBut(block, BUT, B_FS_CANCEL, "Cancel", xmax-loadbutton, filebuty1, loadbutton, 21, params->file, 0.0, (float)FILE_MAXFILE-1, 0, 0, "");
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* menu[0] = NULL happens when no .Bfs is there, and first time browse
|
||||
disallow external directory browsing for databrowse */
|
||||
|
||||
@@ -171,6 +167,8 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
|
||||
}
|
||||
|
||||
MEM_freeN(menu);
|
||||
#endif
|
||||
|
||||
|
||||
uiEndBlock(C, block);
|
||||
uiDrawBlock(C, block);
|
||||
@@ -192,24 +190,49 @@ static void draw_tile(short sx, short sy, short width, short height, int colorid
|
||||
uiRoundBox(sx, sy - height, sx + width, sy, 6);
|
||||
}
|
||||
|
||||
static float shorten_string(char* string, float w)
|
||||
#define FILE_SHORTEN_END 0
|
||||
#define FILE_SHORTEN_FRONT 1
|
||||
|
||||
|
||||
static float shorten_string(char* string, float w, int flag)
|
||||
{
|
||||
char temp[FILE_MAX];
|
||||
short shortened = 0;
|
||||
float sw = 0;
|
||||
|
||||
float pad = 0;
|
||||
|
||||
sw = UI_GetStringWidth(G.font, string,0);
|
||||
while (sw>w) {
|
||||
int slen = strlen(string);
|
||||
string[slen-1] = '\0';
|
||||
sw = UI_GetStringWidth(G.font, string,0);
|
||||
shortened = 1;
|
||||
}
|
||||
if (shortened) {
|
||||
int slen = strlen(string);
|
||||
if (slen > 3) {
|
||||
BLI_strncpy(string+slen-3, "...", 4);
|
||||
if (flag == FILE_SHORTEN_FRONT) {
|
||||
char *s = string;
|
||||
BLI_strncpy(temp, "...", 4);
|
||||
pad = UI_GetStringWidth(G.font, temp,0);
|
||||
while (s && (sw+pad>w)) {
|
||||
s++;
|
||||
sw = UI_GetStringWidth(G.font, s,0);
|
||||
shortened = 1;
|
||||
}
|
||||
if (shortened) {
|
||||
int slen = strlen(s);
|
||||
BLI_strncpy(temp+3, s, slen+1);
|
||||
temp[slen+4] = '\0';
|
||||
BLI_strncpy(string, temp, slen+4);
|
||||
}
|
||||
} else {
|
||||
char *s = string;
|
||||
while (sw>w) {
|
||||
int slen = strlen(string);
|
||||
string[slen-1] = '\0';
|
||||
sw = UI_GetStringWidth(G.font, s,0);
|
||||
shortened = 1;
|
||||
}
|
||||
if (shortened) {
|
||||
int slen = strlen(string);
|
||||
if (slen > 3) {
|
||||
BLI_strncpy(string+slen-3, "...", 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sw;
|
||||
}
|
||||
|
||||
@@ -244,7 +267,7 @@ static void file_draw_icon(short sx, short sy, int icon, short width, short heig
|
||||
UI_icon_draw_aspect_blended(x, y, icon, 1.f, blend);
|
||||
}
|
||||
|
||||
static void file_draw_string(short sx, short sy, char* string, short width, short height)
|
||||
static void file_draw_string(short sx, short sy, char* string, short width, short height, int flag)
|
||||
{
|
||||
short soffs;
|
||||
char fname[FILE_MAXFILE];
|
||||
@@ -252,7 +275,7 @@ static void file_draw_string(short sx, short sy, char* string, short width, shor
|
||||
float x,y;
|
||||
|
||||
BLI_strncpy(fname,string, FILE_MAXFILE);
|
||||
sw = shorten_string(fname, width );
|
||||
sw = shorten_string(fname, width, flag );
|
||||
soffs = (width - sw) / 2;
|
||||
x = (float)(sx);
|
||||
y = (float)(sy-height);
|
||||
@@ -402,7 +425,7 @@ void file_draw_previews(const bContext *C, ARegion *ar)
|
||||
}
|
||||
}
|
||||
}
|
||||
file_draw_string(sx + layout->prv_border_x, sy+4, file->relname, layout->tile_w, layout->tile_h);
|
||||
file_draw_string(sx + layout->prv_border_x, sy+4, file->relname, layout->tile_w, layout->tile_h, FILE_SHORTEN_END);
|
||||
|
||||
if (!sfile->loadimage_timer)
|
||||
sfile->loadimage_timer= WM_event_add_window_timer(CTX_wm_window(C), TIMER1, 1.0/30.0); /* max 30 frames/sec. */
|
||||
@@ -493,7 +516,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
||||
UI_ThemeColor4(TH_TEXT);
|
||||
|
||||
sw = UI_GetStringWidth(G.font, file->size, 0);
|
||||
file_draw_string(spos, sy, file->relname, layout->tile_w - sw - 5, layout->tile_h);
|
||||
file_draw_string(spos, sy, file->relname, layout->tile_w - sw - 5, layout->tile_h, FILE_SHORTEN_END);
|
||||
|
||||
spos += filelist_maxnamelen(sfile->files);
|
||||
if (params->display != FILE_SHOWSHORT) {
|
||||
@@ -518,43 +541,44 @@ void file_draw_list(const bContext *C, ARegion *ar)
|
||||
|
||||
spos += 50;
|
||||
sw = UI_GetStringWidth(G.font, file->date, 0);
|
||||
file_draw_string(spos, sy, file->date, sw, layout->tile_h);
|
||||
file_draw_string(spos, sy, file->date, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||
|
||||
spos += 100;
|
||||
sw = UI_GetStringWidth(G.font, file->time, 0);
|
||||
file_draw_string(spos, sy, file->time, sw, layout->tile_h);
|
||||
file_draw_string(spos, sy, file->time, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||
|
||||
sw = UI_GetStringWidth(G.font, file->size, 0);
|
||||
spos += 200-sw;
|
||||
file_draw_string(spos, sy, file->size, sw, layout->tile_h);
|
||||
file_draw_string(spos, sy, file->size, sw, layout->tile_h, FILE_SHORTEN_END);
|
||||
} else {
|
||||
file_draw_string(sx + layout->tile_w - 2*layout->tile_border_x - sw - 4, sy, file->size, layout->tile_w - layout->tile_border_x - sw - 5, layout->tile_h);
|
||||
file_draw_string(sx + layout->tile_w - 2*layout->tile_border_x - sw - 4, sy, file->size, layout->tile_w - layout->tile_border_x - sw - 5, layout->tile_h, FILE_SHORTEN_END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void file_draw_fsmenu(const bContext *C, ARegion *ar)
|
||||
static void file_draw_fsmenu_category(const bContext *C, ARegion *ar, FSMenuCategory category, const char* category_name, short *starty)
|
||||
{
|
||||
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
|
||||
FileSelectParams* params = ED_fileselect_get_params(sfile);
|
||||
char bookmark[FILE_MAX];
|
||||
int nentries = fsmenu_get_nentries();
|
||||
int linestep = U.fontsize*2.0f;
|
||||
int i;
|
||||
int nentries = fsmenu_get_nentries(category);
|
||||
int linestep = gFontsize*2.0f;
|
||||
short sx, sy, xpos, ypos;
|
||||
int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - TILE_BORDER_X;
|
||||
int fontsize = U.fontsize;
|
||||
int bmwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin - 2*TILE_BORDER_X - ICON_DEFAULT_WIDTH - 4;
|
||||
int fontsize = gFontsize;
|
||||
int i;
|
||||
|
||||
sx = ar->v2d.cur.xmin + TILE_BORDER_X;
|
||||
sy = ar->v2d.cur.ymax-2*TILE_BORDER_Y;
|
||||
|
||||
sx = ar->v2d.cur.xmin + TILE_BORDER_X;
|
||||
sy = *starty;
|
||||
|
||||
UI_ThemeColor(TH_TEXT_HI);
|
||||
file_draw_string(sx, sy, "BOOKMARKS", bmwidth, fontsize);
|
||||
file_draw_string(sx, sy, category_name, bmwidth, fontsize, FILE_SHORTEN_END);
|
||||
|
||||
sy -= linestep;
|
||||
|
||||
|
||||
for (i=0; i< nentries && (sy > ar->v2d.cur.ymin) ;++i) {
|
||||
char *fname = fsmenu_get_entry(i);
|
||||
char *fname = fsmenu_get_entry(category, i);
|
||||
|
||||
if (fname) {
|
||||
int sl;
|
||||
@@ -565,7 +589,7 @@ void file_draw_fsmenu(const bContext *C, ARegion *ar)
|
||||
bookmark[sl] = '\0';
|
||||
sl--;
|
||||
}
|
||||
if (params->active_bookmark == i ) {
|
||||
if (fsmenu_is_selected(category, i) ) {
|
||||
UI_ThemeColor(TH_HILITE);
|
||||
/* uiSetRoundBox(15);
|
||||
* uiRoundBox(sx, sy - linestep, sx + bmwidth, sy, 4.0f); */
|
||||
@@ -580,16 +604,29 @@ void file_draw_fsmenu(const bContext *C, ARegion *ar)
|
||||
|
||||
file_draw_icon(xpos, ypos, ICON_FILE_FOLDER, ICON_DEFAULT_WIDTH, ICON_DEFAULT_WIDTH);
|
||||
xpos += ICON_DEFAULT_WIDTH + 4;
|
||||
file_draw_string(xpos, ypos, bookmark, bmwidth, fontsize);
|
||||
sy -= linestep;
|
||||
} else {
|
||||
UI_ThemeColorShade(TH_PANEL, 30);
|
||||
sdrawline(sx, sy-1-fontsize/2, sx + bmwidth, sy-1-fontsize/2);
|
||||
UI_ThemeColorShade(TH_PANEL, -30);
|
||||
sdrawline(sx, sy-fontsize/2, sx + bmwidth, sy - fontsize/2);
|
||||
|
||||
file_draw_string(xpos, ypos, bookmark, bmwidth, fontsize, FILE_SHORTEN_FRONT);
|
||||
sy -= linestep;
|
||||
fsmenu_set_pos(category, i, xpos, ypos);
|
||||
}
|
||||
}
|
||||
|
||||
*starty = sy;
|
||||
}
|
||||
|
||||
void file_draw_fsmenu(const bContext *C, ARegion *ar)
|
||||
{
|
||||
int linestep = gFontsize*2.0f;
|
||||
|
||||
short sx, sy, xpos, ypos;
|
||||
int fontsize = gFontsize;
|
||||
|
||||
sx = ar->v2d.cur.xmin + TILE_BORDER_X;
|
||||
sy = ar->v2d.cur.ymax-2*TILE_BORDER_Y;
|
||||
|
||||
file_draw_fsmenu_category(C, ar, FS_CATEGORY_SYSTEM, "SYSTEM", &sy);
|
||||
sy -= linestep;
|
||||
file_draw_fsmenu_category(C, ar, FS_CATEGORY_BOOKMARKS, "BOOKMARKS", &sy);
|
||||
sy -= linestep;
|
||||
file_draw_fsmenu_category(C, ar, FS_CATEGORY_RECENT, "RECENT", &sy);
|
||||
|
||||
}
|
||||
|
||||
@@ -247,10 +247,13 @@ static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
rect.ymin = rect.ymax = event->y - ar->winrct.ymin;
|
||||
val = event->val;
|
||||
|
||||
/* single select, deselect all selected first */
|
||||
file_deselect_all(sfile);
|
||||
file_select(sfile, sfile->params, ar, &rect, val );
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
if (BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin)) {
|
||||
|
||||
/* single select, deselect all selected first */
|
||||
file_deselect_all(sfile);
|
||||
file_select(sfile, sfile->params, ar, &rect, val );
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
}
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
@@ -316,7 +319,7 @@ void FILE_OT_select_all(wmOperatorType *ot)
|
||||
|
||||
static void set_active_bookmark(FileSelectParams* params, struct ARegion* ar, short x, short y)
|
||||
{
|
||||
int nentries = fsmenu_get_nentries();
|
||||
int nentries = fsmenu_get_nentries(FS_CATEGORY_BOOKMARKS);
|
||||
float fx, fy;
|
||||
short posy;
|
||||
|
||||
@@ -331,21 +334,57 @@ static void set_active_bookmark(FileSelectParams* params, struct ARegion* ar, sh
|
||||
}
|
||||
}
|
||||
|
||||
static int file_select_bookmark_category(SpaceFile* sfile, ARegion* ar, short x, short y, FSMenuCategory category)
|
||||
{
|
||||
int nentries = fsmenu_get_nentries(category);
|
||||
int linestep = U.fontsize*2.0f;
|
||||
short xs, ys;
|
||||
int i;
|
||||
int selected = -1;
|
||||
|
||||
for (i=0; i < nentries; ++i) {
|
||||
fsmenu_get_pos(category, i, &xs, &ys);
|
||||
if ( (y<=ys) && (y>ys-linestep) ) {
|
||||
fsmenu_select_entry(category, i);
|
||||
selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
static void file_select_bookmark(SpaceFile* sfile, ARegion* ar, short x, short y)
|
||||
{
|
||||
float fx, fy;
|
||||
int selected;
|
||||
FSMenuCategory category = FS_CATEGORY_SYSTEM;
|
||||
|
||||
if (BLI_in_rcti(&ar->v2d.mask, x, y)) {
|
||||
char *selected;
|
||||
set_active_bookmark(sfile->params, ar, x, y);
|
||||
selected= fsmenu_get_entry(sfile->params->active_bookmark);
|
||||
/* which string */
|
||||
if (selected) {
|
||||
FileSelectParams* params = sfile->params;
|
||||
BLI_strncpy(params->dir, selected, sizeof(params->dir));
|
||||
BLI_cleanup_dir(G.sce, params->dir);
|
||||
filelist_free(sfile->files);
|
||||
filelist_setdir(sfile->files, params->dir);
|
||||
params->file[0] = '\0';
|
||||
params->active_file = -1;
|
||||
char *entry;
|
||||
|
||||
UI_view2d_region_to_view(&ar->v2d, x, y, &fx, &fy);
|
||||
selected = file_select_bookmark_category(sfile, ar, fx, fy, FS_CATEGORY_SYSTEM);
|
||||
if (selected<0) {
|
||||
category = FS_CATEGORY_BOOKMARKS;
|
||||
selected = file_select_bookmark_category(sfile, ar, fx, fy, category);
|
||||
}
|
||||
if (selected<0) {
|
||||
category = FS_CATEGORY_RECENT;
|
||||
selected = file_select_bookmark_category(sfile, ar, fx, fy, category);
|
||||
}
|
||||
|
||||
if (selected>=0) {
|
||||
entry= fsmenu_get_entry(category, selected);
|
||||
/* which string */
|
||||
if (entry) {
|
||||
FileSelectParams* params = sfile->params;
|
||||
BLI_strncpy(params->dir, entry, sizeof(params->dir));
|
||||
BLI_cleanup_dir(G.sce, params->dir);
|
||||
filelist_free(sfile->files);
|
||||
filelist_setdir(sfile->files, params->dir);
|
||||
params->file[0] = '\0';
|
||||
params->active_file = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,106 +59,119 @@ struct _FSMenuEntry {
|
||||
|
||||
char *path;
|
||||
short save;
|
||||
short xs, ys;
|
||||
};
|
||||
|
||||
static FSMenuEntry *fsmenu= 0;
|
||||
static FSMenuEntry *fsmenu_system= 0;
|
||||
static FSMenuEntry *fsmenu_bookmarks= 0;
|
||||
static FSMenuEntry *fsmenu_recent= 0;
|
||||
|
||||
int fsmenu_get_nentries(void)
|
||||
static FSMenuCategory selected_category= FS_CATEGORY_SYSTEM;
|
||||
static int selected_entry= 0;
|
||||
|
||||
void fsmenu_select_entry(FSMenuCategory category, int index)
|
||||
{
|
||||
selected_category = category;
|
||||
selected_entry = index;
|
||||
}
|
||||
|
||||
int fsmenu_is_selected(FSMenuCategory category, int index)
|
||||
{
|
||||
return (category==selected_category) && (index==selected_entry);
|
||||
}
|
||||
|
||||
static FSMenuEntry *fsmenu_get(FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsmenu = NULL;
|
||||
|
||||
switch(category) {
|
||||
case FS_CATEGORY_SYSTEM:
|
||||
fsmenu = fsmenu_system;
|
||||
break;
|
||||
case FS_CATEGORY_BOOKMARKS:
|
||||
fsmenu = fsmenu_bookmarks;
|
||||
break;
|
||||
case FS_CATEGORY_RECENT:
|
||||
fsmenu = fsmenu_recent;
|
||||
break;
|
||||
}
|
||||
return fsmenu;
|
||||
}
|
||||
|
||||
static void fsmenu_set(FSMenuCategory category, FSMenuEntry *fsmenu)
|
||||
{
|
||||
switch(category) {
|
||||
case FS_CATEGORY_SYSTEM:
|
||||
fsmenu_system = fsmenu;
|
||||
break;
|
||||
case FS_CATEGORY_BOOKMARKS:
|
||||
fsmenu_bookmarks = fsmenu;
|
||||
break;
|
||||
case FS_CATEGORY_RECENT:
|
||||
fsmenu_recent = fsmenu;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int fsmenu_get_nentries(FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsme;
|
||||
int count= 0;
|
||||
|
||||
for (fsme= fsmenu; fsme; fsme= fsme->next)
|
||||
for (fsme= fsmenu_get(category); fsme; fsme= fsme->next)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
int fsmenu_is_entry_a_separator(int idx)
|
||||
|
||||
char *fsmenu_get_entry(FSMenuCategory category, int idx)
|
||||
{
|
||||
FSMenuEntry *fsme;
|
||||
|
||||
for (fsme= fsmenu; fsme && idx; fsme= fsme->next)
|
||||
idx--;
|
||||
|
||||
return (fsme && !fsme->path)?1:0;
|
||||
}
|
||||
char *fsmenu_get_entry(int idx)
|
||||
{
|
||||
FSMenuEntry *fsme;
|
||||
|
||||
for (fsme= fsmenu; fsme && idx; fsme= fsme->next)
|
||||
for (fsme= fsmenu_get(category); fsme && idx; fsme= fsme->next)
|
||||
idx--;
|
||||
|
||||
return fsme?fsme->path:NULL;
|
||||
}
|
||||
char *fsmenu_build_menu(void)
|
||||
{
|
||||
DynStr *ds= BLI_dynstr_new();
|
||||
FSMenuEntry *fsme;
|
||||
char *menustr;
|
||||
|
||||
for (fsme= fsmenu; fsme; fsme= fsme->next) {
|
||||
if (!fsme->path) {
|
||||
/* clean consecutive seperators and ignore trailing ones */
|
||||
if (fsme->next) {
|
||||
if (fsme->next->path) {
|
||||
BLI_dynstr_append(ds, "%l|");
|
||||
} else {
|
||||
FSMenuEntry *next= fsme->next;
|
||||
fsme->next= next->next;
|
||||
MEM_freeN(next);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fsme->save) {
|
||||
BLI_dynstr_append(ds, "o ");
|
||||
} else {
|
||||
BLI_dynstr_append(ds, " ");
|
||||
}
|
||||
BLI_dynstr_append(ds, fsme->path);
|
||||
if (fsme->next) BLI_dynstr_append(ds, "|");
|
||||
}
|
||||
void fsmenu_set_pos( FSMenuCategory category, int idx, short xs, short ys)
|
||||
{
|
||||
FSMenuEntry *fsme;
|
||||
|
||||
for (fsme= fsmenu_get(category); fsme && idx; fsme= fsme->next)
|
||||
idx--;
|
||||
|
||||
if (fsme) {
|
||||
fsme->xs = xs;
|
||||
fsme->ys = ys;
|
||||
}
|
||||
}
|
||||
|
||||
int fsmenu_get_pos (FSMenuCategory category, int idx, short* xs, short* ys)
|
||||
{
|
||||
FSMenuEntry *fsme;
|
||||
|
||||
for (fsme= fsmenu_get(category); fsme && idx; fsme= fsme->next)
|
||||
idx--;
|
||||
|
||||
if (fsme) {
|
||||
*xs = fsme->xs;
|
||||
*ys = fsme->ys;
|
||||
return 1;
|
||||
}
|
||||
|
||||
menustr= BLI_dynstr_get_cstring(ds);
|
||||
BLI_dynstr_free(ds);
|
||||
return menustr;
|
||||
}
|
||||
static FSMenuEntry *fsmenu_get_last_separator(void)
|
||||
{
|
||||
FSMenuEntry *fsme, *lsep=NULL;
|
||||
|
||||
for (fsme= fsmenu; fsme; fsme= fsme->next)
|
||||
if (!fsme->path)
|
||||
lsep= fsme;
|
||||
|
||||
return lsep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FSMenuEntry *fsmenu_get_first_separator(void)
|
||||
{
|
||||
FSMenuEntry *fsme, *lsep=NULL;
|
||||
|
||||
for (fsme= fsmenu; fsme; fsme= fsme->next)
|
||||
if (!fsme->path) {
|
||||
lsep= fsme;
|
||||
break;
|
||||
}
|
||||
|
||||
return lsep;
|
||||
}
|
||||
|
||||
void fsmenu_insert_entry(char *path, int sorted, short save)
|
||||
void fsmenu_insert_entry(FSMenuCategory category, char *path, int sorted, short save)
|
||||
{
|
||||
FSMenuEntry *prev;
|
||||
FSMenuEntry *fsme;
|
||||
FSMenuEntry *fsmenu;
|
||||
|
||||
if (save) {
|
||||
prev = fsmenu_get_first_separator();
|
||||
} else {
|
||||
prev = fsmenu_get_last_separator();
|
||||
}
|
||||
fsme= prev?prev->next:fsmenu;
|
||||
fsmenu = fsmenu_get(category);
|
||||
prev= fsme= fsmenu;
|
||||
|
||||
for (; fsme; prev= fsme, fsme= fsme->next) {
|
||||
if (fsme->path) {
|
||||
@@ -186,24 +199,14 @@ void fsmenu_insert_entry(char *path, int sorted, short save)
|
||||
prev->next= fsme;
|
||||
} else {
|
||||
fsme->next= fsmenu;
|
||||
fsmenu= fsme;
|
||||
fsmenu_set(category, fsme);
|
||||
}
|
||||
}
|
||||
void fsmenu_append_separator(void)
|
||||
{
|
||||
if (fsmenu) {
|
||||
FSMenuEntry *fsme= fsmenu;
|
||||
|
||||
while (fsme->next) fsme= fsme->next;
|
||||
|
||||
fsme->next= MEM_mallocN(sizeof(*fsme), "fsme");
|
||||
fsme->next->next= NULL;
|
||||
fsme->next->path= NULL;
|
||||
}
|
||||
}
|
||||
void fsmenu_remove_entry(int idx)
|
||||
void fsmenu_remove_entry(FSMenuCategory category, int idx)
|
||||
{
|
||||
FSMenuEntry *prev= NULL, *fsme= fsmenu;
|
||||
FSMenuEntry *prev= NULL, *fsme= NULL;
|
||||
FSMenuEntry *fsmenu = fsmenu_get(category);
|
||||
|
||||
for (fsme= fsmenu; fsme && idx; prev= fsme, fsme= fsme->next)
|
||||
idx--;
|
||||
@@ -219,6 +222,7 @@ void fsmenu_remove_entry(int idx)
|
||||
prev->next= fsme->next;
|
||||
} else {
|
||||
fsmenu= fsme->next;
|
||||
fsmenu_set(category, fsmenu);
|
||||
}
|
||||
/* free entry */
|
||||
MEM_freeN(fsme->path);
|
||||
@@ -229,12 +233,12 @@ void fsmenu_remove_entry(int idx)
|
||||
|
||||
void fsmenu_write_file(const char *filename)
|
||||
{
|
||||
FSMenuEntry *fsme= fsmenu;
|
||||
FSMenuEntry *fsme= NULL;
|
||||
|
||||
FILE *fp = fopen(filename, "w");
|
||||
if (!fp) return;
|
||||
|
||||
for (fsme= fsmenu; fsme; fsme= fsme->next) {
|
||||
for (fsme= fsmenu_get(FS_CATEGORY_BOOKMARKS); fsme; fsme= fsme->next) {
|
||||
if (fsme->path && fsme->save) {
|
||||
fprintf(fp, "%s\n", fsme->path);
|
||||
}
|
||||
@@ -264,19 +268,15 @@ void fsmenu_read_file(const char *filename)
|
||||
tmps[2]='\\';
|
||||
tmps[3]=0;
|
||||
|
||||
fsmenu_insert_entry(tmps, 0, 0);
|
||||
fsmenu_insert_entry(FS_CATEGORY_SYSTEM, tmps, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Adding Desktop and My Documents */
|
||||
fsmenu_append_separator();
|
||||
|
||||
SHGetSpecialFolderPath(0, folder, CSIDL_PERSONAL, 0);
|
||||
fsmenu_insert_entry(folder, 0, 0);
|
||||
fsmenu_insert_entry(FS_CATEGORY_BOOKMARKS, folder, 1, 0);
|
||||
SHGetSpecialFolderPath(0, folder, CSIDL_DESKTOPDIRECTORY, 0);
|
||||
fsmenu_insert_entry(folder, 0, 0);
|
||||
|
||||
fsmenu_append_separator();
|
||||
fsmenu_insert_entry(FS_CATEGORY_BOOKMARKS, folder, 1, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -290,15 +290,15 @@ void fsmenu_read_file(const char *filename)
|
||||
if (line[len-1] == '\n') {
|
||||
line[len-1] = '\0';
|
||||
}
|
||||
fsmenu_insert_entry(line, 0, 1);
|
||||
fsmenu_insert_entry(FS_CATEGORY_BOOKMARKS, line, 0, 1);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void fsmenu_free(void)
|
||||
static void fsmenu_free_category(FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsme= fsmenu;
|
||||
FSMenuEntry *fsme= fsmenu_get(category);
|
||||
|
||||
while (fsme) {
|
||||
FSMenuEntry *n= fsme->next;
|
||||
@@ -310,5 +310,10 @@ void fsmenu_free(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void fsmenu_free(void)
|
||||
{
|
||||
fsmenu_free_category(FS_CATEGORY_SYSTEM);
|
||||
fsmenu_free_category(FS_CATEGORY_BOOKMARKS);
|
||||
fsmenu_free_category(FS_CATEGORY_RECENT);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,37 +31,38 @@
|
||||
#ifndef BSE_FSMENU_H
|
||||
#define BSE_FSMENU_H
|
||||
|
||||
/** Returns the number of entries in the Fileselect Menu */
|
||||
int fsmenu_get_nentries (void);
|
||||
typedef enum FSMenuCategory {
|
||||
FS_CATEGORY_SYSTEM,
|
||||
FS_CATEGORY_BOOKMARKS,
|
||||
FS_CATEGORY_RECENT
|
||||
} FSMenuCategory;
|
||||
|
||||
/** Returns true if the fsmenu entry at @a index exists and
|
||||
* is a seperator.
|
||||
*/
|
||||
int fsmenu_is_entry_a_separator (int index);
|
||||
/** Returns the number of entries in the Fileselect Menu */
|
||||
int fsmenu_get_nentries (FSMenuCategory category);
|
||||
|
||||
/** Returns the fsmenu entry at @a index (or NULL if a bad index)
|
||||
* or a separator.
|
||||
*/
|
||||
char* fsmenu_get_entry (int index);
|
||||
char* fsmenu_get_entry (FSMenuCategory category, int index);
|
||||
|
||||
/** Returns a new menu description string representing the
|
||||
* fileselect menu. Should be free'd with MEM_freeN.
|
||||
*/
|
||||
char* fsmenu_build_menu (void);
|
||||
void fsmenu_select_entry (FSMenuCategory category, int index);
|
||||
|
||||
/** Append a seperator to the FSMenu, inserts always follow the
|
||||
* last seperator.
|
||||
*/
|
||||
void fsmenu_append_separator (void);
|
||||
int fsmenu_is_selected (FSMenuCategory category, int index);
|
||||
|
||||
/** Sets the position of the fsmenu entry at @a index */
|
||||
void fsmenu_set_pos (FSMenuCategory category, int index, short xs, short ys);
|
||||
|
||||
/** Returns the position of the fsmenu entry at @a index. return value is 1 if successful, 0 otherwise */
|
||||
int fsmenu_get_pos (FSMenuCategory category, int index, short* xs, short* ys);
|
||||
|
||||
/** Inserts a new fsmenu entry with the given @a path.
|
||||
* Duplicate entries are not added.
|
||||
* @param sorted Should entry be inserted in sorted order?
|
||||
*/
|
||||
void fsmenu_insert_entry (char *path, int sorted, short save);
|
||||
void fsmenu_insert_entry (FSMenuCategory category, char *path, int sorted, short save);
|
||||
|
||||
/** Removes the fsmenu entry at the given @a index. */
|
||||
void fsmenu_remove_entry (int index);
|
||||
void fsmenu_remove_entry (FSMenuCategory category, int index);
|
||||
|
||||
/** saves the 'bookmarks' to the specified file */
|
||||
void fsmenu_write_file(const char *filename);
|
||||
|
||||
@@ -417,7 +417,7 @@ void ED_spacetype_file(void)
|
||||
/* regions: channels (directories) */
|
||||
art= MEM_callocN(sizeof(ARegionType), "spacetype file region");
|
||||
art->regionid = RGN_TYPE_CHANNELS;
|
||||
art->minsizex= 200;
|
||||
art->minsizex= 240;
|
||||
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
|
||||
art->init= file_channel_area_init;
|
||||
art->draw= file_channel_area_draw;
|
||||
|
||||
Reference in New Issue
Block a user