cmWXMainFrame.cxx 41 KB

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