cmWXMainFrame.cxx 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmWXMainFrame.h"
  14. #include "cmCacheManager.h"
  15. #include "cmWXCacheProperty.h"
  16. #include "cmWXCommandLineInfo.h"
  17. #include "cmake.h"
  18. cmMainFrame::cmMainFrame(const wxString& title, const wxSize& size)
  19. : wxFrame((wxFrame*)NULL, cmMainFrame::ID_MainFrame, title, wxDefaultPosition, size)
  20. {
  21. cmSystemTools::SetErrorCallback(cmMainFrame::MessageCallback, this);
  22. this->m_Clean = true;
  23. this->m_BuildPathChanged = false;
  24. this->m_WhereSource = "";
  25. this->m_WhereBuild = "";
  26. this->m_CMakeInstance = new cmake; // force a register of generators
  27. this->m_Update = false;
  28. this->m_Valid = false;
  29. this->m_EntryRemoved = false;
  30. this->m_CursorChanged = false;
  31. this->m_CacheEntries = new cmMainFrame::CacheMapType;
  32. this->CreateStatusBar(1);
  33. this->SetStatusText("Welcome to CMakeSetup");
  34. this->m_MainPanel = new wxPanel(this, -1);
  35. this->SetBackgroundColour(this->m_MainPanel->GetBackgroundColour());
  36. this->m_TopMostSizer = new wxBoxSizer(wxVERTICAL);
  37. this->m_TopMostSizer->Add( this->m_MainPanel, 1, wxGROW | wxALL, 5 );
  38. wxFlexGridSizer* msizer = new wxFlexGridSizer(1, 5, 5);
  39. msizer->AddGrowableRow(2);
  40. msizer->AddGrowableCol(0);
  41. this->m_MainSizer = msizer;
  42. wxFlexGridSizer* tgrid = new wxFlexGridSizer(7, 2, 2);
  43. tgrid->AddGrowableCol(2);
  44. tgrid->AddGrowableCol(6);
  45. this->m_TopGrid = tgrid;
  46. this->m_TextSource = new wxStaticText(this->m_MainPanel, -1, "Where is the source code:");
  47. this->m_PathSource = new wxComboBox(this->m_MainPanel, -1, "PathSource");
  48. this->m_BrowseSource = new wxButton(this->m_MainPanel, -1, "Browse...");
  49. tgrid = new wxFlexGridSizer(3, 2, 2);
  50. tgrid->AddGrowableCol(2);
  51. this->m_GeneratorFrame = tgrid;
  52. this->m_BuildFor = new wxStaticText(this->m_MainPanel, -1, "Build For:");
  53. this->m_GeneratorMenu = new wxComboBox(this->m_MainPanel, -1, "Generator",
  54. wxDefaultPosition, wxDefaultSize,
  55. 0, 0, wxCB_READONLY);
  56. this->m_GeneratorFrame->Add(this->m_BuildFor, 0, wxALIGN_LEFT);
  57. this->m_GeneratorFrame->Add(5,5,0);
  58. this->m_GeneratorFrame->Add(this->m_GeneratorMenu, 1, wxGROW | wxLEFT | wxRIGHT );
  59. this->m_TextBinary = new wxStaticText(this->m_MainPanel, -1,
  60. "Where to build the binaries:");
  61. this->m_PathBinary = new wxComboBox(this->m_MainPanel, -1, "PathBinary");
  62. this->m_BrowseBinary = new wxButton(this->m_MainPanel, -1, "Browse...");
  63. this->m_ShowAdvancedValues = new wxCheckBox(this->m_MainPanel, -1,
  64. "Show Advanced Values");
  65. this->m_TopGrid->Add(this->m_TextSource, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
  66. this->m_TopGrid->Add(5, 5, 0);
  67. this->m_TopGrid->Add(this->m_PathSource, 1, wxGROW | wxLEFT | wxRIGHT );
  68. this->m_TopGrid->Add(5, 5, 0);
  69. this->m_TopGrid->Add(this->m_BrowseSource, 1, 0);
  70. this->m_TopGrid->Add(5, 5, 0);
  71. this->m_TopGrid->Add(this->m_GeneratorFrame, 1, wxGROW | wxLEFT | wxRIGHT);
  72. this->m_TopGrid->Add(this->m_TextBinary, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
  73. this->m_TopGrid->Add(5, 5, 0);
  74. this->m_TopGrid->Add(this->m_PathBinary, 1, wxGROW | wxLEFT | wxRIGHT );
  75. this->m_TopGrid->Add(5, 5, 0);
  76. this->m_TopGrid->Add(this->m_BrowseBinary, 1, 0);
  77. this->m_TopGrid->Add(5, 5, 0);
  78. this->m_TopGrid->Add(this->m_ShowAdvancedValues, 1, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
  79. this->m_MainSizer->Add(5, 5, 0);
  80. this->m_MainSizer->Add(this->m_TopGrid, 1, wxGROW | wxLEFT | wxRIGHT, 10 );
  81. this->m_CacheValuesBox = new wxStaticBox(this->m_MainPanel, -1, "Cache Values");
  82. //this->m_CacheValuesBox->SetBackgroundColour(*wxWHITE);
  83. this->m_CacheValuesFrame = new wxStaticBoxSizer(this->m_CacheValuesBox,
  84. wxVERTICAL);
  85. this->m_CacheValuesScroll = new wxScrolledWindow(this->m_MainPanel, -1,
  86. wxDefaultPosition, wxDefaultSize,
  87. wxVSCROLL);
  88. this->m_CacheValuesScroll->SetBackgroundColour(*wxWHITE);
  89. this->m_CacheValuesFrame->Add(this->m_CacheValuesScroll, 1, wxEXPAND | wxALL, 0 );
  90. this->m_CacheValuesPanel = new wxPanel(this->m_CacheValuesScroll, -1);
  91. this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150));
  92. wxFlexGridSizer* csizer = new wxFlexGridSizer(2, 1, 1);
  93. csizer->AddGrowableCol(0);
  94. csizer->AddGrowableCol(1);
  95. this->m_CacheValuesSizer = csizer;
  96. this->m_CacheValuesPanel->SetAutoLayout( TRUE );
  97. this->m_CacheValuesPanel->SetSizer(this->m_CacheValuesSizer);
  98. //this->m_CacheValuesPanel->SetBackgroundColour(wxColour(10,10,10));
  99. this->m_CacheValuesSizer->Fit(this->m_CacheValuesPanel);
  100. this->m_CacheValuesSizer->SetSizeHints(this->m_CacheValuesPanel);
  101. //this->m_CacheValuesScroll->SetScrollbars(0, 20, 0, 50);
  102. //wxSize framesize = this->m_CacheValuesBox->GetSize();
  103. //this->m_CacheValuesBox->SetSize(framesize.GetWidth(), 100);
  104. this->SetSizeHints(580, 340);
  105. this->m_MainSizer->Add(this->m_CacheValuesFrame, 1, wxGROW | wxALL );
  106. wxString helpTextData = "";
  107. helpTextData.append
  108. ("Right click on a cache value for additional options "
  109. "(delete, ignore, and help).\n"
  110. "Press Configure to update and display new values in red.\n"
  111. "Press OK to generate selected build files and exit.");
  112. this->m_HelpText = new wxStaticText(this->m_MainPanel, -1, helpTextData,
  113. wxDefaultPosition,
  114. wxDefaultSize,
  115. wxTE_MULTILINE);
  116. this->m_MainSizer->Add(5, 5, 0);
  117. this->m_MainSizer->Add(this->m_HelpText, 0, wxALIGN_CENTER_HORIZONTAL, 10);
  118. this->m_BottomButtonsFrame = new wxBoxSizer(wxHORIZONTAL);
  119. //this->m_VersionText = new wxStaticText(this->m_MainPanel, -1,
  120. //"Version 1.5 - development");
  121. this->m_ConfigureButton = new wxButton(this->m_MainPanel, -1, "Configure");
  122. this->m_OKButton = new wxButton(this->m_MainPanel, -1, "OK");
  123. this->m_CancelButton = new wxButton(this->m_MainPanel, -1, "Cancel");
  124. this->m_HelpButton = new wxButton(this->m_MainPanel, -1, "Help");
  125. this->m_BottomButtonsFrame->Add(m_ConfigureButton, 0, wxALIGN_LEFT, 10);
  126. this->m_BottomButtonsFrame->Add(5, 5, 0);
  127. this->m_BottomButtonsFrame->Add(m_OKButton, 0, wxALIGN_LEFT, 10);
  128. this->m_BottomButtonsFrame->Add(5, 5, 0);
  129. this->m_BottomButtonsFrame->Add(m_CancelButton, 0, wxALIGN_LEFT, 10);
  130. this->m_BottomButtonsFrame->Add(5, 5, 0);
  131. this->m_BottomButtonsFrame->Add(m_HelpButton, 0, wxALIGN_LEFT, 10);
  132. this->m_MainSizer->Add(5, 5, 0);
  133. this->m_MainSizer->Add(m_BottomButtonsFrame, 0, wxALIGN_CENTER_HORIZONTAL, 10);
  134. this->m_MainSizer->Add(5, 5, 0);
  135. this->m_MainPanel->SetAutoLayout( TRUE );
  136. this->m_MainPanel->SetSizer(this->m_MainSizer);
  137. this->m_MainSizer->Fit(this->m_MainPanel);
  138. this->m_MainSizer->SetSizeHints(this->m_MainPanel);
  139. this->SetAutoLayout( TRUE );
  140. this->SetSizer(this->m_TopMostSizer);
  141. this->m_TopMostSizer->Fit(this);
  142. this->m_TopMostSizer->SetSizeHints(this);
  143. // Setup statusbar callbacks
  144. this->SetupStatusBarBinding(this->m_ConfigureButton);
  145. this->SetupStatusBarBinding(this->m_OKButton);
  146. this->SetupStatusBarBinding(this->m_CancelButton);
  147. this->SetupStatusBarBinding(this->m_HelpButton);
  148. this->SetupStatusBarBinding(this->m_PathSource);
  149. this->SetupStatusBarBinding(this->m_BrowseSource);
  150. this->SetupStatusBarBinding(this->m_PathBinary);
  151. this->SetupStatusBarBinding(this->m_BrowseBinary);
  152. this->SetupStatusBarBinding(this->m_GeneratorMenu);
  153. this->SetupStatusBarBinding(this->m_ShowAdvancedValues);
  154. // Setup other callbacks
  155. this->ConnectEvent( this->m_CancelButton, wxEVT_COMMAND_BUTTON_CLICKED,
  156. (wxObjectEventFunction) &cmMainFrame::OnCancel );
  157. this->ConnectEvent( this->m_OKButton, wxEVT_COMMAND_BUTTON_CLICKED,
  158. (wxObjectEventFunction) &cmMainFrame::OnOk );
  159. this->ConnectEvent( this->m_HelpButton, wxEVT_COMMAND_BUTTON_CLICKED,
  160. (wxObjectEventFunction) &cmMainFrame::OnHelp );
  161. this->ConnectEvent( this->m_ConfigureButton, wxEVT_COMMAND_BUTTON_CLICKED,
  162. (wxObjectEventFunction) &cmMainFrame::OnConfigure );
  163. this->ConnectEvent( this, wxEVT_SIZE,
  164. (wxObjectEventFunction) &cmMainFrame::OnResize );
  165. this->ConnectEvent( this->m_ShowAdvancedValues, wxEVT_COMMAND_CHECKBOX_CLICKED,
  166. (wxObjectEventFunction) &cmMainFrame::OnShowAdvancedValues );
  167. this->ConnectEvent( this->m_BrowseSource, wxEVT_COMMAND_BUTTON_CLICKED,
  168. (wxObjectEventFunction) &cmMainFrame::OnBrowseSource );
  169. this->ConnectEvent( this->m_BrowseBinary, wxEVT_COMMAND_BUTTON_CLICKED,
  170. (wxObjectEventFunction) &cmMainFrame::OnBrowseBinary );
  171. this->ConnectEvent( this->m_PathSource, wxEVT_COMMAND_COMBOBOX_SELECTED,
  172. (wxObjectEventFunction) &cmMainFrame::OnSourceSelected );
  173. this->ConnectEvent( this->m_PathSource, wxEVT_COMMAND_TEXT_UPDATED,
  174. (wxObjectEventFunction) &cmMainFrame::OnSourceUpdated );
  175. this->ConnectEvent( this->m_PathBinary, wxEVT_COMMAND_COMBOBOX_SELECTED,
  176. (wxObjectEventFunction) &cmMainFrame::OnBinarySelected );
  177. this->ConnectEvent( this->m_PathBinary, wxEVT_COMMAND_TEXT_UPDATED,
  178. (wxObjectEventFunction) &cmMainFrame::OnBinaryUpdated );
  179. this->ConnectEvent( this->m_PathBinary, wxEVT_COMMAND_TEXT_ENTER,
  180. (wxObjectEventFunction) &cmMainFrame::OnBinaryAccepted );
  181. this->ConnectEvent( this->m_GeneratorMenu, wxEVT_COMMAND_COMBOBOX_SELECTED,
  182. (wxObjectEventFunction) &cmMainFrame::OnGeneratorSelected );
  183. this->ConnectEvent( this->m_GeneratorMenu, wxEVT_COMMAND_TEXT_UPDATED,
  184. (wxObjectEventFunction) &cmMainFrame::OnGeneratorSelected );
  185. this->ConnectEvent( this, wxEVT_TIMER,
  186. (wxObjectEventFunction) &cmMainFrame::OnExitTimer );
  187. this->Connect(cmCacheProperty::Menu_Popup_Ignore, wxEVT_COMMAND_MENU_SELECTED,
  188. (wxObjectEventFunction) &cmMainFrame::OnPopupMenuIgnore);
  189. this->Connect(cmCacheProperty::Menu_Popup_Delete, wxEVT_COMMAND_MENU_SELECTED,
  190. (wxObjectEventFunction) &cmMainFrame::OnPopupMenuDelete);
  191. this->Connect(cmCacheProperty::Menu_Popup_Help, wxEVT_COMMAND_MENU_SELECTED,
  192. (wxObjectEventFunction) &cmMainFrame::OnPopupMenuHelp);
  193. }
  194. cmMainFrame::~cmMainFrame()
  195. {
  196. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  197. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  198. i != items->end(); ++i)
  199. {
  200. cmCacheProperty* item = i->second;
  201. delete item;
  202. }
  203. delete this->m_CacheEntries;
  204. delete this->m_CMakeInstance;
  205. }
  206. void cmMainFrame::MessageCallback(const char* m, const char* title, bool& nomore,
  207. void* clientData)
  208. {
  209. if ( clientData )
  210. {
  211. cmMainFrame* self = static_cast<cmMainFrame*>( clientData );
  212. self->DisplayMessage(m, title, nomore);
  213. }
  214. else
  215. {
  216. std::string message = "The following error happen without frame being set:\n\n";
  217. message += m;
  218. message += "\n\n(Press Cancel to suppress any further messages.)";
  219. if(::wxMessageBox(message.c_str(), title,
  220. wxICON_WARNING | wxOK | wxCANCEL ) == wxCANCEL)
  221. {
  222. nomore = true;
  223. }
  224. }
  225. }
  226. void cmMainFrame::DisplayMessage(const char* m, const char* title, bool& nomore)
  227. {
  228. this->CursorNormal(false);
  229. std::string message = m;
  230. message += "\n\n(Press Cancel to suppress any further messages.)";
  231. if(::wxMessageBox(message.c_str(), title,
  232. wxICON_WARNING | wxOK | wxCANCEL ) == wxCANCEL)
  233. {
  234. nomore = true;
  235. }
  236. if ( this->m_CursorChanged )
  237. {
  238. this->CursorBusy(false);
  239. }
  240. }
  241. void cmMainFrame::ConnectEvent(wxWindow* win, wxEventType et, wxObjectEventFunction func)
  242. {
  243. //
  244. this->Connect((win?win->GetId():-1), et, func);
  245. //
  246. }
  247. void cmMainFrame::ConnectEventTo(wxWindow* win, wxEventType et, wxObjectEventFunction func)
  248. {
  249. //
  250. win->Connect(-1, et, func);
  251. //
  252. }
  253. void cmMainFrame::OnStatusBar(wxEvent& event)
  254. {
  255. wxControl* eobject = static_cast<wxControl*>(event.GetEventObject());
  256. if ( eobject && eobject->GetClientData() )
  257. {
  258. cmMainFrame* self = static_cast<cmMainFrame*>(eobject->GetClientData());
  259. if ( eobject == self->m_OKButton )
  260. {
  261. self->SetStatusText("Press OK to generate selected build files and exit.");
  262. }
  263. else if ( eobject == self->m_CancelButton )
  264. {
  265. self->SetStatusText("Press Cancel to lose the changes and exit.");
  266. }
  267. else if ( eobject == self->m_ConfigureButton )
  268. {
  269. self->SetStatusText("Press Configure to update and display new values in red.");
  270. }
  271. else if ( eobject == self->m_HelpButton )
  272. {
  273. self->SetStatusText("Press Help to display help.");
  274. }
  275. else if ( eobject == self->m_ShowAdvancedValues )
  276. {
  277. self->SetStatusText("Toggle between regular and advanced cache values.");
  278. }
  279. else if ( eobject == self->m_GeneratorMenu )
  280. {
  281. self->SetStatusText("Set the generator to generate the build files.");
  282. }
  283. else if ( eobject == self->m_PathSource )
  284. {
  285. self->SetStatusText("Enter the path to the source files.");
  286. }
  287. else if ( eobject == self->m_BrowseSource )
  288. {
  289. self->SetStatusText("Browse the path to the source files.");
  290. }
  291. else if ( eobject == self->m_PathBinary )
  292. {
  293. self->SetStatusText("Enter the path to the build files.");
  294. }
  295. else if ( eobject == self->m_BrowseBinary )
  296. {
  297. self->SetStatusText("Browse the path to the build files.");
  298. }
  299. else
  300. {
  301. self->SetStatusText("CMakeSetup");
  302. }
  303. }
  304. }
  305. void cmMainFrame::OnCacheStatusBar(wxEvent& event)
  306. {
  307. wxControl* eobject = static_cast<wxControl*>(event.GetEventObject());
  308. if ( eobject && eobject->GetClientData() )
  309. {
  310. cmCacheProperty* cprop = static_cast<cmCacheProperty*>(eobject->GetClientData());
  311. cprop->GetMainFrame()->SetStatusText(cprop->GetHelp().c_str(), 0);
  312. }
  313. }
  314. void cmMainFrame::OnPopupMenu(wxMouseEvent& event)
  315. {
  316. //
  317. wxControl* eobject = static_cast<wxControl*>(event.GetEventObject());
  318. if ( eobject && eobject->GetClientData() )
  319. {
  320. wxMenu menu;
  321. menu.Append(cmCacheProperty::Menu_Popup_Ignore, "Ignore Cache Entry");
  322. menu.Append(cmCacheProperty::Menu_Popup_Delete, "Delete Cache Entry");
  323. menu.Append(cmCacheProperty::Menu_Popup_Help, "Help for Cache Entry");
  324. cmCacheProperty* cprop = static_cast<cmCacheProperty*>(eobject->GetClientData());
  325. cmMainFrame* self = cprop->GetMainFrame();
  326. menu.SetClientData(eobject->GetClientData());
  327. this->PopupMenu(&menu, event.GetPosition());
  328. if ( self->m_EntryRemoved )
  329. {
  330. self->UpdateCacheValuesDisplay();
  331. self->m_EntryRemoved = false;
  332. }
  333. }
  334. }
  335. void cmMainFrame::OnPopupMenuIgnore(wxEvent& event)
  336. {
  337. //
  338. this->OnPopupMenuEntry(event, 0);
  339. //
  340. }
  341. void cmMainFrame::OnPopupMenuDelete(wxEvent& event)
  342. {
  343. //
  344. this->OnPopupMenuEntry(event, 1);
  345. //
  346. }
  347. void cmMainFrame::OnPopupMenuHelp(wxEvent& event)
  348. {
  349. //
  350. this->OnPopupMenuEntry(event, 2);
  351. //
  352. }
  353. void cmMainFrame::OnPopupMenuEntry(wxEvent& event, int idx)
  354. {
  355. wxMenu* eobject = static_cast<wxMenu*>(event.GetEventObject());
  356. if ( eobject && eobject->GetClientData() )
  357. {
  358. cmCacheProperty* cprop = static_cast<cmCacheProperty*>(eobject->GetClientData());
  359. switch ( idx )
  360. {
  361. case 0: this->IgnoreCacheEntry(cprop->GetName().c_str());
  362. break;
  363. case 1: this->RemoveCacheEntry(cprop);
  364. break;
  365. case 2: this->HelpCacheEntry(cprop->GetName().c_str(), cprop->GetHelp().c_str());
  366. break;
  367. }
  368. }
  369. }
  370. void cmMainFrame::OnOk(wxCommandEvent&)
  371. {
  372. // enable error messages each time configure is pressed
  373. cmSystemTools::EnableMessages();
  374. this->ClearDirty();
  375. this->RunCMake(true);
  376. cmMainFrame::Close(TRUE);
  377. }
  378. void cmMainFrame::OnCancel(wxCommandEvent&)
  379. {
  380. if ( this->IsDirty() )
  381. {
  382. // Display dialog
  383. if ( wxMessageBox( "You have changed options but not rebuild, "
  384. "are you sure you want to exit?",
  385. "Confirm Exit", wxICON_WARNING | wxYES_NO ) != wxYES )
  386. {
  387. return;
  388. }
  389. }
  390. cmMainFrame::Close(TRUE);
  391. }
  392. void cmMainFrame::OnConfigure(wxCommandEvent&)
  393. {
  394. // enable error messages each time configure is pressed
  395. cmSystemTools::EnableMessages();
  396. this->m_Update = true;
  397. this->RunCMake(false);
  398. }
  399. void cmMainFrame::OnHelp(wxCommandEvent&)
  400. {
  401. std::string message =
  402. "CMake is used to configure and generate build files for software projects. The basic steps for configuring a\n"
  403. "project are as follows:\n\n"
  404. "1. Select the source directory for the project. This should contain the CMakeLists.txt files for the project.\n\n"
  405. "2. Select the build directory for the project. This is the directory where the project will be built. It can\n"
  406. "be the same or a different directory than the source directory. For easy clean up, a separate build directory\n"
  407. "is recommended. CMake will create the directory if it does not exist.\n\n"
  408. "3. Once the source and binary directories are selected, it is time to press the Configure button. This will cause\n"
  409. "CMake to read all of the input files and discover all the variables used by the project. The first time a\n"
  410. "variable is displayed it will be in Red. Users should inspect red variables making sure the values are correct.\n"
  411. "For some projects the Configure process can be iterative, so continue to press the Configure button until there\n"
  412. " are no longer red entries.\n\n"
  413. "4. Once there are no longer red entries, you should click the OK button. This will write the build files to the\n"
  414. "build directory and exit CMake.";
  415. ::wxMessageBox(message.c_str(), "CMake Help",
  416. wxICON_INFORMATION | wxOK );
  417. }
  418. void cmMainFrame::OnPropertyChanged(wxEvent& event)
  419. {
  420. this->SetDirty();
  421. wxControl* eobject = static_cast<wxControl*>(event.GetEventObject());
  422. if ( eobject && eobject->GetClientData() )
  423. {
  424. cmCacheProperty* property = static_cast<cmCacheProperty*>(
  425. eobject->GetClientData() );
  426. property->OnPropertyChanged(event);
  427. }
  428. }
  429. void cmMainFrame::OnResize(wxSizeEvent& event)
  430. {
  431. this->wxFrame::OnSize(event);
  432. // Expand inner pannel when window resizes
  433. this->ResizeInternal();
  434. }
  435. void cmMainFrame::OnExitTimer(wxEvent&)
  436. {
  437. this->Close();
  438. this->Refresh();
  439. }
  440. void cmMainFrame::ResizeInternal()
  441. {
  442. // Expand inner pannel when window resizes
  443. int x, y;
  444. this->m_CacheValuesScroll->GetClientSize(&x, &y);
  445. wxSize size1 = this->m_CacheValuesPanel->GetSize();
  446. this->m_CacheValuesPanel->SetSize(wxSize(x, size1.GetHeight()));
  447. //this->m_CacheValuesSizer->SetDimension(0,0,x,size1.GetHeight());
  448. }
  449. void cmMainFrame::OnBrowseSource(wxCommandEvent&)
  450. {
  451. std::string path = this->m_PathSource->GetValue().c_str();
  452. if ( path == "PathSource" )
  453. {
  454. path = cmSystemTools::CollapseFullPath(this->m_PathToExecutable.c_str());
  455. }
  456. wxDirDialog dialog ( this, _T("Select path"), path.c_str() );
  457. if (dialog.ShowModal() == wxID_OK)
  458. {
  459. this->SetSourceDir(dialog.GetPath());
  460. }
  461. }
  462. void cmMainFrame::OnBrowseBinary(wxCommandEvent&)
  463. {
  464. std::string path = this->m_PathBinary->GetValue().c_str();
  465. if ( path == "PathBinary" )
  466. {
  467. path = this->m_PathSource->GetValue().c_str();
  468. if ( path == "PathSource" )
  469. {
  470. path = cmSystemTools::CollapseFullPath(this->m_PathToExecutable.c_str());
  471. }
  472. }
  473. wxDirDialog dialog ( this, _T("Select path"), path.c_str() );
  474. if (dialog.ShowModal() == wxID_OK)
  475. {
  476. if ( this->SetBinaryDir(dialog.GetPath()) )
  477. {
  478. this->m_Update = true;
  479. this->ChangeWhereBuild();
  480. }
  481. }
  482. }
  483. void cmMainFrame::Initialize(cmCommandLineInfo* cmdInfo)
  484. {
  485. this->m_PathToExecutable = cmdInfo->GetPathToExecutable();
  486. this->LoadFromRegistry();
  487. std::vector<std::string> names;
  488. this->m_CMakeInstance->GetRegisteredGenerators(names);
  489. int cc = 0;
  490. for(std::vector<std::string>::iterator i = names.begin();
  491. i != names.end(); ++i)
  492. {
  493. this->m_GeneratorMenu->Append(i->c_str());
  494. if ( *i == "Unix Makefiles" )
  495. {
  496. this->m_GeneratorMenu->SetSelection(cc);
  497. }
  498. cc ++;
  499. }
  500. //{{AFX_DATA_INIT(CMakeSetupDialog)
  501. // Get the parameters from the command line info
  502. // If an unknown parameter is found, try to interpret it too, since it
  503. // is likely to be a file dropped on the shortcut :)
  504. if (cmdInfo->m_LastUnknownParameter.empty())
  505. {
  506. if ( cmdInfo->m_WhereSource.size() > 0 )
  507. {
  508. this->SetSourceDir( cmdInfo->m_WhereSource.c_str() );
  509. }
  510. if ( cmdInfo->m_WhereBuild.size() > 0 )
  511. {
  512. this->SetBinaryDir( cmdInfo->m_WhereBuild.c_str() );
  513. }
  514. if ( this->m_GeneratorMenu->GetSelection() >= 0 &&
  515. this->m_GeneratorMenu->GetValue().size() > 0 )
  516. {
  517. this->SetGenerator(this->m_GeneratorMenu->GetValue().c_str());
  518. }
  519. this->m_ShowAdvancedValues->SetValue(cmdInfo->m_AdvancedValues);
  520. }
  521. else
  522. {
  523. this->m_ShowAdvancedValues->SetValue(FALSE);
  524. this->ChangeDirectoriesFromFile(cmdInfo->m_LastUnknownParameter.c_str());
  525. }
  526. /*
  527. this->UpdateSourceBuildMenus();
  528. */
  529. this->LoadCacheFromDiskToGUI();
  530. if ( cmdInfo->m_ExitAfterLoad )
  531. {
  532. this->m_ExitTimer = new wxTimer(this, this->GetId());
  533. this->m_ExitTimer->Start(3000);
  534. }
  535. }
  536. //! Set the current generator
  537. void cmMainFrame::SetGenerator(const char* generator)
  538. {
  539. if ( strlen(generator) > 0 )
  540. {
  541. int pos = this->m_GeneratorMenu->FindString(generator);
  542. if ( pos >= 0 )
  543. {
  544. this->m_GeneratorMenu->SetSelection(pos);
  545. }
  546. }
  547. }
  548. //! Load cache file from m_WhereBuild and display in GUI editor
  549. void cmMainFrame::LoadCacheFromDiskToGUI()
  550. {
  551. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  552. if(this->GetBinaryDir().size() > 0 )
  553. {
  554. cachem->LoadCache(this->m_WhereBuild.c_str());
  555. this->UpdateCacheValuesDisplay();
  556. cmCacheManager::CacheIterator it = cachem->NewIterator();
  557. if(it.Find("CMAKE_GENERATOR"))
  558. {
  559. std::string curGen = it.GetValue();
  560. if(this->m_GeneratorMenu->GetSelection() < 0 ||
  561. std::string(this->m_GeneratorMenu->GetValue().c_str()) != curGen)
  562. {
  563. this->SetGenerator(curGen.c_str());
  564. }
  565. }
  566. }
  567. }
  568. // copy from the cache manager to the cache edit list box
  569. void cmMainFrame::FillCacheGUIFromCacheManager()
  570. {
  571. //size_t size = 0;
  572. //size_t size = this->m_CacheEntriesList.GetItems().size();
  573. //bool reverseOrder = false;
  574. // if there are already entries in the cache, then
  575. // put the new ones in the top, so they show up first
  576. /*
  577. if(size)
  578. {
  579. reverseOrder = true;
  580. }
  581. */
  582. this->UpdateCacheValuesDisplay();
  583. }
  584. void cmMainFrame::OnGeneratorSelected(wxEvent&)
  585. {
  586. }
  587. void cmMainFrame::OnShowAdvancedValues(wxCommandEvent&)
  588. {
  589. this->m_Update = false;
  590. this->UpdateCacheValuesDisplay();
  591. }
  592. // Handle param or single dropped file.
  593. // If the dropped file is a build directory or any file in a
  594. // build directory, set the source dir from the cache file,
  595. // otherwise set the source and build dirs to this file (or dir).
  596. void cmMainFrame::ChangeDirectoriesFromFile(const char* buffer)
  597. {
  598. // Get the path to this file
  599. std::string path = buffer;
  600. if (!cmSystemTools::FileIsDirectory(path.c_str()))
  601. {
  602. path = cmSystemTools::GetFilenamePath(path);
  603. }
  604. else
  605. {
  606. cmSystemTools::ConvertToUnixSlashes(path);
  607. }
  608. // Check if it's a build dir and grab the cache
  609. std::string cache_file = path;
  610. cache_file += "/CMakeCache.txt";
  611. cmCacheManager *cache = this->m_CMakeInstance->GetCacheManager();
  612. cmCacheManager::CacheIterator it = cache->GetCacheIterator("CMAKE_HOME_DIRECTORY");
  613. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  614. cache->LoadCache(path.c_str()) &&
  615. !it.IsAtEnd())
  616. {
  617. path = cmSystemTools::ConvertToOutputPath(path.c_str());
  618. this->SetBinaryDir(path.c_str());
  619. path = cmSystemTools::ConvertToOutputPath(it.GetValue());
  620. this->SetSourceDir(path.c_str());
  621. }
  622. else
  623. {
  624. path = cmSystemTools::ConvertToOutputPath(path.c_str());
  625. this->SetSourceDir(path.c_str());
  626. this->SetBinaryDir(path.c_str());
  627. }
  628. }
  629. void cmMainFrame::UpdateSourceBuildMenus()
  630. {
  631. }
  632. void cmMainFrame::RunCMake(bool generateProjectFiles)
  633. {
  634. if(this->m_GeneratorMenu->GetSelection() < 0 ||
  635. std::string(this->m_GeneratorMenu->GetValue().c_str()) == "")
  636. {
  637. std::string bindir = this->GetBinaryDir();
  638. if ( bindir.find("-") != bindir.npos )
  639. {
  640. std::string message =
  641. "Generator not specified. Please specify the generator for\n"
  642. "building the project.";
  643. wxMessageBox(message.c_str(), "CMake Error", wxICON_ERROR | wxOK );
  644. return;
  645. }
  646. }
  647. if(std::string(this->m_GeneratorMenu->GetValue().c_str()) == "Borland Makefiles")
  648. {
  649. std::string bindir = this->GetBinaryDir();
  650. if ( bindir.find("-") != bindir.npos )
  651. {
  652. std::string message =
  653. "The Borland command line tools do not support path names\n"
  654. "that have - in them. Please re-name your output directory\n"
  655. "and use _ instead of -.";
  656. wxMessageBox(message.c_str(), "CMake Error", wxICON_ERROR | wxOK );
  657. return;
  658. }
  659. }
  660. if(!cmSystemTools::FileExists(this->GetBinaryDir().c_str()))
  661. {
  662. std::string message =
  663. "Build directory does not exist, should I create it?\n\n"
  664. "Directory: ";
  665. message += this->GetBinaryDir();
  666. if(wxMessageBox(message.c_str(), "Create Directory", wxICON_WARNING | wxOK | wxCANCEL) == wxOK)
  667. {
  668. cmSystemTools::MakeDirectory(this->GetBinaryDir().c_str());
  669. }
  670. else
  671. {
  672. (void)wxMessageBox("Build Project aborted, nothing done.", "CMake Aborted",
  673. wxICON_INFORMATION | wxOK);
  674. return;
  675. }
  676. }
  677. // set the wait cursor
  678. this->CursorBusy(true);
  679. // get all the info from the dialog
  680. //this->UpdateData();
  681. // always save the current gui values to disk
  682. this->SaveCacheFromGUI();
  683. // Make sure we are working from the cache on disk
  684. this->LoadCacheFromDiskToGUI();
  685. //
  686. this->m_Valid = true;
  687. this->m_OKButton->Enable(false);
  688. // setup the cmake instance
  689. if (generateProjectFiles)
  690. {
  691. if(this->m_CMakeInstance->Generate() != 0)
  692. {
  693. cmSystemTools::Error(
  694. "Error in generation process, project files may be invalid");
  695. }
  696. }
  697. else
  698. {
  699. this->m_CMakeInstance->SetHomeDirectory(this->GetSourceDir().c_str());
  700. this->m_CMakeInstance->SetStartDirectory(this->GetSourceDir().c_str());
  701. this->m_CMakeInstance->SetHomeOutputDirectory(this->GetBinaryDir().c_str());
  702. this->m_CMakeInstance->SetStartOutputDirectory(this->GetBinaryDir().c_str());
  703. this->m_CMakeInstance->SetGlobalGenerator(
  704. this-> m_CMakeInstance->CreateGlobalGenerator(
  705. this->m_GeneratorMenu->GetValue().c_str()));
  706. this->m_CMakeInstance->SetCMakeCommand(this->m_PathToExecutable.c_str());
  707. this->m_CMakeInstance->LoadCache();
  708. if(this->m_CMakeInstance->Configure() != 0)
  709. {
  710. cmSystemTools::Error(
  711. "Error in configuration process, project files may be invalid");
  712. }
  713. // update the GUI with any new values in the caused by the
  714. // generation process
  715. this->LoadCacheFromDiskToGUI();
  716. }
  717. // save source and build paths to registry
  718. this->SaveToRegistry();
  719. // path is up-to-date now
  720. this->m_BuildPathChanged = false;
  721. // put the cursor back
  722. this->CursorNormal(true);
  723. cmSystemTools::ResetErrorOccuredFlag();
  724. }
  725. //! Save GUI values to cmCacheManager and then save to disk.
  726. void cmMainFrame::SaveCacheFromGUI()
  727. {
  728. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  729. this->FillCacheManagerFromCacheGUI();
  730. if(this->GetBinaryDir() != "")
  731. {
  732. cachem->SaveCache(this->GetBinaryDir().c_str());
  733. }
  734. }
  735. // copy from the list box to the cache manager
  736. void cmMainFrame::FillCacheManagerFromCacheGUI()
  737. {
  738. cmMainFrame::CacheMapType *items = this->m_CacheEntries;
  739. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  740. i != items->end(); ++i)
  741. {
  742. cmCacheProperty* item = i->second;
  743. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  744. cmCacheManager::CacheIterator it = cachem->GetCacheIterator(item->GetName().c_str());
  745. if (!it.IsAtEnd())
  746. {
  747. // if value is enclosed in single quotes ('foo') then remove them
  748. // they were used to enforce the fact that it had 'invisible'
  749. // trailing stuff
  750. std::string str = item->GetValue();
  751. if (str.size() >= 2 &&
  752. str[0] == '\'' &&
  753. str[str.size() - 1] == '\'')
  754. {
  755. it.SetValue(str.substr(1,str.size() - 2).c_str());
  756. }
  757. else
  758. {
  759. it.SetValue(str.c_str());
  760. }
  761. }
  762. }
  763. }
  764. void cmMainFrame::UpdateCacheValuesDisplay()
  765. {
  766. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  767. this->m_CacheValuesScroll->Scroll(0,0);
  768. if ( this->m_Update )
  769. {
  770. // all the current values are not new any more
  771. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  772. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  773. i != items->end(); ++i)
  774. {
  775. cmCacheProperty* item = i->second;
  776. item->SetNewFlag( false );
  777. }
  778. }
  779. // redraw the list
  780. this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE);
  781. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  782. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  783. i != items->end(); ++i)
  784. {
  785. cmCacheProperty* item = i->second;
  786. item->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel);
  787. }
  788. //this->m_CacheValuesPanel->SetSize(5,5);
  789. //this->m_CacheValuesPanel->Fit();
  790. bool showadvancedvalues = this->m_ShowAdvancedValues->GetValue();
  791. int x, y;
  792. this->m_CacheValuesPanel->GetSize(&x, &y);
  793. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  794. !i.IsAtEnd(); i.Next())
  795. {
  796. const char* key = i.GetName();
  797. cmMainFrame::CacheMapType::iterator cprop = this->m_CacheEntries->find(key);
  798. cmCacheProperty *property = 0;
  799. if ( cprop != this->m_CacheEntries->end() )
  800. {
  801. property = cprop->second;
  802. }
  803. std::string value = i.GetValue();
  804. // if value has trailing space or tab, enclose it in single quotes
  805. // to enforce the fact that it has 'invisible' trailing stuff
  806. if (value.size() &&
  807. (value[value.size() - 1] == ' ' ||
  808. value[value.size() - 1] == '\t'))
  809. {
  810. value = '\'' + value + '\'';
  811. }
  812. if ( i.GetType() != cmCacheManager::BOOL &&
  813. i.GetType() != cmCacheManager::FILEPATH &&
  814. i.GetType() != cmCacheManager::PATH &&
  815. i.GetType() != cmCacheManager::STRING ||
  816. !showadvancedvalues && i.GetPropertyAsBool("ADVANCED") )
  817. {
  818. continue;
  819. }
  820. if ( !property )
  821. {
  822. property = new cmCacheProperty(this, key);
  823. property->SetHelp( i.GetProperty("HELPSTRING") );
  824. (*this->m_CacheEntries)[key] = property;
  825. }
  826. if(i.GetPropertyAsBool("ADVANCED"))
  827. {
  828. property->MarkAdvanced();
  829. }
  830. if ( !property->IsRemoved() )
  831. {
  832. property->SetValue(value);
  833. switch(i.GetType() )
  834. {
  835. case cmCacheManager::BOOL:
  836. if(cmSystemTools::IsOn(value.c_str()))
  837. {
  838. property->SetValue("ON");
  839. }
  840. else
  841. {
  842. property->SetValue("OFF");
  843. }
  844. property->SetItemType( cmCacheProperty::CHECKBOX );
  845. break;
  846. case cmCacheManager::PATH:
  847. property->SetItemType( cmCacheProperty::PATH );
  848. break;
  849. case cmCacheManager::FILEPATH:
  850. property->SetItemType( cmCacheProperty::FILE );
  851. break;
  852. case cmCacheManager::STRING:
  853. property->SetItemType( cmCacheProperty::EDIT );
  854. break;
  855. default:
  856. property->MarkRemoved();
  857. }
  858. }
  859. }
  860. if(this->m_CacheEntries->size() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  861. {
  862. bool enable = true;
  863. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  864. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  865. i != items->end(); i++)
  866. {
  867. cmCacheProperty* item = i->second;
  868. if(item && item->GetNewFlag() && !item->IsRemoved())
  869. {
  870. // if one new value then disable to OK button
  871. enable = false;
  872. this->m_Valid = false;
  873. break;
  874. }
  875. }
  876. this->m_OKButton->Enable(this->m_Valid);
  877. this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150));
  878. }
  879. else
  880. {
  881. this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE);
  882. }
  883. if ( this->m_Valid )
  884. {
  885. this->ClearDirty();
  886. }
  887. else
  888. {
  889. this->SetDirty();
  890. }
  891. int max = 0;
  892. int count = 0;
  893. wxSize size1 = this->m_CacheValuesPanel->GetSize();
  894. size1.SetHeight(1);
  895. this->m_CacheValuesPanel->SetSize(size1);
  896. int height = 0;
  897. // redraw the list
  898. cmMainFrame::CacheMapType::iterator nexti;
  899. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  900. i != items->end(); i = nexti)
  901. {
  902. cmCacheProperty* item = i->second;
  903. nexti = i;
  904. nexti++;
  905. if ( item->IsRemoved() )
  906. {
  907. delete item;
  908. items->erase(i);
  909. }
  910. }
  911. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  912. i != items->end(); i++)
  913. {
  914. cmCacheProperty* item = i->second;
  915. if((showadvancedvalues || !item->IsAdvanced()) && !item->GetNewFlag() )
  916. {
  917. int nm = item->Display(this->m_CacheValuesSizer, this->m_CacheValuesPanel);
  918. height += nm + 1;
  919. count ++;
  920. if ( nm > max )
  921. {
  922. max = nm;
  923. }
  924. }
  925. }
  926. for(cmMainFrame::CacheMapType::reverse_iterator i = items->rbegin();
  927. i != items->rend(); i++)
  928. {
  929. cmCacheProperty* item = i->second;
  930. if((showadvancedvalues || !item->IsAdvanced()) && item->GetNewFlag())
  931. {
  932. int nm = item->Display(this->m_CacheValuesSizer, this->m_CacheValuesPanel);
  933. height += nm + 1;
  934. count ++;
  935. if ( nm > max )
  936. {
  937. max = nm;
  938. }
  939. }
  940. }
  941. if ( count > 0 )
  942. {
  943. this->m_CacheValuesPanel->SetBackgroundColour(wxColor(150, 150, 150));
  944. }
  945. else
  946. {
  947. this->m_CacheValuesPanel->SetBackgroundColour(*wxWHITE);
  948. this->ClearDirty();
  949. }
  950. this->m_CacheValuesSizer->Layout();
  951. //max += 1;
  952. // Fix size
  953. int sx, sy;
  954. this->m_CacheValuesScroll->GetClientSize(&sx, &sy);
  955. wxSize size2 = this->m_CacheValuesPanel->GetSize();
  956. sy = size2.GetHeight();
  957. this->m_CacheValuesPanel->SetSize(wxSize(sx, height));
  958. this->m_CacheValuesSizer->Layout();
  959. this->m_CacheValuesScroll->SetScrollbars(0, 2, 0, height/2);
  960. this->ResizeInternal();
  961. }
  962. void cmMainFrame::RemoveAdvancedValues()
  963. {
  964. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  965. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  966. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  967. !i.IsAtEnd(); i.Next())
  968. {
  969. const char* key = i.GetName();
  970. //const cmCacheManager::CacheEntry& value = i.GetEntry();
  971. if(i.GetPropertyAsBool("ADVANCED"))
  972. {
  973. cmCacheProperty* property = (*items)[key];
  974. property->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel);
  975. }
  976. }
  977. }
  978. void cmMainFrame::ChangeWhereBuild()
  979. {
  980. std::string path(this->m_PathBinary->GetValue().c_str());
  981. cmSystemTools::ConvertToUnixSlashes(path);
  982. std::string cache_file = path;
  983. cache_file += "/CMakeCache.txt";
  984. if ( !this->m_CMakeInstance )
  985. {
  986. return;
  987. }
  988. cmCacheManager *cache = this->m_CMakeInstance->GetCacheManager();
  989. cmCacheManager::CacheIterator it = cache->NewIterator();
  990. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  991. cache->LoadCache(path.c_str()) &&
  992. it.Find("CMAKE_HOME_DIRECTORY"))
  993. {
  994. path = cmSystemTools::ConvertToOutputPath(it.GetValue());
  995. if ( this->SetSourceDir(path.c_str()) )
  996. {
  997. this->ChangeWhereSource();
  998. }
  999. }
  1000. this->ClearCache();
  1001. this->LoadCacheFromDiskToGUI();
  1002. this->m_BuildPathChanged = true;
  1003. }
  1004. void cmMainFrame::ChangeWhereSource()
  1005. {
  1006. }
  1007. bool cmMainFrame::SetSourceDir(const char* dir)
  1008. {
  1009. if ( this->m_WhereSource == dir || strlen(dir) == 0 )
  1010. {
  1011. return false;
  1012. }
  1013. if ( this->m_PathSource->FindString(dir) < 0 )
  1014. {
  1015. this->m_PathSource->Append(dir);
  1016. }
  1017. this->m_PathSource->SetValue(dir);
  1018. this->m_WhereSource = dir;
  1019. this->m_Valid = false;
  1020. return true;
  1021. }
  1022. bool cmMainFrame::SetBinaryDir(const char* dir)
  1023. {
  1024. if ( this->m_WhereBuild == dir || strlen(dir) == 0 )
  1025. {
  1026. return false;
  1027. }
  1028. if ( this->m_PathBinary->FindString(dir) < 0 )
  1029. {
  1030. this->m_PathBinary->Append(dir);
  1031. }
  1032. this->m_PathBinary->SetValue(dir);
  1033. this->m_WhereBuild = dir;
  1034. this->m_Valid = false;
  1035. return true;
  1036. }
  1037. void cmMainFrame::ClearCache()
  1038. {
  1039. cmMainFrame::CacheMapType* items = this->m_CacheEntries;
  1040. for(cmMainFrame::CacheMapType::iterator i = items->begin();
  1041. i != items->end(); ++i)
  1042. {
  1043. cmCacheProperty* item = i->second;
  1044. item->Remove(this->m_CacheValuesSizer, this->m_CacheValuesPanel);
  1045. }
  1046. items->erase(items->begin(), items->end());
  1047. }
  1048. void cmMainFrame::OnBinaryAccepted(wxCommandEvent&)
  1049. {
  1050. std::cout << "Pressed enter in binary field" << std::endl;
  1051. }
  1052. void cmMainFrame::OnBinarySelected(wxCommandEvent&)
  1053. {
  1054. if ( this->BuildDirectoryChanged() )
  1055. {
  1056. this->m_WhereBuild = this->GetBinaryDir();
  1057. this->ChangeWhereBuild();
  1058. }
  1059. //this->OnConfigure(e);
  1060. }
  1061. void cmMainFrame::OnSourceSelected(wxCommandEvent&)
  1062. {
  1063. if ( this->SourceDirectoryChanged() )
  1064. {
  1065. this->m_WhereSource = this->GetSourceDir();
  1066. }
  1067. }
  1068. std::string cmMainFrame::GetBinaryDir()
  1069. {
  1070. return std::string(this->m_PathBinary->GetValue().c_str());
  1071. }
  1072. std::string cmMainFrame::GetSourceDir()
  1073. {
  1074. return std::string(this->m_PathSource->GetValue().c_str());
  1075. }
  1076. bool cmMainFrame::SourceDirectoryChanged()
  1077. {
  1078. return (this->m_WhereSource != this->GetSourceDir());
  1079. }
  1080. bool cmMainFrame::BuildDirectoryChanged()
  1081. {
  1082. return (this->m_WhereBuild != this->GetBinaryDir());
  1083. }
  1084. void cmMainFrame::OnRandomEvent(wxEvent& event)
  1085. {
  1086. if ( event.GetEventType() == wxEVT_UPDATE_UI )
  1087. {
  1088. }
  1089. else
  1090. {
  1091. std::cout << "Random event: " << event.GetEventType() << std::endl;
  1092. }
  1093. }
  1094. void cmMainFrame::IgnoreCacheEntry(const char* key)
  1095. {
  1096. std::cout << "IgnoreCacheEntry " << key << std::endl;
  1097. }
  1098. void cmMainFrame::RemoveCacheEntry(cmCacheProperty* cprop)
  1099. {
  1100. this->m_Valid = false;
  1101. this->m_CMakeInstance->GetCacheManager()->RemoveCacheEntry(cprop->GetName().c_str());
  1102. cprop->MarkRemoved();
  1103. this->m_EntryRemoved = true;
  1104. }
  1105. void cmMainFrame::HelpCacheEntry(const char* key, const char* help)
  1106. {
  1107. wxMessageBox( help, key, wxICON_INFORMATION | wxOK );
  1108. }
  1109. void cmMainFrame::LoadFromRegistry()
  1110. {
  1111. //wxConfigBase *conf = (wxConfigBase*) wxConfigBase::Get();//new wxConfig("CMakeSetup");
  1112. wxConfig *conf = new wxConfig("CMakeSetup");
  1113. conf->SetPath("Settings/StartPath");
  1114. int cc;
  1115. char keyName[1024];
  1116. wxString regvalue;
  1117. for ( cc = 1; cc <= 10; cc ++ )
  1118. {
  1119. sprintf(keyName, "WhereSource%i", cc);
  1120. regvalue = "";
  1121. conf->Read(keyName, &regvalue);
  1122. if ( regvalue.size() > 0 )
  1123. {
  1124. if ( cc == 1 )
  1125. {
  1126. this->SetSourceDir(regvalue.c_str());
  1127. }
  1128. else
  1129. {
  1130. this->m_PathSource->Append(regvalue);
  1131. }
  1132. }
  1133. sprintf(keyName, "WhereBuild%i", cc);
  1134. regvalue = "";
  1135. conf->Read(keyName, &regvalue);
  1136. if ( regvalue.size() > 0 )
  1137. {
  1138. if ( cc == 1 )
  1139. {
  1140. this->SetBinaryDir(regvalue.c_str());
  1141. }
  1142. else
  1143. {
  1144. this->m_PathBinary->Append(regvalue);
  1145. }
  1146. }
  1147. }
  1148. delete conf;
  1149. }
  1150. void cmMainFrame::SaveToRegistry()
  1151. {
  1152. //wxConfigBase *conf = (wxConfigBase*) wxConfigBase::Get();//new wxConfig("CMakeSetup");
  1153. wxConfig *conf = new wxConfig("CMakeSetup");
  1154. conf->SetPath("Settings/StartPath");
  1155. wxString regvalue;
  1156. if ( !conf->Read("WhereSource1", &regvalue) )
  1157. {
  1158. regvalue = "";
  1159. }
  1160. int shiftEnd = 9;
  1161. if(this->m_WhereSource != regvalue.c_str())
  1162. {
  1163. char keyName[1024];
  1164. char keyName2[1024];
  1165. int i;
  1166. for (i = 2; i < 10; ++i)
  1167. {
  1168. regvalue = "";
  1169. sprintf(keyName,"WhereSource%i",i);
  1170. conf->Read(keyName, &regvalue);
  1171. // check for short circuit, if the new value is already in
  1172. // the list then we stop
  1173. if (this->m_WhereSource == regvalue.c_str())
  1174. {
  1175. shiftEnd = i - 1;
  1176. }
  1177. }
  1178. for (i = shiftEnd; i; --i)
  1179. {
  1180. regvalue = "";
  1181. sprintf(keyName,"WhereSource%i",i);
  1182. sprintf(keyName2,"WhereSource%i",i+1);
  1183. conf->Read(keyName, &regvalue);
  1184. if (strlen(regvalue.c_str()))
  1185. {
  1186. conf->Write(keyName2, wxString(regvalue.c_str()));
  1187. }
  1188. }
  1189. conf->Write("WhereSource1", wxString(this->m_WhereSource.c_str()));
  1190. }
  1191. conf->Read("WhereBuild1", &regvalue);
  1192. if(m_WhereBuild != regvalue.c_str())
  1193. {
  1194. int i;
  1195. char keyName[1024];
  1196. char keyName2[1024];
  1197. for (i = 2; i < 10; ++i)
  1198. {
  1199. regvalue = "";
  1200. sprintf(keyName,"WhereBuild%i",i);
  1201. conf->Read(keyName, &regvalue);
  1202. // check for short circuit, if the new value is already in
  1203. // the list then we stop
  1204. if (m_WhereBuild == regvalue.c_str())
  1205. {
  1206. shiftEnd = i - 1;
  1207. }
  1208. }
  1209. for (i = shiftEnd; i; --i)
  1210. {
  1211. regvalue = "";
  1212. sprintf(keyName,"WhereBuild%i",i);
  1213. sprintf(keyName2,"WhereBuild%i",i+1);
  1214. conf->Read(keyName, &regvalue);
  1215. if (strlen(regvalue.c_str()))
  1216. {
  1217. conf->Write(keyName2, wxString(regvalue.c_str()));
  1218. }
  1219. }
  1220. conf->Write("WhereBuild1", wxString(this->m_WhereBuild.c_str()));
  1221. }
  1222. delete conf;
  1223. }
  1224. void cmMainFrame::SetupStatusBarBinding(wxWindow* win)
  1225. {
  1226. win->SetClientData(this);
  1227. this->ConnectEventTo(win, wxEVT_MOTION,
  1228. (wxObjectEventFunction) &cmMainFrame::OnStatusBar);
  1229. }
  1230. void cmMainFrame::SetStatusText(const wxString& text, int number)
  1231. {
  1232. this->wxFrame::SetStatusText("________________________________________________");
  1233. this->wxFrame::SetStatusText(text, number);
  1234. }
  1235. void cmMainFrame::CursorBusy(bool s)
  1236. {
  1237. wxSetCursor(*wxHOURGLASS_CURSOR);
  1238. if ( s )
  1239. {
  1240. this->m_CursorChanged = true;
  1241. }
  1242. }
  1243. void cmMainFrame::CursorNormal(bool s)
  1244. {
  1245. wxSetCursor(*wxSTANDARD_CURSOR);
  1246. if ( s )
  1247. {
  1248. this->m_CursorChanged = false;
  1249. }
  1250. }
  1251. void cmMainFrame::OnSourceUpdated(wxCommandEvent& event)
  1252. {
  1253. this->OnSourceSelected(event);
  1254. }
  1255. void cmMainFrame::OnBinaryUpdated(wxCommandEvent&)
  1256. {
  1257. if ( this->BuildDirectoryChanged() )
  1258. {
  1259. this->m_WhereBuild = this->GetBinaryDir();
  1260. this->ChangeWhereBuild();
  1261. }
  1262. }