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, nentries = fsmenu_get_nentries(fsmenu, category); /* reset each time */ *nr = -1; /* hide if no entries */ if (nentries == 0) return; /* layout */ uiLayoutSetAlignment(pa->layout, UI_LAYOUT_ALIGN_LEFT); block = uiLayoutGetBlock(pa->layout); box = uiLayoutBox(pa->layout); col = uiLayoutColumn(box, TRUE); for (i = 0; i < nentries; ++i) { char dir[FILE_MAX]; char temp[FILE_MAX]; uiLayout *layout = uiLayoutRow(col, FALSE); char *entry; entry = fsmenu_get_entry(fsmenu, category, i); /* set this list item as active if we have a match */ if (sfile->params) { if (BLI_path_cmp(sfile->params->dir, entry) == 0) { *nr = i; } } /* create nice bookmark name, shows last directory in the full path currently */ BLI_strncpy(temp, entry, FILE_MAX); BLI_add_slash(temp); BLI_getlastdir(temp, dir, FILE_MAX); BLI_del_slash(dir); if (dir[0] == 0) BLI_strncpy(dir, entry, FILE_MAX); /* create list item */ but = uiDefIconTextButS(block, LISTROW, 0, icon, dir, 0, 0, UI_UNIT_X * 10, UI_UNIT_Y, nr, 0, i, 0, 0, entry); uiButSetFunc(but, file_panel_cb, entry, NULL); uiButClearFlag(but, UI_BUT_UNDO); /* skip undo on screen buttons */ uiButSetFlag(but, UI_ICON_LEFT | UI_TEXT_LEFT); /* create delete button */ if (allow_delete && fsmenu_can_save(fsmenu, category, i)) { uiBlockSetEmboss(block, UI_EMBOSSN); uiItemIntO(layout, "", ICON_X, "FILE_OT_delete_bookmark", "index", i); uiBlockSetEmboss(block, UI_EMBOSS); } } }
/* sends events now, so things get handled on windowqueue level */ int file_exec(bContext *C, wmOperator *exec_op) { wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); char filepath[FILE_MAX]; if (sfile->op) { wmOperator *op = sfile->op; /* when used as a macro, for doubleclick, * to prevent closing when doubleclicking on .. item */ if (RNA_boolean_get(exec_op->ptr, "need_active")) { int i, active = 0; for (i = 0; i < filelist_numfiles(sfile->files); i++) { if (filelist_is_selected(sfile->files, i, CHECK_ALL)) { active = 1; break; } } if (active == 0) return OPERATOR_CANCELLED; } sfile->op = NULL; file_sfile_to_operator(op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE | FS_INSERT_FIRST); } BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu_get(), filepath); WM_event_fileselect_event(wm, op, EVT_FILESELECT_EXEC); } return OPERATOR_FINISHED; }
static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op)) { ScrArea *sa = CTX_wm_area(C); char name[FILE_MAX]; struct FSMenu *fsmenu = fsmenu_get(); while (fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) { fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0); } BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu, name); ED_area_tag_redraw(sa); return OPERATOR_FINISHED; }
static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused)) { wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); struct FSMenu *fsmenu = fsmenu_get(); ED_fileselect_clear(wm, sfile); /* refresh system directory menu */ fsmenu_refresh_system_category(fsmenu); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; }
static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op)) { ScrArea *sa = CTX_wm_area(C); SpaceFile *sfile = CTX_wm_space_file(C); struct FSMenu *fsmenu = fsmenu_get(); struct FileSelectParams *params = ED_fileselect_get_params(sfile); if (params->dir[0] != '\0') { char name[FILE_MAX]; fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, FS_INSERT_SAVE); BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu, name); } ED_area_tag_redraw(sa); return OPERATOR_FINISHED; }
static int bookmark_delete_exec(bContext *C, wmOperator *op) { ScrArea *sa = CTX_wm_area(C); struct FSMenu *fsmenu = fsmenu_get(); int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS); if (RNA_struct_find_property(op->ptr, "index")) { int index = RNA_int_get(op->ptr, "index"); if ((index > -1) && (index < nentries)) { char name[FILE_MAX]; fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index); BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(fsmenu, name); ED_area_tag_redraw(sa); } } return OPERATOR_FINISHED; }