cmake/Source/CursesDialog/cmCursesPathWidget.cxx

82 lines
2.0 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesPathWidget.h"
#include "cmCursesMainForm.h"
2016-10-30 18:24:19 +01:00
#include "cmCursesStringWidget.h"
2017-04-14 19:02:05 +02:00
#include "cmStateTypes.h"
#include "cmSystemTools.h"
2016-10-30 18:24:19 +01:00
#include <vector>
2016-07-09 11:21:54 +02:00
cmCursesPathWidget::cmCursesPathWidget(int width, int height, int left,
int top)
: cmCursesStringWidget(width, height, left, top)
{
2017-04-14 19:02:05 +02:00
this->Type = cmStateEnums::PATH;
this->Cycle = false;
this->CurrentIndex = 0;
}
void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
{
this->Cycle = false;
this->CurrentIndex = 0;
this->LastGlob = "";
this->cmCursesStringWidget::OnType(key, fm, w);
}
void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
{
2016-07-09 11:21:54 +02:00
if (!this->GetString()) {
return;
2016-07-09 11:21:54 +02:00
}
FORM* form = fm->GetForm();
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
std::string cstr = this->GetString();
2016-07-09 11:21:54 +02:00
cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r") + 1);
if (this->LastString != cstr) {
this->Cycle = false;
this->CurrentIndex = 0;
this->LastGlob = "";
2016-07-09 11:21:54 +02:00
}
std::string glob;
2016-07-09 11:21:54 +02:00
if (this->Cycle) {
glob = this->LastGlob;
2016-07-09 11:21:54 +02:00
} else {
glob = cstr + "*";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
std::vector<std::string> dirs;
2016-07-09 11:21:54 +02:00
cmSystemTools::SimpleGlob(glob, dirs,
2017-04-14 19:02:05 +02:00
(this->Type == cmStateEnums::PATH ? -1 : 0));
2016-07-09 11:21:54 +02:00
if (this->CurrentIndex < dirs.size()) {
cstr = dirs[this->CurrentIndex];
2016-07-09 11:21:54 +02:00
}
if (cstr[cstr.size() - 1] == '*') {
cstr = cstr.substr(0, cstr.size() - 1);
}
2016-07-09 11:21:54 +02:00
if (cmSystemTools::FileIsDirectory(cstr)) {
cstr += "/";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
this->SetString(cstr);
2013-03-16 19:13:01 +02:00
touchwin(w);
wrefresh(w);
form_driver(form, REQ_END_FIELD);
this->LastGlob = glob;
this->LastString = cstr;
this->Cycle = true;
2016-07-09 11:21:54 +02:00
this->CurrentIndex++;
if (this->CurrentIndex >= dirs.size()) {
this->CurrentIndex = 0;
2016-07-09 11:21:54 +02:00
}
}
void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
{
this->cmCursesStringWidget::OnReturn(fm, w);
}