cmWXMainFrame.cxx 42 KB

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