Skip to content

Apply name filter if export file lacks extension#8212

Open
sakertooth wants to merge 4 commits intoLMMS:masterfrom
sakertooth:use-selected-name-filter-export
Open

Apply name filter if export file lacks extension#8212
sakertooth wants to merge 4 commits intoLMMS:masterfrom
sakertooth:use-selected-name-filter-export

Conversation

@sakertooth
Copy link
Contributor

When exporting the project, if no extension is specified in the filename, LMMS defaults to using .wav. It would be much better for it to use the selected name filter's extension as a fallback if no extension is in the filename. This PR does exactly that. I also refactored the stuff since it was confusing (it intermingled multi export and non multi export code together).

Note: There is another slightly related bug, where if the file format combobox changes to a new format and the filename already has an extension, the extension associated with the selected file format is appended to it instead of being changed accordingly. This should be looked into and fixed later.

Fixes #8205.

@yohannd1
Copy link
Contributor

Works fine for me in most cases. Only exception is when there is a file without any extensions with the same name (saving, for example, file foo as a MP3 file, while foo already exists - it will ask for overwriting foo when in reality it will write to foo.mp3 - I believe we've talked about this one, but can't find where)
The solution I managed to think for this is to set the FileDialog::DontConfirmOverwrite option, and always check for overwrite through QFile::exists + VersionedSaveDialog::fileExistsQuery. Not as intuitive but more consistent.

diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp
index 44ff2a687..714e06ebf 100644
--- a/src/gui/MainWindow.cpp
+++ b/src/gui/MainWindow.cpp
@@ -1467,6 +1467,7 @@ void MainWindow::exportProject(bool multiExport)
 
 		efd.setFileMode(FileDialog::AnyFile);
 		efd.setAcceptMode(FileDialog::AcceptSave);
+		efd.setOptions(FileDialog::DontConfirmOverwrite);
 		efd.setNameFilters(types);
 		efd.setWindowTitle(tr("Select file for project-export..."));
 
@@ -1484,14 +1485,14 @@ void MainWindow::exportProject(bool multiExport)
 					exportFileName += device.m_extension;
 					break;
 				}
+			}
 
-				// The file with the extension from the name filter might exist, so ask the user if they want to replace
-				// it and back out if they do not
-				if (QFile::exists(exportFileName)
-					&& !VersionedSaveDialog::fileExistsQuery(exportFileName, tr("Save project")))
-				{
-					return;
-				}
+			// The file with the extension from the name filter might exist, so ask the user if they want to replace
+			// it and back out if they do not
+			if (QFile::exists(exportFileName)
+				&& !VersionedSaveDialog::fileExistsQuery(exportFileName, tr("Save project")))
+			{
+				return;
 			}
 
 			auto epd = ExportProjectDialog{exportFileName, getGUI()->mainWindow(), multiExport};

@sakertooth
Copy link
Contributor Author

Works fine for me in most cases. Only exception is when there is a file without any extensions with the same name (saving, for example, file foo as a MP3 file, while foo already exists - it will ask for overwriting foo when in reality it will write to foo.mp3 - I believe we've talked about this one, but can't find where)

The solution I managed to think for this is to set the FileDialog::DontConfirmOverwrite option, and always check for overwrite through QFile::exists + VersionedSaveDialog::fileExistsQuery. Not as intuitive but more consistent.

diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp

index 44ff2a687..714e06ebf 100644

--- a/src/gui/MainWindow.cpp

+++ b/src/gui/MainWindow.cpp

@@ -1467,6 +1467,7 @@ void MainWindow::exportProject(bool multiExport)

 

 		efd.setFileMode(FileDialog::AnyFile);

 		efd.setAcceptMode(FileDialog::AcceptSave);

+		efd.setOptions(FileDialog::DontConfirmOverwrite);

 		efd.setNameFilters(types);

 		efd.setWindowTitle(tr("Select file for project-export..."));

 

@@ -1484,14 +1485,14 @@ void MainWindow::exportProject(bool multiExport)

 					exportFileName += device.m_extension;

 					break;

 				}

+			}

 

-				// The file with the extension from the name filter might exist, so ask the user if they want to replace

-				// it and back out if they do not

-				if (QFile::exists(exportFileName)

-					&& !VersionedSaveDialog::fileExistsQuery(exportFileName, tr("Save project")))

-				{

-					return;

-				}

+			// The file with the extension from the name filter might exist, so ask the user if they want to replace

+			// it and back out if they do not

+			if (QFile::exists(exportFileName)

+				&& !VersionedSaveDialog::fileExistsQuery(exportFileName, tr("Save project")))

+			{

+				return;

 			}

 

 			auto epd = ExportProjectDialog{exportFileName, getGUI()->mainWindow(), multiExport};

But if they did actually mean to overwrite to foo that wouldn't work. We should let the user resolve the ambiguity here, not the code.

@RainbowShatter
Copy link

What if we could change in the settings whether we want ALWAYS wav or OGG or MP3 formats? Maybe that feature could be in the settings, and then you would choose whether I want to always choose WAV first or OGG first

@yohannd1
Copy link
Contributor

yohannd1 commented Feb 6, 2026

That's a good idea, but I'd say that's not something that should be in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension-less exports always become WAVs

3 participants