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