Skip to content

Commit a975bf5

Browse files
committed
dedicated command for picking folders & improved flow when doing directory-only selection
1 parent 6e5f518 commit a975bf5

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/df/core/df_core.mdesk

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ DF_CoreCmdTable:// | | |
367367
{WatchPins 0 Null Nil 0 0 0 0 0 Pin "watch_pins" "Watch Pins" "Opens the watch pins view." "" }
368368
{ExceptionFilters 0 Null Nil 0 0 0 0 0 Gear "exception_filters" "Exception Filters" "Opens the exception filters view." "exceptions,filters" }
369369
{Theme 0 Null Nil 0 0 0 0 0 Palette "theme" "Theme" "Opens the theme view." "theme,color,scheme,palette" }
370-
{PickFile 1 FilePath Nil 0 0 0 0 0 FileOutline "pick_file" "Pick File" "Opens the file browser to pick a file." "" }
370+
{PickFile 1 FilePath Nil 0 0 0 0 1 FileOutline "pick_file" "Pick File" "Opens the file browser to pick a file." "" }
371+
{PickFolder 1 FilePath Nil 1 0 0 0 1 FolderOpenFilled "pick_folder" "Pick Folder" "Opens the file browser to pick a folder." "" }
371372

372373
//- rjf: query completion
373374
{CompleteQuery 1 Null Nil 0 0 0 0 0 Null "complete_query" "Complete Query" "Completes a query." "" }

src/df/core/generated/df_core.meta.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[] =
193193
{ str8_lit_comp("watch_pins"), str8_lit_comp("Opens the watch pins view."), str8_lit_comp(""), str8_lit_comp("Watch Pins"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Pin},
194194
{ str8_lit_comp("exception_filters"), str8_lit_comp("Opens the exception filters view."), str8_lit_comp("exceptions,filters"), str8_lit_comp("Exception Filters"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Gear},
195195
{ str8_lit_comp("theme"), str8_lit_comp("Opens the theme view."), str8_lit_comp("theme,color,scheme,palette"), str8_lit_comp("Theme"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Palette},
196-
{ str8_lit_comp("pick_file"), str8_lit_comp("Opens the file browser to pick a file."), str8_lit_comp(""), str8_lit_comp("Pick File"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline},
196+
{ str8_lit_comp("pick_file"), str8_lit_comp("Opens the file browser to pick a file."), str8_lit_comp(""), str8_lit_comp("Pick File"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_FileOutline},
197+
{ str8_lit_comp("pick_folder"), str8_lit_comp("Opens the file browser to pick a folder."), str8_lit_comp(""), str8_lit_comp("Pick Folder"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*1)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_FolderOpenFilled},
197198
{ str8_lit_comp("complete_query"), str8_lit_comp("Completes a query."), str8_lit_comp(""), str8_lit_comp("Complete Query"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},
198199
{ str8_lit_comp("cancel_query"), str8_lit_comp("Cancels a query."), str8_lit_comp(""), str8_lit_comp("Cancel Query"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},
199200
{ str8_lit_comp("toggle_dev_menu"), str8_lit_comp("Opens and closes the developer menu."), str8_lit_comp(""), str8_lit_comp("Toggle Developer Menu"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_FoldersOnly*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},

src/df/core/generated/df_core.meta.h

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ DF_CoreCmdKind_WatchPins,
244244
DF_CoreCmdKind_ExceptionFilters,
245245
DF_CoreCmdKind_Theme,
246246
DF_CoreCmdKind_PickFile,
247+
DF_CoreCmdKind_PickFolder,
247248
DF_CoreCmdKind_CompleteQuery,
248249
DF_CoreCmdKind_CancelQuery,
249250
DF_CoreCmdKind_ToggleDevMenu,

src/df/gfx/df_views.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem)
20282028
DF_PathQuery path_query = df_path_query_from_string(query_normalized_with_opt_slash);
20292029
F32 row_height_px = floor_f32(ui_top_font_size()*2.5f);
20302030
F32 scroll_bar_dim = floor_f32(ui_top_font_size()*1.5f);
2031-
B32 dir_selection = 0;
2031+
B32 dir_selection = !!(ws->query_cmd_spec->info.query.flags & DF_CmdQueryFlag_FoldersOnly);
20322032

20332033
//- rjf: get extra state for this view
20342034
DF_FileSystemViewState *fs = df_view_user_state(view, DF_FileSystemViewState);
@@ -2209,6 +2209,15 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem)
22092209
}
22102210
}
22112211

2212+
// rjf: command argument is empty, picking folders -> use current folder
2213+
else if(path_query.search.size == 0 && dir_selection)
2214+
{
2215+
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
2216+
params.file_path = path_query.path;
2217+
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_FilePath);
2218+
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_CompleteQuery));
2219+
}
2220+
22122221
// rjf: command argument does not exactly match any file, but lister results are in:
22132222
else if(file_count != 0)
22142223
{
@@ -2796,6 +2805,7 @@ DF_VIEW_CMD_FUNCTION_DEF(Target)
27962805
{
27972806
default:break;
27982807
case DF_CoreCmdKind_PickFile:
2808+
case DF_CoreCmdKind_PickFolder:
27992809
{
28002810
String8 pick_string = cmd->params.file_path;
28012811
DF_Entity *storage_entity = entity;
@@ -2835,18 +2845,19 @@ DF_VIEW_UI_FUNCTION_DEF(Target)
28352845
struct
28362846
{
28372847
B32 fill_with_file;
2848+
B32 fill_with_folder;
28382849
B32 use_code_font;
28392850
String8 key;
28402851
DF_EntityKind storage_child_kind;
28412852
String8 current_text;
28422853
}
28432854
kv_info[] =
28442855
{
2845-
{ 0, 0, str8_lit("Label"), DF_EntityKind_Nil, entity->name },
2846-
{ 1, 0, str8_lit("Executable"), DF_EntityKind_Executable, df_entity_child_from_kind(entity, DF_EntityKind_Executable)->name },
2847-
{ 0, 0, str8_lit("Arguments"), DF_EntityKind_Arguments, df_entity_child_from_kind(entity, DF_EntityKind_Arguments)->name },
2848-
{ 1, 0, str8_lit("Working Directory"), DF_EntityKind_ExecutionPath, df_entity_child_from_kind(entity, DF_EntityKind_ExecutionPath)->name },
2849-
{ 0, 1, str8_lit("Entry Point Override"), DF_EntityKind_EntryPointName, df_entity_child_from_kind(entity, DF_EntityKind_EntryPointName)->name },
2856+
{ 0, 0, 0, str8_lit("Label"), DF_EntityKind_Nil, entity->name },
2857+
{ 1, 0, 0, str8_lit("Executable"), DF_EntityKind_Executable, df_entity_child_from_kind(entity, DF_EntityKind_Executable)->name },
2858+
{ 0, 0, 0, str8_lit("Arguments"), DF_EntityKind_Arguments, df_entity_child_from_kind(entity, DF_EntityKind_Arguments)->name },
2859+
{ 0, 1, 0, str8_lit("Working Directory"), DF_EntityKind_ExecutionPath, df_entity_child_from_kind(entity, DF_EntityKind_ExecutionPath)->name },
2860+
{ 0, 0, 1, str8_lit("Entry Point Override"), DF_EntityKind_EntryPointName, df_entity_child_from_kind(entity, DF_EntityKind_EntryPointName)->name },
28502861
};
28512862

28522863
//- rjf: take controls to start/end editing
@@ -2922,7 +2933,7 @@ DF_VIEW_UI_FUNCTION_DEF(Target)
29222933
UI_TableVector
29232934
{
29242935
B32 row_selected = (tv->cursor.y == idx+1);
2925-
B32 has_browse = kv_info[idx].fill_with_file;
2936+
B32 has_browse = kv_info[idx].fill_with_file || kv_info[idx].fill_with_folder;
29262937

29272938
//- rjf: key (label)
29282939
UI_TableCell UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_WeakText))
@@ -3027,7 +3038,7 @@ DF_VIEW_UI_FUNCTION_DEF(Target)
30273038
if(ui_buttonf("Browse...").clicked)
30283039
{
30293040
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
3030-
params.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_PickFile);
3041+
params.cmd_spec = df_cmd_spec_from_core_cmd_kind(kv_info[idx].fill_with_file ? DF_CoreCmdKind_PickFile : DF_CoreCmdKind_PickFolder);
30313042
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_CmdSpec);
30323043
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand));
30333044
tv->pick_dst_kind = kv_info[idx].storage_child_kind;

0 commit comments

Comments
 (0)