Changeset View
Changeset View
Standalone View
Standalone View
shell/projectcontroller.cpp
Show All 23 Lines | |||||
24 | #include <QAction> | 24 | #include <QAction> | ||
25 | #include <QApplication> | 25 | #include <QApplication> | ||
26 | #include <QDBusConnection> | 26 | #include <QDBusConnection> | ||
27 | #include <QDir> | 27 | #include <QDir> | ||
28 | #include <QGroupBox> | 28 | #include <QGroupBox> | ||
29 | #include <QLabel> | 29 | #include <QLabel> | ||
30 | #include <QList> | 30 | #include <QList> | ||
31 | #include <QMap> | 31 | #include <QMap> | ||
32 | #include <QPointer> | ||||
32 | #include <QPushButton> | 33 | #include <QPushButton> | ||
33 | #include <QRadioButton> | 34 | #include <QRadioButton> | ||
34 | #include <QSet> | 35 | #include <QSet> | ||
35 | #include <QTemporaryFile> | 36 | #include <QTemporaryFile> | ||
36 | #include <QVBoxLayout> | 37 | #include <QVBoxLayout> | ||
37 | 38 | | |||
38 | #include <KActionCollection> | 39 | #include <KActionCollection> | ||
39 | #include <KConfigGroup> | 40 | #include <KConfigGroup> | ||
▲ Show 20 Lines • Show All 374 Lines • ▼ Show 20 Line(s) | 411 | { | |||
414 | return (grp.readEntry( "Name", QString() ) == dlg->projectName() || dlg->projectName() == defaultName) && | 415 | return (grp.readEntry( "Name", QString() ) == dlg->projectName() || dlg->projectName() == defaultName) && | ||
415 | grp.readEntry( "Manager", QString() ) == dlg->projectManager(); | 416 | grp.readEntry( "Manager", QString() ) == dlg->projectManager(); | ||
416 | } | 417 | } | ||
417 | 418 | | |||
418 | QUrl ProjectDialogProvider::askProjectConfigLocation(bool fetch, const QUrl& startUrl, | 419 | QUrl ProjectDialogProvider::askProjectConfigLocation(bool fetch, const QUrl& startUrl, | ||
419 | const QUrl& repoUrl, IPlugin* vcsOrProviderPlugin) | 420 | const QUrl& repoUrl, IPlugin* vcsOrProviderPlugin) | ||
420 | { | 421 | { | ||
421 | Q_ASSERT(d); | 422 | Q_ASSERT(d); | ||
422 | OpenProjectDialog dlg(fetch, startUrl, repoUrl, vcsOrProviderPlugin, Core::self()->uiController()->activeMainWindow()); | 423 | QPointer<OpenProjectDialog> dlg = | ||
423 | if(dlg.exec() == QDialog::Rejected) | 424 | new OpenProjectDialog(fetch, startUrl, repoUrl, vcsOrProviderPlugin, | ||
425 | Core::self()->uiController()->activeMainWindow()); | ||||
426 | if(dlg->exec() == QDialog::Rejected) { | ||||
427 | delete dlg; | ||||
424 | return QUrl(); | 428 | return QUrl(); | ||
429 | } | ||||
425 | 430 | | |||
426 | QUrl projectFileUrl = dlg.projectFileUrl(); | 431 | QUrl projectFileUrl = dlg->projectFileUrl(); | ||
427 | qCDebug(SHELL) << "selected project:" << projectFileUrl << dlg.projectName() << dlg.projectManager(); | 432 | qCDebug(SHELL) << "selected project:" << projectFileUrl << dlg->projectName() << dlg->projectManager(); | ||
428 | if ( dlg.projectManager() == QLatin1String("<built-in>") ) { | 433 | if ( dlg->projectManager() == QLatin1String("<built-in>") ) { | ||
434 | delete dlg; | ||||
429 | return projectFileUrl; | 435 | return projectFileUrl; | ||
430 | } | 436 | } | ||
431 | 437 | | |||
432 | // controls if existing project file should be saved | 438 | // controls if existing project file should be saved | ||
433 | bool writeProjectConfigToFile = true; | 439 | bool writeProjectConfigToFile = true; | ||
434 | if( projectFileExists( projectFileUrl ) ) | 440 | if( projectFileExists( projectFileUrl ) ) | ||
435 | { | 441 | { | ||
436 | // check whether config is equal | 442 | // check whether config is equal | ||
437 | bool shouldAsk = true; | 443 | bool shouldAsk = true; | ||
438 | if( projectFileUrl == dlg.selectedUrl() ) | 444 | if( projectFileUrl == dlg->selectedUrl() ) | ||
439 | { | 445 | { | ||
440 | if( projectFileUrl.isLocalFile() ) | 446 | if( projectFileUrl.isLocalFile() ) | ||
441 | { | 447 | { | ||
442 | shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), &dlg ); | 448 | shouldAsk = !equalProjectFile( projectFileUrl.toLocalFile(), dlg ); | ||
443 | } else { | 449 | } else { | ||
444 | shouldAsk = false; | 450 | shouldAsk = false; | ||
445 | 451 | | |||
446 | QTemporaryFile tmpFile; | 452 | QTemporaryFile tmpFile; | ||
447 | if (tmpFile.open()) { | 453 | if (tmpFile.open()) { | ||
448 | auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); | 454 | auto downloadJob = KIO::file_copy(projectFileUrl, QUrl::fromLocalFile(tmpFile.fileName())); | ||
449 | KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); | 455 | KJobWidgets::setWindow(downloadJob, qApp->activeWindow()); | ||
450 | if (downloadJob->exec()) { | 456 | if (downloadJob->exec()) { | ||
451 | shouldAsk = !equalProjectFile(tmpFile.fileName(), &dlg); | 457 | shouldAsk = !equalProjectFile(tmpFile.fileName(), dlg); | ||
452 | } | 458 | } | ||
453 | } | 459 | } | ||
454 | } | 460 | } | ||
455 | } | 461 | } | ||
456 | 462 | | |||
457 | if ( shouldAsk ) | 463 | if ( shouldAsk ) | ||
458 | { | 464 | { | ||
459 | KGuiItem yes = KStandardGuiItem::yes(); | 465 | KGuiItem yes = KStandardGuiItem::yes(); | ||
Show All 10 Lines | 475 | int ret = KMessageBox::questionYesNoCancel(qApp->activeWindow(), | |||
470 | i18n("There already exists a project configuration file at %1.\n" | 476 | i18n("There already exists a project configuration file at %1.\n" | ||
471 | "Do you want to override it or open the existing file?", projectFileUrl.toDisplayString(QUrl::PreferLocalFile)), | 477 | "Do you want to override it or open the existing file?", projectFileUrl.toDisplayString(QUrl::PreferLocalFile)), | ||
472 | i18n("Override existing project configuration"), yes, no, cancel ); | 478 | i18n("Override existing project configuration"), yes, no, cancel ); | ||
473 | if ( ret == KMessageBox::No ) | 479 | if ( ret == KMessageBox::No ) | ||
474 | { | 480 | { | ||
475 | writeProjectConfigToFile = false; | 481 | writeProjectConfigToFile = false; | ||
476 | } else if ( ret == KMessageBox::Cancel ) | 482 | } else if ( ret == KMessageBox::Cancel ) | ||
477 | { | 483 | { | ||
484 | delete dlg; | ||||
478 | return QUrl(); | 485 | return QUrl(); | ||
479 | } // else fall through and write new file | 486 | } // else fall through and write new file | ||
480 | } else { | 487 | } else { | ||
481 | writeProjectConfigToFile = false; | 488 | writeProjectConfigToFile = false; | ||
482 | } | 489 | } | ||
483 | } | 490 | } | ||
484 | 491 | | |||
485 | if (writeProjectConfigToFile) { | 492 | if (writeProjectConfigToFile) { | ||
486 | if (!writeProjectSettingsToConfigFile(projectFileUrl, &dlg)) { | 493 | if (!writeProjectSettingsToConfigFile(projectFileUrl, dlg)) { | ||
487 | KMessageBox::error(d->m_core->uiControllerInternal()->defaultMainWindow(), | 494 | KMessageBox::error(d->m_core->uiControllerInternal()->defaultMainWindow(), | ||
488 | i18n("Unable to create configuration file %1", projectFileUrl.url())); | 495 | i18n("Unable to create configuration file %1", projectFileUrl.url())); | ||
496 | delete dlg; | ||||
489 | return QUrl(); | 497 | return QUrl(); | ||
490 | } | 498 | } | ||
491 | } | 499 | } | ||
500 | | ||||
501 | delete dlg; | ||||
492 | return projectFileUrl; | 502 | return projectFileUrl; | ||
493 | } | 503 | } | ||
494 | 504 | | |||
495 | bool ProjectDialogProvider::userWantsReopen() | 505 | bool ProjectDialogProvider::userWantsReopen() | ||
496 | { | 506 | { | ||
497 | Q_ASSERT(d); | 507 | Q_ASSERT(d); | ||
498 | return (KMessageBox::questionYesNo( d->m_core->uiControllerInternal()->defaultMainWindow(), | 508 | return (KMessageBox::questionYesNo( d->m_core->uiControllerInternal()->defaultMainWindow(), | ||
499 | i18n( "Reopen the current project?" ) ) | 509 | i18n( "Reopen the current project?" ) ) | ||
▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Line(s) | 789 | foreach(Sublime::MainWindow* window, Core::self()->uiController()->controller()->mainWindows()) | |||
780 | window->close(); | 790 | window->close(); | ||
781 | } | 791 | } | ||
782 | #endif | 792 | #endif | ||
783 | } | 793 | } | ||
784 | } | 794 | } | ||
785 | } | 795 | } | ||
786 | 796 | | |||
787 | if ( ! existingSessions.isEmpty() ) { | 797 | if ( ! existingSessions.isEmpty() ) { | ||
788 | QDialog dialog(Core::self()->uiControllerInternal()->activeMainWindow()); | 798 | QPointer<QDialog> dialog = new QDialog(Core::self()->uiControllerInternal()->activeMainWindow()); | ||
789 | dialog.setWindowTitle(i18n("Project Already Open")); | 799 | dialog->setWindowTitle(i18n("Project Already Open")); | ||
790 | 800 | | |||
791 | auto mainLayout = new QVBoxLayout(&dialog); | 801 | auto mainLayout = new QVBoxLayout(dialog); | ||
792 | mainLayout->addWidget(new QLabel(i18n("The project you're trying to open is already open in at least one " | 802 | mainLayout->addWidget(new QLabel(i18n("The project you're trying to open is already open in at least one " | ||
793 | "other session.<br>What do you want to do?"))); | 803 | "other session.<br>What do you want to do?"))); | ||
794 | QGroupBox sessions; | 804 | QGroupBox sessions; | ||
795 | sessions.setLayout(new QVBoxLayout); | 805 | sessions.setLayout(new QVBoxLayout); | ||
796 | QRadioButton* newSession = new QRadioButton(i18n("Add project to current session")); | 806 | QRadioButton* newSession = new QRadioButton(i18n("Add project to current session")); | ||
797 | sessions.layout()->addWidget(newSession); | 807 | sessions.layout()->addWidget(newSession); | ||
798 | newSession->setChecked(true); | 808 | newSession->setChecked(true); | ||
799 | foreach ( const Session* session, existingSessions ) { | 809 | foreach ( const Session* session, existingSessions ) { | ||
800 | QRadioButton* button = new QRadioButton(i18n("Open session %1", session->description())); | 810 | QRadioButton* button = new QRadioButton(i18n("Open session %1", session->description())); | ||
801 | button->setProperty("sessionid", session->id().toString()); | 811 | button->setProperty("sessionid", session->id().toString()); | ||
802 | sessions.layout()->addWidget(button); | 812 | sessions.layout()->addWidget(button); | ||
803 | } | 813 | } | ||
804 | sessions.layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding)); | 814 | sessions.layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding)); | ||
805 | mainLayout->addWidget(&sessions); | 815 | mainLayout->addWidget(&sessions); | ||
806 | 816 | | |||
807 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort); | 817 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Abort); | ||
808 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | 818 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
809 | okButton->setDefault(true); | 819 | okButton->setDefault(true); | ||
810 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | 820 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | ||
811 | connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); | 821 | connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | ||
812 | connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); | 822 | connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | ||
813 | mainLayout->addWidget(buttonBox); | 823 | mainLayout->addWidget(buttonBox); | ||
814 | 824 | | |||
815 | bool success = dialog.exec(); | 825 | bool success = dialog->exec(); | ||
826 | delete dialog; | ||||
816 | if (!success) | 827 | if (!success) | ||
817 | return; | 828 | return; | ||
818 | 829 | | |||
819 | foreach ( const QObject* obj, sessions.children() ) { | 830 | foreach ( const QObject* obj, sessions.children() ) { | ||
820 | if ( const QRadioButton* button = qobject_cast<const QRadioButton*>(obj) ) { | 831 | if ( const QRadioButton* button = qobject_cast<const QRadioButton*>(obj) ) { | ||
821 | QString sessionid = button->property("sessionid").toString(); | 832 | QString sessionid = button->property("sessionid").toString(); | ||
822 | if ( button->isChecked() && ! sessionid.isEmpty() ) { | 833 | if ( button->isChecked() && ! sessionid.isEmpty() ) { | ||
823 | Core::self()->sessionController()->loadSession(sessionid); | 834 | Core::self()->sessionController()->loadSession(sessionid); | ||
▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Line(s) | 1163 | if(vcs) { | |||
1153 | ICore::self()->documentController()->saveAllDocuments(KDevelop::IDocument::Silent); | 1164 | ICore::self()->documentController()->saveAllDocuments(KDevelop::IDocument::Silent); | ||
1154 | 1165 | | |||
1155 | const Path basePath = project->path(); | 1166 | const Path basePath = project->path(); | ||
1156 | VCSCommitDiffPatchSource* patchSource = new VCSCommitDiffPatchSource(new VCSStandardDiffUpdater(vcs, basePath.toUrl())); | 1167 | VCSCommitDiffPatchSource* patchSource = new VCSCommitDiffPatchSource(new VCSStandardDiffUpdater(vcs, basePath.toUrl())); | ||
1157 | 1168 | | |||
1158 | bool ret = showVcsDiff(patchSource); | 1169 | bool ret = showVcsDiff(patchSource); | ||
1159 | 1170 | | |||
1160 | if(!ret) { | 1171 | if(!ret) { | ||
1161 | VcsCommitDialog *commitDialog = new VcsCommitDialog(patchSource); | 1172 | QPointer<VcsCommitDialog> commitDialog = new VcsCommitDialog(patchSource); | ||
1162 | commitDialog->setCommitCandidates(patchSource->infos()); | 1173 | commitDialog->setCommitCandidates(patchSource->infos()); | ||
1163 | commitDialog->exec(); | 1174 | commitDialog->exec(); | ||
1175 | delete commitDialog; | ||||
1164 | } | 1176 | } | ||
1165 | } | 1177 | } | ||
1166 | } | 1178 | } | ||
1167 | } | 1179 | } | ||
1168 | 1180 | | |||
1169 | QString ProjectController::mapSourceBuild( const QString& path_, bool reverse, bool fallbackRoot ) const | 1181 | QString ProjectController::mapSourceBuild( const QString& path_, bool reverse, bool fallbackRoot ) const | ||
1170 | { | 1182 | { | ||
1171 | Path path(path_); | 1183 | Path path(path_); | ||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |