FLTK logo

[master] f05ee88 - Fluid: Fix relative project paths in GUI mode #1293

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.commit  ]
 
[ Previous Message ] [ Next Message ]

[master] f05ee88 - Fluid: Fix relative project paths in GUI mode #1293 "Matthias Melcher" Aug 13, 2025  
 
commit f05ee883595b910038e49963af6dbaba9081b49f
Author:     Matthias Melcher <github@matthiasm.com>
AuthorDate: Wed Aug 13 21:23:48 2025 +0200
Commit:     Matthias Melcher <github@matthiasm.com>
CommitDate: Wed Aug 13 21:23:48 2025 +0200

    Fluid: Fix relative project paths in GUI mode #1293
    
    Also fixes native "Save as... project file chooser to start
    with current project path.

 fluid/Fluid.cxx   | 26 +++++++++++++++++++++++---
 fluid/Project.cxx | 12 ++++++++++--
 fluid/Project.h   |  3 ++-
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git fluid/Fluid.cxx fluid/Fluid.cxx
index 89ea724..160dabb 100644
--- fluid/Fluid.cxx
+++ fluid/Fluid.cxx
@@ -148,7 +148,14 @@ int Application::run(int argc,char **argv) {
 
   make_main_window();
 
-  if (c) proj.set_filename(c);
+  if (c) {
+    if (batch_mode) {
+      proj.set_filename(c);
+    } else {
+      // In GUI mode, filenames must always be absolute.
+      proj.set_filename(fl_filename_absolute_str(c));
+    }
+  }
   if (!batch_mode) {
 #ifdef __APPLE__
     fl_open_callback(apple_open_cb);
@@ -564,24 +571,37 @@ bool Application::merge_project_file(const std::string &filename_arg) {
  If automatic, this overwrites an existing file. If interactive, if will
  verify with the user.
  \param[in] v if v is not nullptr, or no filename is set, open a filechooser.
+    if (v is (void*)2, don;t update the project filename ("save copy...")
  */
 void Application::save_project_file(void *v) {
   flush_text_widgets();
   Fl_Native_File_Chooser fnfc;
   const char *c = proj.proj_filename;
   if (v || !c || !*c) {
-    fnfc.title("Save To:");
+    fnfc.title("Save Project File As:");
     fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
+#ifndef __APPLE__
+    fnfc.options(Fl_Native_File_Chooser::NEW_FOLDER);
+#else
+    // Apple file choosers always ask to confirm
+    fnfc.options(Fl_Native_File_Chooser::NEW_FOLDER|Fl_Native_File_Chooser::SAVEAS_CONFIRM);
+#endif
     fnfc.filter("FLUID Files\t*.f[ld]");
+    if (!proj.projectfile_path().empty())
+      fnfc.directory(proj.projectfile_path().c_str());
+    if (!proj.projectfile_name().empty())
+      fnfc.preset_file(proj.projectfile_name().c_str());
+    fnfc.filter("Fluid Project\t*.fl\nAny\t*");
     if (fnfc.show() != 0) return;
     c = fnfc.filename();
+#ifndef __APPLE__
     if (!fl_access(c, 0)) {
       std::string basename = fl_filename_name_str(std::string(c));
       if (fl_choice("The file \"%s\" already exists.\n"
                     "Do you want to replace it?", "Cancel",
                     "Replace", nullptr, basename.c_str()) == 0) return;
     }
-
+#endif
     if (v != (void *)2) proj.set_filename(c);
   }
   if (!fld::io::write_file(proj, c)) {
diff --git fluid/Project.cxx fluid/Project.cxx
index cc845ef..750becc 100644
--- fluid/Project.cxx
+++ fluid/Project.cxx
@@ -235,12 +235,20 @@ void Project::leave_project_dir() {
 }
 
 /**
+ Alias for set_filename("").
+ Instead, change proj_filename into a std::string and add clear_filename().
+ */
+void Project::set_filename(std::nullptr_t) {
+  set_filename(std::string());
+}
+
+/**
  Set the filename of the current .fl design.
  \param[in] c the new absolute filename and path
  */
-void Project::set_filename(const char *c) {
+void Project::set_filename(const std::string &c) {
   if (proj_filename) free((void *)proj_filename);
-  proj_filename = c ? fl_strdup(c) : nullptr;
+  proj_filename = c.empty() ? nullptr : fl_strdup(c.c_str());
 
   if (proj_filename && !Fluid.batch_mode)
     Fluid.history.update(proj_filename);
diff --git fluid/Project.h fluid/Project.h
index 065c7d3..d4d60da 100644
--- fluid/Project.h
+++ fluid/Project.h
@@ -104,7 +104,8 @@ public: // Methods
   void enter_project_dir();
   void leave_project_dir();
 
-  void set_filename(const char *c);
+  void set_filename(std::nullptr_t);
+  void set_filename(const std::string &c);
   void write_strings();
 
   void set_modflag(int mf, int mfc = -1);
[ Direct Link to Message ]
 
     
[ Previous Message ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.