implement ui_savefiledialog (Motif)

Sun, 23 Nov 2025 08:44:41 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Nov 2025 08:44:41 +0100
changeset 926
32b16cbca280
parent 925
df27741d02b5
child 927
b8c0f718b141

implement ui_savefiledialog (Motif)

ui/motif/pathbar.c file | annotate | diff | comparison | revisions
ui/motif/pathbar.h file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
--- a/ui/motif/pathbar.c	Sun Nov 23 08:35:40 2025 +0100
+++ b/ui/motif/pathbar.c	Sun Nov 23 08:44:41 2025 +0100
@@ -194,7 +194,7 @@
     return url;
 }
 
-static char* ConcatPath(const char *path1, const char *path2) {
+char* pathbar_concat_path(const char *path1, const char *path2) {
     return concat_path_s(cx_str(path1), cx_str(path2)).ptr;
 }
 
@@ -205,14 +205,14 @@
         if(newpath[0] == '~') {
             char *p = newpath+1;
             char *home = getenv("HOME");
-            char *cp = ConcatPath(home, p);
+            char *cp = pathbar_concat_path(home, p);
             XtFree(newpath);
             newpath = cp;
         } else if(newpath[0] != '/') {
             char curdir[2048];
             curdir[0] = 0;
             getcwd(curdir, 2048);
-            char *cp = ConcatPath(curdir, newpath);
+            char *cp = pathbar_concat_path(curdir, newpath);
             XtFree(newpath);
             newpath = cp;
         }
--- a/ui/motif/pathbar.h	Sun Nov 23 08:35:40 2025 +0100
+++ b/ui/motif/pathbar.h	Sun Nov 23 08:44:41 2025 +0100
@@ -85,6 +85,8 @@
 
 void pathbar_resize(Widget w, PathBar *p, XtPointer d);
 
+char* pathbar_concat_path(const char *path1, const char *path2);
+
 #ifdef __cplusplus
 }
 #endif
--- a/ui/motif/window.c	Sun Nov 23 08:35:40 2025 +0100
+++ b/ui/motif/window.c	Sun Nov 23 08:44:41 2025 +0100
@@ -28,11 +28,15 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
 
 #include "toolkit.h"
 #include "menu.h"
 #include "toolbar.h"
 #include "container.h"
+#include "pathbar.h"
 #include "../ui/window.h"
 #include "../common/context.h"
 
@@ -210,5 +214,41 @@
 }
 
 void ui_savefiledialog(UiObject *obj, const char *name, ui_callback file_selected_callback, void *cbdata) {
+    Arg args[16];
+    int n = 0;
     
+    // Save File Dialog needs this parameter
+    XtSetArg(args[n], XnNfsbType, FILEDIALOG_SAVE); n++;
+    char *selectedpath = (char*)name;
+    if(name) {
+        if(name[0] != '/') {
+            char cwd[PATH_MAX];
+            if(getcwd(cwd, PATH_MAX)) {
+                pathbar_concat_path(cwd, name);
+            } else {
+                fprintf(stderr, "Error: getcwd failed: %s\n", strerror(errno));
+                selectedpath = NULL;
+            }
+        }
+        if(selectedpath) {
+            XtSetArg(args[n], XnNselectedPath, selectedpath); n++;
+        }
+    }
+    Widget dialog = XnCreateFileSelectionDialog(obj->widget, "dialog", args, n);
+    
+    UiEventData *data = malloc(sizeof(UiEventData));
+    memset(data, 0, sizeof(UiEventData));
+    data->obj = obj;
+    data->callback = file_selected_callback;
+    data->userdata = cbdata;
+    
+    XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)filedialog_select, data);
+    XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)filedialog_cancel, data);
+    //XtAddCallback(dialog, XmNhelpCallback, (XtCallbackProc)filedialog_help, wd);
+    
+    XtManageChild(dialog);
+    
+    if(selectedpath != name) {
+        free(selectedpath);
+    }
 }

mercurial