Changeset View
Standalone View
shell/projectcontroller.cpp
Show First 20 Lines • Show All 322 Lines • ▼ Show 20 Line(s) | |||||
323 | {} | 323 | {} | ||
324 | 324 | | |||
325 | ProjectDialogProvider::ProjectDialogProvider(ProjectControllerPrivate* const p) : d(p) | 325 | ProjectDialogProvider::ProjectDialogProvider(ProjectControllerPrivate* const p) : d(p) | ||
326 | {} | 326 | {} | ||
327 | 327 | | |||
328 | ProjectDialogProvider::~ProjectDialogProvider() | 328 | ProjectDialogProvider::~ProjectDialogProvider() | ||
329 | {} | 329 | {} | ||
330 | 330 | | |||
331 | bool writeNewProjectFile( const QString& localConfigFile, const QString& name, const QString& manager ) | 331 | bool writeNewProjectFile( const QString& localConfigFile, const QString& name, const QString& createdFrom, const QString& manager ) | ||
332 | { | 332 | { | ||
333 | KSharedConfigPtr cfg = KSharedConfig::openConfig( localConfigFile, KConfig::SimpleConfig ); | 333 | KSharedConfigPtr cfg = KSharedConfig::openConfig( localConfigFile, KConfig::SimpleConfig ); | ||
334 | if (!cfg->isConfigWritable(true)) { | 334 | if (!cfg->isConfigWritable(true)) { | ||
335 | qCDebug(SHELL) << "can't write to configfile"; | 335 | qCDebug(SHELL) << "can't write to configfile"; | ||
336 | return false; | 336 | return false; | ||
337 | } | 337 | } | ||
338 | KConfigGroup grp = cfg->group( "Project" ); | 338 | KConfigGroup grp = cfg->group( "Project" ); | ||
339 | grp.writeEntry( "Name", name ); | 339 | grp.writeEntry( "Name", name ); | ||
340 | grp.writeEntry( "CreatedFrom", createdFrom ); | ||||
mwolff: why write it to disk? if this is the project url as I think it is, then it equals the position… | |||||
To let project managers find out from what file the project was created. For Haskell, for instance, there could be "project.cabal" or "stack.yaml" and they can be located in the same dir. Without this haskell project manager would be unable to figure out how to handle this project - in cabal way, or stack way. I get your point regarding relocating the project. I guess, it is fine to store relative filename of the origin. arrowd: To let project managers find out from what file the project was created. For Haskell, for… | |||||
yes, definitely make it relative then and also add the above as justification in a comment please mwolff: yes, definitely make it relative then and also add the above as justification in a comment… | |||||
340 | grp.writeEntry( "Manager", manager ); | 341 | grp.writeEntry( "Manager", manager ); | ||
341 | cfg->sync(); | 342 | cfg->sync(); | ||
342 | return true; | 343 | return true; | ||
343 | } | 344 | } | ||
344 | 345 | | |||
345 | bool writeProjectSettingsToConfigFile(const QUrl& projectFileUrl, const QString& projectName, const QString& projectManager) | 346 | bool writeProjectSettingsToConfigFile(const QUrl& projectFileUrl, OpenProjectDialog* dlg) | ||
346 | { | 347 | { | ||
347 | if ( !projectFileUrl.isLocalFile() ) { | 348 | if ( !projectFileUrl.isLocalFile() ) { | ||
348 | QTemporaryFile tmp; | 349 | QTemporaryFile tmp; | ||
349 | if ( !tmp.open() ) { | 350 | if ( !tmp.open() ) { | ||
350 | return false; | 351 | return false; | ||
351 | } | 352 | } | ||
352 | if ( !writeNewProjectFile( tmp.fileName(), projectName, projectManager ) ) { | 353 | if ( !writeNewProjectFile( tmp.fileName(), dlg->projectName(), dlg->selectedUrl().fileName(), dlg->projectManager() ) ) { | ||
353 | return false; | 354 | return false; | ||
354 | } | 355 | } | ||
355 | // explicitly close file before uploading it, see also: https://bugs.kde.org/show_bug.cgi?id=254519 | 356 | // explicitly close file before uploading it, see also: https://bugs.kde.org/show_bug.cgi?id=254519 | ||
356 | tmp.close(); | 357 | tmp.close(); | ||
357 | 358 | | |||
358 | auto uploadJob = KIO::file_copy(QUrl::fromLocalFile(tmp.fileName()), projectFileUrl); | 359 | auto uploadJob = KIO::file_copy(QUrl::fromLocalFile(tmp.fileName()), projectFileUrl); | ||
359 | KJobWidgets::setWindow(uploadJob, Core::self()->uiControllerInternal()->defaultMainWindow()); | 360 | KJobWidgets::setWindow(uploadJob, Core::self()->uiControllerInternal()->defaultMainWindow()); | ||
360 | return uploadJob->exec(); | 361 | return uploadJob->exec(); | ||
361 | } | 362 | } | ||
362 | return writeNewProjectFile( projectFileUrl.toLocalFile(),projectName, projectManager ); | 363 | // Here and above we take .filename() part of the selectedUrl() to make it relative to the project root, | ||
364 | // thus making .kdev file relocatable | ||||
365 | return writeNewProjectFile( projectFileUrl.toLocalFile(), dlg->projectName(), dlg->selectedUrl().fileName(), dlg->projectManager() ); | ||||
363 | } | 366 | } | ||
364 | 367 | | |||
365 | 368 | | |||
366 | bool projectFileExists( const QUrl& u ) | 369 | bool projectFileExists( const QUrl& u ) | ||
367 | { | 370 | { | ||
368 | if( u.isLocalFile() ) | 371 | if( u.isLocalFile() ) | ||
369 | { | 372 | { | ||
370 | return QFileInfo::exists( u.toLocalFile() ); | 373 | return QFileInfo::exists( u.toLocalFile() ); | ||
Show All 25 Lines | 392 | { | |||
396 | qCDebug(SHELL) << "selected project:" << projectFileUrl << dlg.projectName() << dlg.projectManager(); | 399 | qCDebug(SHELL) << "selected project:" << projectFileUrl << dlg.projectName() << dlg.projectManager(); | ||
397 | 400 | | |||
398 | // controls if existing project file should be saved | 401 | // controls if existing project file should be saved | ||
399 | bool writeProjectConfigToFile = true; | 402 | bool writeProjectConfigToFile = true; | ||
400 | if( projectFileExists( projectFileUrl ) ) | 403 | if( projectFileExists( projectFileUrl ) ) | ||
401 | { | 404 | { | ||
402 | // check whether config is equal | 405 | // check whether config is equal | ||
403 | bool shouldAsk = true; | 406 | bool shouldAsk = true; | ||
407 | if( projectFileUrl == dlg.selectedUrl() ) | ||||
I don't get this part - you say you never saw the dialog before, yet restrict it even more with this patch. how can this trigger the dialog from showing up *more*? mwolff: I don't get this part - you say you never saw the dialog before, yet restrict it even more with… | |||||
The thing is projectFileUrl always contains a ".kdev". So even if i select "CMakeLists.txt" in the "Open Project" dialog, it picks up existing ".kdev". From my POV if user wanted to open existing project, he'd select ".kdev" in first place. But if he deliberately selects build system file it is better to ask him what's on his mind. arrowd: The thing is projectFileUrl always contains a ".kdev". So even if i select "CMakeLists.txt" in… | |||||
just to make sure: if I select a folder, and not a file in there, will I get an annoying dialog now, or will it work as before? mwolff: just to make sure: if I select a folder, and not a file in there, will I get an annoying dialog… | |||||
Hum. At least on Windows, i can't select a folder in "Open Project" dialog. Are you able to do this on Linux? arrowd: Hum. At least on Windows, i can't select a folder in "Open Project" dialog. Are you able to do… | |||||
Now i updated to last revision and was able to use a folder. Yes, the dialog pops out in this case. You want it gone? arrowd: Now i updated to last revision and was able to use a folder. Yes, the dialog pops out in this… | |||||
Yes, if I reopen a folder, it just should reuse the existing .kdev4 file (if available). This brings me to another question: What happens to your code with the "origin" url when a user opens a .kdev4 file? It should just open the project as-is and not change the origin url or name or anything like that. mwolff: Yes, if I reopen a folder, it just should reuse the existing .kdev4 file (if available). This… | |||||
Hum, i'm confused with that folder selection. When i initially select a folder, it can't be used to open a project: If i enter it, the "Next" button becomes active: Now if i get back it is still active and when i click it, it prompts me to create a project in root dir using generic project manager: I'm not sure what i should do with this.
Yup, that's how it works. That origin field is filled only during creation of the .kdev file (that is, when we open !.kdev file). arrowd: Hum, i'm confused with that folder selection. When i initially select a folder, it can't be… | |||||
408 | { | ||||
404 | if( projectFileUrl.isLocalFile() ) | 409 | if( projectFileUrl.isLocalFile() ) | ||
405 | { | 410 | { | ||
406 | shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), &dlg ); | 411 | shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), &dlg ); | ||
407 | } else { | 412 | } else { | ||
408 | shouldAsk = false; | 413 | shouldAsk = false; | ||
409 | 414 | | |||
410 | QTemporaryFile tmpFile; | 415 | QTemporaryFile tmpFile; | ||
411 | if (tmpFile.open()) { | 416 | if (tmpFile.open()) { | ||
412 | auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); | 417 | auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); | ||
413 | KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); | 418 | KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); | ||
414 | if (downloadJob->exec()) { | 419 | if (downloadJob->exec()) { | ||
415 | shouldAsk = !equalProjectFile(tmpFile.fileName(), &dlg); | 420 | shouldAsk = !equalProjectFile(tmpFile.fileName(), &dlg); | ||
416 | } | 421 | } | ||
417 | } | 422 | } | ||
418 | } | 423 | } | ||
424 | } | ||||
419 | 425 | | |||
420 | if ( shouldAsk ) | 426 | if ( shouldAsk ) | ||
421 | { | 427 | { | ||
422 | KGuiItem yes = KStandardGuiItem::yes(); | 428 | KGuiItem yes = KStandardGuiItem::yes(); | ||
423 | yes.setText(i18n("Override")); | 429 | yes.setText(i18n("Override")); | ||
424 | yes.setToolTip(i18nc("@info:tooltip", "Continue to open the project and use the just provided project configuration.")); | 430 | yes.setToolTip(i18nc("@info:tooltip", "Continue to open the project and use the just provided project configuration.")); | ||
425 | yes.setIcon(QIcon()); | 431 | yes.setIcon(QIcon()); | ||
426 | KGuiItem no = KStandardGuiItem::no(); | 432 | KGuiItem no = KStandardGuiItem::no(); | ||
Show All 14 Lines | 446 | { | |||
441 | return QUrl(); | 447 | return QUrl(); | ||
442 | } // else fall through and write new file | 448 | } // else fall through and write new file | ||
443 | } else { | 449 | } else { | ||
444 | writeProjectConfigToFile = false; | 450 | writeProjectConfigToFile = false; | ||
445 | } | 451 | } | ||
446 | } | 452 | } | ||
447 | 453 | | |||
448 | if (writeProjectConfigToFile) { | 454 | if (writeProjectConfigToFile) { | ||
449 | if (!writeProjectSettingsToConfigFile(projectFileUrl, dlg.projectName(), dlg.projectManager())) { | 455 | if (!writeProjectSettingsToConfigFile(projectFileUrl, &dlg)) { | ||
450 | KMessageBox::error(d->m_core->uiControllerInternal()->defaultMainWindow(), | 456 | KMessageBox::error(d->m_core->uiControllerInternal()->defaultMainWindow(), | ||
451 | i18n("Unable to create configuration file %1", projectFileUrl.url())); | 457 | i18n("Unable to create configuration file %1", projectFileUrl.url())); | ||
452 | return QUrl(); | 458 | return QUrl(); | ||
453 | } | 459 | } | ||
454 | } | 460 | } | ||
455 | return projectFileUrl; | 461 | return projectFileUrl; | ||
456 | } | 462 | } | ||
457 | 463 | | |||
▲ Show 20 Lines • Show All 733 Lines • Show Last 20 Lines |
why write it to disk? if this is the project url as I think it is, then it equals the position in the file system and should not be hardcoded. The project may be moved to another place, or this file checked into VCS and used on a different machine