cmCursesPathWidget.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. cmCursesPathWidget::cmCursesPathWidget(int width, int height,
  17. int left, int top) :
  18. cmCursesStringWidget(width, height, left, top)
  19. {
  20. this->Type = cmCacheManager::PATH;
  21. this->Cycle = false;
  22. this->CurrentIndex = 0;
  23. }
  24. void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
  25. {
  26. this->Cycle = false;
  27. this->CurrentIndex = 0;
  28. this->LastGlob = "";
  29. this->cmCursesStringWidget::OnType(key, fm, w);
  30. }
  31. void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
  32. {
  33. if ( !this->GetString() )
  34. {
  35. return;
  36. }
  37. FORM* form = fm->GetForm();
  38. form_driver(form, REQ_NEXT_FIELD);
  39. form_driver(form, REQ_PREV_FIELD);
  40. std::string cstr = this->GetString();
  41. cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
  42. if ( this->LastString != cstr )
  43. {
  44. this->Cycle = false;
  45. this->CurrentIndex = 0;
  46. this->LastGlob = "";
  47. }
  48. std::string glob;
  49. if ( this->Cycle )
  50. {
  51. glob = this->LastGlob;
  52. }
  53. else
  54. {
  55. glob = cstr + "*";
  56. }
  57. std::vector<cmStdString> dirs;
  58. cmSystemTools::SimpleGlob(glob.c_str(), dirs, (this->Type == cmCacheManager::PATH?-1:0));
  59. if ( this->CurrentIndex < dirs.size() )
  60. {
  61. cstr = dirs[this->CurrentIndex];
  62. }
  63. if ( cstr[cstr.size()-1] == '*' )
  64. {
  65. cstr = cstr.substr(0, cstr.size()-1);
  66. }
  67. if ( cmSystemTools::FileIsDirectory(cstr.c_str()) )
  68. {
  69. cstr += "/";
  70. }
  71. this->SetString(cstr.c_str());
  72. touchwin(w);
  73. wrefresh(w);
  74. form_driver(form, REQ_END_FIELD);
  75. this->LastGlob = glob;
  76. this->LastString = cstr;
  77. this->Cycle = true;
  78. this->CurrentIndex ++;
  79. if ( this->CurrentIndex >= dirs.size() )
  80. {
  81. this->CurrentIndex = 0;
  82. }
  83. }
  84. void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
  85. {
  86. this->cmCursesStringWidget::OnReturn(fm, w);
  87. }