CMake/Source/CursesDialog/cmCursesMainForm.cxx

1265 lines
34 KiB
C++
Raw Normal View History

2002-01-21 23:30:43 +03:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
2002-01-21 23:30:43 +03:00
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
2002-01-21 23:30:43 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "../cmCacheManager.h"
#include "../cmSystemTools.h"
#include "../cmake.h"
2001-11-05 02:05:21 +03:00
#include "cmCursesMainForm.h"
#include "cmCursesStringWidget.h"
#include "cmCursesLabelWidget.h"
#include "cmCursesBoolWidget.h"
#include "cmCursesPathWidget.h"
#include "cmCursesFilePathWidget.h"
#include "cmCursesDummyWidget.h"
#include "cmCursesCacheEntryComposite.h"
2001-11-30 00:44:22 +03:00
#include "cmCursesLongMessageForm.h"
2001-11-05 02:05:21 +03:00
2001-11-06 06:10:52 +03:00
inline int ctrl(int z)
{
return (z&037);
}
cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
2002-10-17 18:51:23 +04:00
int initWidth) :
m_Args(args), m_InitialWidth(initWidth)
2001-11-05 02:05:21 +03:00
{
2001-12-13 21:28:41 +03:00
m_NumberOfPages = 0;
2001-11-05 02:05:21 +03:00
m_Fields = 0;
m_Entries = 0;
2001-11-30 00:44:22 +03:00
m_AdvancedMode = false;
m_NumberOfVisibleEntries = 0;
m_OkToGenerate = false;
2001-11-30 22:16:28 +03:00
m_HelpMessage.push_back("Welcome to ccmake, curses based user interface for CMake.");
m_HelpMessage.push_back("");
2001-11-30 00:44:22 +03:00
m_HelpMessage.push_back(s_ConstHelpMessage);
m_CMakeInstance = new cmake;
2002-09-06 21:00:12 +04:00
// create the arguments for the cmake object
std::string whereCMake = cmSystemTools::GetProgramPath(m_Args[0].c_str());
whereCMake += "/cmake";
m_Args[0] = whereCMake;
m_CMakeInstance->SetArgs(m_Args);
2002-09-17 22:04:33 +04:00
m_CMakeInstance->SetCMakeCommand(whereCMake.c_str());
2003-03-07 19:27:28 +03:00
m_SearchString = "";
m_OldSearchString = "";
m_SearchMode = false;
2001-11-05 02:05:21 +03:00
}
cmCursesMainForm::~cmCursesMainForm()
{
if (m_Form)
{
unpost_form(m_Form);
free_form(m_Form);
m_Form = 0;
}
delete[] m_Fields;
// Clean-up composites
if (m_Entries)
{
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
delete *it;
}
}
delete m_Entries;
if (this->m_CMakeInstance)
{
delete this->m_CMakeInstance;
this->m_CMakeInstance = 0;
}
2001-11-05 02:05:21 +03:00
}
2001-12-13 21:28:41 +03:00
// See if a cache entry is in the list of entries in the ui.
2001-11-05 02:05:21 +03:00
bool cmCursesMainForm::LookForCacheEntry(const char* key)
{
if (!key || !m_Entries)
{
return false;
}
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (!strcmp(key, (*it)->m_Key.c_str()))
{
return true;
}
}
return false;
}
2001-12-13 21:28:41 +03:00
// Create new cmCursesCacheEntryComposite entries from the cache
2001-11-30 00:44:22 +03:00
void cmCursesMainForm::InitializeUI()
2001-11-05 02:05:21 +03:00
{
2001-12-13 21:28:41 +03:00
// Create a vector of cmCursesCacheEntryComposite's
// which contain labels, entries and new entry markers
2001-11-05 02:05:21 +03:00
std::vector<cmCursesCacheEntryComposite*>* newEntries =
new std::vector<cmCursesCacheEntryComposite*>;
newEntries->reserve(this->m_CMakeInstance->GetCacheManager()->GetSize());
2001-11-05 02:05:21 +03:00
// Count non-internal and non-static entries
int count=0;
2002-08-21 23:37:49 +04:00
for(cmCacheManager::CacheIterator i =
this->m_CMakeInstance->GetCacheManager()->NewIterator();
2002-08-21 23:37:49 +04:00
!i.IsAtEnd(); i.Next())
2001-11-05 02:05:21 +03:00
{
if ( i.GetType() != cmCacheManager::INTERNAL &&
2002-10-17 18:51:23 +04:00
i.GetType() != cmCacheManager::STATIC &&
i.GetType() != cmCacheManager::UNINITIALIZED)
2001-11-05 02:05:21 +03:00
{
++count;
}
}
int entrywidth = m_InitialWidth - 35;
2001-11-05 02:05:21 +03:00
cmCursesCacheEntryComposite* comp;
if ( count == 0 )
{
// If cache is empty, display a label saying so and a
// dummy entry widget (does not respond to input)
comp = new cmCursesCacheEntryComposite("EMPTY CACHE", 30, 30);
2001-11-05 02:05:21 +03:00
comp->m_Entry = new cmCursesDummyWidget(1, 1, 1, 1);
newEntries->push_back(comp);
}
else
{
// Create the composites.
// First add entries which are new
2002-08-21 23:37:49 +04:00
for(cmCacheManager::CacheIterator i =
this->m_CMakeInstance->GetCacheManager()->NewIterator();
2002-08-21 23:37:49 +04:00
!i.IsAtEnd(); i.Next())
2001-11-05 02:05:21 +03:00
{
2002-08-21 23:37:49 +04:00
const char* key = i.GetName();
if ( i.GetType() == cmCacheManager::INTERNAL ||
2002-10-17 18:51:23 +04:00
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
2002-10-17 18:51:23 +04:00
{
continue;
}
2001-11-05 02:05:21 +03:00
if (!this->LookForCacheEntry(key))
2002-10-17 18:51:23 +04:00
{
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
true, 30,
entrywidth));
m_OkToGenerate = false;
}
2001-11-05 02:05:21 +03:00
}
// then add entries which are old
2002-08-21 23:37:49 +04:00
for(cmCacheManager::CacheIterator i =
this->m_CMakeInstance->GetCacheManager()->NewIterator();
2002-08-21 23:37:49 +04:00
!i.IsAtEnd(); i.Next())
2001-11-05 02:05:21 +03:00
{
2002-08-21 23:37:49 +04:00
const char* key = i.GetName();
if ( i.GetType() == cmCacheManager::INTERNAL ||
2002-10-17 18:51:23 +04:00
i.GetType() == cmCacheManager::STATIC ||
i.GetType() == cmCacheManager::UNINITIALIZED )
2002-10-17 18:51:23 +04:00
{
continue;
}
2001-11-05 02:05:21 +03:00
if (this->LookForCacheEntry(key))
2002-10-17 18:51:23 +04:00
{
newEntries->push_back(new cmCursesCacheEntryComposite(key, i,
false, 30,
entrywidth));
}
2001-11-05 02:05:21 +03:00
}
}
2001-12-13 21:28:41 +03:00
// Clean old entries
2001-11-05 02:05:21 +03:00
if (m_Entries)
{
2001-12-13 21:28:41 +03:00
// Have to call delete on each pointer
2001-11-05 02:05:21 +03:00
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
delete *it;
}
}
delete m_Entries;
m_Entries = newEntries;
2001-12-13 21:28:41 +03:00
// Compute fields from composites
2001-11-30 00:44:22 +03:00
this->RePost();
}
void cmCursesMainForm::RePost()
{
2001-11-05 02:05:21 +03:00
// Create the fields to be passed to the form.
if (m_Form)
{
unpost_form(m_Form);
free_form(m_Form);
m_Form = 0;
}
delete[] m_Fields;
2001-11-30 00:44:22 +03:00
if (m_AdvancedMode)
{
m_NumberOfVisibleEntries = m_Entries->size();
}
else
{
2001-12-13 21:28:41 +03:00
// If normal mode, count only non-advanced entries
2001-11-30 00:44:22 +03:00
m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
2002-10-17 18:51:23 +04:00
{
continue;
}
2001-11-30 00:44:22 +03:00
m_NumberOfVisibleEntries++;
}
}
2001-12-13 21:28:41 +03:00
// Assign the fields: 3 for each entry: label, new entry marker
// ('*' or ' ') and entry widget
2001-11-30 00:44:22 +03:00
m_Fields = new FIELD*[3*m_NumberOfVisibleEntries+1];
2001-12-13 21:28:41 +03:00
// Assign fields
2001-11-30 00:44:22 +03:00
int j=0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
2001-11-05 02:05:21 +03:00
{
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
2001-11-30 00:44:22 +03:00
{
continue;
}
m_Fields[3*j] = (*it)->m_Label->m_Field;
m_Fields[3*j+1] = (*it)->m_IsNewLabel->m_Field;
m_Fields[3*j+2] = (*it)->m_Entry->m_Field;
j++;
2001-11-05 02:05:21 +03:00
}
2001-11-30 00:44:22 +03:00
2001-11-05 02:05:21 +03:00
// Has to be null terminated.
2001-11-30 00:44:22 +03:00
m_Fields[3*m_NumberOfVisibleEntries] = 0;
2001-11-05 02:05:21 +03:00
}
void cmCursesMainForm::Render(int left, int top, int width, int height)
{
if (m_Form)
{
FIELD* currentField = current_field(m_Form);
cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
(field_userptr(currentField));
2001-12-13 21:28:41 +03:00
// If in edit mode, get out of it
2001-11-05 02:05:21 +03:00
if ( cw->GetType() == cmCacheManager::STRING ||
2002-10-17 18:51:23 +04:00
cw->GetType() == cmCacheManager::PATH ||
cw->GetType() == cmCacheManager::FILEPATH )
2001-11-05 02:05:21 +03:00
{
cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
sw->SetInEdit(false);
}
2001-12-13 21:28:41 +03:00
// Delete the previous form
2001-11-05 02:05:21 +03:00
unpost_form(m_Form);
free_form(m_Form);
m_Form = 0;
}
2001-12-13 21:28:41 +03:00
// Wrong window size
2001-11-06 06:10:52 +03:00
if ( width < cmCursesMainForm::MIN_WIDTH ||
width < m_InitialWidth ||
2001-11-06 06:10:52 +03:00
height < cmCursesMainForm::MIN_HEIGHT )
2001-11-05 02:05:21 +03:00
{
return;
}
2001-12-13 21:28:41 +03:00
// Leave room for toolbar
height -= 7;
2001-11-05 02:05:21 +03:00
2001-11-30 00:44:22 +03:00
if (m_AdvancedMode)
{
m_NumberOfVisibleEntries = m_Entries->size();
}
else
{
2001-12-13 21:28:41 +03:00
// If normal, display only non-advanced entries
2001-11-30 00:44:22 +03:00
m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
{
2002-10-17 18:51:23 +04:00
continue;
}
2001-11-30 00:44:22 +03:00
m_NumberOfVisibleEntries++;
}
}
2001-12-13 21:28:41 +03:00
// Re-adjust the fields according to their place
2001-11-05 02:05:21 +03:00
bool isNewPage;
2001-11-30 00:44:22 +03:00
int i=0;
2001-12-13 21:28:41 +03:00
m_NumberOfPages = 1;
2001-11-30 00:44:22 +03:00
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
2001-11-05 02:05:21 +03:00
{
cmCacheManager::CacheIterator mit =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator((*it)->GetValue());
if (mit.IsAtEnd() || !m_AdvancedMode && mit.GetPropertyAsBool("ADVANCED"))
2001-11-30 00:44:22 +03:00
{
continue;
}
2001-11-05 02:05:21 +03:00
int row = (i % height) + 1;
int page = (i / height) + 1;
isNewPage = ( page > 1 ) && ( row == 1 );
2001-12-13 21:28:41 +03:00
if (isNewPage)
{
m_NumberOfPages++;
}
2001-11-30 00:44:22 +03:00
(*it)->m_Label->Move(left, top+row-1, isNewPage);
(*it)->m_IsNewLabel->Move(left+32, top+row-1, false);
(*it)->m_Entry->Move(left+33, top+row-1, false);
2001-12-13 21:28:41 +03:00
(*it)->m_Entry->SetPage(m_NumberOfPages);
2001-11-30 00:44:22 +03:00
i++;
2001-11-05 02:05:21 +03:00
}
2001-11-30 00:44:22 +03:00
2001-12-13 21:28:41 +03:00
// Post the form
2001-11-05 02:05:21 +03:00
m_Form = new_form(m_Fields);
post_form(m_Form);
2001-12-13 21:28:41 +03:00
// Update toolbar
2001-11-06 06:10:52 +03:00
this->UpdateStatusBar();
this->PrintKeys();
2001-11-30 00:44:22 +03:00
touchwin(stdscr);
2001-11-05 02:05:21 +03:00
refresh();
}
2002-11-19 21:09:16 +03:00
void cmCursesMainForm::PrintKeys(int process /* = 0 */)
2001-11-05 02:05:21 +03:00
{
int x,y;
2001-11-30 00:44:22 +03:00
getmaxyx(stdscr, y, x);
2001-11-06 06:10:52 +03:00
if ( x < cmCursesMainForm::MIN_WIDTH ||
x < m_InitialWidth ||
2001-11-06 06:10:52 +03:00
y < cmCursesMainForm::MIN_HEIGHT )
{
return;
}
2001-12-13 21:28:41 +03:00
// Give the current widget (if it exists), a chance to print keys
cmCursesWidget* cw = 0;
if (m_Form)
2001-11-30 00:44:22 +03:00
{
2001-12-13 21:28:41 +03:00
FIELD* currentField = current_field(m_Form);
cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
2001-11-30 00:44:22 +03:00
}
2001-12-13 21:28:41 +03:00
2002-09-06 21:00:12 +04:00
if (cw)
2001-11-30 00:44:22 +03:00
{
2002-09-06 21:00:12 +04:00
cw->PrintKeys();
2001-11-30 00:44:22 +03:00
}
2002-09-06 21:00:12 +04:00
// {
// }
// else
// {
2002-11-19 21:09:16 +03:00
char firstLine[512]="";
char secondLine[512]="";
char thirdLine[512]="";
if (process)
{
sprintf(firstLine,
" ");
sprintf(secondLine,
" ");
sprintf(thirdLine,
" ");
}
else
{
2001-12-13 21:28:41 +03:00
if (m_OkToGenerate)
{
2002-11-19 21:09:16 +03:00
sprintf(firstLine,
"Press [c] to configure Press [g] to generate and exit");
2001-12-13 21:28:41 +03:00
}
else
{
2002-09-06 21:00:12 +04:00
sprintf(firstLine, "Press [c] to configure ");
2001-12-13 21:28:41 +03:00
}
if (m_AdvancedMode)
{
sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently On)");
}
else
{
sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently Off)");
}
2002-11-19 21:09:16 +03:00
sprintf(secondLine,
"Press [h] for help Press [q] to quit without generating");
}
2001-12-13 21:28:41 +03:00
2002-11-19 21:09:16 +03:00
curses_move(y-4,0);
char fmt[512] = "Press [enter] to edit option";
2002-11-19 21:09:16 +03:00
if ( process )
{
strcpy(fmt, " ");
2002-11-19 21:09:16 +03:00
}
printw(fmt);
curses_move(y-3,0);
printw(firstLine);
curses_move(y-2,0);
printw(secondLine);
curses_move(y-1,0);
printw(thirdLine);
2001-12-13 21:28:41 +03:00
2002-11-19 21:09:16 +03:00
if (cw)
{
sprintf(firstLine, "Page %d of %d", cw->GetPage(), m_NumberOfPages);
curses_move(0,65-strlen(firstLine)-1);
2001-12-13 21:28:41 +03:00
printw(firstLine);
2002-11-19 21:09:16 +03:00
}
2002-09-06 21:00:12 +04:00
// }
2001-11-06 06:10:52 +03:00
pos_form_cursor(m_Form);
}
// Print the key of the current entry and the CMake version
// on the status bar. Designed for a width of 80 chars.
2002-11-19 21:09:16 +03:00
void cmCursesMainForm::UpdateStatusBar(const char* message)
2001-11-06 06:10:52 +03:00
{
int x,y;
2001-11-30 00:44:22 +03:00
getmaxyx(stdscr, y, x);
2001-12-13 21:28:41 +03:00
// If window size is too small, display error and return
2001-11-06 06:10:52 +03:00
if ( x < cmCursesMainForm::MIN_WIDTH ||
x < m_InitialWidth ||
2001-11-06 06:10:52 +03:00
y < cmCursesMainForm::MIN_HEIGHT )
{
curses_clear();
curses_move(0,0);
2002-06-11 17:14:19 +04:00
char fmt[] = "Window is too small. A size of at least %dx%d is required.";
printw(fmt,
2002-10-17 18:51:23 +04:00
(cmCursesMainForm::MIN_WIDTH < m_InitialWidth ?
m_InitialWidth : cmCursesMainForm::MIN_WIDTH),
cmCursesMainForm::MIN_HEIGHT);
2001-11-30 00:44:22 +03:00
touchwin(stdscr);
wrefresh(stdscr);
2001-11-06 06:10:52 +03:00
return;
}
2001-12-13 21:28:41 +03:00
// Get the key of the current entry
2001-11-06 06:10:52 +03:00
FIELD* cur = current_field(m_Form);
2002-10-17 18:51:23 +04:00
int findex = field_index(cur);
cmCursesWidget* lbl = 0;
2002-10-17 18:51:23 +04:00
if ( findex >= 0 )
{
2002-10-17 18:51:23 +04:00
lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(m_Fields[findex-2]));
}
char help[128] = "";
const char* curField = "";
if ( lbl )
2001-11-30 00:44:22 +03:00
{
curField = lbl->GetValue();
// Get the help string of the current entry
// and add it to the help string
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
if (!it.IsAtEnd())
{
const char* hs = it.GetProperty("HELPSTRING");
if ( hs )
{
strncpy(help, hs, 127);
help[127] = '\0';
}
else
{
help[0] = 0;
}
}
else
{
sprintf(help," ");
}
2001-11-30 00:44:22 +03:00
}
2001-11-05 02:05:21 +03:00
2001-12-13 21:28:41 +03:00
// Join the key, help string and pad with spaces
// (or truncate) as necessary
2001-11-06 06:10:52 +03:00
char bar[cmCursesMainForm::MAX_WIDTH];
int i, curFieldLen = strlen(curField);
2001-11-30 00:44:22 +03:00
int helpLen = strlen(help);
int width;
if (x < cmCursesMainForm::MAX_WIDTH )
2001-11-06 06:10:52 +03:00
{
2001-11-30 00:44:22 +03:00
width = x;
2001-11-06 06:10:52 +03:00
}
else
{
2001-11-30 00:44:22 +03:00
width = cmCursesMainForm::MAX_WIDTH;
2001-11-06 06:10:52 +03:00
}
2002-11-19 21:09:16 +03:00
if ( message )
2001-11-06 06:10:52 +03:00
{
2002-11-19 21:09:16 +03:00
curField = message;
curFieldLen = strlen(message);
if ( curFieldLen < width )
{
strcpy(bar, curField);
for(i=curFieldLen; i < width; ++i)
{
bar[i] = ' ';
}
}
else
{
strncpy(bar, curField, width);
}
}
2001-11-06 06:10:52 +03:00
else
{
2002-11-19 21:09:16 +03:00
if (curFieldLen >= width)
2001-11-06 06:10:52 +03:00
{
2002-11-19 21:09:16 +03:00
strncpy(bar, curField, width);
2001-11-30 00:44:22 +03:00
}
else
{
2002-11-19 21:09:16 +03:00
strcpy(bar, curField);
bar[curFieldLen] = ':';
bar[curFieldLen+1] = ' ';
if (curFieldLen + helpLen + 2 >= width)
{
strncpy(bar+curFieldLen+2, help, width
- curFieldLen - 2);
}
else
{
strcpy(bar+curFieldLen+2, help);
for(i=curFieldLen+helpLen+2; i < width; ++i)
{
bar[i] = ' ';
}
}
2001-11-06 06:10:52 +03:00
}
}
2002-11-19 21:09:16 +03:00
2001-11-06 06:10:52 +03:00
2001-11-30 00:44:22 +03:00
bar[width] = '\0';
2002-11-19 21:09:16 +03:00
2001-12-13 21:28:41 +03:00
// Display CMake version info on the next line
2001-12-05 00:19:33 +03:00
// We want to display this on the right
2001-11-30 00:44:22 +03:00
char version[cmCursesMainForm::MAX_WIDTH];
char vertmp[128];
2002-09-06 21:00:12 +04:00
sprintf(vertmp,"CMake Version %d.%d - %s", cmake::GetMajorVersion(),
2002-10-17 18:51:23 +04:00
cmake::GetMinorVersion(),cmake::GetReleaseVersion());
2001-11-30 00:44:22 +03:00
int sideSpace = (width-strlen(vertmp));
for(i=0; i<sideSpace; i++) { version[i] = ' '; }
sprintf(version+sideSpace, "%s", vertmp);
version[width] = '\0';
2001-12-13 21:28:41 +03:00
// Now print both lines
curses_move(y-5,0);
2001-11-06 06:10:52 +03:00
attron(A_STANDOUT);
2002-11-22 17:45:50 +03:00
char format[] = "%s";
printw(format, bar);
2001-11-06 06:10:52 +03:00
attroff(A_STANDOUT);
2001-12-13 21:28:41 +03:00
curses_move(y-4,0);
2001-11-30 00:44:22 +03:00
printw(version);
2001-11-05 02:05:21 +03:00
pos_form_cursor(m_Form);
}
2002-11-19 21:09:16 +03:00
void cmCursesMainForm::UpdateProgressOld(const char *msg, float prog, void*)
2002-11-19 00:29:14 +03:00
{
if ( prog < 0 )
{
std::cout << "-- " << msg << std::endl;
}
}
2002-11-19 21:09:16 +03:00
void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void* vp)
{
cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp);
if ( !cm )
{
return;
}
char tmp[1024];
const char *cmsg = tmp;
if ( prog >= 0 )
{
sprintf(tmp, "%s %i%%",msg,(int)(100*prog));
}
else
{
cmsg = msg;
}
cm->UpdateStatusBar(cmsg);
cm->PrintKeys(1);
curses_move(1,1);
touchwin(stdscr);
refresh();
}
int cmCursesMainForm::Configure(int noconfigure)
2001-11-05 02:05:21 +03:00
{
2002-10-17 18:51:23 +04:00
int xi,yi;
getmaxyx(stdscr, yi, xi);
2001-11-30 00:44:22 +03:00
curses_move(1,1);
2002-11-19 21:09:16 +03:00
this->UpdateStatusBar("Configuring, please wait...");
this->PrintKeys(1);
touchwin(stdscr);
2001-11-30 00:44:22 +03:00
refresh();
2002-11-19 00:29:14 +03:00
this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
2001-11-05 02:05:21 +03:00
// always save the current gui values to disk
this->FillCacheManagerFromUI();
this->m_CMakeInstance->GetCacheManager()->SaveCache(
m_CMakeInstance->GetHomeOutputDirectory());
2002-09-06 21:00:12 +04:00
2001-11-30 00:44:22 +03:00
// Get rid of previous errors
m_Errors = std::vector<std::string>();
2001-11-05 02:05:21 +03:00
// run the generate process
2001-11-30 00:44:22 +03:00
m_OkToGenerate = true;
int retVal;
if ( noconfigure )
{
retVal = this->m_CMakeInstance->DoPreConfigureChecks();
m_OkToGenerate = false;
if ( retVal > 0 )
{
retVal = 0;
}
}
else
{
retVal = this->m_CMakeInstance->Configure();
}
2002-11-19 00:29:14 +03:00
this->m_CMakeInstance->SetProgressCallback(0, 0);
keypad(stdscr,TRUE); /* Use key symbols as
2002-10-17 18:51:23 +04:00
KEY_DOWN*/
if( retVal != 0 || !m_Errors.empty())
2001-11-05 02:05:21 +03:00
{
// see if there was an error
if(cmSystemTools::GetErrorOccuredFlag())
{
m_OkToGenerate = false;
}
// reset error condition
2001-11-05 02:05:21 +03:00
cmSystemTools::ResetErrorOccuredFlag();
2002-10-17 18:51:23 +04:00
int xx,yy;
getmaxyx(stdscr, yy, xx);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
m_Errors,
cmSystemTools::GetErrorOccuredFlag() ? "Errors occurred during the last pass." :
"CMake produced the following output.");
2001-11-30 00:44:22 +03:00
CurrentForm = msgs;
2002-10-17 18:51:23 +04:00
msgs->Render(1,1,xx,yy);
2001-11-30 00:44:22 +03:00
msgs->HandleInput();
2002-04-24 00:16:48 +04:00
// If they typed the wrong source directory, we report
// an error and exit
if ( retVal == -2 )
{
return retVal;
}
2001-11-30 00:44:22 +03:00
CurrentForm = this;
2002-10-17 18:51:23 +04:00
this->Render(1,1,xx,yy);
2001-11-05 02:05:21 +03:00
}
2001-11-06 06:10:52 +03:00
2001-11-30 00:44:22 +03:00
this->InitializeUI();
2002-10-17 18:51:23 +04:00
this->Render(1, 1, xi, yi);
2001-11-05 02:05:21 +03:00
2002-04-24 00:16:48 +04:00
return 0;
2001-11-05 02:05:21 +03:00
}
2002-09-06 21:00:12 +04:00
int cmCursesMainForm::Generate()
{
2002-10-17 18:51:23 +04:00
int xi,yi;
getmaxyx(stdscr, yi, xi);
2002-09-06 21:00:12 +04:00
curses_move(1,1);
2002-11-19 21:09:16 +03:00
this->UpdateStatusBar("Generating, please wait...");
this->PrintKeys(1);
2002-09-06 21:00:12 +04:00
touchwin(stdscr);
refresh();
2002-11-19 00:29:14 +03:00
this->m_CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
2002-09-06 21:00:12 +04:00
// Get rid of previous errors
m_Errors = std::vector<std::string>();
// run the generate process
int retVal = this->m_CMakeInstance->Generate();
2002-11-19 00:29:14 +03:00
this->m_CMakeInstance->SetProgressCallback(0, 0);
2002-09-06 21:00:12 +04:00
keypad(stdscr,TRUE); /* Use key symbols as
2002-10-17 18:51:23 +04:00
KEY_DOWN*/
2002-09-06 21:00:12 +04:00
if( retVal != 0 || !m_Errors.empty())
{
// see if there was an error
if(cmSystemTools::GetErrorOccuredFlag())
{
m_OkToGenerate = false;
}
// reset error condition
cmSystemTools::ResetErrorOccuredFlag();
2002-10-17 18:51:23 +04:00
int xx,yy;
getmaxyx(stdscr, yy, xx);
2002-09-06 21:00:12 +04:00
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
2002-10-17 18:51:23 +04:00
"Errors occurred during the last pass.");
2002-09-06 21:00:12 +04:00
CurrentForm = msgs;
2002-10-17 18:51:23 +04:00
msgs->Render(1,1,xx,yy);
2002-09-06 21:00:12 +04:00
msgs->HandleInput();
// If they typed the wrong source directory, we report
// an error and exit
if ( retVal == -2 )
{
return retVal;
}
CurrentForm = this;
2002-10-17 18:51:23 +04:00
this->Render(1,1,xx,yy);
2002-09-06 21:00:12 +04:00
}
this->InitializeUI();
2002-10-17 18:51:23 +04:00
this->Render(1, 1, xi, yi);
2002-09-06 21:00:12 +04:00
return 0;
}
void cmCursesMainForm::AddError(const char* message, const char*)
2001-11-30 00:44:22 +03:00
{
m_Errors.push_back(message);
}
void cmCursesMainForm::RemoveEntry(const char* value)
{
if (!value)
{
return;
}
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
const char* val = (*it)->GetValue();
if ( val && !strcmp(value, val) )
{
m_Entries->erase(it);
break;
}
}
}
2001-11-05 02:05:21 +03:00
// copy from the list box to the cache manager
void cmCursesMainForm::FillCacheManagerFromUI()
{
2001-11-05 23:55:24 +03:00
std::string tmpString;
2001-11-05 02:05:21 +03:00
int size = m_Entries->size();
for(int i=0; i < size; i++)
{
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(
2002-10-17 18:51:23 +04:00
(*m_Entries)[i]->m_Key.c_str());
if (!it.IsAtEnd())
2001-11-05 02:05:21 +03:00
{
2001-11-05 23:55:24 +03:00
tmpString = (*m_Entries)[i]->m_Entry->GetValue();
2001-12-07 01:07:18 +03:00
// Remove trailing spaces, convert path to unix slashes
2001-12-07 01:40:25 +03:00
std::string tmpSubString =
2002-10-17 18:51:23 +04:00
tmpString.substr(0,tmpString.find_last_not_of(" ")+1);
if ( it.GetType() == cmCacheManager::PATH ||
2002-10-17 18:51:23 +04:00
it.GetType() == cmCacheManager::FILEPATH )
{
cmSystemTools::ConvertToUnixSlashes(tmpSubString);
}
it.SetValue(tmpSubString.c_str());
2001-11-05 02:05:21 +03:00
}
}
}
2003-03-07 19:27:28 +03:00
#include <unistd.h>
2001-11-05 02:05:21 +03:00
void cmCursesMainForm::HandleInput()
{
2003-03-10 02:16:46 +03:00
int x=0,y=0;
2001-12-13 21:28:41 +03:00
2001-11-05 02:05:21 +03:00
if (!m_Form)
{
return;
}
FIELD* currentField;
cmCursesWidget* currentWidget;
2001-12-04 19:16:04 +03:00
char debugMessage[128];
2001-11-05 02:05:21 +03:00
while(1)
{
2001-11-06 06:10:52 +03:00
this->UpdateStatusBar();
this->PrintKeys();
2003-03-07 19:27:28 +03:00
if ( m_SearchMode )
{
std::string searchstr = "Search: " + m_SearchString;
this->UpdateStatusBar( searchstr.c_str() );
this->PrintKeys(1);
curses_move(y-5,searchstr.size());
//curses_move(1,1);
touchwin(stdscr);
refresh();
}
2001-11-05 02:05:21 +03:00
int key = getch();
2001-12-13 21:28:41 +03:00
getmaxyx(stdscr, y, x);
// If window too small, handle 'q' only
if ( x < cmCursesMainForm::MIN_WIDTH ||
2002-10-17 18:51:23 +04:00
y < cmCursesMainForm::MIN_HEIGHT )
2001-12-13 21:28:41 +03:00
{
// quit
if ( key == 'q' )
2002-10-17 18:51:23 +04:00
{
break;
}
2001-12-13 21:28:41 +03:00
else
2002-10-17 18:51:23 +04:00
{
continue;
}
2001-12-13 21:28:41 +03:00
}
2001-11-05 02:05:21 +03:00
currentField = current_field(m_Form);
currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
currentField));
2003-03-10 02:16:46 +03:00
bool widgetHandled=false;
2003-03-07 19:27:28 +03:00
if ( m_SearchMode )
{
if ( key == 10 || key == KEY_ENTER )
{
m_SearchMode = false;
if ( m_SearchString.size() > 0 )
{
this->JumpToCacheEntry(-1, m_SearchString.c_str());
m_OldSearchString = m_SearchString;
}
m_SearchString = "";
}
/*
else if ( key == KEY_ESCAPE )
{
m_SearchMode = false;
}
*/
else if ( key >= 'a' && key <= 'z' ||
key >= 'A' && key <= 'Z' ||
key >= '0' && key <= '9' ||
key == '_' )
{
2003-03-07 19:53:20 +03:00
if ( m_SearchString.size() < static_cast<std::string::size_type>(x-10) )
2003-03-07 19:27:28 +03:00
{
m_SearchString += key;
}
}
else if ( key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC )
{
if ( m_SearchString.size() > 0 )
{
m_SearchString.resize(m_SearchString.size()-1);
}
}
}
else if (currentWidget && !m_SearchMode)
2002-09-06 21:00:12 +04:00
{
2003-03-07 19:27:28 +03:00
// Ask the current widget if it wants to handle input
2002-09-06 21:00:12 +04:00
widgetHandled = currentWidget->HandleInput(key, this, stdscr);
if (widgetHandled)
{
m_OkToGenerate = false;
this->UpdateStatusBar();
this->PrintKeys();
}
}
2003-03-07 19:27:28 +03:00
if ((!currentWidget || !widgetHandled) && !m_SearchMode)
2001-11-05 02:05:21 +03:00
{
2001-12-13 21:28:41 +03:00
// If the current widget does not want to handle input,
// we handle it.
2001-12-04 19:16:04 +03:00
sprintf(debugMessage, "Main form handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
2001-11-06 06:10:52 +03:00
// quit
2001-11-05 02:05:21 +03:00
if ( key == 'q' )
2002-10-17 18:51:23 +04:00
{
break;
}
2001-11-06 06:10:52 +03:00
// if not end of page, next field otherwise next page
2001-11-30 00:44:22 +03:00
// each entry consists of fields: label, isnew, value
// therefore, the label field for the prev. entry is index-5
// and the label field for the next entry is index+1
// (index always corresponds to the value field)
2001-11-06 06:10:52 +03:00
else if ( key == KEY_DOWN || key == ctrl('n') )
2002-10-17 18:51:23 +04:00
{
FIELD* cur = current_field(m_Form);
int findex = field_index(cur);
if ( findex == 3*m_NumberOfVisibleEntries-1 )
{
continue;
}
if (new_page(m_Fields[findex+1]))
{
form_driver(m_Form, REQ_NEXT_PAGE);
}
else
{
form_driver(m_Form, REQ_NEXT_FIELD);
}
}
2001-11-06 06:10:52 +03:00
// if not beginning of page, previous field, otherwise previous page
2001-11-30 00:44:22 +03:00
// each entry consists of fields: label, isnew, value
// therefore, the label field for the prev. entry is index-5
// and the label field for the next entry is index+1
// (index always corresponds to the value field)
2001-11-06 06:10:52 +03:00
else if ( key == KEY_UP || key == ctrl('p') )
2002-10-17 18:51:23 +04:00
{
FIELD* cur = current_field(m_Form);
int findex = field_index(cur);
if ( findex == 2 )
{
continue;
}
if ( new_page(m_Fields[findex-2]) )
{
form_driver(m_Form, REQ_PREV_PAGE);
set_current_field(m_Form, m_Fields[findex-3]);
}
else
{
form_driver(m_Form, REQ_PREV_FIELD);
}
}
2001-11-06 06:10:52 +03:00
// pg down
else if ( key == KEY_NPAGE || key == ctrl('d') )
2002-10-17 18:51:23 +04:00
{
form_driver(m_Form, REQ_NEXT_PAGE);
}
2001-11-06 06:10:52 +03:00
// pg up
else if ( key == KEY_PPAGE || key == ctrl('u') )
2002-10-17 18:51:23 +04:00
{
form_driver(m_Form, REQ_PREV_PAGE);
}
2001-11-06 06:10:52 +03:00
// configure
2001-11-05 02:05:21 +03:00
else if ( key == 'c' )
2002-10-17 18:51:23 +04:00
{
this->Configure();
}
2001-11-30 00:44:22 +03:00
// display help
else if ( key == 'h' )
2002-10-17 18:51:23 +04:00
{
getmaxyx(stdscr, y, x);
FIELD* cur = current_field(m_Form);
int findex = field_index(cur);
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
m_Fields[findex-2]));
const char* curField = lbl->GetValue();
const char* helpString=0;
cmCacheManager::CacheIterator it =
this->m_CMakeInstance->GetCacheManager()->GetCacheIterator(curField);
if (!it.IsAtEnd())
{
helpString = it.GetProperty("HELPSTRING");
}
if (helpString)
{
char* message = new char[strlen(curField)+strlen(helpString)
+strlen("Current option is: \n Help string for this option is: \n")+10];
sprintf(message,"Current option is: %s\nHelp string for this option is: %s\n", curField, helpString);
m_HelpMessage[1] = message;
delete[] message;
}
else
{
m_HelpMessage[1] = "";
}
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_HelpMessage,
"Help.");
CurrentForm = msgs;
msgs->Render(1,1,x,y);
msgs->HandleInput();
CurrentForm = this;
this->Render(1,1,x,y);
}
2001-11-30 00:44:22 +03:00
// display last errors
else if ( key == 'l' )
2002-10-17 18:51:23 +04:00
{
getmaxyx(stdscr, y, x);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
"Errors occurred during the last pass.");
CurrentForm = msgs;
msgs->Render(1,1,x,y);
msgs->HandleInput();
CurrentForm = this;
this->Render(1,1,x,y);
}
2003-03-07 19:27:28 +03:00
else if ( key == '/' )
{
m_SearchMode = true;
this->UpdateStatusBar("Search");
this->PrintKeys(1);
touchwin(stdscr);
refresh();
}
else if ( key == 'n' )
{
if ( m_OldSearchString.size() > 0 )
{
this->JumpToCacheEntry(-1, m_OldSearchString.c_str());
}
}
2001-11-30 00:44:22 +03:00
// switch advanced on/off
else if ( key == 't' )
2002-10-17 18:51:23 +04:00
{
if (m_AdvancedMode)
{
m_AdvancedMode = false;
}
else
{
m_AdvancedMode = true;
}
getmaxyx(stdscr, y, x);
this->RePost();
this->Render(1, 1, x, y);
}
2001-11-06 06:10:52 +03:00
// generate and exit
else if ( key == 'g' )
2002-10-17 18:51:23 +04:00
{
if ( m_OkToGenerate )
{
this->Generate();
break;
}
}
2001-11-06 06:10:52 +03:00
// delete cache entry
else if ( key == 'd' )
2002-10-17 18:51:23 +04:00
{
2002-09-06 21:00:12 +04:00
m_OkToGenerate = false;
2002-10-17 18:51:23 +04:00
FIELD* cur = current_field(m_Form);
int findex = field_index(cur);
// make the next or prev. current field after deletion
// each entry consists of fields: label, isnew, value
// therefore, the label field for the prev. entry is findex-5
// and the label field for the next entry is findex+1
// (findex always corresponds to the value field)
FIELD* nextCur;
if ( findex == 2 )
{
nextCur=0;
}
else if ( findex == 3*m_NumberOfVisibleEntries-1 )
{
nextCur = m_Fields[findex-5];
}
else
{
nextCur = m_Fields[findex+1];
}
// Get the label widget
// each entry consists of fields: label, isnew, value
// therefore, the label field for the is findex-2
// (findex always corresponds to the value field)
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
m_Fields[findex-2]));
this->m_CMakeInstance->GetCacheManager()->RemoveCacheEntry(lbl->GetValue());
std::string nextVal;
if (nextCur)
{
nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
}
getmaxyx(stdscr, y, x);
this->RemoveEntry(lbl->GetValue());
this->RePost();
this->Render(1, 1, x, y);
if (nextCur)
{
// make the next or prev. current field after deletion
nextCur = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
if (nextVal == (*it)->m_Key)
{
nextCur = (*it)->m_Entry->m_Field;
}
}
if (nextCur)
{
set_current_field(m_Form, nextCur);
}
}
}
2001-11-05 02:05:21 +03:00
}
2001-11-30 00:44:22 +03:00
touchwin(stdscr);
wrefresh(stdscr);
2001-11-05 02:05:21 +03:00
}
}
2001-11-30 00:44:22 +03:00
int cmCursesMainForm::LoadCache(const char *)
{
int r = m_CMakeInstance->LoadCache();
if(r < 0)
{
return r;
}
2002-09-17 22:04:33 +04:00
m_CMakeInstance->SetCacheArgs(m_Args);
return r;
}
2003-03-07 19:27:28 +03:00
void cmCursesMainForm::JumpToCacheEntry(int idx, const char* astr)
{
std::string str;
if ( astr )
{
str = cmSystemTools::LowerCase(astr);
}
if ( idx > m_NumberOfVisibleEntries )
{
return;
}
if ( idx < 0 && str.size() == 0)
{
return;
}
FIELD* cur = current_field(m_Form);
int start_index = field_index(cur);
int findex = start_index;
while ( (findex / 3) != idx )
{
if ( str.size() > 0 )
{
cmCursesWidget* lbl = 0;
if ( findex >= 0 )
{
lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(m_Fields[findex-2]));
}
if ( lbl )
{
const char* curField = lbl->GetValue();
if ( curField )
{
std::string cfld = cmSystemTools::LowerCase(curField);
if ( cfld.find(str) != cfld.npos && findex != start_index )
{
break;
}
}
}
}
if ( findex >= 3* m_NumberOfVisibleEntries-1 )
{
set_current_field(m_Form, m_Fields[2]);
}
else if (new_page(m_Fields[findex+1]))
{
form_driver(m_Form, REQ_NEXT_PAGE);
}
else
{
form_driver(m_Form, REQ_NEXT_FIELD);
}
/*
char buffer[1024];
sprintf(buffer, "Line: %d != %d / %d\n", findex, idx, m_NumberOfVisibleEntries);
touchwin(stdscr);
refresh();
this->UpdateStatusBar( buffer );
usleep(100000);
*/
cur = current_field(m_Form);
findex = field_index(cur);
if ( findex == start_index )
{
break;
}
}
}
2001-11-30 22:16:28 +03:00
const char* cmCursesMainForm::s_ConstHelpMessage =
2001-11-30 21:59:36 +03:00
"CMake is used to configure and generate build files for software projects. "
"The basic steps for configuring a project with ccmake are as follows:\n\n"
"1. Run ccmake in the directory where you want the object and executable files to be placed (build directory). If the source directory is not the same as this build directory, you have to specify it as an argument on the command line.\n\n"
"2. When ccmake is run, it will read the configuration files and display the current build options. "
"If you have run CMake before and have updated the configuration files since then, any new entries will be displayed on top and will be marked with a *. "
"On the other hand, the first time you run ccmake, all build options will be new and will be marked as such. "
"At this point, you can modify any options (see keys below) you want to change. "
"When you are satisfied with your changes, press 'c' to have CMake process the configuration files. "
"Please note that changing some options may cause new ones to appear. These will be shown on top and will be marked with *. "
"Repeat this procedure until you are satisfied with all the options and there are no new entries. "
"At this point, a new command will appear: G)enerate and Exit. You can now hit 'g' to have CMake generate all the build files (i.e. makefiles or project files) and exit. "
"At any point during the process, you can exit ccmake with 'q'. However, this will not generate/change any build files.\n\n"
"ccmake KEYS:\n\n"
"Navigation: "
"You can use the arrow keys and page up, down to navigate the options. Alternatively, you can use the following keys: \n"
" C-n : next option\n"
" C-p : previous options\n"
" C-d : down one page\n"
" C-u : up one page\n\n"
"Editing options: "
"To change an option press enter or return. If the current options is a boolean, this will toggle it's value. "
"Otherwise, ccmake will enter edit mode. In this mode you can edit an option using arrow keys and backspace. Alternatively, you can use the following keys:\n"
" C-b : back one character\n"
" C-f : forward one character\n"
" C-a : go to the beginning of the field\n"
" C-e : go to the end of the field\n"
" C-d : delete previous character\n"
" C-k : kill the rest of the field\n"
2001-11-30 22:24:37 +03:00
" Esc : Restore field (discard last changes)\n"
2001-11-30 23:04:25 +03:00
" Enter : Leave edit mode\n"
2001-11-30 21:59:36 +03:00
"You can also delete an option by pressing 'd'\n\n"
"Commands:\n"
" q : quit ccmake without generating build files\n"
" h : help, shows this screen\n"
" c : process the configuration files with the current options\n"
" g : generate build files and exit, only available when there are no "
"new options and no errors have been detected during last configuration.\n"
" l : shows last errors\n"
" t : toggles advanced mode. In normal mode, only the most important options are shown. In advanced mode, all options are shown. We recommend using normal mode unless you are an expert.\n";