Skip to content

Commit 256325b

Browse files
committed
[Explorer] more ways to "New" file/dir, "Paste"
1 parent 9625210 commit 256325b

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

src/explorer.cpp

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,7 @@ void render_button_pin_cwd(explorer_window &expl, bool cwd_exists_before_edit) n
25182518
swan_popup_modals::open_new_pin(expl.cwd, false);
25192519
}
25202520
bool result = global_state::pinned_save_to_disk();
2521-
print_debug_msg("pinned_save_to_disk: %d", result);
2521+
// print_debug_msg("pinned_save_to_disk: %d", result);
25222522
}
25232523
if (imgui::IsItemHovered()) {
25242524
imgui::SetTooltip("%s current working directory", already_pinned ? "Unpin" : "Pin");
@@ -2528,7 +2528,7 @@ void render_button_pin_cwd(explorer_window &expl, bool cwd_exists_before_edit) n
25282528
static
25292529
bool render_history_browser_button() noexcept
25302530
{
2531-
if (imgui::Button(ICON_CI_HISTORY "##expl.wd_history")) {
2531+
if (imgui::Button(ICON_CI_HISTORY "## expl.wd_history")) {
25322532
return true;
25332533
}
25342534
if (imgui::IsItemHovered()) {
@@ -2629,6 +2629,16 @@ void render_more_controls_button(explorer_window &expl, bool cwd_exists_before_e
26292629

26302630
render_button_pin_cwd(expl, cwd_exists_before_edit);
26312631

2632+
imgui::SameLine();
2633+
2634+
if (imgui::Button(ICON_CI_FILE_ADD)) swan_popup_modals::open_new_file(expl.cwd.data(), expl.id);
2635+
if (imgui::IsItemHovered()) imgui::SetTooltip("New file in cwd");
2636+
2637+
imgui::SameLine();
2638+
2639+
if (imgui::Button(ICON_CI_NEW_FOLDER)) swan_popup_modals::open_new_directory(expl.cwd.data(), expl.id);
2640+
if (imgui::IsItemHovered()) imgui::SetTooltip("New directory in cwd");
2641+
26322642
if (cwd_exists_before_edit) {
26332643
imgui::SameLine();
26342644
imgui::TextDisabled(ICON_CI_KEBAB_VERTICAL);
@@ -2935,6 +2945,33 @@ render_cwd_text_input_result render_cwd_text_input(explorer_window &expl,
29352945
return retval;
29362946
}
29372947

2948+
static
2949+
void render_menu_new_object(explorer_window const &expl, char const *label = "New") noexcept
2950+
{
2951+
if (imgui::BeginMenu(label)) {
2952+
{
2953+
imgui::ScopedTextColor tc(file_color());
2954+
if (imgui::Selectable(ICON_CI_FILE_ADD " File")) swan_popup_modals::open_new_file(expl.cwd.data(), expl.id);
2955+
}
2956+
{
2957+
imgui::ScopedTextColor tc(directory_color());
2958+
if (imgui::Selectable(ICON_CI_NEW_FOLDER " Directory")) swan_popup_modals::open_new_directory(expl.cwd.data(), expl.id);
2959+
}
2960+
imgui::SeparatorText("TODO");
2961+
{
2962+
imgui::ScopedDisable d(true);
2963+
imgui::ScopedTextColor tc(symlink_color());
2964+
if (imgui::Selectable(ICON_CI_NEW_FOLDER " File Symlink")) (void)d;
2965+
}
2966+
{
2967+
imgui::ScopedDisable d(true);
2968+
imgui::ScopedTextColor tc(symlink_color());
2969+
if (imgui::Selectable(ICON_CI_NEW_FILE " Directory Symlink")) (void)d;
2970+
}
2971+
imgui::EndMenu();
2972+
}
2973+
}
2974+
29382975
bool swan_windows::render_explorer(explorer_window &expl, bool &open, finder_window &finder, bool any_popups_open) noexcept
29392976
{
29402977
#if 0
@@ -3491,13 +3528,7 @@ bool swan_windows::render_explorer(explorer_window &expl, bool &open, finder_win
34913528
auto result = g_file_op_payload.execute(expl);
34923529
// TODO: why is result unused?
34933530
}
3494-
3495-
if (imgui::Selectable("New file")) {
3496-
swan_popup_modals::open_new_file(expl.cwd.data(), expl.id);
3497-
}
3498-
if (imgui::Selectable("New directory")) {
3499-
swan_popup_modals::open_new_directory(expl.cwd.data(), expl.id);
3500-
}
3531+
render_menu_new_object(expl);
35013532
};
35023533

35033534
if (!drives_table_rendered) {
@@ -4414,6 +4445,13 @@ render_dirent_context_menu(explorer_window &expl, cwd_count_info const &cnt, swa
44144445

44154446
imgui::Separator();
44164447

4448+
if (!g_file_op_payload.items.empty() && !path_is_empty(expl.cwd) && imgui::Selectable("Paste")) {
4449+
auto result = g_file_op_payload.execute(expl);
4450+
// TODO: why is result unused?
4451+
}
4452+
4453+
render_menu_new_object(expl, "New (in cwd)");
4454+
44174455
if (imgui::BeginMenu("Copy metadata")) {
44184456
if (imgui::Selectable("Name")) {
44194457
imgui::SetClipboardText(expl.context_menu_target->basic.path.data());

0 commit comments

Comments
 (0)