1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCursesPathWidget.cxx,v $
6 Date: $Date: 2006/03/16 15:44:55 $
7 Version: $Revision: 1.10 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCursesPathWidget.h"
19 #include "cmCursesMainForm.h"
20 #include "cmSystemTools.h"
22 cmCursesPathWidget::cmCursesPathWidget(int width
, int height
,
24 cmCursesStringWidget(width
, height
, left
, top
)
26 this->Type
= cmCacheManager::PATH
;
28 this->CurrentIndex
= 0;
31 void cmCursesPathWidget::OnType(int& key
, cmCursesMainForm
* fm
, WINDOW
* w
)
34 this->CurrentIndex
= 0;
36 this->cmCursesStringWidget::OnType(key
, fm
, w
);
39 void cmCursesPathWidget::OnTab(cmCursesMainForm
* fm
, WINDOW
* w
)
41 if ( !this->GetString() )
45 FORM
* form
= fm
->GetForm();
46 form_driver(form
, REQ_NEXT_FIELD
);
47 form_driver(form
, REQ_PREV_FIELD
);
48 std::string cstr
= this->GetString();
49 cstr
= cstr
.substr(0, cstr
.find_last_not_of(" \t\n\r")+1);
50 if ( this->LastString
!= cstr
)
53 this->CurrentIndex
= 0;
59 glob
= this->LastGlob
;
65 std::vector
<cmStdString
> dirs
;
67 cmSystemTools::SimpleGlob(glob
.c_str(), dirs
, (this->Type
== cmCacheManager::PATH
?-1:0));
68 if ( this->CurrentIndex
< dirs
.size() )
70 cstr
= dirs
[this->CurrentIndex
];
72 if ( cstr
[cstr
.size()-1] == '*' )
74 cstr
= cstr
.substr(0, cstr
.size()-1);
77 if ( cmSystemTools::FileIsDirectory(cstr
.c_str()) )
82 this->SetString(cstr
.c_str());
85 form_driver(form
, REQ_END_FIELD
);
86 this->LastGlob
= glob
;
87 this->LastString
= cstr
;
89 this->CurrentIndex
++;
90 if ( this->CurrentIndex
>= dirs
.size() )
92 this->CurrentIndex
= 0;
96 void cmCursesPathWidget::OnReturn(cmCursesMainForm
* fm
, WINDOW
* w
)
98 this->cmCursesStringWidget::OnReturn(fm
, w
);