cmCursesCacheEntryComposite.cxx 4.09 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Will Schroeder's avatar
Will Schroeder committed
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
Will Schroeder's avatar
Will Schroeder committed
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
Berk Geveci's avatar
Berk Geveci committed
12
#include "cmCursesCacheEntryComposite.h"
13
#include "cmCursesOptionsWidget.h"
Berk Geveci's avatar
Berk Geveci committed
14
15
16
17
18
19
#include "cmCursesStringWidget.h"
#include "cmCursesLabelWidget.h"
#include "cmCursesBoolWidget.h"
#include "cmCursesPathWidget.h"
#include "cmCursesFilePathWidget.h"
#include "cmCursesDummyWidget.h"
20
#include "../cmSystemTools.h"
21
#include "../cmake.h"
Stephen Kelly's avatar
Stephen Kelly committed
22
#include "../cmState.h"
23
24

#include <assert.h>
Berk Geveci's avatar
Berk Geveci committed
25

26
27
28
29
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
                                                        const std::string& key,
                                                        int labelwidth,
                                                        int entrywidth) :
Ken Martin's avatar
Ken Martin committed
30
  Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
Berk Geveci's avatar
Berk Geveci committed
31
{
Ken Martin's avatar
Ken Martin committed
32
33
  this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
34
  this->Entry = 0;
35
  this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
Berk Geveci's avatar
Berk Geveci committed
36
37
38
}

cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
39
  const std::string& key, cmake *cm, bool isNew,
40
  int labelwidth, int entrywidth)
Ken Martin's avatar
Ken Martin committed
41
  : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
Berk Geveci's avatar
Berk Geveci committed
42
{
Ken Martin's avatar
Ken Martin committed
43
  this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
Berk Geveci's avatar
Berk Geveci committed
44
45
  if (isNew)
    {
Ken Martin's avatar
Ken Martin committed
46
    this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
Berk Geveci's avatar
Berk Geveci committed
47
48
49
    }
  else
    {
Ken Martin's avatar
Ken Martin committed
50
    this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
Berk Geveci's avatar
Berk Geveci committed
51
52
    }

Ken Martin's avatar
Ken Martin committed
53
  this->Entry = 0;
Stephen Kelly's avatar
Stephen Kelly committed
54
  const char* value = cm->GetState()->GetCacheEntryValue(key);
55
  assert(value);
Stephen Kelly's avatar
Stephen Kelly committed
56
  switch (cm->GetState()->GetCacheEntryType(key))
Berk Geveci's avatar
Berk Geveci committed
57
    {
58
    case cmState::BOOL:
Ken Martin's avatar
Ken Martin committed
59
      this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
60
      if (cmSystemTools::IsOn(value))
61
        {
Ken Martin's avatar
Ken Martin committed
62
        static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
63
        }
Berk Geveci's avatar
Berk Geveci committed
64
      else
65
        {
Ken Martin's avatar
Ken Martin committed
66
        static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
67
        }
Berk Geveci's avatar
Berk Geveci committed
68
      break;
69
    case cmState::PATH:
Ken Martin's avatar
Ken Martin committed
70
      this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
71
      static_cast<cmCursesPathWidget*>(this->Entry)->SetString(value);
Berk Geveci's avatar
Berk Geveci committed
72
      break;
73
    case cmState::FILEPATH:
Ken Martin's avatar
Ken Martin committed
74
      this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
75
      static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
Berk Geveci's avatar
Berk Geveci committed
76
      break;
77
    case cmState::STRING:
78
      {
Stephen Kelly's avatar
Stephen Kelly committed
79
      const char* stringsProp = cm->GetState()
80
81
                                  ->GetCacheEntryProperty(key, "STRINGS");
      if(stringsProp)
82
83
84
85
86
        {
        cmCursesOptionsWidget* ow =
          new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
        this->Entry = ow;
        std::vector<std::string> options;
87
        cmSystemTools::ExpandListArgument(stringsProp, options);
88
89
90
91
92
        for(std::vector<std::string>::iterator
              si = options.begin(); si != options.end(); ++si)
          {
          ow->AddOption(*si);
          }
93
        ow->SetOption(value);
94
95
96
97
        }
      else
        {
        this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
98
        static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
99
        }
100
      break;
101
      }
102
    case cmState::UNINITIALIZED:
103
      cmSystemTools::Error("Found an undefined variable: ",
104
                           key.c_str());
Berk Geveci's avatar
Berk Geveci committed
105
106
107
108
109
110
111
112
113
114
      break;
    default:
      // TODO : put warning message here
      break;
    }

}

cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
{
Ken Martin's avatar
Ken Martin committed
115
116
117
  delete this->Label;
  delete this->IsNewLabel;
  delete this->Entry;
Berk Geveci's avatar
Berk Geveci committed
118
}
119
120
121

const char* cmCursesCacheEntryComposite::GetValue()
{
Ken Martin's avatar
Ken Martin committed
122
  if (this->Label)
123
    {
Ken Martin's avatar
Ken Martin committed
124
    return this->Label->GetValue();
125
126
127
128
129
130
    }
  else
    {
    return 0;
    }
}