CMakeSetupDialog.cxx 44 KB

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