diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 70899cdb..d6da060f 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -2468,37 +2468,47 @@ bool lcMainWindow::OpenProjectFile(const QString& FileName) return false; } -void lcMainWindow::MergeProject() +void lcMainWindow::ShowMergeDialog() { - QString LoadFileName = lcGetActiveProject()->GetFileName(); + QString InitialFolder = lcGetActiveProject()->GetFileName(); - if (LoadFileName.isEmpty()) - LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); + if (InitialFolder.isEmpty()) + InitialFolder = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); + else + InitialFolder = QFileInfo(InitialFolder).absolutePath(); - LoadFileName = QFileDialog::getOpenFileName(this, tr("Merge Model"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); + QStringList LoadFileNames = QFileDialog::getOpenFileNames(this, tr("Merge Model"), InitialFolder, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); - if (LoadFileName.isEmpty()) + if (LoadFileNames.isEmpty()) return; - lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileName).absolutePath()); + lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileNames.first()).absolutePath()); - Project* NewProject = new Project(); + std::vector> ProjectsToMerge; - if (NewProject->Load(LoadFileName, true)) + for (const QString& LoadFileName : LoadFileNames) { - size_t ModelCount = NewProject->GetModels().size(); + std::unique_ptr& NewProject = ProjectsToMerge.emplace_back(std::make_unique()); - lcGetActiveProject()->Merge(NewProject); - - if (ModelCount == 1) - QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel.")); - else - QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount)); - - UpdateModels(); + if (!NewProject->Load(LoadFileName, true)) + return; } - delete NewProject; + size_t ModelCount = 0; + + for (const std::unique_ptr& ProjectToMerge : ProjectsToMerge) + { + ModelCount += ProjectToMerge->GetModels().size(); + + lcGetActiveProject()->Merge(ProjectToMerge.get()); + } + + if (ModelCount == 1) + QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel.")); + else + QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount)); + + UpdateModels(); } void lcMainWindow::ImportLDD() @@ -2674,7 +2684,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_FILE_MERGE: - MergeProject(); + ShowMergeDialog(); break; case LC_FILE_SAVE: diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 5efb4d37..498ea314 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -214,7 +214,6 @@ public: void RemoveAllModelTabs(); void CloseCurrentModelTab(); void SetCurrentModelTab(lcModel* Model); - void ResetCameras(); void AddView(lcView* View); void RemoveView(lcView* View); @@ -238,7 +237,7 @@ public: void NewProject(); bool OpenProject(const QString& FileName); void OpenRecentProject(int RecentFileIndex); - void MergeProject(); + void ShowMergeDialog(); void ImportLDD(); void ImportInventory(); bool SaveProject(const QString& FileName);