CMakeSetupDialog.cxx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "CMakeSetupDialog.h"
  11. #include <QCloseEvent>
  12. #include <QCoreApplication>
  13. #include <QDesktopServices>
  14. #include <QDialogButtonBox>
  15. #include <QDragEnterEvent>
  16. #include <QFileDialog>
  17. #include <QInputDialog>
  18. #include <QKeySequence>
  19. #include <QMenu>
  20. #include <QMenuBar>
  21. #include <QMessageBox>
  22. #include <QMimeData>
  23. #include <QProgressBar>
  24. #include <QSettings>
  25. #include <QShortcut>
  26. #include <QStatusBar>
  27. #include <QToolButton>
  28. #include <QUrl>
  29. #include "AddCacheEntry.h"
  30. #include "FirstConfigure.h"
  31. #include "QCMake.h"
  32. #include "QCMakeCacheView.h"
  33. #include "RegexExplorer.h"
  34. #include "WarningMessagesDialog.h"
  35. #include "cmSystemTools.h"
  36. #include "cmVersion.h"
  37. QCMakeThread::QCMakeThread(QObject* p)
  38. : QThread(p)
  39. , CMakeInstance(CM_NULLPTR)
  40. {
  41. }
  42. QCMake* QCMakeThread::cmakeInstance() const
  43. {
  44. return this->CMakeInstance;
  45. }
  46. void QCMakeThread::run()
  47. {
  48. this->CMakeInstance = new QCMake;
  49. // emit that this cmake thread is ready for use
  50. emit this->cmakeInitialized();
  51. this->exec();
  52. delete this->CMakeInstance;
  53. this->CMakeInstance = CM_NULLPTR;
  54. }
  55. CMakeSetupDialog::CMakeSetupDialog()
  56. : ExitAfterGenerate(true)
  57. , CacheModified(false)
  58. , ConfigureNeeded(true)
  59. , CurrentState(Interrupting)
  60. {
  61. QString title = QString(tr("CMake %1"));
  62. title = title.arg(cmVersion::GetCMakeVersion());
  63. this->setWindowTitle(title);
  64. // create the GUI
  65. QSettings settings;
  66. settings.beginGroup("Settings/StartPath");
  67. restoreGeometry(settings.value("geometry").toByteArray());
  68. restoreState(settings.value("windowState").toByteArray());
  69. this->AddVariableNames =
  70. settings.value("AddVariableNames", QStringList("CMAKE_INSTALL_PREFIX"))
  71. .toStringList();
  72. this->AddVariableTypes =
  73. settings.value("AddVariableTypes", QStringList("PATH")).toStringList();
  74. QWidget* cont = new QWidget(this);
  75. this->setupUi(cont);
  76. this->Splitter->setStretchFactor(0, 3);
  77. this->Splitter->setStretchFactor(1, 1);
  78. this->setCentralWidget(cont);
  79. this->ProgressBar->reset();
  80. this->RemoveEntry->setEnabled(false);
  81. this->AddEntry->setEnabled(false);
  82. QByteArray p = settings.value("SplitterSizes").toByteArray();
  83. this->Splitter->restoreState(p);
  84. bool groupView = settings.value("GroupView", false).toBool();
  85. this->setGroupedView(groupView);
  86. this->groupedCheck->setCheckState(groupView ? Qt::Checked : Qt::Unchecked);
  87. bool advancedView = settings.value("AdvancedView", false).toBool();
  88. this->setAdvancedView(advancedView);
  89. this->advancedCheck->setCheckState(advancedView ? Qt::Checked
  90. : Qt::Unchecked);
  91. QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
  92. this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
  93. QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)), this,
  94. SLOT(doReloadCache()));
  95. this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
  96. QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)), this,
  97. SLOT(doDeleteCache()));
  98. this->ExitAction = FileMenu->addAction(tr("E&xit"));
  99. this->ExitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
  100. QObject::connect(this->ExitAction, SIGNAL(triggered(bool)), this,
  101. SLOT(close()));
  102. QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
  103. this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
  104. // prevent merging with Preferences menu item on Mac OS X
  105. this->ConfigureAction->setMenuRole(QAction::NoRole);
  106. QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)), this,
  107. SLOT(doConfigure()));
  108. this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
  109. QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)), this,
  110. SLOT(doGenerate()));
  111. QAction* showChangesAction = ToolsMenu->addAction(tr("&Show My Changes"));
  112. QObject::connect(showChangesAction, SIGNAL(triggered(bool)), this,
  113. SLOT(showUserChanges()));
  114. #if defined(Q_WS_MAC) || defined(Q_OS_MAC)
  115. this->InstallForCommandLineAction =
  116. ToolsMenu->addAction(tr("&How to Install For Command Line Use"));
  117. QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
  118. this, SLOT(doInstallForCommandLine()));
  119. #endif
  120. ToolsMenu->addSeparator();
  121. ToolsMenu->addAction(tr("Regular Expression Explorer..."), this,
  122. SLOT(doRegexExplorerDialog()));
  123. ToolsMenu->addSeparator();
  124. ToolsMenu->addAction(tr("&Find in Output..."), this,
  125. SLOT(doOutputFindDialog()), QKeySequence::Find);
  126. ToolsMenu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()),
  127. QKeySequence::FindNext);
  128. ToolsMenu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()),
  129. QKeySequence::FindPrevious);
  130. ToolsMenu->addAction(tr("Goto Next Error"), this, SLOT(doOutputErrorNext()),
  131. QKeySequence(Qt::Key_F8)); // in Visual Studio
  132. new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period), this,
  133. SLOT(doOutputErrorNext())); // in Eclipse
  134. QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
  135. OptionsMenu->addAction(tr("Warning Messages..."), this,
  136. SLOT(doWarningMessagesDialog()));
  137. this->WarnUninitializedAction =
  138. OptionsMenu->addAction(tr("&Warn Uninitialized (--warn-uninitialized)"));
  139. this->WarnUninitializedAction->setCheckable(true);
  140. this->WarnUnusedAction =
  141. OptionsMenu->addAction(tr("&Warn Unused (--warn-unused-vars)"));
  142. this->WarnUnusedAction->setCheckable(true);
  143. QAction* debugAction = OptionsMenu->addAction(tr("&Debug Output"));
  144. debugAction->setCheckable(true);
  145. QObject::connect(debugAction, SIGNAL(toggled(bool)), this,
  146. SLOT(setDebugOutput(bool)));
  147. OptionsMenu->addSeparator();
  148. QAction* expandAction =
  149. OptionsMenu->addAction(tr("&Expand Grouped Entries"));
  150. QObject::connect(expandAction, SIGNAL(triggered(bool)), this->CacheValues,
  151. SLOT(expandAll()));
  152. QAction* collapseAction =
  153. OptionsMenu->addAction(tr("&Collapse Grouped Entries"));
  154. QObject::connect(collapseAction, SIGNAL(triggered(bool)), this->CacheValues,
  155. SLOT(collapseAll()));
  156. QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
  157. QAction* a = HelpMenu->addAction(tr("About"));
  158. QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doAbout()));
  159. a = HelpMenu->addAction(tr("Help"));
  160. QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doHelp()));
  161. this->setAcceptDrops(true);
  162. // get the saved binary directories
  163. QStringList buildPaths = this->loadBuildPaths();
  164. this->BinaryDirectory->addItems(buildPaths);
  165. this->BinaryDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  166. this->SourceDirectory->setCompleter(new QCMakeFileCompleter(this, true));
  167. // fixed pitch font in output window
  168. QFont outputFont("Courier");
  169. this->Output->setFont(outputFont);
  170. this->ErrorFormat.setForeground(QBrush(Qt::red));
  171. this->Output->setContextMenuPolicy(Qt::CustomContextMenu);
  172. connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
  173. this, SLOT(doOutputContextMenu(const QPoint&)));
  174. // start the cmake worker thread
  175. this->CMakeThread = new QCMakeThread(this);
  176. QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()), this,
  177. SLOT(initialize()), Qt::QueuedConnection);
  178. this->CMakeThread->start();
  179. this->enterState(ReadyConfigure);
  180. ProgressOffset = 0.0;
  181. ProgressFactor = 1.0;
  182. }
  183. void CMakeSetupDialog::initialize()
  184. {
  185. // now the cmake worker thread is running, lets make our connections to it
  186. QObject::connect(this->CMakeThread->cmakeInstance(),
  187. SIGNAL(propertiesChanged(const QCMakePropertyList&)),
  188. this->CacheValues->cacheModel(),
  189. SLOT(setProperties(const QCMakePropertyList&)));
  190. QObject::connect(this->ConfigureButton, SIGNAL(clicked(bool)), this,
  191. SLOT(doConfigure()));
  192. QObject::connect(this->CMakeThread->cmakeInstance(),
  193. SIGNAL(configureDone(int)), this, SLOT(exitLoop(int)));
  194. QObject::connect(this->CMakeThread->cmakeInstance(),
  195. SIGNAL(generateDone(int)), this, SLOT(exitLoop(int)));
  196. QObject::connect(this->GenerateButton, SIGNAL(clicked(bool)), this,
  197. SLOT(doGenerate()));
  198. QObject::connect(this->OpenProjectButton, SIGNAL(clicked(bool)), this,
  199. SLOT(doOpenProject()));
  200. QObject::connect(this->BrowseSourceDirectoryButton, SIGNAL(clicked(bool)),
  201. this, SLOT(doSourceBrowse()));
  202. QObject::connect(this->BrowseBinaryDirectoryButton, SIGNAL(clicked(bool)),
  203. this, SLOT(doBinaryBrowse()));
  204. QObject::connect(this->BinaryDirectory, SIGNAL(editTextChanged(QString)),
  205. this, SLOT(onBinaryDirectoryChanged(QString)));
  206. QObject::connect(this->SourceDirectory, SIGNAL(textChanged(QString)), this,
  207. SLOT(onSourceDirectoryChanged(QString)));
  208. QObject::connect(this->CMakeThread->cmakeInstance(),
  209. SIGNAL(sourceDirChanged(QString)), this,
  210. SLOT(updateSourceDirectory(QString)));
  211. QObject::connect(this->CMakeThread->cmakeInstance(),
  212. SIGNAL(binaryDirChanged(QString)), this,
  213. SLOT(updateBinaryDirectory(QString)));
  214. QObject::connect(this->CMakeThread->cmakeInstance(),
  215. SIGNAL(progressChanged(QString, float)), this,
  216. SLOT(showProgress(QString, float)));
  217. QObject::connect(this->CMakeThread->cmakeInstance(),
  218. SIGNAL(errorMessage(QString)), this, SLOT(error(QString)));
  219. QObject::connect(this->CMakeThread->cmakeInstance(),
  220. SIGNAL(outputMessage(QString)), this,
  221. SLOT(message(QString)));
  222. QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)), this,
  223. SLOT(setGroupedView(bool)));
  224. QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)), this,
  225. SLOT(setAdvancedView(bool)));
  226. QObject::connect(this->Search, SIGNAL(textChanged(QString)), this,
  227. SLOT(setSearchFilter(QString)));
  228. QObject::connect(this->CMakeThread->cmakeInstance(),
  229. SIGNAL(generatorChanged(QString)), this,
  230. SLOT(updateGeneratorLabel(QString)));
  231. this->updateGeneratorLabel(QString());
  232. QObject::connect(this->CacheValues->cacheModel(),
  233. SIGNAL(dataChanged(QModelIndex, QModelIndex)), this,
  234. SLOT(setCacheModified()));
  235. QObject::connect(this->CacheValues->selectionModel(),
  236. SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
  237. this, SLOT(selectionChanged()));
  238. QObject::connect(this->RemoveEntry, SIGNAL(clicked(bool)), this,
  239. SLOT(removeSelectedCacheEntries()));
  240. QObject::connect(this->AddEntry, SIGNAL(clicked(bool)), this,
  241. SLOT(addCacheEntry()));
  242. QObject::connect(this->WarnUninitializedAction, SIGNAL(triggered(bool)),
  243. this->CMakeThread->cmakeInstance(),
  244. SLOT(setWarnUninitializedMode(bool)));
  245. QObject::connect(this->WarnUnusedAction, SIGNAL(triggered(bool)),
  246. this->CMakeThread->cmakeInstance(),
  247. SLOT(setWarnUnusedMode(bool)));
  248. if (!this->SourceDirectory->text().isEmpty() ||
  249. !this->BinaryDirectory->lineEdit()->text().isEmpty()) {
  250. this->onSourceDirectoryChanged(this->SourceDirectory->text());
  251. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  252. } else {
  253. this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
  254. }
  255. }
  256. CMakeSetupDialog::~CMakeSetupDialog()
  257. {
  258. QSettings settings;
  259. settings.beginGroup("Settings/StartPath");
  260. settings.setValue("windowState", QVariant(saveState()));
  261. settings.setValue("geometry", QVariant(saveGeometry()));
  262. settings.setValue("SplitterSizes", this->Splitter->saveState());
  263. // wait for thread to stop
  264. this->CMakeThread->quit();
  265. this->CMakeThread->wait();
  266. }
  267. bool CMakeSetupDialog::prepareConfigure()
  268. {
  269. // make sure build directory exists
  270. QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
  271. QDir dir(bindir);
  272. if (!dir.exists()) {
  273. QString msg = tr("Build directory does not exist, "
  274. "should I create it?\n\n"
  275. "Directory: ");
  276. msg += bindir;
  277. QString title = tr("Create Directory");
  278. QMessageBox::StandardButton btn;
  279. btn = QMessageBox::information(this, title, msg,
  280. QMessageBox::Yes | QMessageBox::No);
  281. if (btn == QMessageBox::No) {
  282. return false;
  283. }
  284. if (!dir.mkpath(".")) {
  285. QMessageBox::information(
  286. this, tr("Create Directory Failed"),
  287. QString(tr("Failed to create directory %1")).arg(dir.path()),
  288. QMessageBox::Ok);
  289. return false;
  290. }
  291. }
  292. // if no generator, prompt for it and other setup stuff
  293. if (this->CMakeThread->cmakeInstance()->generator().isEmpty()) {
  294. if (!this->setupFirstConfigure()) {
  295. return false;
  296. }
  297. }
  298. // remember path
  299. this->addBinaryPath(dir.absolutePath());
  300. return true;
  301. }
  302. void CMakeSetupDialog::exitLoop(int err)
  303. {
  304. this->LocalLoop.exit(err);
  305. }
  306. void CMakeSetupDialog::doConfigure()
  307. {
  308. if (this->CurrentState == Configuring) {
  309. // stop configure
  310. doInterrupt();
  311. return;
  312. }
  313. if (!prepareConfigure()) {
  314. return;
  315. }
  316. this->enterState(Configuring);
  317. bool ret = doConfigureInternal();
  318. if (ret) {
  319. this->ConfigureNeeded = false;
  320. }
  321. if (ret && !this->CacheValues->cacheModel()->newPropertyCount()) {
  322. this->enterState(ReadyGenerate);
  323. } else {
  324. this->enterState(ReadyConfigure);
  325. this->CacheValues->scrollToTop();
  326. }
  327. this->ProgressBar->reset();
  328. }
  329. bool CMakeSetupDialog::doConfigureInternal()
  330. {
  331. this->Output->clear();
  332. this->CacheValues->selectionModel()->clear();
  333. QMetaObject::invokeMethod(
  334. this->CMakeThread->cmakeInstance(), "setProperties", Qt::QueuedConnection,
  335. Q_ARG(QCMakePropertyList, this->CacheValues->cacheModel()->properties()));
  336. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "configure",
  337. Qt::QueuedConnection);
  338. int err = this->LocalLoop.exec();
  339. if (err != 0) {
  340. QMessageBox::critical(
  341. this, tr("Error"),
  342. tr("Error in configuration process, project files may be invalid"),
  343. QMessageBox::Ok);
  344. }
  345. return 0 == err;
  346. }
  347. void CMakeSetupDialog::doInstallForCommandLine()
  348. {
  349. QString title = tr("How to Install For Command Line Use");
  350. QString msg = tr("One may add CMake to the PATH:\n"
  351. "\n"
  352. " PATH=\"%1\":\"$PATH\"\n"
  353. "\n"
  354. "Or, to install symlinks to '/usr/local/bin', run:\n"
  355. "\n"
  356. " sudo \"%2\" --install\n"
  357. "\n"
  358. "Or, to install symlinks to another directory, run:\n"
  359. "\n"
  360. " sudo \"%3\" --install=/path/to/bin\n");
  361. msg = msg.arg(
  362. cmSystemTools::GetFilenamePath(cmSystemTools::GetCMakeCommand()).c_str());
  363. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  364. msg = msg.arg(cmSystemTools::GetCMakeGUICommand().c_str());
  365. QDialog dialog;
  366. dialog.setWindowTitle(title);
  367. QVBoxLayout* l = new QVBoxLayout(&dialog);
  368. QLabel* lab = new QLabel(&dialog);
  369. l->addWidget(lab);
  370. lab->setText(msg);
  371. lab->setWordWrap(false);
  372. lab->setTextInteractionFlags(Qt::TextSelectableByMouse);
  373. QDialogButtonBox* btns =
  374. new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
  375. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  376. l->addWidget(btns);
  377. dialog.exec();
  378. }
  379. bool CMakeSetupDialog::doGenerateInternal()
  380. {
  381. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "generate",
  382. Qt::QueuedConnection);
  383. int err = this->LocalLoop.exec();
  384. if (err != 0) {
  385. QMessageBox::critical(
  386. this, tr("Error"),
  387. tr("Error in generation process, project files may be invalid"),
  388. QMessageBox::Ok);
  389. }
  390. return 0 == err;
  391. }
  392. void CMakeSetupDialog::doGenerate()
  393. {
  394. if (this->CurrentState == Generating) {
  395. // stop generate
  396. doInterrupt();
  397. return;
  398. }
  399. // see if we need to configure
  400. // we'll need to configure if:
  401. // the configure step hasn't been done yet
  402. // generate was the last step done
  403. if (this->ConfigureNeeded) {
  404. if (!prepareConfigure()) {
  405. return;
  406. }
  407. }
  408. this->enterState(Generating);
  409. bool config_passed = true;
  410. if (this->ConfigureNeeded) {
  411. this->CacheValues->cacheModel()->setShowNewProperties(false);
  412. this->ProgressFactor = 0.5;
  413. config_passed = doConfigureInternal();
  414. this->ProgressOffset = 0.5;
  415. }
  416. if (config_passed) {
  417. doGenerateInternal();
  418. }
  419. this->ProgressOffset = 0.0;
  420. this->ProgressFactor = 1.0;
  421. this->CacheValues->cacheModel()->setShowNewProperties(true);
  422. this->enterState(ReadyConfigure);
  423. this->ProgressBar->reset();
  424. this->ConfigureNeeded = true;
  425. }
  426. QString CMakeSetupDialog::getProjectFilename()
  427. {
  428. QStringList nameFilter;
  429. nameFilter << "*.sln"
  430. << "*.xcodeproj";
  431. QDir directory(this->BinaryDirectory->currentText());
  432. QStringList nlnFile = directory.entryList(nameFilter);
  433. if (nlnFile.count() == 1) {
  434. return this->BinaryDirectory->currentText() + "/" + nlnFile.at(0);
  435. }
  436. return QString();
  437. }
  438. void CMakeSetupDialog::doOpenProject()
  439. {
  440. QDesktopServices::openUrl(QUrl::fromLocalFile(this->getProjectFilename()));
  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. if (!this->getProjectFilename().isEmpty()) {
  553. this->OpenProjectButton->setEnabled(true);
  554. } else {
  555. this->OpenProjectButton->setEnabled(false);
  556. }
  557. }
  558. void CMakeSetupDialog::doBinaryBrowse()
  559. {
  560. QString dir = QFileDialog::getExistingDirectory(
  561. this, tr("Enter Path to Build"), this->BinaryDirectory->currentText(),
  562. QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  563. if (!dir.isEmpty() && dir != this->BinaryDirectory->currentText()) {
  564. this->setBinaryDirectory(dir);
  565. }
  566. }
  567. void CMakeSetupDialog::setBinaryDirectory(const QString& dir)
  568. {
  569. this->BinaryDirectory->setEditText(dir);
  570. }
  571. void CMakeSetupDialog::onSourceDirectoryChanged(const QString& dir)
  572. {
  573. this->Output->clear();
  574. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  575. "setSourceDirectory", Qt::QueuedConnection,
  576. Q_ARG(QString, dir));
  577. }
  578. void CMakeSetupDialog::onBinaryDirectoryChanged(const QString& dir)
  579. {
  580. QString title = QString(tr("CMake %1 - %2"));
  581. title = title.arg(cmVersion::GetCMakeVersion());
  582. title = title.arg(dir);
  583. this->setWindowTitle(title);
  584. this->CacheModified = false;
  585. this->CacheValues->cacheModel()->clear();
  586. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())
  587. ->clearChanges();
  588. this->Output->clear();
  589. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  590. "setBinaryDirectory", Qt::QueuedConnection,
  591. Q_ARG(QString, dir));
  592. }
  593. void CMakeSetupDialog::setSourceDirectory(const QString& dir)
  594. {
  595. this->SourceDirectory->setText(dir);
  596. }
  597. void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
  598. {
  599. percent = (percent * ProgressFactor) + ProgressOffset;
  600. this->ProgressBar->setValue(qRound(percent * 100));
  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()->setToolset(dialog.getToolset());
  647. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  648. if (dialog.compilerSetup()) {
  649. QString fortranCompiler = dialog.getFortranCompiler();
  650. if (!fortranCompiler.isEmpty()) {
  651. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  652. "Fortran compiler.", fortranCompiler, false);
  653. }
  654. QString cxxCompiler = dialog.getCXXCompiler();
  655. if (!cxxCompiler.isEmpty()) {
  656. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  657. "CXX compiler.", cxxCompiler, false);
  658. }
  659. QString cCompiler = dialog.getCCompiler();
  660. if (!cCompiler.isEmpty()) {
  661. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  662. "C compiler.", cCompiler, false);
  663. }
  664. } else if (dialog.crossCompilerSetup()) {
  665. QString fortranCompiler = dialog.getFortranCompiler();
  666. if (!fortranCompiler.isEmpty()) {
  667. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_Fortran_COMPILER",
  668. "Fortran compiler.", fortranCompiler, false);
  669. }
  670. QString mode = dialog.getCrossIncludeMode();
  671. m->insertProperty(QCMakeProperty::STRING,
  672. "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE",
  673. tr("CMake Find Include Mode"), mode, false);
  674. mode = dialog.getCrossLibraryMode();
  675. m->insertProperty(QCMakeProperty::STRING,
  676. "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY",
  677. tr("CMake Find Library Mode"), mode, false);
  678. mode = dialog.getCrossProgramMode();
  679. m->insertProperty(QCMakeProperty::STRING,
  680. "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM",
  681. tr("CMake Find Program Mode"), mode, false);
  682. QString rootPath = dialog.getCrossRoot();
  683. m->insertProperty(QCMakeProperty::PATH, "CMAKE_FIND_ROOT_PATH",
  684. tr("CMake Find Root Path"), rootPath, false);
  685. QString systemName = dialog.getSystemName();
  686. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_NAME",
  687. tr("CMake System Name"), systemName, false);
  688. QString systemVersion = dialog.getSystemVersion();
  689. m->insertProperty(QCMakeProperty::STRING, "CMAKE_SYSTEM_VERSION",
  690. tr("CMake System Version"), systemVersion, false);
  691. QString cxxCompiler = dialog.getCXXCompiler();
  692. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_CXX_COMPILER",
  693. tr("CXX compiler."), cxxCompiler, false);
  694. QString cCompiler = dialog.getCCompiler();
  695. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_C_COMPILER",
  696. tr("C compiler."), cCompiler, false);
  697. } else if (dialog.crossCompilerToolChainFile()) {
  698. QString toolchainFile = dialog.getCrossCompilerToolChainFile();
  699. m->insertProperty(QCMakeProperty::FILEPATH, "CMAKE_TOOLCHAIN_FILE",
  700. tr("Cross Compile ToolChain File"), toolchainFile,
  701. false);
  702. }
  703. return true;
  704. }
  705. return false;
  706. }
  707. void CMakeSetupDialog::updateGeneratorLabel(const QString& gen)
  708. {
  709. QString str = tr("Current Generator: ");
  710. if (gen.isEmpty()) {
  711. str += tr("None");
  712. } else {
  713. str += gen;
  714. }
  715. this->Generator->setText(str);
  716. }
  717. void CMakeSetupDialog::doReloadCache()
  718. {
  719. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "reloadCache",
  720. Qt::QueuedConnection);
  721. }
  722. void CMakeSetupDialog::doDeleteCache()
  723. {
  724. QString title = tr("Delete Cache");
  725. QString msg = tr("Are you sure you want to delete the cache?");
  726. QMessageBox::StandardButton btn;
  727. btn = QMessageBox::information(this, title, msg,
  728. QMessageBox::Yes | QMessageBox::No);
  729. if (btn == QMessageBox::No) {
  730. return;
  731. }
  732. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "deleteCache",
  733. Qt::QueuedConnection);
  734. }
  735. void CMakeSetupDialog::doAbout()
  736. {
  737. QString msg = tr(
  738. "CMake %1 (cmake.org).\n"
  739. "CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
  740. "Distributed under terms of the BSD 3-Clause License.\n"
  741. "\n"
  742. "CMake GUI maintained by csimsoft,\n"
  743. "built using Qt %2 (qt-project.org).\n"
  744. #ifdef USE_LGPL
  745. "\n"
  746. "The Qt Toolkit is Copyright (C) Digia Plc and/or its subsidiary(-ies).\n"
  747. "Qt is licensed under terms of the GNU LGPLv" USE_LGPL ", available at:\n"
  748. " \"%3\""
  749. #endif
  750. );
  751. msg = msg.arg(cmVersion::GetCMakeVersion());
  752. msg = msg.arg(qVersion());
  753. #ifdef USE_LGPL
  754. std::string lgpl =
  755. cmSystemTools::GetCMakeRoot() + "/Licenses/LGPLv" USE_LGPL ".txt";
  756. msg = msg.arg(lgpl.c_str());
  757. #endif
  758. QDialog dialog;
  759. dialog.setWindowTitle(tr("About"));
  760. QVBoxLayout* l = new QVBoxLayout(&dialog);
  761. QLabel* lab = new QLabel(&dialog);
  762. l->addWidget(lab);
  763. lab->setText(msg);
  764. lab->setWordWrap(true);
  765. QDialogButtonBox* btns =
  766. new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, &dialog);
  767. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  768. l->addWidget(btns);
  769. dialog.exec();
  770. }
  771. void CMakeSetupDialog::setExitAfterGenerate(bool b)
  772. {
  773. this->ExitAfterGenerate = b;
  774. }
  775. void CMakeSetupDialog::addBinaryPath(const QString& path)
  776. {
  777. QString cleanpath = QDir::cleanPath(path);
  778. // update UI
  779. this->BinaryDirectory->blockSignals(true);
  780. int idx = this->BinaryDirectory->findText(cleanpath);
  781. if (idx != -1) {
  782. this->BinaryDirectory->removeItem(idx);
  783. }
  784. this->BinaryDirectory->insertItem(0, cleanpath);
  785. this->BinaryDirectory->setCurrentIndex(0);
  786. this->BinaryDirectory->blockSignals(false);
  787. // save to registry
  788. QStringList buildPaths = this->loadBuildPaths();
  789. buildPaths.removeAll(cleanpath);
  790. buildPaths.prepend(cleanpath);
  791. this->saveBuildPaths(buildPaths);
  792. }
  793. void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
  794. {
  795. if (!(this->CurrentState == ReadyConfigure ||
  796. this->CurrentState == ReadyGenerate)) {
  797. e->ignore();
  798. return;
  799. }
  800. const QMimeData* dat = e->mimeData();
  801. QList<QUrl> urls = dat->urls();
  802. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  803. if (!file.isEmpty() &&
  804. (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
  805. file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))) {
  806. e->accept();
  807. } else {
  808. e->ignore();
  809. }
  810. }
  811. void CMakeSetupDialog::dropEvent(QDropEvent* e)
  812. {
  813. if (!(this->CurrentState == ReadyConfigure ||
  814. this->CurrentState == ReadyGenerate)) {
  815. return;
  816. }
  817. const QMimeData* dat = e->mimeData();
  818. QList<QUrl> urls = dat->urls();
  819. QString file = urls.count() ? urls[0].toLocalFile() : QString();
  820. if (file.endsWith("CMakeCache.txt", Qt::CaseInsensitive)) {
  821. QFileInfo info(file);
  822. if (this->CMakeThread->cmakeInstance()->binaryDirectory() !=
  823. info.absolutePath()) {
  824. this->setBinaryDirectory(info.absolutePath());
  825. }
  826. } else if (file.endsWith("CMakeLists.txt", Qt::CaseInsensitive)) {
  827. QFileInfo info(file);
  828. if (this->CMakeThread->cmakeInstance()->binaryDirectory() !=
  829. info.absolutePath()) {
  830. this->setSourceDirectory(info.absolutePath());
  831. this->setBinaryDirectory(info.absolutePath());
  832. }
  833. }
  834. }
  835. QStringList CMakeSetupDialog::loadBuildPaths()
  836. {
  837. QSettings settings;
  838. settings.beginGroup("Settings/StartPath");
  839. QStringList buildPaths;
  840. for (int i = 0; i < 10; i++) {
  841. QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
  842. if (!p.isEmpty()) {
  843. buildPaths.append(p);
  844. }
  845. }
  846. return buildPaths;
  847. }
  848. void CMakeSetupDialog::saveBuildPaths(const QStringList& paths)
  849. {
  850. QSettings settings;
  851. settings.beginGroup("Settings/StartPath");
  852. int num = paths.count();
  853. if (num > 10) {
  854. num = 10;
  855. }
  856. for (int i = 0; i < num; i++) {
  857. settings.setValue(QString("WhereBuild%1").arg(i), paths[i]);
  858. }
  859. }
  860. void CMakeSetupDialog::setCacheModified()
  861. {
  862. this->CacheModified = true;
  863. this->ConfigureNeeded = true;
  864. this->enterState(ReadyConfigure);
  865. }
  866. void CMakeSetupDialog::removeSelectedCacheEntries()
  867. {
  868. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  869. QList<QPersistentModelIndex> pidxs;
  870. foreach (QModelIndex i, idxs) {
  871. pidxs.append(i);
  872. }
  873. foreach (QPersistentModelIndex pi, pidxs) {
  874. this->CacheValues->model()->removeRow(pi.row(), pi.parent());
  875. }
  876. }
  877. void CMakeSetupDialog::selectionChanged()
  878. {
  879. QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
  880. if (idxs.count() && (this->CurrentState == ReadyConfigure ||
  881. this->CurrentState == ReadyGenerate)) {
  882. this->RemoveEntry->setEnabled(true);
  883. } else {
  884. this->RemoveEntry->setEnabled(false);
  885. }
  886. }
  887. void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
  888. {
  889. if (s == this->CurrentState) {
  890. return;
  891. }
  892. this->CurrentState = s;
  893. if (s == Interrupting) {
  894. this->ConfigureButton->setEnabled(false);
  895. this->GenerateButton->setEnabled(false);
  896. this->OpenProjectButton->setEnabled(false);
  897. } else if (s == Configuring) {
  898. this->setEnabledState(false);
  899. this->GenerateButton->setEnabled(false);
  900. this->GenerateAction->setEnabled(false);
  901. this->OpenProjectButton->setEnabled(false);
  902. this->ConfigureButton->setText(tr("&Stop"));
  903. } else if (s == Generating) {
  904. this->CacheModified = false;
  905. this->setEnabledState(false);
  906. this->ConfigureButton->setEnabled(false);
  907. this->GenerateAction->setEnabled(false);
  908. this->OpenProjectButton->setEnabled(false);
  909. this->GenerateButton->setText(tr("&Stop"));
  910. } else if (s == ReadyConfigure) {
  911. this->setEnabledState(true);
  912. this->GenerateButton->setEnabled(true);
  913. this->GenerateAction->setEnabled(true);
  914. this->ConfigureButton->setEnabled(true);
  915. if (!this->getProjectFilename().isEmpty()) {
  916. this->OpenProjectButton->setEnabled(true);
  917. }
  918. this->ConfigureButton->setText(tr("&Configure"));
  919. this->GenerateButton->setText(tr("&Generate"));
  920. } else if (s == ReadyGenerate) {
  921. this->setEnabledState(true);
  922. this->GenerateButton->setEnabled(true);
  923. this->GenerateAction->setEnabled(true);
  924. this->ConfigureButton->setEnabled(true);
  925. if (!this->getProjectFilename().isEmpty()) {
  926. this->OpenProjectButton->setEnabled(true);
  927. }
  928. this->ConfigureButton->setText(tr("&Configure"));
  929. this->GenerateButton->setText(tr("&Generate"));
  930. }
  931. }
  932. void CMakeSetupDialog::addCacheEntry()
  933. {
  934. QDialog dialog(this);
  935. dialog.resize(400, 200);
  936. dialog.setWindowTitle(tr("Add Cache Entry"));
  937. QVBoxLayout* l = new QVBoxLayout(&dialog);
  938. AddCacheEntry* w =
  939. new AddCacheEntry(&dialog, this->AddVariableNames, this->AddVariableTypes);
  940. QDialogButtonBox* btns = new QDialogButtonBox(
  941. QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
  942. QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
  943. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(reject()));
  944. l->addWidget(w);
  945. l->addStretch();
  946. l->addWidget(btns);
  947. if (QDialog::Accepted == dialog.exec()) {
  948. QCMakeCacheModel* m = this->CacheValues->cacheModel();
  949. m->insertProperty(w->type(), w->name(), w->description(), w->value(),
  950. false);
  951. // only add variable names to the completion which are new
  952. if (!this->AddVariableNames.contains(w->name())) {
  953. this->AddVariableNames << w->name();
  954. this->AddVariableTypes << w->typeString();
  955. // limit to at most 100 completion items
  956. if (this->AddVariableNames.size() > 100) {
  957. this->AddVariableNames.removeFirst();
  958. this->AddVariableTypes.removeFirst();
  959. }
  960. // make sure CMAKE_INSTALL_PREFIX is always there
  961. if (!this->AddVariableNames.contains("CMAKE_INSTALL_PREFIX")) {
  962. this->AddVariableNames << "CMAKE_INSTALL_PREFIX";
  963. this->AddVariableTypes << "PATH";
  964. }
  965. QSettings settings;
  966. settings.beginGroup("Settings/StartPath");
  967. settings.setValue("AddVariableNames", this->AddVariableNames);
  968. settings.setValue("AddVariableTypes", this->AddVariableTypes);
  969. }
  970. }
  971. }
  972. void CMakeSetupDialog::startSearch()
  973. {
  974. this->Search->setFocus(Qt::OtherFocusReason);
  975. this->Search->selectAll();
  976. }
  977. void CMakeSetupDialog::setDebugOutput(bool flag)
  978. {
  979. QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
  980. "setDebugOutput", Qt::QueuedConnection,
  981. Q_ARG(bool, flag));
  982. }
  983. void CMakeSetupDialog::setGroupedView(bool v)
  984. {
  985. this->CacheValues->cacheModel()->setViewType(v ? QCMakeCacheModel::GroupView
  986. : QCMakeCacheModel::FlatView);
  987. this->CacheValues->setRootIsDecorated(v);
  988. QSettings settings;
  989. settings.beginGroup("Settings/StartPath");
  990. settings.setValue("GroupView", v);
  991. }
  992. void CMakeSetupDialog::setAdvancedView(bool v)
  993. {
  994. this->CacheValues->setShowAdvanced(v);
  995. QSettings settings;
  996. settings.beginGroup("Settings/StartPath");
  997. settings.setValue("AdvancedView", v);
  998. }
  999. void CMakeSetupDialog::showUserChanges()
  1000. {
  1001. QSet<QCMakeProperty> changes =
  1002. qobject_cast<QCMakeCacheModelDelegate*>(this->CacheValues->itemDelegate())
  1003. ->changes();
  1004. QDialog dialog(this);
  1005. dialog.setWindowTitle(tr("My Changes"));
  1006. dialog.resize(600, 400);
  1007. QVBoxLayout* l = new QVBoxLayout(&dialog);
  1008. QTextEdit* textedit = new QTextEdit(&dialog);
  1009. textedit->setReadOnly(true);
  1010. l->addWidget(textedit);
  1011. QDialogButtonBox* btns =
  1012. new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
  1013. QObject::connect(btns, SIGNAL(rejected()), &dialog, SLOT(accept()));
  1014. l->addWidget(btns);
  1015. QString command;
  1016. QString cache;
  1017. foreach (QCMakeProperty prop, changes) {
  1018. QString type;
  1019. switch (prop.Type) {
  1020. case QCMakeProperty::BOOL:
  1021. type = "BOOL";
  1022. break;
  1023. case QCMakeProperty::PATH:
  1024. type = "PATH";
  1025. break;
  1026. case QCMakeProperty::FILEPATH:
  1027. type = "FILEPATH";
  1028. break;
  1029. case QCMakeProperty::STRING:
  1030. type = "STRING";
  1031. break;
  1032. }
  1033. QString value;
  1034. if (prop.Type == QCMakeProperty::BOOL) {
  1035. value = prop.Value.toBool() ? "1" : "0";
  1036. } else {
  1037. value = prop.Value.toString();
  1038. }
  1039. QString line("%1:%2=");
  1040. line = line.arg(prop.Key);
  1041. line = line.arg(type);
  1042. command += QString("-D%1\"%2\" ").arg(line).arg(value);
  1043. cache += QString("%1%2\n").arg(line).arg(value);
  1044. }
  1045. textedit->append(tr("Commandline options:"));
  1046. textedit->append(command);
  1047. textedit->append("\n");
  1048. textedit->append(tr("Cache file:"));
  1049. textedit->append(cache);
  1050. dialog.exec();
  1051. }
  1052. void CMakeSetupDialog::setSearchFilter(const QString& str)
  1053. {
  1054. this->CacheValues->selectionModel()->clear();
  1055. this->CacheValues->setSearchFilter(str);
  1056. }
  1057. void CMakeSetupDialog::doOutputContextMenu(const QPoint& pt)
  1058. {
  1059. QMenu* menu = this->Output->createStandardContextMenu();
  1060. menu->addSeparator();
  1061. menu->addAction(tr("Find..."), this, SLOT(doOutputFindDialog()),
  1062. QKeySequence::Find);
  1063. menu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()),
  1064. QKeySequence::FindNext);
  1065. menu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()),
  1066. QKeySequence::FindPrevious);
  1067. menu->addSeparator();
  1068. menu->addAction(tr("Goto Next Error"), this, SLOT(doOutputErrorNext()),
  1069. QKeySequence(Qt::Key_F8));
  1070. menu->exec(this->Output->mapToGlobal(pt));
  1071. delete menu;
  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. }