--- 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); + } }