From ad6c6bc8fd356275d216442983dc75fffb85f27c Mon Sep 17 00:00:00 2001 From: timpieces Date: Thu, 18 Dec 2025 10:37:42 +0800 Subject: [PATCH] Gui: Default load/save img to working directory (#26182) - FileOptionsDialog is only used in the 'save screenshot / save image' codepath, and currently it doesn't set a directory to it defaults to process CWD, which is surely not what the user wants. - The load image codepath uses a custom QFileDialog instead of the helper code in FileDialog, there doesn't seem to be a great reason for this, although the helper doesn't have support for mime types it seems. - I haven't changed the dialogs to 'set/store' the working directory. I'm not sure this is desired as this isn't a 'normal' save/load operation. - It would be ideal to remove the FileOptionsDialog in future. The extended functionality could be turned into a separate dialog which opens before or after the file chooser. This would allow native dialogs to be used and would unify the code paths for file selection. - Further, it would be nice to just merge at least the load image into the existing import/open option, and to put 'save image' next to 'export', but those changes may be much more time consuming. For now I've kept it simple. Let's see what others think. --- src/Gui/CommandView.cpp | 1 + src/Gui/FileDialog.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 939ffa4531..d5a85516e6 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -2238,6 +2238,7 @@ void StdViewLoadImage::activated(int iMsg) // Reading an image QFileDialog dialog(Gui::getMainWindow()); dialog.setWindowTitle(QObject::tr("Choose an Image File to Open")); + dialog.setDirectory(FileDialog::getWorkingDirectory()); dialog.setMimeTypeFilters(mimeTypeFilters); dialog.selectMimeTypeFilter(QStringLiteral("image/png")); dialog.setDefaultSuffix(QStringLiteral("png")); diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index 778b1d3b5c..58c3cf725c 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -562,6 +562,7 @@ FileOptionsDialog::FileOptionsDialog(QWidget* parent, Qt::WindowFlags fl) extensionButton->setText(tr("Extended")); setOption(QFileDialog::DontUseNativeDialog); + setDirectory(FileDialog::getWorkingDirectory()); // search for the grid layout and add the new button auto grid = this->findChild();