From 9bd3739122d99951e9fe1b494fd8f10d7613b5db Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 17 Jul 2021 14:41:57 +0200 Subject: Bind F7 to an mkdir prompt This might have needed more thought, but we'll see. --- sdn.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sdn.cpp b/sdn.cpp index 87560df..30b0495 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -407,7 +407,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode XX(UP) XX(DOWN) XX(TOP) XX(BOTTOM) XX(HIGH) XX(MIDDLE) XX(LOW) \ XX(PAGE_PREVIOUS) XX(PAGE_NEXT) XX(SCROLL_UP) XX(SCROLL_DOWN) \ XX(CHDIR) XX(PARENT) XX(GO_START) XX(GO_HOME) \ - XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \ + XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) XX(MKDIR) \ XX(TOGGLE_FULL) XX(REVERSE_SORT) XX(SHOW_HIDDEN) XX(REDRAW) XX(RELOAD) \ XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE) XX(INPUT_DELETE) \ XX(INPUT_B_KILL_LINE) XX(INPUT_KILL_LINE) XX(INPUT_QUOTED_INSERT) \ @@ -441,6 +441,7 @@ static map g_normal_actions { {'&', ACTION_GO_START}, {'~', ACTION_GO_HOME}, {'/', ACTION_SEARCH}, {'s', ACTION_SEARCH}, {ALT | 'e', ACTION_RENAME_PREFILL}, {'e', ACTION_RENAME}, + {KEY (F (7)), ACTION_MKDIR}, {'t', ACTION_TOGGLE_FULL}, {ALT | 't', ACTION_TOGGLE_FULL}, {'R', ACTION_REVERSE_SORT}, {ALT | '.', ACTION_SHOW_HIDDEN}, {CTRL ('L'), ACTION_REDRAW}, {'r', ACTION_RELOAD}, @@ -1427,7 +1428,16 @@ fun handle (wint_t c) -> bool { g.editor = L"rename"; g.editor_on_confirm = [] { auto mb = to_mb (g.editor_line); - rename (at_cursor ().filename.c_str (), mb.c_str ()); + if (rename (at_cursor ().filename.c_str (), mb.c_str ())) + show_message (strerror (errno)); + reload (true); + }; + break; + case ACTION_MKDIR: + g.editor = L"mkdir"; + g.editor_on_confirm = [] { + if (mkdir (to_mb (g.editor_line).c_str (), 0777)) + show_message (strerror (errno)); reload (true); }; break; -- cgit v1.2.3-70-g09d2