CMakeSetupDialog.cxx 43 KB

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