3939#include < coreplugin/internal/BehaviorPreference.h>
4040#include < coreplugin/internal/CoreAchievementsModel.h>
4141#include < coreplugin/internal/ProjectStartupTimerAddOn.h>
42+ #include < coreplugin/OpenSaveProjectFileScenario.h>
4243#include < coreplugin/ProjectDocumentContext.h>
4344#include < coreplugin/ProjectWindowInterface.h>
4445
@@ -224,12 +225,6 @@ namespace Core {
224225 QQmlEngine::setObjectOwnership (windowInterface, QQmlEngine::CppOwnership);
225226 }
226227
227- QString CoreInterface::dspxFileFilter (bool withAllFiles) {
228- auto dspxFileFilter = tr (" DiffScope Project Exchange Format (*.dspx)" );
229- auto allFileFilter = tr (" All Files (*)" );
230- return withAllFiles ? dspxFileFilter + " ;;" + allFileFilter : dspxFileFilter;
231- }
232-
233228 static ProjectWindowInterface *createProjectWindow (ProjectDocumentContext *projectDocumentContext) {
234229 Internal::ProjectStartupTimerAddOn::startTimer ();
235230 auto windowInterface = ProjectWindowInterfaceRegistry::instance ()->create (projectDocumentContext);
@@ -244,28 +239,6 @@ namespace Core {
244239 return windowInterface;
245240 }
246241
247- static QString promptOpenDspxFile (QWindow *parent) {
248- auto settings = RuntimeInterface::settings ();
249- settings->beginGroup (CoreInterface::staticMetaObject.className ());
250- auto defaultOpenDir = settings->value (QStringLiteral (" defaultOpenDir" ), QStandardPaths::writableLocation (QStandardPaths::DocumentsLocation)).toString ();
251- settings->endGroup ();
252-
253- auto path = QFileDialog::getOpenFileName (
254- nullptr ,
255- {},
256- defaultOpenDir,
257- CoreInterface::dspxFileFilter (true )
258- );
259- if (path.isEmpty ())
260- return {};
261-
262- settings->beginGroup (CoreInterface::staticMetaObject.className ());
263- settings->setValue (QStringLiteral (" defaultOpenDir" ), QFileInfo (path).absolutePath ());
264- settings->endGroup ();
265-
266- return path;
267- }
268-
269242 static void triggerAchievementAfterNewProjectWindowOpened (QWindow *win) {
270243 class ExposedListener : public QObject {
271244 public:
@@ -285,25 +258,31 @@ namespace Core {
285258 }
286259
287260 ProjectWindowInterface *CoreInterface::newFile (QWindow *parent) {
288- static QDspx::Model defaultModel;
261+ static QDspx::Model defaultModel{
262+ .version = QDspx::Model::V1 ,
263+ .content = {
264+
265+ }
266+ };
289267 qCInfo (lcCoreInterface) << " New file" ;
290268 auto projectDocumentContext = std::make_unique<ProjectDocumentContext>();
291- projectDocumentContext->newFile (defaultModel, false , parent );
269+ projectDocumentContext->newFile (defaultModel, false );
292270 auto windowInterface = createProjectWindow (projectDocumentContext.release ());
293271 triggerAchievementAfterNewProjectWindowOpened (windowInterface->window ());
294272 return windowInterface;
295273 }
296274
297275 ProjectWindowInterface *CoreInterface::newFileFromTemplate (const QString &templateFilePath_, QWindow *parent) {
298276 qCInfo (lcCoreInterface) << " New file from template" << templateFilePath_;
277+ auto projectDocumentContext = std::make_unique<ProjectDocumentContext>();
278+ projectDocumentContext->openSaveProjectFileScenario ()->setWindow (parent);
299279 auto templateFilePath = templateFilePath_;
300280 if (templateFilePath.isEmpty ()) {
301- templateFilePath = promptOpenDspxFile (parent );
281+ templateFilePath = projectDocumentContext-> openSaveProjectFileScenario ()-> openProjectFile ( );
302282 if (templateFilePath.isEmpty ())
303283 return nullptr ;
304284 }
305- auto projectDocumentContext = std::make_unique<ProjectDocumentContext>();
306- if (!projectDocumentContext->newFile (templateFilePath, false , nullptr )) {
285+ if (!projectDocumentContext->newFile (templateFilePath, false )) {
307286 return nullptr ;
308287 }
309288 auto windowInterface = createProjectWindow (projectDocumentContext.release ());
@@ -313,9 +292,11 @@ namespace Core {
313292
314293 ProjectWindowInterface *CoreInterface::openFile (const QString &filePath_, QWindow *parent) {
315294 qCInfo (lcCoreInterface) << " Open file" << filePath_;
295+ auto projectDocumentContext = std::make_unique<ProjectDocumentContext>();
296+ projectDocumentContext->openSaveProjectFileScenario ()->setWindow (parent);
316297 auto filePath = filePath_;
317298 if (filePath.isEmpty ()) {
318- filePath = promptOpenDspxFile (parent );
299+ filePath = projectDocumentContext-> openSaveProjectFileScenario ()-> openProjectFile ( );
319300 if (filePath.isEmpty ())
320301 return nullptr ;
321302 }
@@ -334,8 +315,7 @@ namespace Core {
334315 raiseWindow ((*openedWindow)->window ());
335316 return qobject_cast<ProjectWindowInterface *>(*openedWindow);
336317 }
337- auto projectDocumentContext = std::make_unique<ProjectDocumentContext>();
338- if (!projectDocumentContext->openFile (filePath, parent)) {
318+ if (!projectDocumentContext->openFile (filePath)) {
339319 return nullptr ;
340320 }
341321 auto windowInterface = createProjectWindow (projectDocumentContext.release ());
0 commit comments