]> git.mdlowis.com Git - projs/tide.git/commitdiff
move file loading and saving into win.c so that we can set properties when the filena...
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Aug 2017 19:46:39 +0000 (15:46 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 10 Aug 2017 19:46:39 +0000 (15:46 -0400)
lib/win.c
pick.c
tide.c

index 85cf96ed9449ab31adbdf9304b729fc71cf403ca..96779faec1fbd66ca277cb5364f24001b7854fc4 100644 (file)
--- 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 8892f1d2c2704d673101c7b0b33cb97d8b63b3c5..eb9b95cd500386640572c93a66c629ea0cee2b0c 100644 (file)
--- 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 00327b1a6367bf6c2522592be15394aabbc468c0..7dd7a6e3e0d483d51bf8318e2d2b6b2e2228a6b2 100644 (file)
--- 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 */