CMakeSetupFrame.cpp 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. /*=========================================================================
  2. Program: WXDialog - wxWidgets X-platform GUI Front-End for CMake
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Jorgen Bodde
  8. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  9. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notices for more information.
  13. =========================================================================*/
  14. #if defined(__GNUG__) && !defined(__APPLE__)
  15. #pragma implementation "CMakeSetupFrame.h"
  16. #endif
  17. // For compilers that support precompilation, includes "wx/wx.h".
  18. #include "wx/wxprec.h"
  19. #ifdef __BORLANDC__
  20. #pragma hdrstop
  21. #endif
  22. #ifndef WX_PRECOMP
  23. #include "wx/wx.h"
  24. #endif
  25. ////@begin includes
  26. ////@end includes
  27. #include <wx/dirdlg.h>
  28. #include <wx/msgdlg.h>
  29. #include <wx/filename.h>
  30. #include "CMakeSetupFrame.h"
  31. #include "PropertyList.h"
  32. #include "app_resources.h"
  33. #include "CMakeIcon.xpm"
  34. #include "aboutdlg.h"
  35. // cmake includes
  36. #include "../cmVersion.h"
  37. #include "../cmListFileCache.h"
  38. #include "../cmCacheManager.h"
  39. #include "../cmGlobalGenerator.h"
  40. #include "../cmDynamicLoader.h"
  41. ////@begin XPM images
  42. ////@end XPM images
  43. /*!
  44. * CMakeSetupFrm type definition
  45. */
  46. IMPLEMENT_CLASS( CMakeSetupFrm, wxFrame )
  47. /*!
  48. * CMakeSetupFrm event table definition
  49. */
  50. BEGIN_EVENT_TABLE( CMakeSetupFrm, wxFrame )
  51. ////@begin CMakeSetupFrm event table entries
  52. EVT_CLOSE( CMakeSetupFrm::OnCloseWindow )
  53. EVT_SPLITTER_SASH_POS_CHANGING( ID_SPLITTERWINDOW, CMakeSetupFrm::OnSplitterPosChanging )
  54. EVT_SPLITTER_DCLICK( ID_SPLITTERWINDOW, CMakeSetupFrm::OnSplitterwindowSashDClick )
  55. EVT_BUTTON( ID_BROWSE_PROJECT, CMakeSetupFrm::OnButtonBrowseProject )
  56. EVT_TEXT( ID_SOURCE_BUILD_PATH, CMakeSetupFrm::OnSourceBuildPathUpdated )
  57. EVT_TEXT_ENTER( ID_SOURCE_BUILD_PATH, CMakeSetupFrm::OnSourceBuildPathEnter )
  58. EVT_BUTTON( ID_BROWSE_BUILD, CMakeSetupFrm::OnButtonBrowseBuild )
  59. EVT_COMBOBOX( ID_SEARCHQUERY, CMakeSetupFrm::OnSearchquerySelected )
  60. EVT_TEXT( ID_SEARCHQUERY, CMakeSetupFrm::OnSearchqueryUpdated )
  61. EVT_CHECKBOX( ID_SHOW_ADVANCED, CMakeSetupFrm::OnShowAdvancedValues )
  62. EVT_GRID_CELL_CHANGE( CMakeSetupFrm::OnCellChange )
  63. EVT_GRID_SELECT_CELL( CMakeSetupFrm::OnGridSelectCell )
  64. EVT_MOTION( CMakeSetupFrm::OnPropertyMotion )
  65. EVT_BUTTON( ID_DO_CONFIGURE, CMakeSetupFrm::OnButtonConfigure )
  66. EVT_BUTTON( ID_DO_OK, CMakeSetupFrm::OnButtonOk )
  67. EVT_BUTTON( ID_DO_CANCEL, CMakeSetupFrm::OnButtonCancel )
  68. EVT_BUTTON( ID_DO_DELETE_CACHE, CMakeSetupFrm::OnButtonDeleteCache )
  69. EVT_BUTTON( ID_CLEAR_LOG, CMakeSetupFrm::OnClearLogClick )
  70. EVT_BUTTON( ID_BROWSE_GRID, CMakeSetupFrm::OnBrowseGridClick )
  71. EVT_MENU( ID_MENU_RELOAD_CACHE, CMakeSetupFrm::OnMenuReloadCacheClick )
  72. EVT_MENU( ID_MENU_DELETE_CACHE, CMakeSetupFrm::OnMenuDeleteCacheClick )
  73. EVT_MENU( ID_MENU_QUIT, CMakeSetupFrm::OnMenuQuitClick )
  74. EVT_MENU( ID_MENU_CONFIGURE, CMakeSetupFrm::OnMenuConfigureClick )
  75. EVT_MENU( ID_MENU_EXITGENERATE, CMakeSetupFrm::OnMenuGenerateClick )
  76. EVT_MENU( ID_MENU_TOGGLE_ADVANCED, CMakeSetupFrm::OnMenuToggleAdvancedClick )
  77. EVT_MENU( ID_CMAKE_OPTIONS, CMakeSetupFrm::OnOptionsClick )
  78. EVT_MENU( ID_ABOUTDLG, CMakeSetupFrm::OnAboutClick )
  79. ////@end CMakeSetupFrm event table entries
  80. EVT_MENU_RANGE(CM_RECENT_BUILD_ITEM, CM_RECENT_BUILD_ITEM + CM_MAX_RECENT_PATHS, CMakeSetupFrm::OnRecentFileMenu)
  81. EVT_TEXT_ENTER(ID_SEARCHQUERY, CMakeSetupFrm::OnAddQuery )
  82. END_EVENT_TABLE()
  83. /** Callback function for CMake generator, to tell user how
  84. far the generation actually is */
  85. void updateProgress(const char *msg, float prog, void *cd)
  86. {
  87. // TODO: Make some kind of progress counter
  88. CMakeSetupFrm *fm = (CMakeSetupFrm *)cd;
  89. if(fm)
  90. {
  91. if(prog < 0)
  92. fm->LogMessage(0, msg);
  93. else
  94. {
  95. fm->UpdateProgress(prog);
  96. fm->IssueUpdate();
  97. }
  98. }
  99. }
  100. /** Callback function for CMake generator, to tell user about stuff. This should be
  101. logged in the m_log window */
  102. void MFCMessageCallback(const char* m, const char* title, bool& nomore, void *clientdata)
  103. {
  104. CMakeSetupFrm *fm = (CMakeSetupFrm *)clientdata;
  105. if(fm)
  106. {
  107. wxString what = m, msg;
  108. if(what.StartsWith("CMake Error: "))
  109. fm->LogMessage(-1, m);
  110. else
  111. fm->LogMessage(1, m);
  112. }
  113. }
  114. // Convert to Win32 path (slashes). This calls the system tools one and then
  115. // removes the spaces. It is not in system tools because we don't want any
  116. // generators accidentally use it
  117. std::string ConvertToWindowsPath(const char* path)
  118. {
  119. // Convert to output path.
  120. // Remove the "" around it (if any) since it's an output path for
  121. // the shell. If another shell-oriented feature is not designed
  122. // for a GUI use, then we are in trouble.
  123. // save the value of the force to unix path option
  124. bool saveForce = cmSystemTools::GetForceUnixPaths();
  125. // make sure we get windows paths no matter what for the GUI
  126. cmSystemTools::SetForceUnixPaths(false);
  127. std::string s = cmSystemTools::ConvertToOutputPath(path);
  128. // now restore the force unix path to its previous value
  129. cmSystemTools::SetForceUnixPaths(saveForce);
  130. if (s.size())
  131. {
  132. std::string::iterator i = s.begin();
  133. if (*i == '\"')
  134. {
  135. s.erase(i, i + 1);
  136. }
  137. i = s.begin() + s.length() - 1;
  138. if (*i == '\"')
  139. {
  140. s.erase(i, i + 1);
  141. }
  142. }
  143. return s;
  144. }
  145. bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString& filenames)
  146. {
  147. size_t nFiles = filenames.GetCount();
  148. // only one item allowed
  149. if(nFiles > 1)
  150. return false;
  151. if(nFiles == 1)
  152. {
  153. // only one dir allowed
  154. if(!wxDirExists(filenames[0]))
  155. return false;
  156. // strip the seperator
  157. wxFileName name;
  158. name.AssignDir(filenames[0]);
  159. // issue a 'drop' by changing text ctrl
  160. m_pOwner->SetValue(name.GetFullPath());
  161. return true;
  162. }
  163. return false;
  164. }
  165. /*!
  166. * CMakeSetupFrm constructors
  167. */
  168. CMakeSetupFrm::CMakeSetupFrm( )
  169. : m_cmake(0)
  170. {
  171. }
  172. CMakeSetupFrm::CMakeSetupFrm( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
  173. : m_cmake(0)
  174. {
  175. Create( parent, id, caption, pos, size, style );
  176. }
  177. /*!
  178. * CMakeSetupFrm creator
  179. */
  180. bool CMakeSetupFrm::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
  181. {
  182. ////@begin CMakeSetupFrm member initialisation
  183. m_splitter = NULL;
  184. m_cmProjectPath = NULL;
  185. m_BrowseProjectPathButton = NULL;
  186. m_cmBuildPath = NULL;
  187. m_BrowseSourcePathButton = NULL;
  188. m_cmGeneratorChoice = NULL;
  189. m_cmSearchQuery = NULL;
  190. m_cmShowAdvanced = NULL;
  191. m_cmOptions = NULL;
  192. m_cmLog = NULL;
  193. m_cmDescription = NULL;
  194. m_ConfigureButton = NULL;
  195. m_OkButton = NULL;
  196. m_CancelButton = NULL;
  197. m_DeleteCacheButton = NULL;
  198. m_ClearLogButton = NULL;
  199. m_cmBrowseCell = NULL;
  200. ////@end CMakeSetupFrm member initialisation
  201. wxFrame::Create( parent, id, caption, pos, size, style );
  202. // make sure the developer does not assign more then 100
  203. // would be rediculous but also overlap other id's
  204. wxASSERT(CM_MAX_RECENT_PATHS < 100);
  205. m_ExitTimer = 0;
  206. m_progressDlg = 0;
  207. m_noRefresh = false;
  208. m_quitAfterGenerating = false;
  209. m_config = new wxConfig("CMakeSetup");
  210. wxIcon icon(CMakeIcon_xpm);
  211. SetIcon(icon);
  212. CreateControls();
  213. //SetIcon(GetIconResource(wxT("cmake_icon.xpm")));
  214. //SetIcon(wxIcon("NGDialog.ico", wxBITMAP_TYPE_ICO_RESOURCE));
  215. Centre();
  216. // is it needed to hide console?
  217. m_RunningConfigure = false;
  218. cmSystemTools::SetRunCommandHideConsole(true);
  219. cmSystemTools::SetErrorCallback(MFCMessageCallback, (void *)this);
  220. // create our cmake instance
  221. m_cmake = new cmake;
  222. m_cmake->SetProgressCallback(updateProgress, (void *)this);
  223. return TRUE;
  224. }
  225. CMakeSetupFrm::~CMakeSetupFrm()
  226. {
  227. wxString str;
  228. // write configs back to disk
  229. m_config->Write(CM_LASTPROJECT_PATH, m_cmProjectPath->GetValue());
  230. m_config->Write(CM_LASTBUILD_PATH, m_cmBuildPath->GetValue());
  231. // clear the config first
  232. for(size_t i = 0 ; i < CM_MAX_RECENT_PATHS; i++)
  233. {
  234. str.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
  235. m_config->Write(str, _(""));
  236. }
  237. // write the last CM_MAX_RECENT_PATHS items back to config
  238. int i = (m_recentPaths.Count() >= CM_MAX_RECENT_PATHS ? CM_MAX_RECENT_PATHS : m_recentPaths.Count());
  239. while(i > 0)
  240. {
  241. str.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
  242. m_config->Write(str, m_recentPaths[i - 1]);
  243. i--;
  244. }
  245. // write recent query list to config
  246. for(int j = 0; j < m_cmSearchQuery->GetCount(); j++)
  247. {
  248. // allow max to be written
  249. if(j < CM_MAX_SEARCH_QUERIES)
  250. {
  251. str.Printf("%s%i", _(CM_SEARCH_QUERY), j);
  252. m_config->Write(str, m_cmSearchQuery->GetString(j));
  253. }
  254. else
  255. break;
  256. }
  257. // set window pos + size in settings
  258. if(!IsIconized() && !IsMaximized())
  259. {
  260. int xsize, ysize;
  261. GetSize(&xsize, &ysize);
  262. if(xsize > 0 && ysize > 0)
  263. {
  264. m_config->Write(CM_XSIZE, (long)xsize);
  265. m_config->Write(CM_YSIZE, (long)ysize);
  266. }
  267. if(m_splitter->GetSashPosition() > 0)
  268. m_config->Write(CM_SPLITTERPOS, (long)m_splitter->GetSashPosition());
  269. GetPosition(&xsize, &ysize);
  270. if(xsize != 0 && ysize != 0)
  271. {
  272. m_config->Write(CM_XPOS, (long)xsize);
  273. m_config->Write(CM_YPOS, (long)ysize);
  274. }
  275. }
  276. // write changes (will be done before deletion)
  277. delete m_config;
  278. // delete timer
  279. if(m_ExitTimer)
  280. delete m_ExitTimer;
  281. // delete our cmake instance again
  282. if(m_cmake)
  283. delete m_cmake;
  284. }
  285. void CMakeSetupFrm::UpdateWindowState()
  286. {
  287. bool dogenerate = !m_RunningConfigure && !m_cmOptions->IsCacheDirty() &&
  288. (m_cmOptions->GetCount() != 0);
  289. // when configure is running, disable a lot of stuff
  290. m_cmProjectPath->Enable(!m_RunningConfigure);
  291. m_BrowseProjectPathButton->Enable(!m_RunningConfigure);
  292. m_cmBuildPath->Enable(!m_RunningConfigure);
  293. m_BrowseSourcePathButton->Enable(!m_RunningConfigure);
  294. m_cmGeneratorChoice->Enable(!m_RunningConfigure);
  295. m_cmShowAdvanced->Enable(!m_RunningConfigure);
  296. m_cmOptions->Enable(!m_RunningConfigure);
  297. m_ConfigureButton->Enable(!m_RunningConfigure);
  298. m_OkButton->Enable(dogenerate);
  299. m_CancelButton->Enable(m_RunningConfigure);
  300. m_DeleteCacheButton->Enable(!m_RunningConfigure);
  301. m_ClearLogButton->Enable(!m_RunningConfigure);
  302. if(m_RunningConfigure)
  303. m_cmBrowseCell->Enable(false);
  304. // when cache loaded (items available show other control)
  305. m_cmGeneratorChoice->Enable(m_cmOptions->GetCount() == 0 && !m_RunningConfigure);
  306. m_cmSearchQuery->Enable(!m_RunningConfigure);
  307. m_cmBrowseCell->Enable(!m_RunningConfigure && m_cmOptions->IsSelectedItemBrowsable());
  308. // disable the menus when configuring
  309. if(GetMenuBar())
  310. {
  311. // disable configure button when there is nothing, and generate and exit
  312. // only when it is allowed to generate
  313. GetMenuBar()->Enable(ID_MENU_EXITGENERATE, dogenerate);
  314. GetMenuBar()->Enable(ID_MENU_CONFIGURE, !m_RunningConfigure);
  315. for(size_t i = 0; i < GetMenuBar()->GetMenuCount(); i++)
  316. GetMenuBar()->EnableTop(i, !m_RunningConfigure);
  317. }
  318. }
  319. void CMakeSetupFrm::LogMessage(int logkind, const char *msg)
  320. {
  321. // put CR first but prevent a CR at the end
  322. #ifndef __LINUX__
  323. if(m_cmLog->IsModified())
  324. (*m_cmLog) << wxT("\n");
  325. #else
  326. // Linux requires a different approach
  327. if(!m_cmLog->GetValue().IsEmpty())
  328. (*m_cmLog) << wxT("\n");
  329. #endif
  330. // log error, warning, or message
  331. wxTextAttr defattr = m_cmLog->GetDefaultStyle();
  332. switch(logkind)
  333. {
  334. // user message
  335. case 1:
  336. {
  337. wxTextAttr colattr(*wxBLUE);
  338. m_cmLog->SetDefaultStyle(colattr);
  339. (*m_cmLog) << msg;
  340. m_cmLog->SetDefaultStyle(defattr);
  341. }
  342. break;
  343. // progress
  344. case 0:
  345. (*m_cmLog) << msg;
  346. break;
  347. // error
  348. case -1:
  349. {
  350. wxTextAttr colattr(*wxRED);
  351. m_cmLog->SetDefaultStyle(colattr);
  352. (*m_cmLog) << msg;
  353. m_cmLog->SetDefaultStyle(defattr);
  354. }
  355. break;
  356. }
  357. IssueUpdate();
  358. }
  359. void CMakeSetupFrm::IssueUpdate()
  360. {
  361. //::wxSafeYield(m_CancelButton, true);
  362. ::wxYield();
  363. // when we pressed cancel on the progress dialog
  364. // stop all activities
  365. if(m_progressDlg)
  366. {
  367. if(m_progressDlg->CancelPressed() && !m_progressDlg->IsCancelling())
  368. {
  369. m_progressDlg->CancelAcknowledged();
  370. // send a button event to cancel the progress
  371. wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, ID_DO_CANCEL);
  372. wxPostEvent(this, event);
  373. }
  374. }
  375. }
  376. /*!
  377. * Control creation for CMakeSetupFrm
  378. */
  379. void CMakeSetupFrm::CreateControls()
  380. {
  381. ////@begin CMakeSetupFrm content construction
  382. CMakeSetupFrm* itemFrame1 = this;
  383. wxMenuBar* menuBar = new wxMenuBar;
  384. wxMenu* itemMenu37 = new wxMenu;
  385. itemMenu37->Append(ID_MENU_RELOAD_CACHE, _("&Reload Cache\tCtrl+R"), _("Reload the cache from disk"), wxITEM_NORMAL);
  386. itemMenu37->Append(ID_MENU_DELETE_CACHE, _("&Delete Cache\tCtrl+D"), _("Delete the cache on disk of the current path"), wxITEM_NORMAL);
  387. itemMenu37->AppendSeparator();
  388. itemMenu37->Append(ID_MENU_QUIT, _("E&xit\tAlt+F4"), _("Quit CMake Setup"), wxITEM_NORMAL);
  389. menuBar->Append(itemMenu37, _("&File"));
  390. wxMenu* itemMenu42 = new wxMenu;
  391. itemMenu42->Append(ID_MENU_CONFIGURE, _("&Configure\tCtrl+N"), _T(""), wxITEM_NORMAL);
  392. itemMenu42->Append(ID_MENU_EXITGENERATE, _("&Generate and Exit\tCtrl+G"), _T(""), wxITEM_NORMAL);
  393. itemMenu42->Append(ID_MENU_TOGGLE_ADVANCED, _("Toggle &Advanced\tCtrl+A"), _T(""), wxITEM_NORMAL);
  394. itemMenu42->AppendSeparator();
  395. itemMenu42->Append(ID_CMAKE_OPTIONS, _("&Options\tCtrl+O"), _T(""), wxITEM_NORMAL);
  396. menuBar->Append(itemMenu42, _("&Tools"));
  397. wxMenu* itemMenu48 = new wxMenu;
  398. itemMenu48->Append(ID_ABOUTDLG, _("&About ..."), _("Shows the about dialog ..."), wxITEM_NORMAL);
  399. menuBar->Append(itemMenu48, _("&Help"));
  400. itemFrame1->SetMenuBar(menuBar);
  401. m_splitter = new wxSplitterWindow( itemFrame1, ID_SPLITTERWINDOW, wxDefaultPosition, wxSize(100, 100), wxSP_3DBORDER|wxSP_3DSASH|wxNO_BORDER );
  402. wxPanel* itemPanel3 = new wxPanel( m_splitter, ID_MAINPANEL, wxDefaultPosition, wxSize(600, 400), wxNO_BORDER|wxTAB_TRAVERSAL );
  403. itemPanel3->SetExtraStyle(itemPanel3->GetExtraStyle()|wxWS_EX_VALIDATE_RECURSIVELY);
  404. wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
  405. itemPanel3->SetSizer(itemBoxSizer4);
  406. wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
  407. itemBoxSizer4->Add(itemBoxSizer5, 0, wxGROW|wxTOP|wxBOTTOM, 5);
  408. wxFlexGridSizer* itemFlexGridSizer6 = new wxFlexGridSizer(2, 3, 0, 0);
  409. itemFlexGridSizer6->AddGrowableRow(1);
  410. itemFlexGridSizer6->AddGrowableCol(1);
  411. itemBoxSizer5->Add(itemFlexGridSizer6, 1, wxALIGN_TOP|wxLEFT, 5);
  412. wxStaticText* itemStaticText7 = new wxStaticText( itemPanel3, wxID_STATIC, _("CMake project path"), wxDefaultPosition, wxDefaultSize, 0 );
  413. itemFlexGridSizer6->Add(itemStaticText7, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
  414. m_cmProjectPath = new wxTextCtrl( itemPanel3, ID_PROJECT_PATH, _T(""), wxDefaultPosition, wxSize(50, -1), 0 );
  415. itemFlexGridSizer6->Add(m_cmProjectPath, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
  416. m_BrowseProjectPathButton = new wxButton( itemPanel3, ID_BROWSE_PROJECT, _("Browse"), wxDefaultPosition, wxSize(55, -1), 0 );
  417. itemFlexGridSizer6->Add(m_BrowseProjectPathButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
  418. wxStaticText* itemStaticText10 = new wxStaticText( itemPanel3, wxID_STATIC, _("Project build path"), wxDefaultPosition, wxDefaultSize, 0 );
  419. itemFlexGridSizer6->Add(itemStaticText10, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5);
  420. m_cmBuildPath = new wxTextCtrl( itemPanel3, ID_SOURCE_BUILD_PATH, _T(""), wxDefaultPosition, wxSize(50, -1), 0 );
  421. itemFlexGridSizer6->Add(m_cmBuildPath, 1, wxGROW|wxALIGN_TOP|wxTOP|wxBOTTOM, 5);
  422. m_BrowseSourcePathButton = new wxButton( itemPanel3, ID_BROWSE_BUILD, _("Browse"), wxDefaultPosition, wxSize(55, -1), 0 );
  423. itemFlexGridSizer6->Add(m_BrowseSourcePathButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
  424. wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxVERTICAL);
  425. itemBoxSizer5->Add(itemBoxSizer13, 0, wxGROW|wxLEFT|wxRIGHT, 5);
  426. wxFlexGridSizer* itemFlexGridSizer14 = new wxFlexGridSizer(2, 2, 0, 0);
  427. itemBoxSizer13->Add(itemFlexGridSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
  428. wxStaticText* itemStaticText15 = new wxStaticText( itemPanel3, wxID_STATIC, _("Generate"), wxDefaultPosition, wxDefaultSize, 0 );
  429. itemFlexGridSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxADJUST_MINSIZE, 5);
  430. wxString* m_cmGeneratorChoiceStrings = NULL;
  431. m_cmGeneratorChoice = new wxComboBox( itemPanel3, ID_CHOOSE_GENERATOR, _T(""), wxDefaultPosition, wxSize(170, -1), 0, m_cmGeneratorChoiceStrings, wxCB_READONLY );
  432. itemFlexGridSizer14->Add(m_cmGeneratorChoice, 1, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxTOP|wxBOTTOM, 5);
  433. wxStaticText* itemStaticText17 = new wxStaticText( itemPanel3, wxID_STATIC, _("Search"), wxDefaultPosition, wxDefaultSize, 0 );
  434. itemFlexGridSizer14->Add(itemStaticText17, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT|wxADJUST_MINSIZE, 5);
  435. wxString* m_cmSearchQueryStrings = NULL;
  436. m_cmSearchQuery = new wxComboBox( itemPanel3, ID_SEARCHQUERY, _T(""), wxDefaultPosition, wxSize(170, -1), 0, m_cmSearchQueryStrings, wxWANTS_CHARS );
  437. itemFlexGridSizer14->Add(m_cmSearchQuery, 1, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxTOP|wxBOTTOM, 5);
  438. m_cmShowAdvanced = new wxCheckBox( itemPanel3, ID_SHOW_ADVANCED, _("Show advanced values"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE );
  439. m_cmShowAdvanced->SetValue(FALSE);
  440. itemBoxSizer13->Add(m_cmShowAdvanced, 0, wxALIGN_RIGHT|wxLEFT|wxRIGHT, 5);
  441. m_cmOptions = new wxPropertyList( itemPanel3, ID_OPTIONS, wxDefaultPosition, wxSize(200, 150), wxSTATIC_BORDER|wxWANTS_CHARS|wxVSCROLL );
  442. m_cmOptions->SetDefaultColSize(250);
  443. m_cmOptions->SetDefaultRowSize(25);
  444. m_cmOptions->SetColLabelSize(20);
  445. m_cmOptions->SetRowLabelSize(0);
  446. m_cmOptions->CreateGrid(10, 2, wxGrid::wxGridSelectRows);
  447. itemBoxSizer4->Add(m_cmOptions, 1, wxGROW|wxALL, 5);
  448. wxPanel* itemPanel21 = new wxPanel( m_splitter, ID_LOGPANEL, wxDefaultPosition, wxSize(-1, 100), wxNO_BORDER|wxTAB_TRAVERSAL );
  449. wxBoxSizer* itemBoxSizer22 = new wxBoxSizer(wxVERTICAL);
  450. itemPanel21->SetSizer(itemBoxSizer22);
  451. wxBoxSizer* itemBoxSizer23 = new wxBoxSizer(wxHORIZONTAL);
  452. itemBoxSizer22->Add(itemBoxSizer23, 1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
  453. m_cmLog = new wxTextCtrl( itemPanel21, ID_LOG_AREA, _("Select your project path (where CMakeLists.txt is) and then select the build path (where the projects should be saved), or select a previous build path.\n\nRight click on a cache value for additional options (delete and ignore). Press configure to update and display new values in red, press OK to generate the projects and exit."), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH2|wxSTATIC_BORDER );
  454. itemBoxSizer23->Add(m_cmLog, 1, wxGROW|wxRIGHT, 5);
  455. m_cmDescription = new wxTextCtrl( itemPanel21, ID_DESCRIPTION, _T(""), wxDefaultPosition, wxSize(200, -1), wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH2|wxSTATIC_BORDER );
  456. itemBoxSizer23->Add(m_cmDescription, 0, wxGROW|wxLEFT, 5);
  457. wxBoxSizer* itemBoxSizer26 = new wxBoxSizer(wxHORIZONTAL);
  458. itemBoxSizer22->Add(itemBoxSizer26, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
  459. m_ConfigureButton = new wxButton( itemPanel21, ID_DO_CONFIGURE, _("Co&nfigure"), wxDefaultPosition, wxDefaultSize, 0 );
  460. m_ConfigureButton->SetDefault();
  461. itemBoxSizer26->Add(m_ConfigureButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  462. m_OkButton = new wxButton( itemPanel21, ID_DO_OK, _("&Generate!"), wxDefaultPosition, wxDefaultSize, 0 );
  463. itemBoxSizer26->Add(m_OkButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  464. m_CancelButton = new wxButton( itemPanel21, ID_DO_CANCEL, _("C&ancel"), wxDefaultPosition, wxDefaultSize, 0 );
  465. itemBoxSizer26->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  466. #if defined(__WXMSW__)
  467. wxStaticLine* itemStaticLine30 = new wxStaticLine( itemPanel21, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
  468. itemBoxSizer26->Add(itemStaticLine30, 0, wxGROW|wxALL, 5);
  469. #endif
  470. m_DeleteCacheButton = new wxButton( itemPanel21, ID_DO_DELETE_CACHE, _("&Delete Cache"), wxDefaultPosition, wxDefaultSize, 0 );
  471. itemBoxSizer26->Add(m_DeleteCacheButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  472. m_ClearLogButton = new wxButton( itemPanel21, ID_CLEAR_LOG, _("Clear &Log"), wxDefaultPosition, wxDefaultSize, 0 );
  473. itemBoxSizer26->Add(m_ClearLogButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  474. #if defined(__WXMSW__)
  475. wxStaticLine* itemStaticLine33 = new wxStaticLine( itemPanel21, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
  476. itemBoxSizer26->Add(itemStaticLine33, 0, wxGROW|wxALL, 5);
  477. #endif
  478. m_cmBrowseCell = new wxButton( itemPanel21, ID_BROWSE_GRID, _("&Browse"), wxDefaultPosition, wxDefaultSize, 0 );
  479. itemBoxSizer26->Add(m_cmBrowseCell, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  480. m_splitter->SplitHorizontally(itemPanel3, itemPanel21, 300);
  481. wxStatusBar* itemStatusBar35 = new wxStatusBar( itemFrame1, ID_STATUSBAR, wxST_SIZEGRIP|wxNO_BORDER );
  482. itemStatusBar35->SetFieldsCount(2);
  483. itemFrame1->SetStatusBar(itemStatusBar35);
  484. ////@end CMakeSetupFrm content construction
  485. }
  486. void CMakeSetupFrm::DoInitFrame(cmCommandLineInfo &cm, const wxString &fn)
  487. {
  488. // path to where cmake.exe is
  489. // m_PathToExecutable = cm.GetPathToExecutable().c_str();
  490. m_PathToExecutable = fn;
  491. // adjust size of last bar, to display % progress
  492. wxStatusBar *bar = GetStatusBar();
  493. if(bar)
  494. {
  495. wxASSERT(bar->GetFieldsCount() > 1);
  496. // fill all with -1. Why this way? because the count of the status bars
  497. // can change. All of the widths must be accounted for and initialised
  498. int *widths = new int[bar->GetFieldsCount()];
  499. for(int i = 0; i < bar->GetFieldsCount(); i++)
  500. widths[i] = -1;
  501. // the % field
  502. widths[1] = 75;
  503. bar->SetStatusWidths(bar->GetFieldsCount(), widths);
  504. delete widths;
  505. }
  506. wxString name, generator;
  507. std::vector<std::string> names;
  508. m_RunningConfigure = false;
  509. // set grid labels
  510. m_cmOptions->SetColLabelValue(0, wxT("Cache Name"));
  511. m_cmOptions->SetColLabelValue(1, wxT("Cache Value"));
  512. m_cmOptions->SetProjectGenerated(false);
  513. // set drop target
  514. m_cmOptions->SetDropTarget(new DnDFile(m_cmBuildPath));
  515. m_cmake->GetRegisteredGenerators(names);
  516. for(std::vector<std::string>::iterator i = names.begin(); i != names.end(); ++i)
  517. {
  518. name = i->c_str();
  519. m_cmGeneratorChoice->Append(name);
  520. }
  521. // sync advanced option with grid
  522. m_cmOptions->SetShowAdvanced(m_cmShowAdvanced->GetValue());
  523. // if we have a command line query that a generator
  524. // needs to be chosen instead of the default, take it
  525. bool foundGivenGenerator = false;
  526. if(!cm.m_GeneratorChoiceString.IsEmpty())
  527. {
  528. // set proper discovered generator
  529. foundGivenGenerator = m_cmGeneratorChoice->SetStringSelection(cm.m_GeneratorChoiceString);
  530. }
  531. // if none selected, we will see if VS8, VS7 or VS6 is present
  532. if(!foundGivenGenerator || m_cmGeneratorChoice->GetValue().IsEmpty())
  533. {
  534. std::string mp;
  535. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\Setup;Dbghelp_path]";
  536. cmSystemTools::ExpandRegistryValues(mp);
  537. if(mp != "/registry")
  538. generator = wxT("Visual Studio 8 2005");
  539. else
  540. {
  541. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1;InstallDir]";
  542. cmSystemTools::ExpandRegistryValues(mp);
  543. if (mp != "/registry")
  544. generator = wxT("Visual Studio 7 .NET 2003");
  545. else
  546. {
  547. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0;InstallDir]";
  548. cmSystemTools::ExpandRegistryValues(mp);
  549. if (mp != "/registry")
  550. generator = wxT("Visual Studio 7");
  551. else
  552. generator = wxT("Visual Studio 6");
  553. }
  554. }
  555. }
  556. // set proper discovered generator
  557. m_cmGeneratorChoice->SetStringSelection(generator);
  558. wxString str;
  559. str.Printf("CMake %s", cmVersion::GetCMakeVersion());
  560. str.Printf("CMakeSetup v%i.%i%s", CMAKEGUI_MAJORVER, CMAKEGUI_MINORVER, CMAKEGUI_ADDVER);
  561. SetTitle(str);
  562. wxString path;
  563. // get last 5 used projects
  564. for(size_t i = 0; i < CM_MAX_RECENT_PATHS; i++)
  565. {
  566. path.Printf("%s%i", _(CM_RECENT_BUILD_PATH), i);
  567. if(m_config->Read(path, &str))
  568. AppendPathToRecentList(str);
  569. }
  570. // get query items
  571. for(size_t i = 0; i < CM_MAX_SEARCH_QUERIES; i++)
  572. {
  573. path.Printf("%s%i", _(CM_SEARCH_QUERY), i);
  574. if(m_config->Read(path, &str))
  575. m_cmSearchQuery->Append(str);
  576. }
  577. // make sure the call to update grid is not executed
  578. m_noRefresh = true;
  579. m_cmSearchQuery->SetValue(_(""));
  580. m_noRefresh = false;
  581. // Get the parameters from the command line info
  582. // If an unknown parameter is found, try to interpret it too, since it
  583. // is likely to be a file dropped on the shortcut :)
  584. bool sourceDirLoaded = false,
  585. buildDirLoaded = false;
  586. if(cm.m_LastUnknownParameter.empty())
  587. {
  588. if(cm.m_WhereSource.size() > 0 )
  589. {
  590. m_cmProjectPath->SetValue(cm.m_WhereSource.c_str());
  591. sourceDirLoaded = true;
  592. }
  593. if (cm.m_WhereBuild.size() > 0 )
  594. {
  595. m_cmBuildPath->SetValue(cm.m_WhereBuild.c_str());
  596. buildDirLoaded = true;
  597. }
  598. m_cmShowAdvanced->SetValue(cm.m_AdvancedValues);
  599. }
  600. else
  601. {
  602. m_cmShowAdvanced->SetValue(false);
  603. // TODO: Interpret directory from dropped shortcut
  604. //this->ChangeDirectoriesFromFile(cmdInfo->m_LastUnknownParameter.c_str());
  605. }
  606. if (cm.m_ExitAfterLoad)
  607. {
  608. int id = GetId();
  609. m_ExitTimer = new wxTimer(this, id);
  610. m_ExitTimer->Start(3000);
  611. Connect( id, wxEVT_TIMER,(wxObjectEventFunction) &CMakeSetupFrm::OnExitTimer );
  612. }
  613. // retrieve settings, this needs to be done here
  614. // because writing to the m_cmBuildPath triggers a cache reload
  615. if(!sourceDirLoaded && m_config->Read(CM_LASTPROJECT_PATH, &str))
  616. m_cmProjectPath->SetValue(str);
  617. if(!buildDirLoaded)
  618. {
  619. m_cmOptions->RemoveAll();
  620. if(m_config->Read(CM_LASTBUILD_PATH, &str))
  621. m_cmBuildPath->SetValue(str);
  622. }
  623. // set window size from settings
  624. long xsize, ysize, splitpos;
  625. if(m_config->Read(CM_XSIZE, &xsize) && m_config->Read(CM_YSIZE, &ysize) &&
  626. m_config->Read(CM_SPLITTERPOS, &splitpos))
  627. {
  628. SetSize(xsize, ysize);
  629. m_splitter->SetSashPosition(splitpos);
  630. }
  631. if(m_config->Read(CM_XPOS, &xsize) && m_config->Read(CM_YPOS, &ysize))
  632. SetSize(xsize, ysize, -1, -1, wxSIZE_USE_EXISTING);
  633. UpdateWindowState();
  634. }
  635. void CMakeSetupFrm::LoadCacheFromDiskToGUI()
  636. {
  637. wxString builddir = m_cmBuildPath->GetValue();
  638. cmCacheManager *cachem = m_cmake->GetCacheManager();
  639. if(cachem && !builddir.Trim().IsEmpty())
  640. {
  641. if(cachem->LoadCache(builddir.c_str()))
  642. AppendPathToRecentList(builddir);
  643. // represent this cache in the grid, but not before we
  644. // wiped all of the old items
  645. FillCacheGUIFromCacheManager();
  646. // set the generator string to the one used in the cache
  647. cmCacheManager::CacheIterator it = cachem->GetCacheIterator("CMAKE_GENERATOR");
  648. if(!it.IsAtEnd())
  649. {
  650. wxString curGen = it.GetValue();
  651. m_cmGeneratorChoice->SetStringSelection(curGen);
  652. }
  653. }
  654. }
  655. void CMakeSetupFrm::AppendPathToRecentList(const wxString &p)
  656. {
  657. wxFileName path;
  658. wxString str;
  659. if(p.IsEmpty())
  660. return;
  661. // cheap way to get rid of trailing seperators
  662. path.AssignDir(p);
  663. str = path.GetPath();
  664. // append the item, or add it to end to make sure
  665. // it is remembered between sessions
  666. for(size_t i = 0; i < m_recentPaths.Count(); i++)
  667. {
  668. if(m_recentPaths[i].IsSameAs(str, false))
  669. {
  670. m_recentPaths.RemoveAt(i);
  671. // only re-add when item is still valid
  672. if(::wxDirExists(str))
  673. m_recentPaths.Add(str);
  674. else
  675. return; // no add when the item is not existing
  676. return;
  677. }
  678. }
  679. if(GetMenuBar())
  680. {
  681. // get file menu
  682. int lastUsedID = 0;
  683. wxMenu *mnu = GetMenuBar()->GetMenu(0);
  684. wxASSERT(mnu != 0);
  685. if(::wxDirExists(str))
  686. {
  687. // add to array
  688. if(m_recentPaths.Count() == 0)
  689. mnu->AppendSeparator();
  690. lastUsedID = CM_RECENT_BUILD_ITEM + m_recentPaths.Count();
  691. m_recentPaths.Add(str);
  692. // when we have more in list then we can display, prune and
  693. // remove some menu items until we have room (and available ID's again)
  694. if(m_recentPaths.Count() > CM_MAX_RECENT_PATHS)
  695. {
  696. // prune the list
  697. while(m_recentPaths.Count() > CM_MAX_RECENT_PATHS)
  698. m_recentPaths.RemoveAt(0);
  699. // now determine count, and remove until we have room
  700. int index = mnu->GetMenuItemCount() - 1;
  701. int count = 0;
  702. wxASSERT(index > 0);
  703. wxMenuItem *item;
  704. do
  705. {
  706. item = mnu->FindItemByPosition(index);
  707. if(item)
  708. {
  709. if(item->IsSeparator())
  710. {
  711. // next index is valid item
  712. index ++;
  713. break;
  714. }
  715. else
  716. count ++;
  717. }
  718. index --;
  719. }
  720. while(index >= 0 && item);
  721. // ok, if count > CM_MAX_RECENT_PATHS then we are going to
  722. // delete some items on the index position
  723. if(count >= CM_MAX_RECENT_PATHS)
  724. {
  725. // delete items that are exceeding
  726. while(count >= CM_MAX_RECENT_PATHS)
  727. {
  728. lastUsedID = mnu->FindItemByPosition(index)->GetId();
  729. mnu->Delete(lastUsedID);
  730. count --;
  731. }
  732. }
  733. }
  734. // append item
  735. mnu->Append(lastUsedID, str);
  736. }
  737. }
  738. }
  739. bool CMakeSetupFrm::PerformCacheRun()
  740. {
  741. bool enable = false;
  742. cmCacheManager *cachem = m_cmake->GetCacheManager();
  743. cmCacheManager::CacheIterator it = cachem->NewIterator();
  744. // remove all items that are no longer present
  745. size_t j = 0;
  746. while(j < m_cmOptions->GetCount())
  747. {
  748. // check to see if it is still in the CMake cache
  749. // if it is still in the cache then it is no longer new
  750. wxPropertyItem *item = m_cmOptions->GetItem(j);
  751. if ( !it.Find((const char*)item->GetPropName().c_str()) )
  752. m_cmOptions->RemoveProperty(item);
  753. else
  754. {
  755. // ok we found it, mark as old
  756. item->SetNewValue(false);
  757. int row = m_cmOptions->FindProperty(item);
  758. if(row != -1)
  759. m_cmOptions->UpdatePropertyItem(item, row);
  760. j++;
  761. }
  762. }
  763. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  764. {
  765. bool enable = true;
  766. for(size_t i = 0; i < m_cmOptions->GetCount(); i++)
  767. {
  768. wxPropertyItem* item = m_cmOptions->GetItem(i);
  769. if(item->GetAdvanced())
  770. {
  771. if(item->GetNewValue() && m_cmOptions->GetShowAdvanced())
  772. {
  773. // if one new value then disable to OK button
  774. enable = false;
  775. break;
  776. }
  777. }
  778. else
  779. {
  780. if(item->GetNewValue())
  781. {
  782. // if one new value then disable to OK button
  783. enable = false;
  784. break;
  785. }
  786. }
  787. }
  788. }
  789. return enable;
  790. }
  791. void CMakeSetupFrm::FillCacheGUIFromCacheManager()
  792. {
  793. cmCacheManager *cachem = m_cmake->GetCacheManager();
  794. cmCacheManager::CacheIterator it = cachem->NewIterator();
  795. // remove all items that are no longer present
  796. size_t j = 0;
  797. while(j < m_cmOptions->GetCount())
  798. {
  799. // check to see if it is still in the CMake cache
  800. // if it is still in the cache then it is no longer new
  801. wxPropertyItem *item = m_cmOptions->GetItem(j);
  802. if ( !it.Find((const char*)item->GetPropName().c_str()) )
  803. m_cmOptions->RemoveProperty(item);
  804. else
  805. j++;
  806. }
  807. // if there are already entries in the cache, then
  808. // put the new ones in the top, so they show up first
  809. bool reverseOrder = false;
  810. for(cmCacheManager::CacheIterator i = cachem->NewIterator(); !i.IsAtEnd(); i.Next())
  811. {
  812. const char* key = i.GetName();
  813. // if value has trailing space or tab, enclose it in single quotes
  814. // to enforce the fact that it has 'invisible' trailing stuff
  815. std::string value = i.GetValue();
  816. if (value.size() && (value[value.size() - 1] == ' ' || value[value.size() - 1] == '\t'))
  817. value = '\'' + value + '\'';
  818. bool advanced = i.GetPropertyAsBool("ADVANCED");
  819. switch(i.GetType() )
  820. {
  821. case cmCacheManager::BOOL:
  822. {
  823. wxString OnOff;
  824. if(cmSystemTools::IsOn(value.c_str()))
  825. OnOff = wxT("ON");
  826. else
  827. OnOff = wxT("OFF");
  828. m_cmOptions->AddProperty(key,
  829. OnOff.c_str(),
  830. i.GetProperty("HELPSTRING"),
  831. wxPropertyList::CHECKBOX, "ON|OFF",
  832. reverseOrder,
  833. advanced );
  834. }
  835. break;
  836. case cmCacheManager::PATH:
  837. m_cmOptions->AddProperty(key,
  838. value.c_str(),
  839. i.GetProperty("HELPSTRING"),
  840. wxPropertyList::PATH,"",
  841. reverseOrder, advanced);
  842. break;
  843. case cmCacheManager::FILEPATH:
  844. m_cmOptions->AddProperty(key,
  845. value.c_str(),
  846. i.GetProperty("HELPSTRING"),
  847. wxPropertyList::FILE,"",
  848. reverseOrder, advanced);
  849. break;
  850. case cmCacheManager::STRING:
  851. m_cmOptions->AddProperty(key,
  852. value.c_str(),
  853. i.GetProperty("HELPSTRING"),
  854. wxPropertyList::EDIT,"",
  855. reverseOrder, advanced);
  856. break;
  857. case cmCacheManager::INTERNAL:
  858. {
  859. wxPropertyItem *pItem = m_cmOptions->FindPropertyByName(key);
  860. if(pItem)
  861. m_cmOptions->RemoveProperty(pItem);
  862. }
  863. break;
  864. }
  865. }
  866. }
  867. void CMakeSetupFrm::OnExitTimer(wxTimerEvent &event)
  868. {
  869. Close();
  870. }
  871. /*!
  872. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_PROJECT
  873. */
  874. void CMakeSetupFrm::OnButtonBrowseProject( wxCommandEvent& event )
  875. {
  876. const wxString& dir = wxDirSelector("Select project directory", m_cmProjectPath->GetValue());
  877. if(!dir.IsEmpty())
  878. m_cmProjectPath->SetValue(dir);
  879. }
  880. /*!
  881. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_BUILD
  882. */
  883. void CMakeSetupFrm::OnButtonBrowseBuild( wxCommandEvent& event )
  884. {
  885. const wxString& dir = wxDirSelector("Select build directory", m_cmBuildPath->GetValue());
  886. if(!dir.IsEmpty())
  887. m_cmBuildPath->SetValue(dir);
  888. }
  889. /*!
  890. * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_SHOW_ADVANCED
  891. */
  892. void CMakeSetupFrm::OnShowAdvancedValues( wxCommandEvent& event )
  893. {
  894. if(m_cmShowAdvanced->GetValue())
  895. m_cmOptions->ShowAdvanced();
  896. else
  897. m_cmOptions->HideAdvanced();
  898. }
  899. /*!
  900. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CONFIGURE
  901. */
  902. void CMakeSetupFrm::OnButtonConfigure( wxCommandEvent& event )
  903. {
  904. DoConfigure();
  905. }
  906. void CMakeSetupFrm::DoConfigure()
  907. {
  908. // enable error messages each time configure is pressed
  909. cmSystemTools::EnableMessages();
  910. m_cmOptions->HideControls();
  911. cmSystemTools::ResetErrorOccuredFlag();
  912. // instantiate a dialog for the progress meter
  913. PerformCacheRun();
  914. RunCMake(false);
  915. }
  916. int CMakeSetupFrm::RunCMake(bool generateProjectFiles)
  917. {
  918. int value = -1;
  919. // clear log
  920. m_cmLog->Clear();
  921. m_cmLog->DiscardEdits();
  922. wxString builddir = m_cmBuildPath->GetValue(),
  923. sourcedir = m_cmProjectPath->GetValue(),
  924. err = wxT("Error in configuration process, project files may be invalid");
  925. // sanity check for people pressing OK on empty dirs
  926. if(builddir.Trim().IsEmpty() || sourcedir.Trim().IsEmpty())
  927. {
  928. wxMessageBox(wxT("Please enter a valid source directory and build directory"), wxT("Error"), wxOK | wxICON_ERROR, this);
  929. return -1;
  930. }
  931. // check if the directory exists, if not, create it
  932. if(!cmSystemTools::FileExists(builddir.c_str()))
  933. {
  934. wxString str;
  935. str << wxT("Build directory does not exist, should I create it?\n\nDirectory: ") << builddir;
  936. int answer = wxMessageBox(str, wxT("Create directory"), wxYES_NO, this);
  937. if (answer == wxYES)
  938. {
  939. if(!cmSystemTools::MakeDirectory(builddir.c_str()))
  940. {
  941. // could not create, tell and abort
  942. wxMessageBox(wxT("Could not create directory"), wxT("Error"), wxOK | wxICON_ERROR, this);
  943. return -1;
  944. }
  945. }
  946. else
  947. {
  948. // we abort because the user did not want to make the directory
  949. wxMessageBox(wxT("Build Project aborted, nothing done."), wxT("Aborted"),
  950. wxOK | wxICON_EXCLAMATION, this);
  951. return -1;
  952. }
  953. }
  954. /** show progress dialog that informs the user with a progress bar */
  955. if(m_progressDlg)
  956. m_progressDlg->Destroy();
  957. m_progressDlg = new CMProgressDialog(this);
  958. m_progressDlg->Show();
  959. // set the wait cursor
  960. m_RunningConfigure = true;
  961. UpdateWindowState();
  962. // always save the current gui values to disk
  963. SaveCacheFromGUI();
  964. // Make sure we are working from the cache on disk
  965. LoadCacheFromDiskToGUI();
  966. // setup the cmake instance
  967. if (generateProjectFiles)
  968. {
  969. if(m_cmake->Generate() != 0)
  970. {
  971. wxMessageBox(err, wxT("Error"), wxOK | wxICON_ERROR, this);
  972. cmSystemTools::Error(err.c_str());
  973. value = -1;
  974. }
  975. else
  976. {
  977. value = 0;
  978. m_cmOptions->SetProjectGenerated(true); // clear cache dirty when generated
  979. }
  980. }
  981. else
  982. {
  983. // set paths
  984. m_cmake->SetHomeDirectory(m_cmProjectPath->GetValue().c_str());
  985. m_cmake->SetStartDirectory(m_cmProjectPath->GetValue().c_str());
  986. m_cmake->SetHomeOutputDirectory(m_cmBuildPath->GetValue().c_str());
  987. m_cmake->SetStartOutputDirectory(m_cmBuildPath->GetValue().c_str());
  988. m_cmake->SetGlobalGenerator(m_cmake->CreateGlobalGenerator(m_cmGeneratorChoice->GetValue().c_str()));
  989. m_cmake->SetCMakeCommand(m_PathToExecutable.c_str());
  990. m_cmake->LoadCache();
  991. if(m_cmake->Configure() != 0)
  992. {
  993. wxMessageBox(err, wxT("Error"), wxOK | wxICON_ERROR, this);
  994. cmSystemTools::Error(err.c_str());
  995. }
  996. // update the GUI with any new values in the caused by the
  997. // generation process
  998. LoadCacheFromDiskToGUI();
  999. }
  1000. m_RunningConfigure = false;
  1001. if(!value)
  1002. cmSystemTools::ResetErrorOccuredFlag();
  1003. m_progressDlg->Destroy();
  1004. m_progressDlg = 0;
  1005. // reset the statusbar progress
  1006. wxStatusBar *bar = GetStatusBar();
  1007. if(bar)
  1008. bar->SetStatusText(wxEmptyString, 1);
  1009. UpdateWindowState();
  1010. return value;
  1011. }
  1012. //! Save GUI values to cmCacheManager and then save to disk.
  1013. void CMakeSetupFrm::SaveCacheFromGUI()
  1014. {
  1015. cmCacheManager *cachem = m_cmake->GetCacheManager();
  1016. FillCacheManagerFromCacheGUI();
  1017. // write the cache to disk
  1018. if(!m_cmBuildPath->GetValue().Trim().IsEmpty())
  1019. cachem->SaveCache(m_cmBuildPath->GetValue().c_str());
  1020. }
  1021. void CMakeSetupFrm::FillCacheManagerFromCacheGUI()
  1022. {
  1023. cmCacheManager *cachem = m_cmake->GetCacheManager();
  1024. cmCacheManager::CacheIterator it = cachem->NewIterator();
  1025. for(size_t i = 0; i < m_cmOptions->GetCount(); i++)
  1026. {
  1027. wxPropertyItem* item = m_cmOptions->GetItem(i);
  1028. if ( it.Find((const char*)item->GetPropName().c_str()) )
  1029. {
  1030. // if value is enclosed in single quotes ('foo') then remove them
  1031. // they were used to enforce the fact that it had 'invisible'
  1032. // trailing stuff
  1033. if (item->GetCurValue().Len() >= 2 &&
  1034. item->GetCurValue().GetChar(0) == '\'' &&
  1035. item->GetCurValue().GetChar(item->GetCurValue().Len() - 1) == '\'')
  1036. {
  1037. it.SetValue(item->GetCurValue().Mid(1, item->GetCurValue().Len() - 2).c_str());
  1038. }
  1039. else
  1040. it.SetValue(item->GetCurValue().c_str());
  1041. }
  1042. }
  1043. }
  1044. /*!
  1045. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_OK
  1046. */
  1047. void CMakeSetupFrm::OnButtonOk( wxCommandEvent& event )
  1048. {
  1049. DoGenerate();
  1050. }
  1051. void CMakeSetupFrm::DoGenerate()
  1052. {
  1053. cmSystemTools::EnableMessages();
  1054. cmSystemTools::ResetErrorOccuredFlag();
  1055. m_cmOptions->HideControls();
  1056. PerformCacheRun();
  1057. if(!RunCMake(true))
  1058. {
  1059. // issue a close when this is done (this is issued by menu "Generate and Exit"
  1060. if(m_quitAfterGenerating)
  1061. Close();
  1062. else if(!wxGetKeyState(WXK_SHIFT))
  1063. {
  1064. bool close;
  1065. m_config->Read(CM_CLOSEAFTERGEN, &close, CM_CLOSEAFTERGEN_DEF);
  1066. if(!close)
  1067. wxMessageBox(wxT("Building of project files succesful!"), wxT("Success!"), wxOK|wxICON_INFORMATION);
  1068. else
  1069. Close();
  1070. }
  1071. }
  1072. }
  1073. /*!
  1074. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_CANCEL
  1075. */
  1076. void CMakeSetupFrm::OnButtonCancel( wxCommandEvent& event )
  1077. {
  1078. DoCancelButton();
  1079. }
  1080. void CMakeSetupFrm::DoCancelButton()
  1081. {
  1082. if(m_RunningConfigure)
  1083. {
  1084. int result = wxMessageBox(wxT("You are in the middle of a Configure.\n"
  1085. "If you Cancel now the configure information will be lost.\n"
  1086. "Are you sure you want to Cancel?"), wxT("Warning"), wxYES_NO|wxICON_WARNING);
  1087. if(result == wxYES)
  1088. cmSystemTools::SetFatalErrorOccured();
  1089. else
  1090. if(m_progressDlg)
  1091. m_progressDlg->ResetCancel();
  1092. }
  1093. }
  1094. /*!
  1095. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DO_DELETE_CACHE
  1096. */
  1097. void CMakeSetupFrm::OnButtonDeleteCache( wxCommandEvent& event )
  1098. {
  1099. DoDeleteCache();
  1100. }
  1101. void CMakeSetupFrm::DoDeleteCache()
  1102. {
  1103. bool deletecache = true;
  1104. if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
  1105. {
  1106. int result = ::wxMessageBox(_("You have changed options, are you sure you want to delete all items?\n"),
  1107. _("Warning"), wxYES_NO|wxICON_QUESTION);
  1108. // when user wants to wait, wait.. else quit
  1109. if(result == wxNO)
  1110. deletecache = false;
  1111. }
  1112. if(deletecache)
  1113. {
  1114. // indicate that we haven't generated a project yet
  1115. m_cmOptions->SetProjectGenerated(false);
  1116. if(!m_cmBuildPath->GetValue().Trim().IsEmpty() && m_cmake != 0)
  1117. m_cmake->GetCacheManager()->DeleteCache(m_cmBuildPath->GetValue().Trim());
  1118. LoadCacheFromDiskToGUI();
  1119. UpdateWindowState();
  1120. }
  1121. }
  1122. /*!
  1123. * Should we show tooltips?
  1124. */
  1125. bool CMakeSetupFrm::ShowToolTips()
  1126. {
  1127. return TRUE;
  1128. }
  1129. /*!
  1130. * Get bitmap resources
  1131. */
  1132. wxBitmap CMakeSetupFrm::GetBitmapResource( const wxString& name )
  1133. {
  1134. // Bitmap retrieval
  1135. ////@begin CMakeSetupFrm bitmap retrieval
  1136. return wxNullBitmap;
  1137. ////@end CMakeSetupFrm bitmap retrieval
  1138. }
  1139. /*!
  1140. * Get icon resources
  1141. */
  1142. wxIcon CMakeSetupFrm::GetIconResource( const wxString& name )
  1143. {
  1144. // Icon retrieval
  1145. ////@begin CMakeSetupFrm icon retrieval
  1146. if (name == wxT("cmake_icon.xpm"))
  1147. {
  1148. wxIcon icon(_T("cmake_icon.xpm"), wxBITMAP_TYPE_XPM);
  1149. return icon;
  1150. }
  1151. return wxNullIcon;
  1152. ////@end CMakeSetupFrm icon retrieval
  1153. }
  1154. /*!
  1155. * wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING event handler for ID_SPLITTERWINDOW
  1156. */
  1157. void CMakeSetupFrm::OnSplitterPosChanging( wxSplitterEvent& event )
  1158. {
  1159. int width, height;
  1160. GetSize(&width, &height);
  1161. if((height > 100))
  1162. {
  1163. if(event.GetSashPosition() < 170)
  1164. event.SetSashPosition(170);
  1165. else
  1166. {
  1167. if(event.GetSashPosition() > (height - 180))
  1168. event.SetSashPosition(height - 180);
  1169. }
  1170. }
  1171. else
  1172. event.Veto();
  1173. }
  1174. /*!
  1175. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_CLEAR_LOG
  1176. */
  1177. void CMakeSetupFrm::OnClearLogClick( wxCommandEvent& event )
  1178. {
  1179. // delete the log text
  1180. m_cmLog->Clear();
  1181. m_cmLog->DiscardEdits();
  1182. }
  1183. /*!
  1184. * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SOURCE_BUILD_PATH
  1185. */
  1186. void CMakeSetupFrm::OnSourceBuildPathUpdated( wxCommandEvent& event )
  1187. {
  1188. DoReloadCache();
  1189. }
  1190. void CMakeSetupFrm::DoReloadCache()
  1191. {
  1192. wxString buildpath = m_cmBuildPath->GetValue();
  1193. // The build dir has changed, check if there is a cache, and
  1194. // grab the source dir from it
  1195. // make sure the call to update grid is not executed
  1196. m_noRefresh = true;
  1197. m_cmSearchQuery->SetValue(_(""));
  1198. m_noRefresh = false;
  1199. std::string path = buildpath.c_str();
  1200. cmSystemTools::ConvertToUnixSlashes(path);
  1201. // adjust the cmake instance
  1202. m_cmake->SetHomeOutputDirectory(buildpath.c_str());
  1203. m_cmake->SetStartOutputDirectory(buildpath.c_str());
  1204. std::string cache_file = path;
  1205. cache_file += "/CMakeCache.txt";
  1206. // fill in the project path where the source is located, this is
  1207. // read from the CMake cache
  1208. cmCacheManager *cachem = m_cmake->GetCacheManager();
  1209. cmCacheManager::CacheIterator it = cachem->NewIterator();
  1210. if (cmSystemTools::FileExists(cache_file.c_str()) && cachem->LoadCache(path.c_str()) &&
  1211. it.Find("CMAKE_HOME_DIRECTORY"))
  1212. {
  1213. path = ConvertToWindowsPath(it.GetValue());
  1214. m_cmProjectPath->SetValue(path.c_str());
  1215. }
  1216. m_cmOptions->RemoveAll();
  1217. LoadCacheFromDiskToGUI();
  1218. UpdateWindowState();
  1219. }
  1220. /*!
  1221. * wxEVT_COMMAND_TEXT_ENTER event handler for ID_SOURCE_BUILD_PATH
  1222. */
  1223. void CMakeSetupFrm::OnSourceBuildPathEnter( wxCommandEvent& event )
  1224. {
  1225. OnSourceBuildPathUpdated(event);
  1226. }
  1227. /*!
  1228. * wxEVT_MOTION event handler for ID_OPTIONS
  1229. */
  1230. void CMakeSetupFrm::OnPropertyMotion( wxMouseEvent& event )
  1231. {
  1232. ShowPropertyDescription(m_cmOptions->YToRow(event.GetY()));
  1233. event.Skip();
  1234. }
  1235. /*!
  1236. * wxEVT_GRID_SELECT_CELL event handler for ID_OPTIONS
  1237. */
  1238. void CMakeSetupFrm::OnGridSelectCell( wxGridEvent& event )
  1239. {
  1240. // show description
  1241. ShowPropertyDescription(event.GetRow());
  1242. // enable or disable the browse button
  1243. m_cmBrowseCell->Enable(m_cmOptions->IsSelectedItemBrowsable(event.GetRow()));
  1244. event.Skip();
  1245. }
  1246. void CMakeSetupFrm::ShowPropertyDescription(int row)
  1247. {
  1248. if(row == wxNOT_FOUND || row < 0)
  1249. m_cmDescription->SetValue(wxEmptyString);
  1250. else
  1251. {
  1252. wxPropertyItem *pItem = m_cmOptions->GetPropertyItemFromRow(row);
  1253. if(pItem)
  1254. m_cmDescription->SetValue(pItem->GetHelpString());
  1255. else
  1256. m_cmDescription->SetValue(wxEmptyString);
  1257. }
  1258. }
  1259. /*!
  1260. * wxEVT_GRID_CELL_CHANGE event handler for ID_OPTIONS
  1261. */
  1262. void CMakeSetupFrm::OnCellChange( wxGridEvent& event )
  1263. {
  1264. // update the button state when the cache is invalidated
  1265. UpdateWindowState();
  1266. }
  1267. void CMakeSetupFrm::OnRecentFileMenu( wxCommandEvent &event )
  1268. {
  1269. if(GetMenuBar())
  1270. {
  1271. // get file menu
  1272. wxMenu *mnu = GetMenuBar()->GetMenu(0);
  1273. wxASSERT(mnu != 0);
  1274. wxMenuItem *item = mnu->FindItem(event.GetId());
  1275. if(item)
  1276. m_cmBuildPath->SetValue(item->GetLabel());
  1277. }
  1278. }
  1279. /*!
  1280. * wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBOBOX
  1281. */
  1282. void CMakeSetupFrm::OnSearchquerySelected( wxCommandEvent& event )
  1283. {
  1284. m_cmOptions->SetQuery(m_cmSearchQuery->GetValue());
  1285. }
  1286. void CMakeSetupFrm::OnAddQuery ( wxCommandEvent &event )
  1287. {
  1288. // add current text if not yet present
  1289. if(m_cmSearchQuery->FindString(m_cmSearchQuery->GetValue()) == wxNOT_FOUND)
  1290. {
  1291. m_cmSearchQuery->Append(m_cmSearchQuery->GetValue());
  1292. // if too many items are present, prune
  1293. while(m_cmSearchQuery->GetCount() > CM_MAX_SEARCH_QUERIES)
  1294. m_cmSearchQuery->Delete(0);
  1295. }
  1296. }
  1297. /*!
  1298. * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SEARCHQUERY
  1299. */
  1300. void CMakeSetupFrm::OnSearchqueryUpdated( wxCommandEvent& event )
  1301. {
  1302. // only refresh when this event was caused by user
  1303. if(!m_noRefresh)
  1304. m_cmOptions->SetQuery(m_cmSearchQuery->GetValue());
  1305. }
  1306. /*!
  1307. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE_GRID
  1308. */
  1309. void CMakeSetupFrm::OnBrowseGridClick( wxCommandEvent& event )
  1310. {
  1311. m_cmOptions->BrowseSelectedItem();
  1312. }
  1313. /*!
  1314. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_RELOAD_CACHE
  1315. */
  1316. void CMakeSetupFrm::OnMenuReloadCacheClick( wxCommandEvent& event )
  1317. {
  1318. bool reload = true;
  1319. if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
  1320. {
  1321. int result = ::wxMessageBox(_("You have changed options, are you sure you want to reload?\n"),
  1322. _("Warning"), wxYES_NO|wxICON_QUESTION);
  1323. // when user wants to wait, wait.. else quit
  1324. if(result == wxNO)
  1325. reload = false;
  1326. }
  1327. if(reload)
  1328. DoReloadCache();
  1329. }
  1330. /*!
  1331. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_DELETE_CACHE
  1332. */
  1333. void CMakeSetupFrm::OnMenuDeleteCacheClick( wxCommandEvent& event )
  1334. {
  1335. DoDeleteCache();
  1336. }
  1337. /*!
  1338. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_QUIT
  1339. */
  1340. void CMakeSetupFrm::OnMenuQuitClick( wxCommandEvent& event )
  1341. {
  1342. // the close event will veto if the user
  1343. // did not want to quit due to unsaved changes
  1344. Close();
  1345. }
  1346. /*!
  1347. * wxEVT_CLOSE_WINDOW event handler for ID_FRAME
  1348. */
  1349. void CMakeSetupFrm::OnCloseWindow( wxCloseEvent& event )
  1350. {
  1351. // ask quit if:
  1352. // - The cache is dirty
  1353. // - Or the cache is OK and has some items, and no project was generated recently (configure -> generate)
  1354. if(m_cmOptions->IsCacheDirty() || (m_cmOptions->GetCount() > 0 && !m_cmOptions->IsGenerated()))
  1355. {
  1356. int result = ::wxMessageBox(_("You have changed options, but not yet generated the projects\n"
  1357. "are you sure you want to quit?"), _("Warning"), wxYES_NO|wxICON_QUESTION);
  1358. // when user wants to wait, wait.. else quit
  1359. if(result == wxNO)
  1360. event.Veto();
  1361. else
  1362. event.Skip();
  1363. }
  1364. else
  1365. event.Skip();
  1366. }
  1367. /*!
  1368. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_ABOUTDLG
  1369. */
  1370. void CMakeSetupFrm::OnAboutClick( wxCommandEvent& event )
  1371. {
  1372. CMAboutDlg *dlg = new CMAboutDlg(this);
  1373. wxArrayString generators;
  1374. std::vector<std::string> names;
  1375. m_cmake->GetRegisteredGenerators(names);
  1376. for(std::vector<std::string>::iterator i = names.begin(); i != names.end(); ++i)
  1377. generators.Add(i->c_str());
  1378. wxString cmversion, cmsversion;
  1379. cmsversion.Printf("v%i.%i%s", CMAKEGUI_MAJORVER, CMAKEGUI_MINORVER, CMAKEGUI_ADDVER);
  1380. dlg->SetAboutText(cmversion, cmsversion, generators);
  1381. dlg->ShowModal();
  1382. dlg->Destroy();
  1383. }
  1384. /*!
  1385. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_CMAKE_OPTIONS
  1386. */
  1387. void CMakeSetupFrm::OnOptionsClick( wxCommandEvent& event )
  1388. {
  1389. CMOptionsDlg *dlg = new CMOptionsDlg(this);
  1390. dlg->SetConfig(m_config);
  1391. if(dlg->ShowModal() == wxID_OK)
  1392. {
  1393. // store volatile settings
  1394. dlg->GetConfig(m_config);
  1395. // apply non volatile setting such as clear search query, recent menu, etc.
  1396. SyncFormOptions(dlg);
  1397. }
  1398. dlg->Destroy();
  1399. }
  1400. void CMakeSetupFrm::SyncFormOptions(CMOptionsDlg *dlg)
  1401. {
  1402. // TODO: Clear search query etc.
  1403. }
  1404. /*!
  1405. * wxEVT_COMMAND_SPLITTER_DOUBLECLICKED event handler for ID_SPLITTERWINDOW
  1406. */
  1407. void CMakeSetupFrm::OnSplitterwindowSashDClick( wxSplitterEvent& event )
  1408. {
  1409. event.Veto();
  1410. }
  1411. /*!
  1412. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_CONFIGURE
  1413. */
  1414. void CMakeSetupFrm::OnMenuConfigureClick( wxCommandEvent& event )
  1415. {
  1416. DoConfigure();
  1417. }
  1418. /*!
  1419. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_EXITGENERATE
  1420. */
  1421. void CMakeSetupFrm::OnMenuGenerateClick( wxCommandEvent& event )
  1422. {
  1423. // set flag so that a close command is issued
  1424. // after generating the cmake cache to projects
  1425. m_quitAfterGenerating = true;
  1426. DoGenerate();
  1427. m_quitAfterGenerating = false;
  1428. }
  1429. /*!
  1430. * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MENU_TOGGLE_ADVANCED
  1431. */
  1432. void CMakeSetupFrm::OnMenuToggleAdvancedClick( wxCommandEvent& event )
  1433. {
  1434. // toggle the check box
  1435. m_cmShowAdvanced->SetValue(!m_cmShowAdvanced->GetValue());
  1436. OnShowAdvancedValues(event);
  1437. }