cmCursesPathWidget.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if ( !this->GetString() )
  35. {
  36. return;
  37. }
  38. FORM* form = fm->GetForm();
  39. form_driver(form, REQ_NEXT_FIELD);
  40. form_driver(form, REQ_PREV_FIELD);
  41. std::string cstr = this->GetString();
  42. cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
  43. if ( m_LastString != cstr )
  44. {
  45. m_Cycle = false;
  46. m_CurrentIndex = 0;
  47. m_LastGlob = "";
  48. }
  49. std::string glob;
  50. if ( m_Cycle )
  51. {
  52. glob = m_LastGlob;
  53. }
  54. else
  55. {
  56. glob = cstr + "*";
  57. }
  58. std::vector<std::string> dirs;
  59. cmSystemTools::SimpleGlob(glob.c_str(), dirs, (m_Type == cmCacheManager::PATH?-1:0));
  60. if ( m_CurrentIndex < dirs.size() )
  61. {
  62. cstr = dirs[m_CurrentIndex];
  63. }
  64. if ( cstr[cstr.size()-1] == '*' )
  65. {
  66. cstr = cstr.substr(0, cstr.size()-1);
  67. }
  68. if ( cmSystemTools::FileIsDirectory(cstr.c_str()) )
  69. {
  70. cstr += "/";
  71. }
  72. this->SetString(cstr.c_str());
  73. touchwin(w);
  74. wrefresh(w);
  75. form_driver(form, REQ_END_FIELD);
  76. m_LastGlob = glob;
  77. m_LastString = cstr;
  78. m_Cycle = true;
  79. m_CurrentIndex ++;
  80. if ( m_CurrentIndex >= dirs.size() )
  81. {
  82. m_CurrentIndex = 0;
  83. }
  84. }
  85. void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
  86. {
  87. this->cmCursesStringWidget::OnReturn(fm, w);
  88. }