2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2013-09-21 01:47:38 +04:00
|
|
|
#include "cmCursesOptionsWidget.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-01 22:55:09 +03:00
|
|
|
#include "cmCursesWidget.h"
|
|
|
|
#include "cmState.h"
|
2013-09-21 01:47:38 +04:00
|
|
|
|
2016-08-18 20:39:54 +03:00
|
|
|
#define ctrl(z) ((z)&037)
|
2013-09-21 01:47:38 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left,
|
|
|
|
int top)
|
|
|
|
: cmCursesWidget(width, height, left, top)
|
2013-09-21 01:47:38 +04:00
|
|
|
{
|
2015-04-07 23:45:54 +03:00
|
|
|
this->Type = cmState::BOOL; // this is a bit of a hack
|
2013-09-21 01:47:38 +04:00
|
|
|
// there is no option type, and string type causes ccmake to cast
|
|
|
|
// the widget into a string widget at some point. BOOL is safe for
|
|
|
|
// now.
|
2016-05-16 17:34:04 +03:00
|
|
|
set_field_fore(this->Field, A_NORMAL);
|
|
|
|
set_field_back(this->Field, A_STANDOUT);
|
|
|
|
field_opts_off(this->Field, O_STATIC);
|
2013-09-21 01:47:38 +04:00
|
|
|
}
|
|
|
|
|
2016-08-17 02:49:57 +03:00
|
|
|
bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
|
|
|
|
WINDOW* w)
|
2013-09-21 01:47:38 +04:00
|
|
|
{
|
2016-08-18 20:39:54 +03:00
|
|
|
switch (key) {
|
|
|
|
case 10: // 10 == enter
|
|
|
|
case KEY_ENTER:
|
|
|
|
this->NextOption();
|
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
return true;
|
|
|
|
case KEY_LEFT:
|
|
|
|
case ctrl('b'):
|
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
this->PreviousOption();
|
|
|
|
return true;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case ctrl('f'):
|
|
|
|
this->NextOption();
|
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-09-21 01:47:38 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCursesOptionsWidget::AddOption(std::string const& option)
|
2013-09-21 01:47:38 +04:00
|
|
|
{
|
|
|
|
this->Options.push_back(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesOptionsWidget::NextOption()
|
|
|
|
{
|
|
|
|
this->CurrentOption++;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CurrentOption > this->Options.size() - 1) {
|
2013-09-21 01:47:38 +04:00
|
|
|
this->CurrentOption = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetValue(this->Options[this->CurrentOption]);
|
2013-09-21 01:47:38 +04:00
|
|
|
}
|
|
|
|
void cmCursesOptionsWidget::PreviousOption()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CurrentOption == 0) {
|
|
|
|
this->CurrentOption = this->Options.size() - 1;
|
|
|
|
} else {
|
2013-09-21 01:47:38 +04:00
|
|
|
this->CurrentOption--;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetValue(this->Options[this->CurrentOption]);
|
2013-09-21 01:47:38 +04:00
|
|
|
}
|
|
|
|
|
2014-02-22 04:05:55 +04:00
|
|
|
void cmCursesOptionsWidget::SetOption(const std::string& value)
|
2013-09-21 01:47:38 +04:00
|
|
|
{
|
|
|
|
this->CurrentOption = 0; // default to 0 index
|
|
|
|
this->SetValue(value);
|
|
|
|
int index = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = this->Options.begin();
|
|
|
|
i != this->Options.end(); ++i) {
|
|
|
|
if (*i == value) {
|
2013-09-21 01:47:38 +04:00
|
|
|
this->CurrentOption = index;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
index++;
|
|
|
|
}
|
2013-09-21 01:47:38 +04:00
|
|
|
}
|