mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 11:25:22 +08:00
Fluid: Fix relative project paths in GUI mode #1293
Also fixes native "Save as... project file chooser to start with current project path.
This commit is contained in:
+23
-3
@@ -148,7 +148,14 @@ int Application::run(int argc,char **argv) {
|
|||||||
|
|
||||||
make_main_window();
|
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) {
|
if (!batch_mode) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
fl_open_callback(apple_open_cb);
|
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
|
If automatic, this overwrites an existing file. If interactive, if will
|
||||||
verify with the user.
|
verify with the user.
|
||||||
\param[in] v if v is not nullptr, or no filename is set, open a filechooser.
|
\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) {
|
void Application::save_project_file(void *v) {
|
||||||
flush_text_widgets();
|
flush_text_widgets();
|
||||||
Fl_Native_File_Chooser fnfc;
|
Fl_Native_File_Chooser fnfc;
|
||||||
const char *c = proj.proj_filename;
|
const char *c = proj.proj_filename;
|
||||||
if (v || !c || !*c) {
|
if (v || !c || !*c) {
|
||||||
fnfc.title("Save To:");
|
fnfc.title("Save Project File As:");
|
||||||
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
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]");
|
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;
|
if (fnfc.show() != 0) return;
|
||||||
c = fnfc.filename();
|
c = fnfc.filename();
|
||||||
|
#ifndef __APPLE__
|
||||||
if (!fl_access(c, 0)) {
|
if (!fl_access(c, 0)) {
|
||||||
std::string basename = fl_filename_name_str(std::string(c));
|
std::string basename = fl_filename_name_str(std::string(c));
|
||||||
if (fl_choice("The file \"%s\" already exists.\n"
|
if (fl_choice("The file \"%s\" already exists.\n"
|
||||||
"Do you want to replace it?", "Cancel",
|
"Do you want to replace it?", "Cancel",
|
||||||
"Replace", nullptr, basename.c_str()) == 0) return;
|
"Replace", nullptr, basename.c_str()) == 0) return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (v != (void *)2) proj.set_filename(c);
|
if (v != (void *)2) proj.set_filename(c);
|
||||||
}
|
}
|
||||||
if (!fld::io::write_file(proj, c)) {
|
if (!fld::io::write_file(proj, c)) {
|
||||||
|
|||||||
+10
-2
@@ -234,13 +234,21 @@ 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.
|
Set the filename of the current .fl design.
|
||||||
\param[in] c the new absolute filename and path
|
\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);
|
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)
|
if (proj_filename && !Fluid.batch_mode)
|
||||||
Fluid.history.update(proj_filename);
|
Fluid.history.update(proj_filename);
|
||||||
|
|||||||
+2
-1
@@ -104,7 +104,8 @@ public: // Methods
|
|||||||
void enter_project_dir();
|
void enter_project_dir();
|
||||||
void leave_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 write_strings();
|
||||||
|
|
||||||
void set_modflag(int mf, int mfc = -1);
|
void set_modflag(int mf, int mfc = -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user