Compare commits
2 Commits
aeffe40efc
...
916f354c9b
Author | SHA1 | Date | |
---|---|---|---|
916f354c9b | |||
050f875c47 |
26
sdn.cpp
26
sdn.cpp
@ -543,7 +543,6 @@ static struct {
|
|||||||
int editor_cursor = 0; ///< Cursor position
|
int editor_cursor = 0; ///< Cursor position
|
||||||
bool editor_inserting; ///< Inserting a literal character
|
bool editor_inserting; ///< Inserting a literal character
|
||||||
void (*editor_on_change) (); ///< Callback on editor change
|
void (*editor_on_change) (); ///< Callback on editor change
|
||||||
void (*editor_on_confirm) (); ///< Callback on editor confirmation
|
|
||||||
map<action, void (*) ()> editor_on; ///< Handlers for custom actions
|
map<action, void (*) ()> editor_on; ///< Handlers for custom actions
|
||||||
|
|
||||||
enum { AT_CURSOR, AT_BAR, AT_CWD, AT_INPUT, AT_INFO, AT_CMDLINE, AT_COUNT };
|
enum { AT_CURSOR, AT_BAR, AT_CWD, AT_INPUT, AT_INFO, AT_CMDLINE, AT_COUNT };
|
||||||
@ -829,8 +828,7 @@ fun at_cursor () -> const entry & {
|
|||||||
return g.cursor >= int (g.entries.size ()) ? invalid : g.entries[g.cursor];
|
return g.cursor >= int (g.entries.size ()) ? invalid : g.entries[g.cursor];
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resort (const string anchor = at_cursor ().filename) {
|
fun focus (const string &anchor) {
|
||||||
sort (begin (g.entries), end (g.entries));
|
|
||||||
if (!anchor.empty ()) {
|
if (!anchor.empty ()) {
|
||||||
for (size_t i = 0; i < g.entries.size (); i++)
|
for (size_t i = 0; i < g.entries.size (); i++)
|
||||||
if (g.entries[i].filename == anchor)
|
if (g.entries[i].filename == anchor)
|
||||||
@ -838,6 +836,11 @@ fun resort (const string anchor = at_cursor ().filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resort (const string anchor = at_cursor ().filename) {
|
||||||
|
sort (begin (g.entries), end (g.entries));
|
||||||
|
focus (anchor);
|
||||||
|
}
|
||||||
|
|
||||||
fun reload (bool keep_anchor) {
|
fun reload (bool keep_anchor) {
|
||||||
g.unames.clear();
|
g.unames.clear();
|
||||||
while (auto *ent = getpwent ())
|
while (auto *ent = getpwent ())
|
||||||
@ -1249,8 +1252,8 @@ fun handle_editor (wint_t c) {
|
|||||||
auto original = g.editor_line;
|
auto original = g.editor_line;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_INPUT_CONFIRM:
|
case ACTION_INPUT_CONFIRM:
|
||||||
if (g.editor_on_confirm)
|
if (auto handler = g.editor_on[action])
|
||||||
g.editor_on_confirm ();
|
handler ();
|
||||||
// Fall-through
|
// Fall-through
|
||||||
case ACTION_INPUT_ABORT:
|
case ACTION_INPUT_ABORT:
|
||||||
g.editor = 0;
|
g.editor = 0;
|
||||||
@ -1259,7 +1262,6 @@ fun handle_editor (wint_t c) {
|
|||||||
g.editor_cursor = 0;
|
g.editor_cursor = 0;
|
||||||
g.editor_inserting = false;
|
g.editor_inserting = false;
|
||||||
g.editor_on_change = nullptr;
|
g.editor_on_change = nullptr;
|
||||||
g.editor_on_confirm = nullptr;
|
|
||||||
g.editor_on.clear ();
|
g.editor_on.clear ();
|
||||||
return;
|
return;
|
||||||
case ACTION_INPUT_BEGINNING:
|
case ACTION_INPUT_BEGINNING:
|
||||||
@ -1411,7 +1413,7 @@ fun handle (wint_t c) -> bool {
|
|||||||
|
|
||||||
case ACTION_CHDIR:
|
case ACTION_CHDIR:
|
||||||
g.editor = L"chdir";
|
g.editor = L"chdir";
|
||||||
g.editor_on_confirm = [] {
|
g.editor_on[ACTION_INPUT_CONFIRM] = [] {
|
||||||
change_dir (untilde (to_mb (g.editor_line)));
|
change_dir (untilde (to_mb (g.editor_line)));
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@ -1430,7 +1432,7 @@ fun handle (wint_t c) -> bool {
|
|||||||
g.editor_on_change = [] { search_interactive (0); };
|
g.editor_on_change = [] { search_interactive (0); };
|
||||||
g.editor_on[ACTION_UP] = [] { search_interactive (-1); };
|
g.editor_on[ACTION_UP] = [] { search_interactive (-1); };
|
||||||
g.editor_on[ACTION_DOWN] = [] { search_interactive (+1); };
|
g.editor_on[ACTION_DOWN] = [] { search_interactive (+1); };
|
||||||
g.editor_on_confirm = [] { choose (at_cursor ()); };
|
g.editor_on[ACTION_INPUT_CONFIRM] = [] { choose (at_cursor ()); };
|
||||||
break;
|
break;
|
||||||
case ACTION_RENAME_PREFILL:
|
case ACTION_RENAME_PREFILL:
|
||||||
g.editor_line = to_wide (current.filename);
|
g.editor_line = to_wide (current.filename);
|
||||||
@ -1438,7 +1440,7 @@ fun handle (wint_t c) -> bool {
|
|||||||
// Fall-through
|
// Fall-through
|
||||||
case ACTION_RENAME:
|
case ACTION_RENAME:
|
||||||
g.editor = L"rename";
|
g.editor = L"rename";
|
||||||
g.editor_on_confirm = [] {
|
g.editor_on[ACTION_INPUT_CONFIRM] = [] {
|
||||||
auto mb = to_mb (g.editor_line);
|
auto mb = to_mb (g.editor_line);
|
||||||
if (rename (at_cursor ().filename.c_str (), mb.c_str ()))
|
if (rename (at_cursor ().filename.c_str (), mb.c_str ()))
|
||||||
show_message (strerror (errno));
|
show_message (strerror (errno));
|
||||||
@ -1447,10 +1449,12 @@ fun handle (wint_t c) -> bool {
|
|||||||
break;
|
break;
|
||||||
case ACTION_MKDIR:
|
case ACTION_MKDIR:
|
||||||
g.editor = L"mkdir";
|
g.editor = L"mkdir";
|
||||||
g.editor_on_confirm = [] {
|
g.editor_on[ACTION_INPUT_CONFIRM] = [] {
|
||||||
if (mkdir (to_mb (g.editor_line).c_str (), 0777))
|
auto mb = to_mb (g.editor_line);
|
||||||
|
if (mkdir (mb.c_str (), 0777))
|
||||||
show_message (strerror (errno));
|
show_message (strerror (errno));
|
||||||
reload (true);
|
reload (true);
|
||||||
|
focus (mb);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user