cmCursesMainForm.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. #include "../cmCacheManager.h"
  2. #include "../cmSystemTools.h"
  3. #include "../cmake.h"
  4. #include "cmCursesMainForm.h"
  5. #include "cmCursesStringWidget.h"
  6. #include "cmCursesLabelWidget.h"
  7. #include "cmCursesBoolWidget.h"
  8. #include "cmCursesPathWidget.h"
  9. #include "cmCursesFilePathWidget.h"
  10. #include "cmCursesDummyWidget.h"
  11. #include "cmCursesCacheEntryComposite.h"
  12. #include "cmCursesLongMessageForm.h"
  13. inline int ctrl(int z)
  14. {
  15. return (z&037);
  16. }
  17. cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args) :
  18. m_Args(args)
  19. {
  20. m_Fields = 0;
  21. m_Height = 0;
  22. m_Entries = 0;
  23. m_AdvancedMode = false;
  24. m_NumberOfVisibleEntries = 0;
  25. m_OkToGenerate = false;
  26. m_HelpMessage.push_back("Welcome to ccmake, curses based user interface for CMake.");
  27. m_HelpMessage.push_back("");
  28. m_HelpMessage.push_back(s_ConstHelpMessage);
  29. }
  30. cmCursesMainForm::~cmCursesMainForm()
  31. {
  32. if (m_Form)
  33. {
  34. unpost_form(m_Form);
  35. free_form(m_Form);
  36. m_Form = 0;
  37. }
  38. delete[] m_Fields;
  39. // Clean-up composites
  40. if (m_Entries)
  41. {
  42. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  43. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  44. {
  45. delete *it;
  46. }
  47. }
  48. delete m_Entries;
  49. }
  50. bool cmCursesMainForm::LookForCacheEntry(const char* key)
  51. {
  52. if (!key || !m_Entries)
  53. {
  54. return false;
  55. }
  56. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  57. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  58. {
  59. if (!strcmp(key, (*it)->m_Key.c_str()))
  60. {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. void cmCursesMainForm::InitializeUI()
  67. {
  68. // Get the cache entries.
  69. const cmCacheManager::CacheEntryMap &cache =
  70. cmCacheManager::GetInstance()->GetCacheMap();
  71. std::vector<cmCursesCacheEntryComposite*>* newEntries =
  72. new std::vector<cmCursesCacheEntryComposite*>;
  73. newEntries->reserve(cache.size());
  74. // Count non-internal and non-static entries
  75. int count=0;
  76. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  77. i != cache.end(); ++i)
  78. {
  79. const cmCacheManager::CacheEntry& value = i->second;
  80. if ( value.m_Type != cmCacheManager::INTERNAL &&
  81. value.m_Type != cmCacheManager::STATIC )
  82. {
  83. ++count;
  84. }
  85. }
  86. cmCursesCacheEntryComposite* comp;
  87. if ( count == 0 )
  88. {
  89. // If cache is empty, display a label saying so and a
  90. // dummy entry widget (does not respond to input)
  91. comp = new cmCursesCacheEntryComposite("EMPTY CACHE");
  92. comp->m_Entry = new cmCursesDummyWidget(1, 1, 1, 1);
  93. newEntries->push_back(comp);
  94. }
  95. else
  96. {
  97. // Create the composites.
  98. // First add entries which are new
  99. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  100. i != cache.end(); ++i)
  101. {
  102. const char* key = i->first.c_str();
  103. const cmCacheManager::CacheEntry& value = i->second;
  104. if ( value.m_Type == cmCacheManager::INTERNAL ||
  105. value.m_Type == cmCacheManager::STATIC )
  106. {
  107. continue;
  108. }
  109. if (!this->LookForCacheEntry(key))
  110. {
  111. newEntries->push_back(new cmCursesCacheEntryComposite(key, value,
  112. true));
  113. m_OkToGenerate = false;
  114. }
  115. }
  116. // then add entries which are old
  117. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  118. i != cache.end(); ++i)
  119. {
  120. const char* key = i->first.c_str();
  121. const cmCacheManager::CacheEntry& value = i->second;
  122. if ( value.m_Type == cmCacheManager::INTERNAL ||
  123. value.m_Type == cmCacheManager::STATIC )
  124. {
  125. continue;
  126. }
  127. if (this->LookForCacheEntry(key))
  128. {
  129. newEntries->push_back(new cmCursesCacheEntryComposite(key, value,
  130. false));
  131. }
  132. }
  133. }
  134. if (m_Entries)
  135. {
  136. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  137. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  138. {
  139. delete *it;
  140. }
  141. }
  142. delete m_Entries;
  143. m_Entries = newEntries;
  144. this->RePost();
  145. }
  146. void cmCursesMainForm::RePost()
  147. {
  148. // Create the fields to be passed to the form.
  149. if (m_Form)
  150. {
  151. unpost_form(m_Form);
  152. free_form(m_Form);
  153. m_Form = 0;
  154. }
  155. delete[] m_Fields;
  156. if (m_AdvancedMode)
  157. {
  158. m_NumberOfVisibleEntries = m_Entries->size();
  159. }
  160. else
  161. {
  162. m_NumberOfVisibleEntries = 0;
  163. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  164. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  165. {
  166. if (!m_AdvancedMode && cmCacheManager::GetInstance()->IsAdvanced(
  167. (*it)->GetValue()))
  168. {
  169. continue;
  170. }
  171. m_NumberOfVisibleEntries++;
  172. }
  173. }
  174. m_Fields = new FIELD*[3*m_NumberOfVisibleEntries+1];
  175. int j=0;
  176. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  177. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  178. {
  179. if (!m_AdvancedMode && cmCacheManager::GetInstance()->IsAdvanced(
  180. (*it)->GetValue()))
  181. {
  182. continue;
  183. }
  184. m_Fields[3*j] = (*it)->m_Label->m_Field;
  185. m_Fields[3*j+1] = (*it)->m_IsNewLabel->m_Field;
  186. m_Fields[3*j+2] = (*it)->m_Entry->m_Field;
  187. j++;
  188. }
  189. // Has to be null terminated.
  190. m_Fields[3*m_NumberOfVisibleEntries] = 0;
  191. }
  192. void cmCursesMainForm::Render(int left, int top, int width, int height)
  193. {
  194. if (m_Form)
  195. {
  196. FIELD* currentField = current_field(m_Form);
  197. cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
  198. (field_userptr(currentField));
  199. if ( cw->GetType() == cmCacheManager::STRING ||
  200. cw->GetType() == cmCacheManager::PATH ||
  201. cw->GetType() == cmCacheManager::FILEPATH )
  202. {
  203. cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
  204. sw->SetInEdit(false);
  205. }
  206. unpost_form(m_Form);
  207. free_form(m_Form);
  208. m_Form = 0;
  209. }
  210. if ( width < cmCursesMainForm::MIN_WIDTH ||
  211. height < cmCursesMainForm::MIN_HEIGHT )
  212. {
  213. return;
  214. }
  215. height -= 6;
  216. m_Height = height;
  217. if (m_AdvancedMode)
  218. {
  219. m_NumberOfVisibleEntries = m_Entries->size();
  220. }
  221. else
  222. {
  223. m_NumberOfVisibleEntries = 0;
  224. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  225. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  226. {
  227. if (!m_AdvancedMode && cmCacheManager::GetInstance()->IsAdvanced(
  228. (*it)->GetValue()))
  229. {
  230. continue;
  231. }
  232. m_NumberOfVisibleEntries++;
  233. }
  234. }
  235. bool isNewPage;
  236. int i=0;
  237. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  238. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  239. {
  240. if (!m_AdvancedMode && cmCacheManager::GetInstance()->IsAdvanced(
  241. (*it)->GetValue()))
  242. {
  243. continue;
  244. }
  245. int row = (i % height) + 1;
  246. int page = (i / height) + 1;
  247. isNewPage = ( page > 1 ) && ( row == 1 );
  248. (*it)->m_Label->Move(left, top+row-1, isNewPage);
  249. (*it)->m_IsNewLabel->Move(left+32, top+row-1, false);
  250. (*it)->m_Entry->Move(left+33, top+row-1, false);
  251. i++;
  252. }
  253. m_Form = new_form(m_Fields);
  254. post_form(m_Form);
  255. this->UpdateStatusBar();
  256. this->PrintKeys();
  257. touchwin(stdscr);
  258. refresh();
  259. }
  260. void cmCursesMainForm::PrintKeys()
  261. {
  262. int x,y;
  263. getmaxyx(stdscr, y, x);
  264. if ( x < cmCursesMainForm::MIN_WIDTH ||
  265. y < cmCursesMainForm::MIN_HEIGHT )
  266. {
  267. return;
  268. }
  269. char firstLine[512], secondLine[512];
  270. if (m_OkToGenerate)
  271. {
  272. sprintf(firstLine, "C)onfigure G)enerate and Exit H)elp");
  273. }
  274. else
  275. {
  276. sprintf(firstLine, "C)onfigure H)elp");
  277. }
  278. if (m_AdvancedMode)
  279. {
  280. sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (On)");
  281. }
  282. else
  283. {
  284. sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (Off)");
  285. }
  286. curses_move(y-2,0);
  287. printw(firstLine);
  288. curses_move(y-1,0);
  289. printw(secondLine);
  290. pos_form_cursor(m_Form);
  291. }
  292. // Print the key of the current entry and the CMake version
  293. // on the status bar. Designed for a width of 80 chars.
  294. void cmCursesMainForm::UpdateStatusBar()
  295. {
  296. int x,y;
  297. getmaxyx(stdscr, y, x);
  298. if ( x < cmCursesMainForm::MIN_WIDTH ||
  299. y < cmCursesMainForm::MIN_HEIGHT )
  300. {
  301. curses_clear();
  302. curses_move(0,0);
  303. printw("Window is too small. A size of at least %dx%d is required.",
  304. cmCursesMainForm::MIN_WIDTH, cmCursesMainForm::MIN_HEIGHT);
  305. touchwin(stdscr);
  306. wrefresh(stdscr);
  307. return;
  308. }
  309. FIELD* cur = current_field(m_Form);
  310. int index = field_index(cur);
  311. cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
  312. m_Fields[index-2]));
  313. const char* curField = lbl->GetValue();
  314. // We want to display this on the right
  315. char help[128];
  316. const char* helpString;
  317. cmCacheManager::CacheEntry *entry =
  318. cmCacheManager::GetInstance()->GetCacheEntry(curField);
  319. if (entry)
  320. {
  321. helpString = entry->m_HelpString.c_str();
  322. if (strlen(helpString) > 127)
  323. {
  324. sprintf(help,"%127s", helpString);
  325. }
  326. else
  327. {
  328. sprintf(help,"%s", helpString);
  329. }
  330. }
  331. else
  332. {
  333. sprintf(help," ");
  334. }
  335. char bar[cmCursesMainForm::MAX_WIDTH];
  336. int i, curFieldLen = strlen(curField);
  337. int helpLen = strlen(help);
  338. int width;
  339. if (x < cmCursesMainForm::MAX_WIDTH )
  340. {
  341. width = x;
  342. }
  343. else
  344. {
  345. width = cmCursesMainForm::MAX_WIDTH;
  346. }
  347. if (curFieldLen >= width)
  348. {
  349. strncpy(bar, curField, width);
  350. }
  351. else
  352. {
  353. strcpy(bar, curField);
  354. bar[curFieldLen] = ':';
  355. bar[curFieldLen+1] = ' ';
  356. if (curFieldLen + helpLen + 2 >= width)
  357. {
  358. strncpy(bar+curFieldLen+2, help, width
  359. - curFieldLen - 2);
  360. }
  361. else
  362. {
  363. strcpy(bar+curFieldLen+2, help);
  364. for(i=curFieldLen+helpLen+2; i < width; ++i)
  365. {
  366. bar[i] = ' ';
  367. }
  368. }
  369. }
  370. bar[width] = '\0';
  371. char version[cmCursesMainForm::MAX_WIDTH];
  372. char vertmp[128];
  373. sprintf(vertmp,"CMake Version %d.%d", cmMakefile::GetMajorVersion(),
  374. cmMakefile::GetMinorVersion());
  375. int sideSpace = (width-strlen(vertmp));
  376. for(i=0; i<sideSpace; i++) { version[i] = ' '; }
  377. sprintf(version+sideSpace, "%s", vertmp);
  378. version[width] = '\0';
  379. curses_move(y-4,0);
  380. attron(A_STANDOUT);
  381. printw(bar);
  382. attroff(A_STANDOUT);
  383. curses_move(y-3,0);
  384. printw(version);
  385. pos_form_cursor(m_Form);
  386. }
  387. void cmCursesMainForm::RunCMake(bool generateMakefiles)
  388. {
  389. int x,y;
  390. getmaxyx(stdscr, y, x);
  391. curses_clear();
  392. curses_move(1,1);
  393. touchwin(stdscr);
  394. refresh();
  395. endwin();
  396. std::cerr << "Running CMake, please wait...\n\r";
  397. // always save the current gui values to disk
  398. this->FillCacheManagerFromUI();
  399. cmCacheManager::GetInstance()->SaveCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
  400. // create a cmake object
  401. cmake make;
  402. // create the arguments for the cmake object
  403. std::string whereCMake = cmSystemTools::GetProgramPath(m_Args[0].c_str());
  404. whereCMake += "/cmake";
  405. m_Args[0] = whereCMake;
  406. // Get rid of previous errors
  407. m_Errors = std::vector<std::string>();
  408. // run the generate process
  409. m_OkToGenerate = true;
  410. if(make.Generate(m_Args, generateMakefiles) != 0 || !m_Errors.empty())
  411. {
  412. m_OkToGenerate = false;
  413. cmSystemTools::ResetErrorOccuredFlag();
  414. int x,y;
  415. getmaxyx(stdscr, y, x);
  416. cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
  417. "Errors which during last pass.");
  418. CurrentForm = msgs;
  419. msgs->Render(1,1,x,y);
  420. msgs->HandleInput();
  421. CurrentForm = this;
  422. this->Render(1,1,x,y);
  423. }
  424. initscr(); /* Initialization */
  425. noecho(); /* Echo off */
  426. cbreak(); /* nl- or cr not needed */
  427. keypad(stdscr,TRUE); /* Use key symbols as
  428. KEY_DOWN*/
  429. this->InitializeUI();
  430. this->Render(1, 1, x, y);
  431. }
  432. void cmCursesMainForm::AddError(const char* message, const char* title)
  433. {
  434. m_Errors.push_back(message);
  435. }
  436. void cmCursesMainForm::RemoveEntry(const char* value)
  437. {
  438. if (!value)
  439. {
  440. return;
  441. }
  442. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  443. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  444. {
  445. const char* val = (*it)->GetValue();
  446. if ( val && !strcmp(value, val) )
  447. {
  448. m_Entries->erase(it);
  449. break;
  450. }
  451. }
  452. }
  453. // copy from the list box to the cache manager
  454. void cmCursesMainForm::FillCacheManagerFromUI()
  455. {
  456. std::string tmpString;
  457. cmCacheManager::GetInstance()->GetCacheMap();
  458. int size = m_Entries->size();
  459. for(int i=0; i < size; i++)
  460. {
  461. cmCacheManager::CacheEntry *entry =
  462. cmCacheManager::GetInstance()->GetCacheEntry(
  463. (*m_Entries)[i]->m_Key.c_str());
  464. if (entry)
  465. {
  466. tmpString = (*m_Entries)[i]->m_Entry->GetValue();
  467. // Remove trailing spaces
  468. entry->m_Value = tmpString.substr(0,tmpString.find_last_not_of(" ")+1);
  469. }
  470. }
  471. }
  472. void cmCursesMainForm::HandleInput()
  473. {
  474. if (!m_Form)
  475. {
  476. return;
  477. }
  478. FIELD* currentField;
  479. cmCursesWidget* currentWidget;
  480. while(1)
  481. {
  482. this->UpdateStatusBar();
  483. this->PrintKeys();
  484. int key = getch();
  485. currentField = current_field(m_Form);
  486. currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
  487. currentField));
  488. if (!currentWidget || !currentWidget->HandleInput(key, m_Form, stdscr))
  489. {
  490. // quit
  491. if ( key == 'q' )
  492. {
  493. break;
  494. }
  495. // if not end of page, next field otherwise next page
  496. // each entry consists of fields: label, isnew, value
  497. // therefore, the label field for the prev. entry is index-5
  498. // and the label field for the next entry is index+1
  499. // (index always corresponds to the value field)
  500. else if ( key == KEY_DOWN || key == ctrl('n') )
  501. {
  502. FIELD* cur = current_field(m_Form);
  503. int index = field_index(cur);
  504. if ( index == 3*m_NumberOfVisibleEntries-1 )
  505. {
  506. continue;
  507. }
  508. if (new_page(m_Fields[index+1]))
  509. {
  510. form_driver(m_Form, REQ_NEXT_PAGE);
  511. }
  512. else
  513. {
  514. form_driver(m_Form, REQ_NEXT_FIELD);
  515. }
  516. }
  517. // if not beginning of page, previous field, otherwise previous page
  518. // each entry consists of fields: label, isnew, value
  519. // therefore, the label field for the prev. entry is index-5
  520. // and the label field for the next entry is index+1
  521. // (index always corresponds to the value field)
  522. else if ( key == KEY_UP || key == ctrl('p') )
  523. {
  524. FIELD* cur = current_field(m_Form);
  525. int index = field_index(cur);
  526. if ( index == 2 )
  527. {
  528. continue;
  529. }
  530. if ( new_page(m_Fields[index-2]) )
  531. {
  532. form_driver(m_Form, REQ_PREV_PAGE);
  533. set_current_field(m_Form, m_Fields[index-3]);
  534. }
  535. else
  536. {
  537. form_driver(m_Form, REQ_PREV_FIELD);
  538. }
  539. }
  540. // pg down
  541. else if ( key == KEY_NPAGE || key == ctrl('d') )
  542. {
  543. form_driver(m_Form, REQ_NEXT_PAGE);
  544. }
  545. // pg up
  546. else if ( key == KEY_PPAGE || key == ctrl('u') )
  547. {
  548. form_driver(m_Form, REQ_PREV_PAGE);
  549. }
  550. // configure
  551. else if ( key == 'c' )
  552. {
  553. this->RunCMake(false);
  554. }
  555. // display help
  556. else if ( key == 'h' )
  557. {
  558. int x,y;
  559. getmaxyx(stdscr, y, x);
  560. FIELD* cur = current_field(m_Form);
  561. int index = field_index(cur);
  562. cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
  563. m_Fields[index-2]));
  564. const char* curField = lbl->GetValue();
  565. const char* helpString=0;
  566. cmCacheManager::CacheEntry *entry =
  567. cmCacheManager::GetInstance()->GetCacheEntry(curField);
  568. if (entry)
  569. {
  570. helpString = entry->m_HelpString.c_str();
  571. }
  572. if (helpString)
  573. {
  574. char* message = new char[strlen(curField)+strlen(helpString)
  575. +strlen("Current option is: \n Help string for this option is: \n")+10];
  576. sprintf(message,"Current option is: %s\nHelp string for this option is: %s\n", curField, helpString);
  577. m_HelpMessage[1] = message;
  578. delete[] message;
  579. }
  580. else
  581. {
  582. m_HelpMessage[1] = "";
  583. }
  584. cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_HelpMessage,
  585. "Help.");
  586. CurrentForm = msgs;
  587. msgs->Render(1,1,x,y);
  588. msgs->HandleInput();
  589. CurrentForm = this;
  590. this->Render(1,1,x,y);
  591. }
  592. // display last errors
  593. else if ( key == 'l' )
  594. {
  595. int x,y;
  596. getmaxyx(stdscr, y, x);
  597. cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
  598. "Errors which during last pass.");
  599. CurrentForm = msgs;
  600. msgs->Render(1,1,x,y);
  601. msgs->HandleInput();
  602. CurrentForm = this;
  603. this->Render(1,1,x,y);
  604. }
  605. // switch advanced on/off
  606. else if ( key == 't' )
  607. {
  608. if (m_AdvancedMode)
  609. {
  610. m_AdvancedMode = false;
  611. }
  612. else
  613. {
  614. m_AdvancedMode = true;
  615. }
  616. int x,y;
  617. getmaxyx(stdscr, y, x);
  618. this->RePost();
  619. this->Render(1, 1, x, y);
  620. }
  621. // generate and exit
  622. else if ( key == 'g' )
  623. {
  624. if ( m_OkToGenerate )
  625. {
  626. this->RunCMake(true);
  627. break;
  628. }
  629. }
  630. // delete cache entry
  631. else if ( key == 'd' )
  632. {
  633. FIELD* cur = current_field(m_Form);
  634. int index = field_index(cur);
  635. // make the next or prev. current field after deletion
  636. // each entry consists of fields: label, isnew, value
  637. // therefore, the label field for the prev. entry is index-5
  638. // and the label field for the next entry is index+1
  639. // (index always corresponds to the value field)
  640. FIELD* nextCur;
  641. if ( index == 2 )
  642. {
  643. nextCur=0;
  644. }
  645. else if ( index == 3*m_NumberOfVisibleEntries-1 )
  646. {
  647. nextCur = m_Fields[index-5];
  648. }
  649. else
  650. {
  651. nextCur = m_Fields[index+1];
  652. }
  653. // Get the label widget
  654. // each entry consists of fields: label, isnew, value
  655. // therefore, the label field for the is index-2
  656. // (index always corresponds to the value field)
  657. cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
  658. m_Fields[index-2]));
  659. cmCacheManager::GetInstance()->RemoveCacheEntry(lbl->GetValue());
  660. std::string nextVal;
  661. if (nextCur)
  662. {
  663. nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
  664. }
  665. int x,y;
  666. getmaxyx(stdscr, y, x);
  667. this->RemoveEntry(lbl->GetValue());
  668. this->RePost();
  669. this->Render(1, 1, x, y);
  670. if (nextCur)
  671. {
  672. // make the next or prev. current field after deletion
  673. nextCur = 0;
  674. std::vector<cmCursesCacheEntryComposite*>::iterator it;
  675. for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
  676. {
  677. if (nextVal == (*it)->m_Key)
  678. {
  679. nextCur = (*it)->m_Entry->m_Field;
  680. }
  681. }
  682. if (nextCur)
  683. {
  684. set_current_field(m_Form, nextCur);
  685. }
  686. }
  687. }
  688. }
  689. touchwin(stdscr);
  690. wrefresh(stdscr);
  691. }
  692. }
  693. const char* cmCursesMainForm::s_ConstHelpMessage =
  694. "CMake is used to configure and generate build files for software projects. "
  695. "The basic steps for configuring a project with ccmake are as follows:\n\n"
  696. "1. Run ccmake in the directory where you want the object and executable files to be placed (build directory). If the source directory is not the same as this build directory, you have to specify it as an argument on the command line.\n\n"
  697. "2. When ccmake is run, it will read the configuration files and display the current build options. "
  698. "If you have run CMake before and have updated the configuration files since then, any new entries will be displayed on top and will be marked with a *. "
  699. "On the other hand, the first time you run ccmake, all build options will be new and will be marked as such. "
  700. "At this point, you can modify any options (see keys below) you want to change. "
  701. "When you are satisfied with your changes, press 'c' to have CMake process the configuration files. "
  702. "Please note that changing some options may cause new ones to appear. These will be shown on top and will be marked with *. "
  703. "Repeat this procedure until you are satisfied with all the options and there are no new entries. "
  704. "At this point, a new command will appear: G)enerate and Exit. You can now hit 'g' to have CMake generate all the build files (i.e. makefiles or project files) and exit. "
  705. "At any point during the process, you can exit ccmake with 'q'. However, this will not generate/change any build files.\n\n"
  706. "ccmake KEYS:\n\n"
  707. "Navigation: "
  708. "You can use the arrow keys and page up, down to navigate the options. Alternatively, you can use the following keys: \n"
  709. " C-n : next option\n"
  710. " C-p : previous options\n"
  711. " C-d : down one page\n"
  712. " C-u : up one page\n\n"
  713. "Editing options: "
  714. "To change an option press enter or return. If the current options is a boolean, this will toggle it's value. "
  715. "Otherwise, ccmake will enter edit mode. In this mode you can edit an option using arrow keys and backspace. Alternatively, you can use the following keys:\n"
  716. " C-b : back one character\n"
  717. " C-f : forward one character\n"
  718. " C-a : go to the beginning of the field\n"
  719. " C-e : go to the end of the field\n"
  720. " C-d : delete previous character\n"
  721. " C-k : kill the rest of the field\n"
  722. " Esc : Restore field (discard last changes)\n"
  723. " Enter : Leave edit mode\n"
  724. "You can also delete an option by pressing 'd'\n\n"
  725. "Commands:\n"
  726. " q : quit ccmake without generating build files\n"
  727. " h : help, shows this screen\n"
  728. " c : process the configuration files with the current options\n"
  729. " g : generate build files and exit, only available when there are no "
  730. "new options and no errors have been detected during last configuration.\n"
  731. " l : shows last errors\n"
  732. " t : toggles advanced mode. In normal mode, only the most important options are shown. In advanced mode, all options are shown. We recommend using normal mode unless you are an expert.\n";