CMakeSetupDialog.cxx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "CMakeSetupDialog.h"
  4. #include <cm/memory>
  5. #include <QCloseEvent>
  6. #include <QCoreApplication>
  7. #include <QDesktopServices>
  8. #include <QDialogButtonBox>
  9. #include <QDragEnterEvent>
  10. #include <QFileDialog>
  11. #include <QInputDialog>
  12. #include <QKeySequence>
  13. #include <QMenu>
  14. #include <QMenuBar>
  15. #include <QMessageBox>
  16. #include <QMimeData>
  17. #include <QProgressBar>
  18. #include <QSettings>
  19. #include <QShortcut>
  20. #include <QStatusBar>
  21. #include <QToolButton>
  22. #include <QUrl>
  23. #ifdef QT_WINEXTRAS
  24. # include <QWinTaskbarButton>
  25. # include <QWinTaskbarProgress>
  26. #endif
  27. #include "QCMake.h"
  28. #include "QCMakeCacheView.h"
  29. #include "cmSystemTools.h"
  30. #include "cmVersion.h"
  31. #include "AddCacheEntry.h"
  32. #include "FirstConfigure.h"
  33. #include "RegexExplorer.h"
  34. #include "WarningMessagesDialog.h"
  35. QCMakeThread::QCMakeThread(QObject* p)
  36. : QThread(p)
  37. {
  38. }
  39. QCMake* QCMakeThread::cmakeInstance() const
  40. {
  41. return this->CMakeInstance.get();
  42. }
  43. void QCMakeThread::run()
  44. {
  45. this->CMakeInstance = cm::make_unique<QCMake>();
  46. // emit that this cmake thread is ready for use
  47. emit this->cmakeInitialized();
  48. this->exec();
  49. this->CMakeInstance.reset();
  50. }
  51. CMakeSetupDialog::CMakeSetupDialog()
  52. : ExitAfterGenerate(true)
  53. , CacheModified(false)
  54. , ConfigureNeeded(true)
  55. , CurrentState(Interrupting)
  56. {
  57. QString title = QString(tr("CMake %1"));
  58. title = title.arg(cmVersion::GetCMakeVersion());
  59. this->setWindowTitle(title);
  60. // create the GUI
  61. QSettings settings;
  62. settings.beginGroup("Settings/StartPath");
  63. restoreGeometry(settings.value("geometry").toByteArray());
  64. restoreState(settings.value("windowState").toByteArray());
  65. this->AddVariableNames =
  66. settings.value("AddVariableNames", QStringList("CMAKE_INSTALL_PREFIX"))
  67. .toStringList();
  68. this->AddVariableTypes =
  69. settings.value("AddVariableTypes", QStringList("PATH")).toStringList();
  70. QWidget* cont = new QWidget(this);
  71. this->setupUi(cont);
  72. this->Splitter->setStretchFactor(0, 3);
  73. this->Splitter->setStretchFactor(1, 1);
  74. this->setCentralWidget(cont);
  75. this->ProgressBar->reset();
  76. this->RemoveEntry->setEnabled(false);
  77. this->AddEntry->setEnabled(false);
  78. QByteArray p = settings.value("SplitterSizes").toByteArray();
  79. this->Splitter->restoreState(p);
  80. bool groupView = settings.value("GroupView", false).toBool();
  81. this->setGroupedView(groupView);
  82. this->groupedCheck->setCheckState(groupView ? Qt::Checked : Qt::Unchecked);
  83. bool advancedView = settings.value("AdvancedView", false).toBool();
  84. this->setAdvancedView(advancedView);
  85. this->advancedCheck->setCheckState(advancedView ? Qt::Checked
  86. : Qt::Unchecked);
  87. QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
  88. this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
  89. QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)), this,
  90. SLOT(doReloadCache()));
  91. this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
  92. QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)), this,
  93. SLOT(doDeleteCache()));
  94. this->ExitAction = FileMenu->addAction(tr("E&xit"));
  95. this->ExitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
  96. QObject::connect(this->ExitAction, SIGNAL(triggered(bool)), this,
  97. SLOT(close()));
  98. QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  99. this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
  100. // prevent merging with Preferences menu item on macOS
  101. this->ConfigureAction->setMenuRole(QAction::NoRole);
  102. QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)), this,
  103. SLOT(doConfigure()));
  104. this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
  105. QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)), this,
  106. SLOT(doGenerate()));
  107. QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
  108. QObject::connect(showChangesAction, SIGNAL(triggered(bool)), this,
  109. SLOT(showUserChanges()));
  110. #if defined(Q_WS_MAC) || defined(Q_OS_MAC)
  111. this->InstallForCommandLineAction =
  112. ToolsMenu->addAction(tr("&How to Install For Command Line Use"));
  113. QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
  114. this, SLOT(doInstallForCommandLine()));
  115. #endif
  116. ToolsMenu->addSeparator();
  117. ToolsMenu->addAction(tr("Regular Expression Explorer..."), this,
  118. SLOT(doRegexExplorerDialog()));
  119. ToolsMenu->addSeparator();
  120. ToolsMenu->addAction(tr("&Find in Output..."), this,
  121. SLOT(doOutputFindDialog()), QKeySequence::Find);
  122. ToolsMenu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()),
  123. QKeySequence::FindNext);
  124. ToolsMenu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()),
  125. QKeySequence::FindPrevious);
  126. ToolsMenu->addAction(tr("Goto Next Error"), this, SLOT(doOutputErrorNext()),
  127. QKeySequence(Qt::Key_F8)); // in Visual Studio
  128. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period), this,
  129. SLOT(doOutputErrorNext())); // in Eclipse
  130. QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
  131. OptionsMenu->addAction(tr("Warning Messages..."), this,
  132. SLOT(doWarningMessagesDialog()));
  133. this->WarnUninitializedAction =
  134. OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
  135. this->WarnUninitializedAction->setCheckable(true);
  136. QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
  137. debugAction->setCheckable(true);
  138. QObject::connect(debugAction, SIGNAL(toggled(bool)), this,
  139. SLOT(setDebugOutput(bool)));
  140. OptionsMenu->addSeparator();
  141. QAction* expandAction =
  142. OptionsMenu->addAction(tr("&Expand Grouped Entries"));
  143. QObject::connect(expandAction, SIGNAL(triggered(bool)), this->CacheValues,
  144. SLOT(expandAll()));
  145. QAction* collapseAction =
  146. OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
  147. QObject::connect(collapseAction, SIGNAL(triggered(bool)), this->CacheValues,
  148. SLOT(collapseAll()));
  149. QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
  150. QAction* a = HelpMenu->addAction(tr("About"));
  151. QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doAbout()));
  152. a = HelpMenu->addAction(tr("Help"));
  153. QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doHelp()));
  154. this->setAcceptDrops(true);
  155. // get the saved binary directories
  156. QStringList buildPaths = this->loadBuildPaths();
  157. this->BinaryDirectory->addItems(buildPaths);
  158. this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  159. this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  160. // fixed pitch font in output window
  161. QFont outputFont("Courier");
  162. this->Output->setFont(outputFont);
  163. this->ErrorFormat.setForeground(QBrush(Qt::red));
  164. this->Output->setContextMenuPolicy(Qt::CustomContextMenu);
  165. connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
  166. this, SLOT(doOutputContextMenu(const QPoint&)));
  167. // disable open project button
  168. this->OpenProjectButton->setDisabled(true);
  169. // start the cmake worker thread
  170. this->CMakeThread = new QCMakeThread(this);
  171. QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()), this,
  172. SLOT(initialize()), Qt::QueuedConnection);
  173. this->CMakeThread->start();
  174. this->enterState(ReadyConfigure);
  175. ProgressOffset = 0.0;
  176. ProgressFactor = 1.0;
  177. }
  178. void CMakeSetupDialog::initialize()
  179. {
  180. // now the cmake worker thread is running, lets make our connections to it
  181. QObject::connect(this->CMakeThread->cmakeInstance(),
  182. SIGNAL(propertiesChanged(const QCMakePropertyList&)),
  183. this->CacheValues->cacheModel(),
  184. SLOT(setProperties(const QCMakePropertyList&)));
  185. QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)), this,
  186. SLOT(doConfigure()));
  187. QObject::connect(this->CMakeThread->cmakeInstance(),
  188. SIGNAL(configureDone(int)), this, SLOT(exitLoop(int)));
  189. QObject::connect(this->CMakeThread->cmakeInstance(),
  190. SIGNAL(generateDone(int)), this, SLOT(exitLoop(int)));
  191. QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)), this,
  192. SLOT(doGenerate()));
  193. QObject::connect(this->OpenProjectButton, SIGNAL(clicked(bool)), this,
  194. SLOT(doOpenProject()));
  195. QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
  196. this, SLOT(doSourceBrowse()));
  197. QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
  198. this, SLOT(doBinaryBrowse()));
  199. QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
  200. this, SLOT(onBinaryDirectoryChanged(QString)));
  201. QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)), this,
  202. SLOT(onSourceDirectoryChanged(QString)));
  203. QObject::connect(this->CMakeThread->cmakeInstance(),
  204. SIGNAL(sourceDirChanged(QString)), this,
  205. SLOT(updateSourceDirectory(QString)));
  206. QObject::connect(this->CMakeThread->cmakeInstance(),
  207. SIGNAL(binaryDirChanged(QString)), this,
  208. SLOT(updateBinaryDirectory(QString)));
  209. QObject::connect(this->CMakeThread->cmakeInstance(),
  210. SIGNAL(progressChanged(QString, float)), this,
  211. SLOT(showProgress(QString, float)));
  212. QObject::connect(this->CMakeThread->cmakeInstance(),
  213. SIGNAL(errorMessage(QString)), this, SLOT(error(QString)));
  214. QObject::connect(this->CMakeThread->cmakeInstance(),
  215. SIGNAL(outputMessage(QString)), this,
  216. SLOT(message(QString)));
  217. QObject::connect(this->CMakeThread->cmakeInstance(),
  218. SIGNAL(openPossible(bool)), this->OpenProjectButton,
  219. SLOT(setEnabled(bool)));
  220. QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)), this,
  221. SLOT(setGroupedView(bool)));
  222. QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)), this,
  223. SLOT(setAdvancedView(bool)));
  224. QObject::connect(this->Search, SIGNAL(textChanged(QString)), this,
  225. SLOT(setSearchFilter(QString)));
  226. QObject::connect(this->CMakeThread->cmakeInstance(),
  227. SIGNAL(generatorChanged(QString)), this,
  228. SLOT(updateGeneratorLabel(QString)));
  229. this->updateGeneratorLabel(QString());
  230. QObject::connect(this->CacheValues->cacheModel(),
  231. SIGNAL(dataChanged(QModelIndex, QModelIndex)), this,
  232. SLOT(setCacheModified()));
  233. QObject::connect(this->CacheValues->selectionModel(),
  234. SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
  235. this, SLOT(selectionChanged()));
  236. QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)), this,
  237. SLOT(removeSelectedCacheEntries()));
  238. QObject::connect(this->AddEntry, SIGNAL(clicked(bool)), this,
  239. SLOT(addCacheEntry()));
  240. QObject::connect(this->WarnUninitializedAction, SIGNAL(triggered(bool)),
  241. this->CMakeThread->cmakeInstance(),
  242. SLOT(setWarnUninitializedMode(bool)));
  243. if (!this->SourceDirectory->text().isEmpty() ||
  244. !this->BinaryDirectory->lineEdit()->text().isEmpty()) {
  245. this->onSourceDirectoryChanged(this->SourceDirectory->text());
  246. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  247. } else {
  248. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  249. }
  250. #ifdef QT_WINEXTRAS
  251. this->TaskbarButton = new QWinTaskbarButton(this);
  252. this->TaskbarButton->setWindow(this->windowHandle());
  253. #endif
  254. }
  255. CMakeSetupDialog::~CMakeSetupDialog()
  256. {
  257. QSettings settings;
  258. settings.beginGroup("Settings/StartPath");
  259. settings.setValue("windowState", QVariant(saveState()));
  260. settings.setValue("geometry", QVariant(saveGeometry()));
  261. settings.setValue("SplitterSizes", this->Splitter->saveState());
  262. // wait for thread to stop
  263. this->CMakeThread->quit();
  264. this->CMakeThread->wait();
  265. }
  266. bool CMakeSetupDialog::prepareConfigure()
  267. {
  268. // make sure build directory exists
  269. QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  270. QDir dir(bindir);
  271. if (!dir.exists()) {
  272. QString msg = tr("Build directory does not exist, "
  273. "should I create it?\n\n"
  274. "Directory: ");
  275. msg += bindir;
  276. QString title = tr("Create Directory");
  277. QMessageBox::StandardButton btn;
  278. btn = QMessageBox::information(this, title, msg,
  279. QMessageBox::Yes | QMessageBox::No);
  280. if (btn == QMessageBox::No) {
  281. return false;
  282. }
  283. if (!dir.mkpath(".")) {
  284. QMessageBox::information(
  285. this, tr("Create Directory Failed"),
  286. QString(tr("Failed to create directory %1")).arg(dir.path()),
  287. QMessageBox::Ok);
  288. return false;
  289. }
  290. }
  291. // if no generator, prompt for it and other setup stuff
  292. if (this->CMakeThread->cmakeInstance()->generator().isEmpty()) {
  293. if (!this->setupFirstConfigure()) {
  294. return false;
  295. }
  296. }
  297. // remember path
  298. this->addBinaryPath(dir.absolutePath());
  299. return true;
  300. }
  301. void CMakeSetupDialog::exitLoop(int err)
  302. {
  303. this->LocalLoop.exit(err);
  304. }
  305. void CMakeSetupDialog::doConfigure()
  306. {
  307. if (this->CurrentState == Configuring) {
  308. // stop configure
  309. doInterrupt();
  310. return;
  311. }
  312. if (!prepareConfigure()) {
  313. return;
  314. }
  315. this->enterState(Configuring);
  316. bool ret = doConfigureInternal();
  317. if (ret) {
  318. this->ConfigureNeeded = false;
  319. }
  320. if (ret && !this->CacheValues->cacheModel()->newPropertyCount()) {
  321. this->enterState(ReadyGenerate);
  322. } else {
  323. this->enterState(ReadyConfigure);
  324. this->CacheValues->scrollToTop();
  325. }
  326. this->ProgressBar->reset();
  327. #ifdef QT_WINEXTRAS
  328. this->TaskbarButton->progress()->reset();
  329. #endif
  330. }
  331. bool CMakeSetupDialog::doConfigureInternal()
  332. {
  333. this->Output->clear();
  334. this->CacheValues->selectionModel()->clear();
  335. QMetaObject::invokeMethod(
  336. this->CMakeThread->cmakeInstance(), "setProperties", Qt::QueuedConnection,
  337. Q_ARG(QCMakePropertyList, this->CacheValues->cacheModel()->properties()));
  338. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "configure",
  339. Qt::QueuedConnection);
  340. int err = this->LocalLoop.exec();
  341. if (err != 0) {
  342. QMessageBox::critical(
  343. this, tr("Error"),
  344. tr("Error in configuration process, project files may be invalid"),
  345. QMessageBox::Ok);
  346. }
  347. return 0 == err;
  348. }
  349. void CMakeSetupDialog::doInstallForCommandLine()
  350. {
  351. QString title = tr("How to Install For Command Line Use");
  352. QString msg = tr("One may add CMake to the PATH:\n"
  353. "\n"
  354. " PATH=\"%1\":\"$PATH\"\n"
  355. "\n"
  356. "Or, to install symlinks to '/usr/local/bin', run:\n"
  357. "\n"
  358. " sudo \"%2\" --install\n"
  359. "\n"
  360. "Or, to install symlinks to another directory, run:\n"
  361. "\n"
  362. " sudo \"%3\" --install=/path/to/bin\n");
  363. msg = msg.arg(
  364. cmSystemTools::GetFilenamePath(cmSystemTools::GetCMakeCommand()).c_str());
  365. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  366. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  367. QDialog dialog;
  368. dialog.setWindowTitle(title);
  369. QVBoxLayout* l = new QVBoxLayout(&dialog);
  370. QLabel* lab = new QLabel(&dialog);
  371. l->addWidget(lab);
  372. lab->setText(msg);
  373. lab->setWordWrap(false);
  374. lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
  375. QDialogButtonBox* btns =
  376. new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
  377. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  378. l->addWidget(btns);
  379. dialog.exec();
  380. }
  381. bool CMakeSetupDialog::doGenerateInternal()
  382. {
  383. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "generate",
  384. Qt::QueuedConnection);
  385. int err = this->LocalLoop.exec();
  386. if (err != 0) {
  387. QMessageBox::critical(
  388. this, tr("Error"),
  389. tr("Error in generation process, project files may be invalid"),
  390. QMessageBox::Ok);
  391. }
  392. return 0 == err;
  393. }
  394. void CMakeSetupDialog::doGenerate()
  395. {
  396. if (this->CurrentState == Generating) {
  397. // stop generate
  398. doInterrupt();
  399. return;
  400. }
  401. // see if we need to configure
  402. // we'll need to configure if:
  403. // the configure step hasn't been done yet
  404. // generate was the last step done
  405. if (this->ConfigureNeeded) {
  406. if (!prepareConfigure()) {
  407. return;
  408. }
  409. }
  410. this->enterState(Generating);
  411. bool config_passed = true;
  412. if (this->ConfigureNeeded) {
  413. this->CacheValues->cacheModel()->setShowNewProperties(false);
  414. this->ProgressFactor = 0.5;
  415. config_passed = doConfigureInternal();
  416. this->ProgressOffset = 0.5;
  417. }
  418. if (config_passed) {
  419. doGenerateInternal();
  420. }
  421. this->ProgressOffset = 0.0;
  422. this->ProgressFactor = 1.0;
  423. this->CacheValues->cacheModel()->setShowNewProperties(true);
  424. this->enterState(ReadyConfigure);
  425. this->ProgressBar->reset();
  426. #ifdef QT_WINEXTRAS
  427. this->TaskbarButton->progress()->reset();
  428. #endif
  429. this->ConfigureNeeded = true;
  430. }
  431. void CMakeSetupDialog::doOpenProject()
  432. {
  433. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "open",
  434. Qt::QueuedConnection);
  435. }
  436. void CMakeSetupDialog::closeEvent(QCloseEvent* e)
  437. {
  438. // prompt for close if there are unsaved changes, and we're not busy
  439. if (this->CacheModified) {
  440. QString msg = tr("You have changed options but not rebuilt, "
  441. "are you sure you want to exit?");
  442. QString title = tr("Confirm Exit");
  443. QMessageBox::StandardButton btn;
  444. btn = QMessageBox::critical(this, title, msg,
  445. QMessageBox::Yes | QMessageBox::No);
  446. if (btn == QMessageBox::No) {
  447. e->ignore();
  448. }
  449. }
  450. // don't close if we're busy, unless the user really wants to
  451. if (this->CurrentState == Configuring) {
  452. QString msg =
  453. tr("You are in the middle of a Configure.\n"
  454. "If you Exit now the configure information will be lost.\n"
  455. "Are you sure you want to Exit?");
  456. QString title = tr("Confirm Exit");
  457. QMessageBox::StandardButton btn;
  458. btn = QMessageBox::critical(this, title, msg,
  459. QMessageBox::Yes | QMessageBox::No);
  460. if (btn == QMessageBox::No) {
  461. e->ignore();
  462. } else {
  463. this->doInterrupt();
  464. }
  465. }
  466. // let the generate finish
  467. if (this->CurrentState == Generating) {
  468. e->ignore();
  469. }
  470. }
  471. void CMakeSetupDialog::doHelp()
  472. {
  473. QString msg = tr(
  474. "CMake is used to configure and generate build files for "
  475. "software projects. The basic steps for configuring a project are as "
  476. "follows:\r\n\r\n1. Select the source directory for the project. This "
  477. "should "
  478. "contain the CMakeLists.txt files for the project.\r\n\r\n2. Select the "
  479. "build "
  480. "directory for the project. This is the directory where the project "
  481. "will be "
  482. "built. It can be the same or a different directory than the source "
  483. "directory. For easy clean up, a separate build directory is "
  484. "recommended. "
  485. "CMake will create the directory if it does not exist.\r\n\r\n3. Once the "
  486. "source and binary directories are selected, it is time to press the "
  487. "Configure button. This will cause CMake to read all of the input files "
  488. "and "
  489. "discover all the variables used by the project. The first time a "
  490. "variable "
  491. "is displayed it will be in Red. Users should inspect red variables "
  492. "making "
  493. "sure the values are correct. For some projects the Configure process "
  494. "can "
  495. "be iterative, so continue to press the Configure button until there are "
  496. "no "
  497. "longer red entries.\r\n\r\n4. Once there are no longer red entries, you "
  498. "should click the Generate button. This will write the build files to "
  499. "the build "
  500. "directory.");
  501. QDialog dialog;
  502. QFontMetrics met(this->font());
  503. #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
  504. int msgWidth = met.horizontalAdvance(msg);
  505. #else
  506. int msgWidth = met.width(msg);
  507. #endif
  508. dialog.setMinimumSize(msgWidth / 15, 20);
  509. dialog.setWindowTitle(tr("Help"));
  510. QVBoxLayout* l = new QVBoxLayout(&dialog);
  511. QLabel* lab = new QLabel(&dialog);
  512. lab->setText(msg);
  513. lab->setWordWrap(true);
  514. QDialogButtonBox* btns =
  515. new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
  516. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  517. l->addWidget(lab);
  518. l->addWidget(btns);
  519. dialog.exec();
  520. }
  521. void CMakeSetupDialog::doInterrupt()
  522. {
  523. this->enterState(Interrupting);
  524. this->CMakeThread->cmakeInstance()->interrupt();
  525. }
  526. void CMakeSetupDialog::doSourceBrowse()
  527. {
  528. QString dir = QFileDialog::getExistingDirectory(
  529. this, tr("Enter Path to Source"), this->SourceDirectory->text(),
  530. QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  531. if (!dir.isEmpty()) {
  532. this->setSourceDirectory(dir);
  533. }
  534. }
  535. void CMakeSetupDialog::updateSourceDirectory(const QString& dir)
  536. {
  537. if (this->SourceDirectory->text() != dir) {
  538. this->SourceDirectory->blockSignals(true);
  539. this->SourceDirectory->setText(dir);
  540. this->SourceDirectory->blockSignals(false);
  541. }
  542. }
  543. void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
  544. {
  545. if (this->BinaryDirectory->currentText() != dir) {
  546. this->BinaryDirectory->blockSignals(true);
  547. this->BinaryDirectory->setEditText(dir);
  548. this->BinaryDirectory->blockSignals(false);
  549. }
  550. }
  551. void CMakeSetupDialog::doBinaryBrowse()
  552. {
  553. QString dir = QFileDialog::getExistingDirectory(
  554. this, tr("Enter Path to Build"), this->BinaryDirectory->currentText(),
  555. QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  556. if (!dir.isEmpty() && dir != this->BinaryDirectory->currentText()) {
  557. this->setBinaryDirectory(dir);
  558. }
  559. }
  560. void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
  561. {
  562. this->BinaryDirectory->setEditText(dir);
  563. }
  564. void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
  565. {
  566. this->Output->clear();
  567. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  568. "setSourceDirectory", Qt::QueuedConnection,
  569. Q_ARG(QString, dir));
  570. }
  571. void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
  572. {
  573. QString title = QString(tr("CMake %1 - %2"));
  574. title = title.arg(cmVersion::GetCMakeVersion());
  575. title = title.arg(dir);
  576. this->setWindowTitle(title);
  577. this->CacheModified = false;
  578. this->CacheValues->cacheModel()->clear();
  579. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())
  580. ->clearChanges();
  581. this->Output->clear();
  582. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  583. "setBinaryDirectory", Qt::QueuedConnection,
  584. Q_ARG(QString, dir));
  585. }
  586. void CMakeSetupDialog::setSourceDirectory(const QString& dir)
  587. {
  588. this->SourceDirectory->setText(dir);
  589. }
  590. void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
  591. {
  592. percent = (percent * ProgressFactor) + ProgressOffset;
  593. this->ProgressBar->setValue(qRound(percent * 100));
  594. #ifdef QT_WINEXTRAS
  595. QWinTaskbarProgress* progress = this->TaskbarButton->progress();
  596. progress->setVisible(true);
  597. progress->setValue(qRound(percent * 100));
  598. #endif
  599. }
  600. void CMakeSetupDialog::error(const QString& msg)
  601. {
  602. this->Output->setCurrentCharFormat(this->ErrorFormat);
  603. // QTextEdit will terminate the msg with a ParagraphSeparator, but it also
  604. // replaces
  605. // all newlines with ParagraphSeparators. By replacing the newlines by
  606. // ourself, one
  607. // error msg will be one paragraph.
  608. QString paragraph(msg);
  609. paragraph.replace(QLatin1Char('\n'), QChar::LineSeparator);
  610. this->Output->append(paragraph);
  611. }
  612. void CMakeSetupDialog::message(const QString& msg)
  613. {
  614. this->Output->setCurrentCharFormat(this->MessageFormat);
  615. this->Output->append(msg);
  616. }
  617. void CMakeSetupDialog::setEnabledState(bool enabled)
  618. {
  619. // disable parts of the GUI during configure/generate
  620. this->CacheValues->cacheModel()->setEditEnabled(enabled);
  621. this->SourceDirectory->setEnabled(enabled);
  622. this->BrowseSourceDirectoryButton->setEnabled(enabled);
  623. this->BinaryDirectory->setEnabled(enabled);
  624. this->BrowseBinaryDirectoryButton->setEnabled(enabled);
  625. this->ReloadCacheAction->setEnabled(enabled);
  626. this->DeleteCacheAction->setEnabled(enabled);
  627. this->ExitAction->setEnabled(enabled);
  628. this->ConfigureAction->setEnabled(enabled);
  629. this->AddEntry->setEnabled(enabled);
  630. this->RemoveEntry->setEnabled(false); // let selection re-enable it
  631. }
  632. bool CMakeSetupDialog::setupFirstConfigure()
  633. {
  634. FirstConfigure dialog;
  635. // initialize dialog and restore saved settings
  636. // add generators
  637. dialog.setGenerators(
  638. this->CMakeThread->cmakeInstance()->availableGenerators());
  639. // restore from settings
  640. dialog.loadFromSettings();
  641. if (dialog.exec() == QDialog::Accepted) {
  642. dialog.saveToSettings();
  643. this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
  644. this->CMakeThread->cmakeInstance()->setPlatform(dialog.getPlatform());
  645. this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset());
  646. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  647. if (dialog.compilerSetup()) {
  648. QString fortranCompiler = dialog.getFortranCompiler();
  649. if (!fortranCompiler.isEmpty()) {
  650. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  651. "Fortran compiler.", fortranCompiler, false);
  652. }
  653. QString cxxCompiler = dialog.getCXXCompiler();
  654. if (!cxxCompiler.isEmpty()) {
  655. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  656. "CXX compiler.", cxxCompiler, false);
  657. }
  658. QString cCompiler = dialog.getCCompiler();
  659. if (!cCompiler.isEmpty()) {
  660. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  661. "C compiler.", cCompiler, false);
  662. }
  663. } else if (dialog.crossCompilerSetup()) {
  664. QString fortranCompiler = dialog.getFortranCompiler();
  665. if (!fortranCompiler.isEmpty()) {
  666. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  667. "Fortran compiler.", fortranCompiler, false);
  668. }
  669. QString mode = dialog.getCrossIncludeMode();
  670. m->insertProperty(QCMakeProperty::STRING,
  671. "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
  672. tr("CMake Find Include Mode"), mode, false);
  673. mode = dialog.getCrossLibraryMode();
  674. m->insertProperty(QCMakeProperty::STRING,
  675. "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
  676. tr("CMake Find Library Mode"), mode, false);
  677. mode = dialog.getCrossProgramMode();
  678. m->insertProperty(QCMakeProperty::STRING,
  679. "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
  680. tr("CMake Find Program Mode"), mode, false);
  681. QString rootPath = dialog.getCrossRoot();
  682. m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
  683. tr("CMake Find Root Path"), rootPath, false);
  684. QString systemName = dialog.getSystemName();
  685. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
  686. tr("CMake System Name"), systemName, false);
  687. QString systemVersion = dialog.getSystemVersion();
  688. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION",
  689. tr("CMake System Version"), systemVersion, false);
  690. QString systemProcessor = dialog.getSystemProcessor();
  691. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_PROCESSOR",
  692. tr("CMake System Processor"), systemProcessor, false);
  693. QString cxxCompiler = dialog.getCXXCompiler();
  694. if (!cxxCompiler.isEmpty()) {
  695. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  696. tr("CXX compiler."), cxxCompiler, false);
  697. }
  698. QString cCompiler = dialog.getCCompiler();
  699. if (!cCompiler.isEmpty()) {
  700. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  701. tr("C compiler."), cCompiler, false);
  702. }
  703. } else if (dialog.crossCompilerToolChainFile()) {
  704. QString toolchainFile = dialog.getCrossCompilerToolChainFile();
  705. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
  706. tr("Cross Compile ToolChain File"), toolchainFile,
  707. false);
  708. }
  709. return true;
  710. }
  711. return false;
  712. }
  713. void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
  714. {
  715. QString str = tr("Current Generator: ");
  716. if (gen.isEmpty()) {
  717. str += tr("None");
  718. } else {
  719. str += gen;
  720. }
  721. this->Generator->setText(str);
  722. }
  723. void CMakeSetupDialog::doReloadCache()
  724. {
  725. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "reloadCache",
  726. Qt::QueuedConnection);
  727. }
  728. void CMakeSetupDialog::doDeleteCache()
  729. {
  730. QString title = tr("Delete Cache");
  731. QString msg = tr("Are you sure you want to delete the cache?");
  732. QMessageBox::StandardButton btn;
  733. btn = QMessageBox::information(this, title, msg,
  734. QMessageBox::Yes | QMessageBox::No);
  735. if (btn == QMessageBox::No) {
  736. return;
  737. }
  738. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "deleteCache",
  739. Qt::QueuedConnection);
  740. }
  741. void CMakeSetupDialog::doAbout()
  742. {
  743. QString msg = tr(
  744. "CMake %1 (cmake.org).\n"
  745. "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
  746. "Distributed under terms of the BSD 3-Clause License.\n"
  747. "\n"
  748. "CMake GUI maintained by csimsoft,\n"
  749. "built using Qt %2 (qt-project.org).\n"
  750. #ifdef USE_LGPL
  751. "\n"
  752. "The Qt Toolkit is Copyright (C) The Qt Company Ltd.\n"
  753. "Qt is licensed under terms of the GNU LGPLv" USE_LGPL ", available at:\n"
  754. " \"%3\""
  755. #endif
  756. );
  757. msg = msg.arg(cmVersion::GetCMakeVersion());
  758. msg = msg.arg(qVersion());
  759. #ifdef USE_LGPL
  760. std::string lgpl =
  761. cmSystemTools::GetCMakeRoot() + "/Licenses/LGPLv" USE_LGPL ".txt";
  762. msg = msg.arg(lgpl.c_str());
  763. #endif
  764. QDialog dialog;
  765. dialog.setWindowTitle(tr("About"));
  766. QVBoxLayout* l = new QVBoxLayout(&dialog);
  767. QLabel* lab = new QLabel(&dialog);
  768. l->addWidget(lab);
  769. lab->setText(msg);
  770. lab->setWordWrap(true);
  771. QDialogButtonBox* btns =
  772. new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
  773. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  774. l->addWidget(btns);
  775. dialog.exec();
  776. }
  777. void CMakeSetupDialog::setExitAfterGenerate(bool b)
  778. {
  779. this->ExitAfterGenerate = b;
  780. }
  781. void CMakeSetupDialog::addBinaryPath(const QString& path)
  782. {
  783. QString cleanpath = QDir::cleanPath(path);
  784. // update UI
  785. this->BinaryDirectory->blockSignals(true);
  786. int idx = this->BinaryDirectory->findText(cleanpath);
  787. if (idx != -1) {
  788. this->BinaryDirectory->removeItem(idx);
  789. }
  790. this->BinaryDirectory->insertItem(0, cleanpath);
  791. this->BinaryDirectory->setCurrentIndex(0);
  792. this->BinaryDirectory->blockSignals(false);
  793. // save to registry
  794. QStringList buildPaths = this->loadBuildPaths();
  795. buildPaths.removeAll(cleanpath);
  796. buildPaths.prepend(cleanpath);
  797. this->saveBuildPaths(buildPaths);
  798. }
  799. void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
  800. {
  801. if (!(this->CurrentState == ReadyConfigure ||
  802. this->CurrentState == ReadyGenerate)) {
  803. e->ignore();
  804. return;
  805. }
  806. const QMimeData* dat = e->mimeData();
  807. QList<QUrl> urls = dat->urls();
  808. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  809. if (!file.isEmpty() &&
  810. (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
  811. file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))) {
  812. e->accept();
  813. } else {
  814. e->ignore();
  815. }
  816. }
  817. void CMakeSetupDialog::dropEvent(QDropEvent* e)
  818. {
  819. if (!(this->CurrentState == ReadyConfigure ||
  820. this->CurrentState == ReadyGenerate)) {
  821. return;
  822. }
  823. const QMimeData* dat = e->mimeData();
  824. QList<QUrl> urls = dat->urls();
  825. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  826. if (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive)) {
  827. QFileInfo info(file);
  828. if (this->CMakeThread->cmakeInstance()->binaryDirectory() !=
  829. info.absolutePath()) {
  830. this->setBinaryDirectory(info.absolutePath());
  831. }
  832. } else if (file.endsWith("CMakeLists.txt", Qt::CaseInsensitive)) {
  833. QFileInfo info(file);
  834. if (this->CMakeThread->cmakeInstance()->binaryDirectory() !=
  835. info.absolutePath()) {
  836. this->setSourceDirectory(info.absolutePath());
  837. this->setBinaryDirectory(info.absolutePath());
  838. }
  839. }
  840. }
  841. QStringList CMakeSetupDialog::loadBuildPaths()
  842. {
  843. QSettings settings;
  844. settings.beginGroup("Settings/StartPath");
  845. QStringList buildPaths;
  846. for (int i = 0; i < 10; i++) {
  847. QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
  848. if (!p.isEmpty()) {
  849. buildPaths.append(p);
  850. }
  851. }
  852. return buildPaths;
  853. }
  854. void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
  855. {
  856. QSettings settings;
  857. settings.beginGroup("Settings/StartPath");
  858. int num = paths.count();
  859. if (num > 10) {
  860. num = 10;
  861. }
  862. for (int i = 0; i < num; i++) {
  863. settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
  864. }
  865. }
  866. void CMakeSetupDialog::setCacheModified()
  867. {
  868. this->CacheModified = true;
  869. this->ConfigureNeeded = true;
  870. this->enterState(ReadyConfigure);
  871. }
  872. void CMakeSetupDialog::removeSelectedCacheEntries()
  873. {
  874. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  875. QList<QPersistentModelIndex> pidxs;
  876. foreach (QModelIndex const& i, idxs) {
  877. pidxs.append(i);
  878. }
  879. foreach (QPersistentModelIndex const& pi, pidxs) {
  880. this->CacheValues->model()->removeRow(pi.row(), pi.parent());
  881. }
  882. }
  883. void CMakeSetupDialog::selectionChanged()
  884. {
  885. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  886. if (idxs.count() &&
  887. (this->CurrentState == ReadyConfigure ||
  888. this->CurrentState == ReadyGenerate)) {
  889. this->RemoveEntry->setEnabled(true);
  890. } else {
  891. this->RemoveEntry->setEnabled(false);
  892. }
  893. }
  894. void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
  895. {
  896. if (s == this->CurrentState) {
  897. return;
  898. }
  899. this->CurrentState = s;
  900. if (s == Interrupting) {
  901. this->ConfigureButton->setEnabled(false);
  902. this->GenerateButton->setEnabled(false);
  903. this->OpenProjectButton->setEnabled(false);
  904. } else if (s == Configuring) {
  905. this->setEnabledState(false);
  906. this->GenerateButton->setEnabled(false);
  907. this->GenerateAction->setEnabled(false);
  908. this->OpenProjectButton->setEnabled(false);
  909. this->ConfigureButton->setText(tr("&Stop"));
  910. } else if (s == Generating) {
  911. this->CacheModified = false;
  912. this->setEnabledState(false);
  913. this->ConfigureButton->setEnabled(false);
  914. this->GenerateAction->setEnabled(false);
  915. this->OpenProjectButton->setEnabled(false);
  916. this->GenerateButton->setText(tr("&Stop"));
  917. } else if (s == ReadyConfigure || s == ReadyGenerate) {
  918. this->setEnabledState(true);
  919. this->GenerateButton->setEnabled(true);
  920. this->GenerateAction->setEnabled(true);
  921. this->ConfigureButton->setEnabled(true);
  922. this->ConfigureButton->setText(tr("&Configure"));
  923. this->GenerateButton->setText(tr("&Generate"));
  924. }
  925. }
  926. void CMakeSetupDialog::addCacheEntry()
  927. {
  928. QDialog dialog(this);
  929. dialog.resize(400, 200);
  930. dialog.setWindowTitle(tr("Add Cache Entry"));
  931. QVBoxLayout* l = new QVBoxLayout(&dialog);
  932. AddCacheEntry* w =
  933. new AddCacheEntry(&dialog, this->AddVariableNames, this->AddVariableTypes);
  934. QDialogButtonBox* btns = new QDialogButtonBox(
  935. QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
  936. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  937. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
  938. l->addWidget(w);
  939. l->addStretch();
  940. l->addWidget(btns);
  941. if (QDialog::Accepted == dialog.exec()) {
  942. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  943. m->insertProperty(w->type(), w->name(), w->description(), w->value(),
  944. false);
  945. // only add variable names to the completion which are new
  946. if (!this->AddVariableNames.contains(w->name())) {
  947. this->AddVariableNames << w->name();
  948. this->AddVariableTypes << w->typeString();
  949. // limit to at most 100 completion items
  950. if (this->AddVariableNames.size() > 100) {
  951. this->AddVariableNames.removeFirst();
  952. this->AddVariableTypes.removeFirst();
  953. }
  954. // make sure CMAKE_INSTALL_PREFIX is always there
  955. if (!this->AddVariableNames.contains("CMAKE_INSTALL_PREFIX")) {
  956. this->AddVariableNames << "CMAKE_INSTALL_PREFIX";
  957. this->AddVariableTypes << "PATH";
  958. }
  959. QSettings settings;
  960. settings.beginGroup("Settings/StartPath");
  961. settings.setValue("AddVariableNames", this->AddVariableNames);
  962. settings.setValue("AddVariableTypes", this->AddVariableTypes);
  963. }
  964. }
  965. }
  966. void CMakeSetupDialog::startSearch()
  967. {
  968. this->Search->setFocus(Qt::OtherFocusReason);
  969. this->Search->selectAll();
  970. }
  971. void CMakeSetupDialog::setDebugOutput(bool flag)
  972. {
  973. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  974. "setDebugOutput", Qt::QueuedConnection,
  975. Q_ARG(bool, flag));
  976. }
  977. void CMakeSetupDialog::setGroupedView(bool v)
  978. {
  979. this->CacheValues->cacheModel()->setViewType(v ? QCMakeCacheModel::GroupView
  980. : QCMakeCacheModel::FlatView);
  981. this->CacheValues->setRootIsDecorated(v);
  982. QSettings settings;
  983. settings.beginGroup("Settings/StartPath");
  984. settings.setValue("GroupView", v);
  985. }
  986. void CMakeSetupDialog::setAdvancedView(bool v)
  987. {
  988. this->CacheValues->setShowAdvanced(v);
  989. QSettings settings;
  990. settings.beginGroup("Settings/StartPath");
  991. settings.setValue("AdvancedView", v);
  992. }
  993. void CMakeSetupDialog::showUserChanges()
  994. {
  995. QSet<QCMakeProperty> changes =
  996. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())
  997. ->changes();
  998. QDialog dialog(this);
  999. dialog.setWindowTitle(tr("My Changes"));
  1000. dialog.resize(600, 400);
  1001. QVBoxLayout* l = new QVBoxLayout(&dialog);
  1002. QTextEdit* textedit = new QTextEdit(&dialog);
  1003. textedit->setReadOnly(true);
  1004. l->addWidget(textedit);
  1005. QDialogButtonBox* btns =
  1006. new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
  1007. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(accept()));
  1008. l->addWidget(btns);
  1009. QString command;
  1010. QString cache;
  1011. foreach (QCMakeProperty const& prop, changes) {
  1012. QString type;
  1013. switch (prop.Type) {
  1014. case QCMakeProperty::BOOL:
  1015. type = "BOOL";
  1016. break;
  1017. case QCMakeProperty::PATH:
  1018. type = "PATH";
  1019. break;
  1020. case QCMakeProperty::FILEPATH:
  1021. type = "FILEPATH";
  1022. break;
  1023. case QCMakeProperty::STRING:
  1024. type = "STRING";
  1025. break;
  1026. }
  1027. QString value;
  1028. if (prop.Type == QCMakeProperty::BOOL) {
  1029. value = prop.Value.toBool() ? "1" : "0";
  1030. } else {
  1031. value = prop.Value.toString();
  1032. }
  1033. QString const line = QString("%1:%2=").arg(prop.Key, type);
  1034. command += QString("-D%1\"%2\" ").arg(line, value);
  1035. cache += QString("%1%2\n").arg(line, value);
  1036. }
  1037. textedit->append(tr("Commandline options:"));
  1038. textedit->append(command);
  1039. textedit->append("\n");
  1040. textedit->append(tr("Cache file:"));
  1041. textedit->append(cache);
  1042. dialog.exec();
  1043. }
  1044. void CMakeSetupDialog::setSearchFilter(const QString& str)
  1045. {
  1046. this->CacheValues->selectionModel()->clear();
  1047. this->CacheValues->setSearchFilter(str);
  1048. }
  1049. void CMakeSetupDialog::doOutputContextMenu(QPoint pt)
  1050. {
  1051. std::unique_ptr<QMenu> menu(this->Output->createStandardContextMenu());
  1052. menu->addSeparator();
  1053. menu->addAction(tr("Find..."), this, SLOT(doOutputFindDialog()),
  1054. QKeySequence::Find);
  1055. menu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()),
  1056. QKeySequence::FindNext);
  1057. menu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()),
  1058. QKeySequence::FindPrevious);
  1059. menu->addSeparator();
  1060. menu->addAction(tr("Goto Next Error"), this, SLOT(doOutputErrorNext()),
  1061. QKeySequence(Qt::Key_F8));
  1062. menu->exec(this->Output->mapToGlobal(pt));
  1063. }
  1064. void CMakeSetupDialog::doOutputFindDialog()
  1065. {
  1066. QStringList strings(this->FindHistory);
  1067. QString selection = this->Output->textCursor().selectedText();
  1068. if (!selection.isEmpty() && !selection.contains(QChar::ParagraphSeparator) &&
  1069. !selection.contains(QChar::LineSeparator)) {
  1070. strings.push_front(selection);
  1071. }
  1072. bool ok;
  1073. QString search = QInputDialog::getItem(this, tr("Find in Output"),
  1074. tr("Find:"), strings, 0, true, &ok);
  1075. if (ok && !search.isEmpty()) {
  1076. if (!this->FindHistory.contains(search)) {
  1077. this->FindHistory.push_front(search);
  1078. }
  1079. doOutputFindNext();
  1080. }
  1081. }
  1082. void CMakeSetupDialog::doRegexExplorerDialog()
  1083. {
  1084. RegexExplorer dialog(this);
  1085. dialog.exec();
  1086. }
  1087. void CMakeSetupDialog::doOutputFindPrev()
  1088. {
  1089. doOutputFindNext(false);
  1090. }
  1091. void CMakeSetupDialog::doOutputFindNext(bool directionForward)
  1092. {
  1093. if (this->FindHistory.isEmpty()) {
  1094. doOutputFindDialog(); // will re-call this function again
  1095. return;
  1096. }
  1097. QString search = this->FindHistory.front();
  1098. QTextCursor textCursor = this->Output->textCursor();
  1099. QTextDocument* document = this->Output->document();
  1100. QTextDocument::FindFlags flags;
  1101. if (!directionForward) {
  1102. flags |= QTextDocument::FindBackward;
  1103. }
  1104. textCursor = document->find(search, textCursor, flags);
  1105. if (textCursor.isNull()) {
  1106. // first search found nothing, wrap around and search again
  1107. textCursor = this->Output->textCursor();
  1108. textCursor.movePosition(directionForward ? QTextCursor::Start
  1109. : QTextCursor::End);
  1110. textCursor = document->find(search, textCursor, flags);
  1111. }
  1112. if (textCursor.hasSelection()) {
  1113. this->Output->setTextCursor(textCursor);
  1114. }
  1115. }
  1116. void CMakeSetupDialog::doOutputErrorNext()
  1117. {
  1118. QTextCursor textCursor = this->Output->textCursor();
  1119. bool atEnd = false;
  1120. // move cursor out of current error-block
  1121. if (textCursor.blockCharFormat() == this->ErrorFormat) {
  1122. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1123. }
  1124. // move cursor to next error-block
  1125. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd) {
  1126. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1127. }
  1128. if (atEnd) {
  1129. // first search found nothing, wrap around and search again
  1130. atEnd = !textCursor.movePosition(QTextCursor::Start);
  1131. // move cursor to next error-block
  1132. while (textCursor.blockCharFormat() != this->ErrorFormat && !atEnd) {
  1133. atEnd = !textCursor.movePosition(QTextCursor::NextBlock);
  1134. }
  1135. }
  1136. if (!atEnd) {
  1137. textCursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
  1138. QTextCharFormat selectionFormat;
  1139. selectionFormat.setBackground(Qt::yellow);
  1140. QTextEdit::ExtraSelection extraSelection = { textCursor, selectionFormat };
  1141. this->Output->setExtraSelections(QList<QTextEdit::ExtraSelection>()
  1142. << extraSelection);
  1143. // make the whole error-block visible
  1144. this->Output->setTextCursor(textCursor);
  1145. // remove the selection to see the extraSelection
  1146. textCursor.setPosition(textCursor.anchor());
  1147. this->Output->setTextCursor(textCursor);
  1148. }
  1149. }
  1150. void CMakeSetupDialog::doWarningMessagesDialog()
  1151. {
  1152. WarningMessagesDialog dialog(this, this->CMakeThread->cmakeInstance());
  1153. dialog.exec();
  1154. }