Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CursesDialog / cmCursesPathWidget.cxx
blobfe1c4f95416f567467c703f7c88b9ba142ce8d9b
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCursesPathWidget.cxx,v $
5 Language: C++
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,
23 int left, int top) :
24 cmCursesStringWidget(width, height, left, top)
26 this->Type = cmCacheManager::PATH;
27 this->Cycle = false;
28 this->CurrentIndex = 0;
31 void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
33 this->Cycle = false;
34 this->CurrentIndex = 0;
35 this->LastGlob = "";
36 this->cmCursesStringWidget::OnType(key, fm, w);
39 void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
41 if ( !this->GetString() )
43 return;
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 )
52 this->Cycle = false;
53 this->CurrentIndex = 0;
54 this->LastGlob = "";
56 std::string glob;
57 if ( this->Cycle )
59 glob = this->LastGlob;
61 else
63 glob = cstr + "*";
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()) )
79 cstr += "/";
82 this->SetString(cstr.c_str());
83 touchwin(w);
84 wrefresh(w);
85 form_driver(form, REQ_END_FIELD);
86 this->LastGlob = glob;
87 this->LastString = cstr;
88 this->Cycle = true;
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);