cmCursesPathWidget.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCursesPathWidget.h"
  14. #include "cmCursesMainForm.h"
  15. #include "cmSystemTools.h"
  16. #include "cmDirectory.h"
  17. cmCursesPathWidget::cmCursesPathWidget(int width, int height,
  18. int left, int top) :
  19. cmCursesStringWidget(width, height, left, top)
  20. {
  21. m_Type = cmCacheManager::PATH;
  22. m_Cycle = false;
  23. m_CurrentIndex = 0;
  24. }
  25. void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
  26. {
  27. m_Cycle = false;
  28. m_CurrentIndex = 0;
  29. m_LastGlob = "";
  30. this->cmCursesStringWidget::OnType(key, fm, w);
  31. }
  32. void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
  33. {
  34. std::string::size_type cc;
  35. if ( !this->GetString() )
  36. {
  37. return;
  38. }
  39. FORM* form = fm->GetForm();
  40. form_driver(form, REQ_NEXT_FIELD);
  41. form_driver(form, REQ_PREV_FIELD);
  42. std::string cstr = this->GetString();
  43. cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
  44. if ( m_LastString != cstr )
  45. {
  46. m_Cycle = false;
  47. m_CurrentIndex = 0;
  48. m_LastGlob = "";
  49. }
  50. std::string glob;
  51. if ( m_Cycle )
  52. {
  53. glob = m_LastGlob;
  54. }
  55. else
  56. {
  57. glob = cstr + "*";
  58. }
  59. std::vector<std::string> dirs;
  60. cmSystemTools::SimpleGlob(glob.c_str(), dirs, (m_Type == cmCacheManager::PATH?-1:0));
  61. if ( m_CurrentIndex < dirs.size() )
  62. {
  63. cstr = dirs[m_CurrentIndex];
  64. }
  65. if ( cstr[cstr.size()-1] == '*' )
  66. {
  67. cstr = cstr.substr(0, cstr.size()-1);
  68. }
  69. this->SetString(cstr.c_str());
  70. touchwin(w);
  71. wrefresh(w);
  72. form_driver(form, REQ_END_FIELD);
  73. m_LastGlob = glob;
  74. m_LastString = cstr;
  75. m_Cycle = true;
  76. m_CurrentIndex ++;
  77. if ( m_CurrentIndex >= dirs.size() )
  78. {
  79. m_CurrentIndex = 0;
  80. }
  81. }
  82. void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
  83. {
  84. this->cmCursesStringWidget::OnReturn(fm, w);
  85. }