From 26419805068fa1136300a05339422590026edf3e Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 10 Aug 2017 15:46:39 -0400 Subject: [PATCH] move file loading and saving into win.c so that we can set properties when the filename changes --- lib/win.c | 15 +++++++++++++++ pick.c | 2 +- tide.c | 16 ++++------------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/win.c b/lib/win.c index 85cf96e..96779fa 100644 --- a/lib/win.c +++ b/lib/win.c @@ -65,6 +65,21 @@ static void win_update(int xfd, void* data) { x11_flush(); } +void win_load(char* path) { + View* view = win_view(EDIT); + view_init(view, path, view->buffer.errfn); +} + +void win_save(char* path) { + View* view = win_view(EDIT); + if (!path) path = view->buffer.path; + if (!path) return; + path = stringdup(path); + free(view->buffer.path); + view->buffer.path = path; + buf_save(&(view->buffer)); +} + void win_loop(void) { x11_show(); x11_flip(); diff --git a/pick.c b/pick.c index 8892f1d..eb9b95c 100644 --- a/pick.c +++ b/pick.c @@ -225,7 +225,7 @@ int main(int argc, char** argv) { char* title = getenv("PICKTITLE"); load_choices(); if (vec_size(&Choices) > 1) { - win_dialog("pick", true, onerror); + win_window("pick", true, onerror); win_setkeys(Bindings, NULL); win_settext(STATUS, (title ? title : "pick")); if (argc >= 2) { diff --git a/tide.c b/tide.c index 00327b1..7dd7a6e 100644 --- a/tide.c +++ b/tide.c @@ -163,7 +163,7 @@ static bool changed_externally(Buf* buf) { static void overwrite(void) { trim_whitespace(); - buf_save(win_buf(EDIT)); + win_save(NULL); } static void save(void) { @@ -232,13 +232,7 @@ void onmouseright(WinRegion id, bool pressed, size_t row, size_t col) { /* Keyboard Handling ******************************************************************************/ static void saveas(char* arg) { - //win_saveas(stringdup(arg)); - if (arg) { - char* path = win_buf(EDIT)->path; - win_buf(EDIT)->path = stringdup(arg); - buf_save(win_buf(EDIT)); - free(path); - } + win_save(arg); } static void tag_undo(void) { @@ -570,12 +564,10 @@ void edit_relative(char* path) { else strconcat(currpath, fname, 0); chdir(currdir); - //win_open(currpath, ondiagmsg); - view_init(win_view(EDIT), currpath, ondiagmsg); + win_load(currpath); } else { chdir(origdir); - //win_open(path, ondiagmsg); - view_init(win_view(EDIT), path, ondiagmsg); + win_load(path); } /* cleanup */ -- 2.49.0