cmCursesPathWidget.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCursesPathWidget.h"
  11. #include "cmCursesMainForm.h"
  12. #include "cmSystemTools.h"
  13. cmCursesPathWidget::cmCursesPathWidget(int width, int height,
  14. int left, int top) :
  15. cmCursesStringWidget(width, height, left, top)
  16. {
  17. this->Type = cmCacheManager::PATH;
  18. this->Cycle = false;
  19. this->CurrentIndex = 0;
  20. }
  21. void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
  22. {
  23. this->Cycle = false;
  24. this->CurrentIndex = 0;
  25. this->LastGlob = "";
  26. this->cmCursesStringWidget::OnType(key, fm, w);
  27. }
  28. void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
  29. {
  30. if ( !this->GetString() )
  31. {
  32. return;
  33. }
  34. FORM* form = fm->GetForm();
  35. form_driver(form, REQ_NEXT_FIELD);
  36. form_driver(form, REQ_PREV_FIELD);
  37. std::string cstr = this->GetString();
  38. cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
  39. if ( this->LastString != cstr )
  40. {
  41. this->Cycle = false;
  42. this->CurrentIndex = 0;
  43. this->LastGlob = "";
  44. }
  45. std::string glob;
  46. if ( this->Cycle )
  47. {
  48. glob = this->LastGlob;
  49. }
  50. else
  51. {
  52. glob = cstr + "*";
  53. }
  54. std::vector<std::string> dirs;
  55. cmSystemTools::SimpleGlob(glob, dirs, (this->Type == cmCacheManager::PATH?-1:0));
  56. if ( this->CurrentIndex < dirs.size() )
  57. {
  58. cstr = dirs[this->CurrentIndex];
  59. }
  60. if ( cstr[cstr.size()-1] == '*' )
  61. {
  62. cstr = cstr.substr(0, cstr.size()-1);
  63. }
  64. if ( cmSystemTools::FileIsDirectory(cstr) )
  65. {
  66. cstr += "/";
  67. }
  68. this->SetString(cstr);
  69. touchwin(w);
  70. wrefresh(w);
  71. form_driver(form, REQ_END_FIELD);
  72. this->LastGlob = glob;
  73. this->LastString = cstr;
  74. this->Cycle = true;
  75. this->CurrentIndex ++;
  76. if ( this->CurrentIndex >= dirs.size() )
  77. {
  78. this->CurrentIndex = 0;
  79. }
  80. }
  81. void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
  82. {
  83. this->cmCursesStringWidget::OnReturn(fm, w);
  84. }