ENH: Disable menu/buttons when doing configure.

Also disable generate until configure is done.
      Save more settings (last 10 binary directories, exit after generate,
                          last generator)
      Some UI tweaks for better layout.
      Support drag & drop of CMakeLists.txt/CMakeCache.txt files.
This commit is contained in:
Clinton Stimpson 2007-11-06 19:25:43 -05:00
parent 433a914910
commit 1e91100599
7 changed files with 197 additions and 61 deletions

View File

@ -17,8 +17,6 @@
#include "QCMake.h" // include to disable MS warnings #include "QCMake.h" // include to disable MS warnings
#include <QApplication> #include <QApplication>
#include "cmSystemTools.h"
#include "CMakeSetupDialog.h" #include "CMakeSetupDialog.h"
int main(int argc, char** argv) int main(int argc, char** argv)

View File

@ -28,6 +28,9 @@
#include <QSettings> #include <QSettings>
#include <QMenu> #include <QMenu>
#include <QMenuBar> #include <QMenuBar>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QUrl>
#include "QCMake.h" #include "QCMake.h"
#include "QCMakeCacheView.h" #include "QCMakeCacheView.h"
@ -63,7 +66,7 @@ void QCMakeThread::run()
} }
CMakeSetupDialog::CMakeSetupDialog() CMakeSetupDialog::CMakeSetupDialog()
: QuitOnConfigure(true) : ExitAfterGenerate(true)
{ {
// create the GUI // create the GUI
QSettings settings; QSettings settings;
@ -87,25 +90,31 @@ CMakeSetupDialog::CMakeSetupDialog()
this->statusBar()->addPermanentWidget(this->ProgressBar); this->statusBar()->addPermanentWidget(this->ProgressBar);
QMenu* FileMenu = this->menuBar()->addMenu(tr("&File")); QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
QAction* a = FileMenu->addAction(tr("&Reload Cache")); this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doReloadCache())); QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
a = FileMenu->addAction(tr("&Delete Cache")); this, SLOT(doReloadCache()));
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doDeleteCache())); this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
a = FileMenu->addAction(tr("&Exit")); QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(close())); this, SLOT(doDeleteCache()));
a = FileMenu->addAction(tr("Exit after Generation")); this->ExitAction = FileMenu->addAction(tr("&Exit"));
a->setCheckable(true); QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
a->setChecked(true); // TODO read from registry this, SLOT(close()));
QObject::connect(a, SIGNAL(triggered(bool)),
this, SLOT(setExitAfterGenerate(bool)));
a = FileMenu->addSeparator();
// TODO: recent list
QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools")); QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
a = ToolsMenu->addAction(tr("&Configure")); this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doConfigure())); QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
a = ToolsMenu->addAction(tr("&Generate")); this, SLOT(doConfigure()));
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doGenerate())); this->GenerateAction = ToolsMenu->addAction(tr("&Generate"));
QObject::connect(this->GenerateAction, SIGNAL(triggered(bool)),
this, SLOT(doGenerate()));
QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options"));
QAction* a = OptionsMenu->addAction(tr("Exit after Generation"));
a->setCheckable(true);
this->ExitAfterGenerate = settings.value("ExitAfterGenerate", true).toBool();
a->setChecked(this->ExitAfterGenerate);
QObject::connect(a, SIGNAL(triggered(bool)),
this, SLOT(setExitAfterGenerate(bool)));
QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help")); QMenu* HelpMenu = this->menuBar()->addMenu(tr("&Help"));
a = HelpMenu->addAction(tr("About")); a = HelpMenu->addAction(tr("About"));
@ -115,6 +124,10 @@ CMakeSetupDialog::CMakeSetupDialog()
QObject::connect(a, SIGNAL(triggered(bool)), QObject::connect(a, SIGNAL(triggered(bool)),
this, SLOT(doHelp())); this, SLOT(doHelp()));
this->setGenerateEnabled(false);
this->setAcceptDrops(true);
// start the cmake worker thread // start the cmake worker thread
this->CMakeThread = new QCMakeThread(this); this->CMakeThread = new QCMakeThread(this);
QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()), QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
@ -184,19 +197,17 @@ void CMakeSetupDialog::initialize()
SIGNAL(generatorChanged(QString)), SIGNAL(generatorChanged(QString)),
this, SLOT(updateGeneratorLabel(QString))); this, SLOT(updateGeneratorLabel(QString)));
this->updateGeneratorLabel(QString()); this->updateGeneratorLabel(QString());
QObject::connect(this->CacheValues->cacheModel(),
SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(cacheModelDirty()));
QObject::connect(this->CacheValues->cacheModel(), SIGNAL(modelReset()),
this, SLOT(cacheModelDirty()));
// get the saved binary directories // get the saved binary directories
QSettings settings; QSettings settings;
settings.beginGroup("Settings/StartPath"); settings.beginGroup("Settings/StartPath");
QStringList buildPaths; QStringList buildPaths = settings.value("WhereBuild").toStringList();
for(int i=0; i<10; i++)
{
QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
if(!p.isEmpty())
{
buildPaths.append(p);
}
}
this->BinaryDirectory->addItems(buildPaths); this->BinaryDirectory->addItems(buildPaths);
} }
@ -214,13 +225,14 @@ CMakeSetupDialog::~CMakeSetupDialog()
void CMakeSetupDialog::doConfigure() void CMakeSetupDialog::doConfigure()
{ {
QDir dir(this->BinaryDirectory->currentText()); QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
QDir dir(bindir);
if(!dir.exists()) if(!dir.exists())
{ {
QString message = tr("Build directory does not exist, " QString message = tr("Build directory does not exist, "
"should I create it?\n\n" "should I create it?\n\n"
"Directory: "); "Directory: ");
message += this->BinaryDirectory->currentText(); message += bindir;
QString title = tr("Create Directory"); QString title = tr("Create Directory");
QMessageBox::StandardButton btn; QMessageBox::StandardButton btn;
btn = QMessageBox::information(this, title, message, btn = QMessageBox::information(this, title, message,
@ -238,6 +250,9 @@ void CMakeSetupDialog::doConfigure()
this->promptForGenerator(); this->promptForGenerator();
} }
// remember path
this->addBinaryPath(dir.absolutePath());
this->InterruptButton->setEnabled(true); this->InterruptButton->setEnabled(true);
this->setEnabledState(false); this->setEnabledState(false);
this->Output->clear(); this->Output->clear();
@ -261,12 +276,17 @@ void CMakeSetupDialog::finishConfigure(int err)
tr("Error in configuration process, project files may be invalid"), tr("Error in configuration process, project files may be invalid"),
QMessageBox::Ok); QMessageBox::Ok);
} }
if(!this->CacheValues->cacheModel()->modifiedValues())
{
this->setGenerateEnabled(true);
}
} }
void CMakeSetupDialog::finishGenerate(int err) void CMakeSetupDialog::finishGenerate(int err)
{ {
this->InterruptButton->setEnabled(false); this->InterruptButton->setEnabled(false);
this->setEnabledState(true); this->setEnabledState(true);
this->setGenerateEnabled(true);
this->ProgressBar->reset(); this->ProgressBar->reset();
this->statusBar()->showMessage(tr("Generate Done"), 2000); this->statusBar()->showMessage(tr("Generate Done"), 2000);
if(err != 0) if(err != 0)
@ -275,7 +295,7 @@ void CMakeSetupDialog::finishGenerate(int err)
tr("Error in generation process, project files may be invalid"), tr("Error in generation process, project files may be invalid"),
QMessageBox::Ok); QMessageBox::Ok);
} }
else if(this->QuitOnConfigure) else if(this->ExitAfterGenerate)
{ {
QApplication::quit(); QApplication::quit();
} }
@ -285,6 +305,7 @@ void CMakeSetupDialog::doGenerate()
{ {
this->InterruptButton->setEnabled(true); this->InterruptButton->setEnabled(true);
this->setEnabledState(false); this->setEnabledState(false);
this->setGenerateEnabled(false);
this->Output->clear(); this->Output->clear();
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
"generate", Qt::QueuedConnection); "generate", Qt::QueuedConnection);
@ -299,7 +320,7 @@ void CMakeSetupDialog::closeEvent(QCloseEvent* e)
} }
// prompt for close if there are unsaved changes // prompt for close if there are unsaved changes
if(this->CacheValues->cacheModel()->isDirty()) if(this->CacheValues->cacheModel()->modifiedValues())
{ {
QString message = tr("You have changed options but not rebuilt, " QString message = tr("You have changed options but not rebuilt, "
"are you sure you want to exit?"); "are you sure you want to exit?");
@ -401,7 +422,9 @@ void CMakeSetupDialog::error(const QString& title, const QString& message,
bool* cancel) bool* cancel)
{ {
QMessageBox::StandardButton btn; QMessageBox::StandardButton btn;
btn = QMessageBox::critical(this, title, message, QString msg = message + "\n\n" +
tr("(Press cancel to suppress any further messages.)");
btn = QMessageBox::critical(this, title, msg,
QMessageBox::Ok | QMessageBox::Cancel); QMessageBox::Ok | QMessageBox::Cancel);
if(btn == QMessageBox::Cancel) if(btn == QMessageBox::Cancel)
{ {
@ -411,17 +434,26 @@ void CMakeSetupDialog::error(const QString& title, const QString& message,
void CMakeSetupDialog::setEnabledState(bool enabled) void CMakeSetupDialog::setEnabledState(bool enabled)
{ {
// disable parts of the GUI during configure/generate
this->CacheValues->setEnabled(enabled); this->CacheValues->setEnabled(enabled);
this->SourceDirectory->setEnabled(enabled); this->SourceDirectory->setEnabled(enabled);
this->BrowseSourceDirectoryButton->setEnabled(enabled); this->BrowseSourceDirectoryButton->setEnabled(enabled);
this->BinaryDirectory->setEnabled(enabled); this->BinaryDirectory->setEnabled(enabled);
this->BrowseBinaryDirectoryButton->setEnabled(enabled); this->BrowseBinaryDirectoryButton->setEnabled(enabled);
this->ConfigureButton->setEnabled(enabled); this->ConfigureButton->setEnabled(enabled);
this->GenerateButton->setEnabled(enabled); this->ReloadCacheAction->setEnabled(enabled);
this->DeleteCacheAction->setEnabled(enabled);
this->ExitAction->setEnabled(enabled);
this->ConfigureAction->setEnabled(enabled);
// generate button/action are handled separately
} }
void CMakeSetupDialog::promptForGenerator() void CMakeSetupDialog::promptForGenerator()
{ {
QSettings settings;
settings.beginGroup("Settings/StartPath");
QString lastGen = settings.value("LastGenerator").toString();
QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators(); QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators();
QDialog dialog; QDialog dialog;
dialog.setWindowTitle(tr("CMakeSetup choose generator")); dialog.setWindowTitle(tr("CMakeSetup choose generator"));
@ -431,6 +463,11 @@ void CMakeSetupDialog::promptForGenerator()
"Press OK once you have made your selection.")); "Press OK once you have made your selection."));
QComboBox* combo = new QComboBox(&dialog); QComboBox* combo = new QComboBox(&dialog);
combo->addItems(gens); combo->addItems(gens);
int idx = combo->findText(lastGen);
if(idx != -1)
{
combo->setCurrentIndex(idx);
}
QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok, QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
Qt::Horizontal, &dialog); Qt::Horizontal, &dialog);
QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept())); QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
@ -440,6 +477,9 @@ void CMakeSetupDialog::promptForGenerator()
l->addWidget(combo); l->addWidget(combo);
l->addWidget(btns); l->addWidget(btns);
dialog.exec(); dialog.exec();
lastGen = combo->currentText();
settings.setValue("LastGenerator", lastGen);
this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText()); this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText());
} }
@ -489,9 +529,81 @@ void CMakeSetupDialog::doAbout()
void CMakeSetupDialog::setExitAfterGenerate(bool b) void CMakeSetupDialog::setExitAfterGenerate(bool b)
{ {
this->QuitOnConfigure = b; this->ExitAfterGenerate = b;
// TODO QSettings settings;
// save to registry settings.beginGroup("Settings/StartPath");
settings.setValue("ExitAfterGenerate", b);
} }
void CMakeSetupDialog::cacheModelDirty()
{
if(this->CacheValues->cacheModel()->modifiedValues())
{
this->setGenerateEnabled(false);
}
}
void CMakeSetupDialog::setGenerateEnabled(bool b)
{
this->GenerateButton->setEnabled(b);
this->GenerateAction->setEnabled(b);
}
void CMakeSetupDialog::addBinaryPath(const QString& path)
{
QString cleanpath = QDir::cleanPath(path);
QSettings settings;
settings.beginGroup("Settings/StartPath");
QStringList buildPaths = settings.value("WhereBuild").toStringList();
buildPaths.removeAll(cleanpath);
int idx = this->BinaryDirectory->findText(cleanpath);
if(idx != -1)
{
this->BinaryDirectory->removeItem(idx);
}
this->BinaryDirectory->insertItem(0, cleanpath);
this->BinaryDirectory->setCurrentIndex(0);
buildPaths.prepend(cleanpath);
while(buildPaths.count() > 10)
{
buildPaths.removeLast();
}
settings.setValue("WhereBuild", buildPaths);
}
void CMakeSetupDialog::dragEnterEvent(QDragEnterEvent* e)
{
const QMimeData* data = e->mimeData();
QList<QUrl> urls = data->urls();
QString file = urls.count() ? urls[0].toLocalFile() : QString();
if(!file.isEmpty() &&
(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive) ||
file.endsWith("CMakeLists.txt", Qt::CaseInsensitive) ) )
{
e->accept();
}
else
{
e->ignore();
}
}
void CMakeSetupDialog::dropEvent(QDropEvent* e)
{
const QMimeData* data = e->mimeData();
QList<QUrl> urls = data->urls();
QString file = urls.count() ? urls[0].toLocalFile() : QString();
if(file.endsWith("CMakeCache.txt", Qt::CaseInsensitive))
{
QFileInfo info(file);
this->setBinaryDirectory(info.absolutePath());
}
else if(file.endsWith("CMakeLists.txt", Qt::CaseInsensitive))
{
QFileInfo info(file);
this->SourceDirectory->setText(info.absolutePath());
this->setBinaryDirectory(info.absolutePath());
}
}

View File

@ -58,14 +58,24 @@ protected slots:
void promptForGenerator(); void promptForGenerator();
void updateGeneratorLabel(const QString& gen); void updateGeneratorLabel(const QString& gen);
void setExitAfterGenerate(bool); void setExitAfterGenerate(bool);
void cacheModelDirty();
void setGenerateEnabled(bool);
void addBinaryPath(const QString&);
protected: protected:
void closeEvent(QCloseEvent*); void closeEvent(QCloseEvent*);
void dragEnterEvent(QDragEnterEvent*);
void dropEvent(QDropEvent*);
QCMakeThread* CMakeThread; QCMakeThread* CMakeThread;
QProgressBar* ProgressBar; QProgressBar* ProgressBar;
QToolButton* InterruptButton; QToolButton* InterruptButton;
bool QuitOnConfigure; bool ExitAfterGenerate;
QAction* ReloadCacheAction;
QAction* DeleteCacheAction;
QAction* ExitAction;
QAction* ConfigureAction;
QAction* GenerateAction;
}; };
// QCMake instance on a thread // QCMake instance on a thread

View File

@ -60,6 +60,13 @@
</item> </item>
<item row="1" column="0" > <item row="1" column="0" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<item>
<widget class="QCheckBox" name="Advanced" >
<property name="text" >
<string>Show Advanced</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="label_4" > <widget class="QLabel" name="label_4" >
<property name="sizePolicy" > <property name="sizePolicy" >
@ -76,37 +83,36 @@
<item> <item>
<widget class="QLineEdit" name="Search" > <widget class="QLineEdit" name="Search" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" > <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="Advanced" >
<property name="text" >
<string>Show Advanced</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="Generator" >
</widget>
</item>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType" >
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" > <property name="sizeHint" >
<size> <size>
<width>141</width> <width>61</width>
<height>23</height> <height>23</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QLabel" name="Generator" >
<property name="text" >
<string>Current Generator:</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item row="2" column="0" > <item row="2" column="0" >

View File

@ -238,6 +238,16 @@ void QCMake::errorCallback(const char* msg, const char* title,
emit self->error(title, msg, &stop); emit self->error(title, msg, &stop);
} }
QString QCMake::binaryDirectory() const
{
return this->BinaryDirectory;
}
QString QCMake::sourceDirectory() const
{
return this->SourceDirectory;
}
QString QCMake::generator() const QString QCMake::generator() const
{ {
return this->Generator; return this->Generator;

View File

@ -124,7 +124,7 @@ void QCMakeCacheView::setSearchFilter(const QString& s)
} }
QCMakeCacheModel::QCMakeCacheModel(QObject* p) QCMakeCacheModel::QCMakeCacheModel(QObject* p)
: QAbstractTableModel(p), NewCount(0), IsDirty(false) : QAbstractTableModel(p), NewCount(0), ModifiedValues(false)
{ {
} }
@ -132,9 +132,9 @@ QCMakeCacheModel::~QCMakeCacheModel()
{ {
} }
bool QCMakeCacheModel::isDirty() const bool QCMakeCacheModel::modifiedValues() const
{ {
return this->IsDirty; return this->ModifiedValues;
} }
static uint qHash(const QCMakeCacheProperty& p) static uint qHash(const QCMakeCacheProperty& p)
@ -164,8 +164,8 @@ void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props)
qSort(tmp); qSort(tmp);
this->Properties += tmp; this->Properties += tmp;
this->ModifiedValues = NewCount != 0;
this->reset(); this->reset();
this->IsDirty = false;
} }
QCMakeCachePropertyList QCMakeCacheModel::properties() const QCMakeCachePropertyList QCMakeCacheModel::properties() const
@ -268,19 +268,19 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i
if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole)) if(idx.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole))
{ {
this->Properties[idx.row()].Key = value.toString(); this->Properties[idx.row()].Key = value.toString();
this->IsDirty = true; this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole)) else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
{ {
this->Properties[idx.row()].Value = value.toString(); this->Properties[idx.row()].Value = value.toString();
this->IsDirty = true; this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
else if(idx.column() == 1 && (role == Qt::CheckStateRole)) else if(idx.column() == 1 && (role == Qt::CheckStateRole))
{ {
this->Properties[idx.row()].Value = value.toInt() == Qt::Checked; this->Properties[idx.row()].Value = value.toInt() == Qt::Checked;
this->IsDirty = true; this->ModifiedValues = true;
emit this->dataChanged(idx, idx); emit this->dataChanged(idx, idx);
} }
return false; return false;

View File

@ -77,14 +77,14 @@ public:
bool setData ( const QModelIndex& index, const QVariant& value, int role ); bool setData ( const QModelIndex& index, const QVariant& value, int role );
// flag if a cache property has been modified // flag if a cache property has been modified
bool isDirty() const; bool modifiedValues() const;
// get the properties // get the properties
QCMakeCachePropertyList properties() const; QCMakeCachePropertyList properties() const;
protected: protected:
QCMakeCachePropertyList Properties; QCMakeCachePropertyList Properties;
int NewCount; int NewCount;
bool IsDirty; bool ModifiedValues;
}; };
/// Qt delegate class for interaction (or other customization) /// Qt delegate class for interaction (or other customization)