CMakeSetupDialog.cxx 43 KB

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