CMakeSetupDialog.cxx 43 KB

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