UI: Bring back features for file path button
Adds back auto-completion and auto-creation (inserting a non-existing file-path would create it) for the file path button. The second feature was left out knowingly, but seems there are reasonable use cases for it. We can't add these features to the button in the Python script, we have to call into C. So using a template to do that. Note that this is based on the old file browser code, I've copied over the TODO comment.
This commit is contained in:
@@ -391,7 +391,7 @@ class FILEBROWSER_PT_directory_path(Panel):
|
||||
row.operator("file.directory_new", icon='NEWFOLDER', text="")
|
||||
|
||||
subrow = row.row()
|
||||
subrow.prop(params, "directory", text="")
|
||||
subrow.template_file_select_path(params)
|
||||
|
||||
subrow = row.row()
|
||||
subrow.scale_x = 0.5
|
||||
|
||||
@@ -25,11 +25,13 @@
|
||||
#define __ED_FILESELECT_H__
|
||||
|
||||
struct ARegion;
|
||||
struct bScreen;
|
||||
struct FileSelectParams;
|
||||
struct ScrArea;
|
||||
struct SpaceFile;
|
||||
struct bContext;
|
||||
struct wmWindowManager;
|
||||
struct uiBlock;
|
||||
|
||||
#define FILE_LAYOUT_HOR 1
|
||||
#define FILE_LAYOUT_VER 2
|
||||
@@ -133,6 +135,11 @@ void ED_file_read_bookmarks(void);
|
||||
|
||||
void ED_file_change_dir(struct bContext *C);
|
||||
|
||||
void ED_file_path_button(struct bScreen *screen,
|
||||
const struct SpaceFile *sfile,
|
||||
struct FileSelectParams *params,
|
||||
struct uiBlock *block);
|
||||
|
||||
/* File menu stuff */
|
||||
|
||||
/* FSMenuEntry's without paths indicate separators */
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
struct ARegion;
|
||||
struct AutoComplete;
|
||||
struct FileSelectParams;
|
||||
struct ID;
|
||||
struct IDProperty;
|
||||
struct ImBuf;
|
||||
@@ -2082,6 +2083,9 @@ void uiTemplateColormanagedViewSettings(struct uiLayout *layout,
|
||||
const char *propname);
|
||||
|
||||
int uiTemplateRecentFiles(struct uiLayout *layout, int rows);
|
||||
void uiTemplateFileSelectPath(uiLayout *layout,
|
||||
struct bContext *C,
|
||||
struct FileSelectParams *params);
|
||||
|
||||
/* items */
|
||||
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname);
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
#include "DEG_depsgraph.h"
|
||||
#include "DEG_depsgraph_build.h"
|
||||
|
||||
#include "ED_fileselect.h"
|
||||
#include "ED_screen.h"
|
||||
#include "ED_object.h"
|
||||
#include "ED_render.h"
|
||||
@@ -6779,3 +6780,13 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows)
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/******************************* FileSelectParams Path Button *******************************/
|
||||
|
||||
void uiTemplateFileSelectPath(uiLayout *layout, bContext *C, FileSelectParams *params)
|
||||
{
|
||||
bScreen *screen = CTX_wm_screen(C);
|
||||
SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
|
||||
ED_file_path_button(screen, sfile, params, uiLayoutGetBlock(layout));
|
||||
}
|
||||
|
||||
@@ -71,6 +71,52 @@
|
||||
|
||||
#include "file_intern.h" // own include
|
||||
|
||||
void ED_file_path_button(bScreen *screen,
|
||||
const SpaceFile *sfile,
|
||||
FileSelectParams *params,
|
||||
uiBlock *block)
|
||||
{
|
||||
PointerRNA params_rna_ptr;
|
||||
uiBut *but;
|
||||
|
||||
RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, ¶ms_rna_ptr);
|
||||
|
||||
/* callbacks for operator check functions */
|
||||
UI_block_func_set(block, file_draw_check_cb, NULL, NULL);
|
||||
|
||||
but = uiDefButR(block,
|
||||
UI_BTYPE_TEXT,
|
||||
-1,
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
UI_UNIT_X * 10,
|
||||
UI_UNIT_Y,
|
||||
¶ms_rna_ptr,
|
||||
"directory",
|
||||
0,
|
||||
0.0f,
|
||||
(float)FILE_MAX,
|
||||
0.0f,
|
||||
0.0f,
|
||||
TIP_("File path"));
|
||||
|
||||
BLI_assert(!UI_but_flag_is_set(but, UI_BUT_UNDO));
|
||||
BLI_assert(!UI_but_is_utf8(but));
|
||||
|
||||
UI_but_func_complete_set(but, autocomplete_directory, NULL);
|
||||
UI_but_funcN_set(but, file_directory_enter_handle, NULL, but);
|
||||
|
||||
/* TODO, directory editing is non-functional while a library is loaded
|
||||
* until this is properly supported just disable it. */
|
||||
if (sfile && sfile->files && filelist_lib(sfile->files)) {
|
||||
UI_but_flag_enable(but, UI_BUT_DISABLED);
|
||||
}
|
||||
|
||||
/* clear func */
|
||||
UI_block_func_set(block, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Dummy helper - we need dynamic tooltips here. */
|
||||
static char *file_draw_tooltip_func(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
|
||||
{
|
||||
|
||||
@@ -1519,6 +1519,13 @@ void RNA_api_ui_layout(StructRNA *srna)
|
||||
RNA_def_int(func, "rows", 5, 1, INT_MAX, "", "Maximum number of items to show", 1, INT_MAX);
|
||||
parm = RNA_def_int(func, "found", 0, 0, INT_MAX, "", "Number of items drawn", 0, INT_MAX);
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
func = RNA_def_function(srna, "template_file_select_path", "uiTemplateFileSelectPath");
|
||||
RNA_def_function_ui_description(func,
|
||||
"Item. A text button to set the active file browser path.");
|
||||
parm = RNA_def_pointer(func, "params", "FileSelectParams", "", "");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user