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:
parent
433a914910
commit
1e91100599
|
@ -17,8 +17,6 @@
|
|||
#include "QCMake.h" // include to disable MS warnings
|
||||
#include <QApplication>
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
#include "CMakeSetupDialog.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include <QSettings>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
#include "QCMake.h"
|
||||
#include "QCMakeCacheView.h"
|
||||
|
@ -63,7 +66,7 @@ void QCMakeThread::run()
|
|||
}
|
||||
|
||||
CMakeSetupDialog::CMakeSetupDialog()
|
||||
: QuitOnConfigure(true)
|
||||
: ExitAfterGenerate(true)
|
||||
{
|
||||
// create the GUI
|
||||
QSettings settings;
|
||||
|
@ -87,25 +90,31 @@ CMakeSetupDialog::CMakeSetupDialog()
|
|||
this->statusBar()->addPermanentWidget(this->ProgressBar);
|
||||
|
||||
QMenu* FileMenu = this->menuBar()->addMenu(tr("&File"));
|
||||
QAction* a = FileMenu->addAction(tr("&Reload Cache"));
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doReloadCache()));
|
||||
a = FileMenu->addAction(tr("&Delete Cache"));
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doDeleteCache()));
|
||||
a = FileMenu->addAction(tr("&Exit"));
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(close()));
|
||||
a = FileMenu->addAction(tr("Exit after Generation"));
|
||||
a->setCheckable(true);
|
||||
a->setChecked(true); // TODO read from registry
|
||||
QObject::connect(a, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setExitAfterGenerate(bool)));
|
||||
a = FileMenu->addSeparator();
|
||||
// TODO: recent list
|
||||
this->ReloadCacheAction = FileMenu->addAction(tr("&Reload Cache"));
|
||||
QObject::connect(this->ReloadCacheAction, SIGNAL(triggered(bool)),
|
||||
this, SLOT(doReloadCache()));
|
||||
this->DeleteCacheAction = FileMenu->addAction(tr("&Delete Cache"));
|
||||
QObject::connect(this->DeleteCacheAction, SIGNAL(triggered(bool)),
|
||||
this, SLOT(doDeleteCache()));
|
||||
this->ExitAction = FileMenu->addAction(tr("&Exit"));
|
||||
QObject::connect(this->ExitAction, SIGNAL(triggered(bool)),
|
||||
this, SLOT(close()));
|
||||
|
||||
QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
|
||||
a = ToolsMenu->addAction(tr("&Configure"));
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doConfigure()));
|
||||
a = ToolsMenu->addAction(tr("&Generate"));
|
||||
QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doGenerate()));
|
||||
this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
|
||||
QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)),
|
||||
this, SLOT(doConfigure()));
|
||||
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"));
|
||||
a = HelpMenu->addAction(tr("About"));
|
||||
|
@ -115,6 +124,10 @@ CMakeSetupDialog::CMakeSetupDialog()
|
|||
QObject::connect(a, SIGNAL(triggered(bool)),
|
||||
this, SLOT(doHelp()));
|
||||
|
||||
this->setGenerateEnabled(false);
|
||||
|
||||
this->setAcceptDrops(true);
|
||||
|
||||
// start the cmake worker thread
|
||||
this->CMakeThread = new QCMakeThread(this);
|
||||
QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()),
|
||||
|
@ -185,18 +198,16 @@ void CMakeSetupDialog::initialize()
|
|||
this, SLOT(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
|
||||
QSettings settings;
|
||||
settings.beginGroup("Settings/StartPath");
|
||||
QStringList buildPaths;
|
||||
for(int i=0; i<10; i++)
|
||||
{
|
||||
QString p = settings.value(QString("WhereBuild%1").arg(i)).toString();
|
||||
if(!p.isEmpty())
|
||||
{
|
||||
buildPaths.append(p);
|
||||
}
|
||||
}
|
||||
QStringList buildPaths = settings.value("WhereBuild").toStringList();
|
||||
this->BinaryDirectory->addItems(buildPaths);
|
||||
}
|
||||
|
||||
|
@ -214,13 +225,14 @@ CMakeSetupDialog::~CMakeSetupDialog()
|
|||
|
||||
void CMakeSetupDialog::doConfigure()
|
||||
{
|
||||
QDir dir(this->BinaryDirectory->currentText());
|
||||
QString bindir = this->CMakeThread->cmakeInstance()->binaryDirectory();
|
||||
QDir dir(bindir);
|
||||
if(!dir.exists())
|
||||
{
|
||||
QString message = tr("Build directory does not exist, "
|
||||
"should I create it?\n\n"
|
||||
"Directory: ");
|
||||
message += this->BinaryDirectory->currentText();
|
||||
message += bindir;
|
||||
QString title = tr("Create Directory");
|
||||
QMessageBox::StandardButton btn;
|
||||
btn = QMessageBox::information(this, title, message,
|
||||
|
@ -238,6 +250,9 @@ void CMakeSetupDialog::doConfigure()
|
|||
this->promptForGenerator();
|
||||
}
|
||||
|
||||
// remember path
|
||||
this->addBinaryPath(dir.absolutePath());
|
||||
|
||||
this->InterruptButton->setEnabled(true);
|
||||
this->setEnabledState(false);
|
||||
this->Output->clear();
|
||||
|
@ -261,12 +276,17 @@ void CMakeSetupDialog::finishConfigure(int err)
|
|||
tr("Error in configuration process, project files may be invalid"),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
if(!this->CacheValues->cacheModel()->modifiedValues())
|
||||
{
|
||||
this->setGenerateEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeSetupDialog::finishGenerate(int err)
|
||||
{
|
||||
this->InterruptButton->setEnabled(false);
|
||||
this->setEnabledState(true);
|
||||
this->setGenerateEnabled(true);
|
||||
this->ProgressBar->reset();
|
||||
this->statusBar()->showMessage(tr("Generate Done"), 2000);
|
||||
if(err != 0)
|
||||
|
@ -275,7 +295,7 @@ void CMakeSetupDialog::finishGenerate(int err)
|
|||
tr("Error in generation process, project files may be invalid"),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
else if(this->QuitOnConfigure)
|
||||
else if(this->ExitAfterGenerate)
|
||||
{
|
||||
QApplication::quit();
|
||||
}
|
||||
|
@ -285,6 +305,7 @@ void CMakeSetupDialog::doGenerate()
|
|||
{
|
||||
this->InterruptButton->setEnabled(true);
|
||||
this->setEnabledState(false);
|
||||
this->setGenerateEnabled(false);
|
||||
this->Output->clear();
|
||||
QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(),
|
||||
"generate", Qt::QueuedConnection);
|
||||
|
@ -299,7 +320,7 @@ void CMakeSetupDialog::closeEvent(QCloseEvent* e)
|
|||
}
|
||||
|
||||
// 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, "
|
||||
"are you sure you want to exit?");
|
||||
|
@ -401,7 +422,9 @@ void CMakeSetupDialog::error(const QString& title, const QString& message,
|
|||
bool* cancel)
|
||||
{
|
||||
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);
|
||||
if(btn == QMessageBox::Cancel)
|
||||
{
|
||||
|
@ -411,17 +434,26 @@ void CMakeSetupDialog::error(const QString& title, const QString& message,
|
|||
|
||||
void CMakeSetupDialog::setEnabledState(bool enabled)
|
||||
{
|
||||
// disable parts of the GUI during configure/generate
|
||||
this->CacheValues->setEnabled(enabled);
|
||||
this->SourceDirectory->setEnabled(enabled);
|
||||
this->BrowseSourceDirectoryButton->setEnabled(enabled);
|
||||
this->BinaryDirectory->setEnabled(enabled);
|
||||
this->BrowseBinaryDirectoryButton->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()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("Settings/StartPath");
|
||||
QString lastGen = settings.value("LastGenerator").toString();
|
||||
|
||||
QStringList gens = this->CMakeThread->cmakeInstance()->availableGenerators();
|
||||
QDialog dialog;
|
||||
dialog.setWindowTitle(tr("CMakeSetup choose generator"));
|
||||
|
@ -431,6 +463,11 @@ void CMakeSetupDialog::promptForGenerator()
|
|||
"Press OK once you have made your selection."));
|
||||
QComboBox* combo = new QComboBox(&dialog);
|
||||
combo->addItems(gens);
|
||||
int idx = combo->findText(lastGen);
|
||||
if(idx != -1)
|
||||
{
|
||||
combo->setCurrentIndex(idx);
|
||||
}
|
||||
QDialogButtonBox* btns = new QDialogButtonBox(QDialogButtonBox::Ok,
|
||||
Qt::Horizontal, &dialog);
|
||||
QObject::connect(btns, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
||||
|
@ -440,6 +477,9 @@ void CMakeSetupDialog::promptForGenerator()
|
|||
l->addWidget(combo);
|
||||
l->addWidget(btns);
|
||||
dialog.exec();
|
||||
|
||||
lastGen = combo->currentText();
|
||||
settings.setValue("LastGenerator", lastGen);
|
||||
this->CMakeThread->cmakeInstance()->setGenerator(combo->currentText());
|
||||
}
|
||||
|
||||
|
@ -489,9 +529,81 @@ void CMakeSetupDialog::doAbout()
|
|||
|
||||
void CMakeSetupDialog::setExitAfterGenerate(bool b)
|
||||
{
|
||||
this->QuitOnConfigure = b;
|
||||
// TODO
|
||||
// save to registry
|
||||
this->ExitAfterGenerate = b;
|
||||
QSettings settings;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,14 +58,24 @@ protected slots:
|
|||
void promptForGenerator();
|
||||
void updateGeneratorLabel(const QString& gen);
|
||||
void setExitAfterGenerate(bool);
|
||||
void cacheModelDirty();
|
||||
void setGenerateEnabled(bool);
|
||||
void addBinaryPath(const QString&);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent*);
|
||||
void dragEnterEvent(QDragEnterEvent*);
|
||||
void dropEvent(QDropEvent*);
|
||||
|
||||
QCMakeThread* CMakeThread;
|
||||
QProgressBar* ProgressBar;
|
||||
QToolButton* InterruptButton;
|
||||
bool QuitOnConfigure;
|
||||
bool ExitAfterGenerate;
|
||||
QAction* ReloadCacheAction;
|
||||
QAction* DeleteCacheAction;
|
||||
QAction* ExitAction;
|
||||
QAction* ConfigureAction;
|
||||
QAction* GenerateAction;
|
||||
};
|
||||
|
||||
// QCMake instance on a thread
|
||||
|
|
|
@ -60,6 +60,13 @@
|
|||
</item>
|
||||
<item row="1" column="0" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QCheckBox" name="Advanced" >
|
||||
<property name="text" >
|
||||
<string>Show Advanced</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4" >
|
||||
<property name="sizePolicy" >
|
||||
|
@ -76,37 +83,36 @@
|
|||
<item>
|
||||
<widget class="QLineEdit" name="Search" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Minimum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>141</width>
|
||||
<width>61</width>
|
||||
<height>23</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="Generator" >
|
||||
<property name="text" >
|
||||
<string>Current Generator:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
|
|
|
@ -238,6 +238,16 @@ void QCMake::errorCallback(const char* msg, const char* title,
|
|||
emit self->error(title, msg, &stop);
|
||||
}
|
||||
|
||||
QString QCMake::binaryDirectory() const
|
||||
{
|
||||
return this->BinaryDirectory;
|
||||
}
|
||||
|
||||
QString QCMake::sourceDirectory() const
|
||||
{
|
||||
return this->SourceDirectory;
|
||||
}
|
||||
|
||||
QString QCMake::generator() const
|
||||
{
|
||||
return this->Generator;
|
||||
|
|
|
@ -124,7 +124,7 @@ void QCMakeCacheView::setSearchFilter(const QString& s)
|
|||
}
|
||||
|
||||
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)
|
||||
|
@ -164,8 +164,8 @@ void QCMakeCacheModel::setProperties(const QCMakeCachePropertyList& props)
|
|||
qSort(tmp);
|
||||
this->Properties += tmp;
|
||||
|
||||
this->ModifiedValues = NewCount != 0;
|
||||
this->reset();
|
||||
this->IsDirty = false;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
this->Properties[idx.row()].Key = value.toString();
|
||||
this->IsDirty = true;
|
||||
this->ModifiedValues = true;
|
||||
emit this->dataChanged(idx, idx);
|
||||
}
|
||||
else if(idx.column() == 1 && (role == Qt::DisplayRole || role == Qt::EditRole))
|
||||
{
|
||||
this->Properties[idx.row()].Value = value.toString();
|
||||
this->IsDirty = true;
|
||||
this->ModifiedValues = true;
|
||||
emit this->dataChanged(idx, idx);
|
||||
}
|
||||
else if(idx.column() == 1 && (role == Qt::CheckStateRole))
|
||||
{
|
||||
this->Properties[idx.row()].Value = value.toInt() == Qt::Checked;
|
||||
this->IsDirty = true;
|
||||
this->ModifiedValues = true;
|
||||
emit this->dataChanged(idx, idx);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -77,14 +77,14 @@ public:
|
|||
bool setData ( const QModelIndex& index, const QVariant& value, int role );
|
||||
|
||||
// flag if a cache property has been modified
|
||||
bool isDirty() const;
|
||||
bool modifiedValues() const;
|
||||
// get the properties
|
||||
QCMakeCachePropertyList properties() const;
|
||||
|
||||
protected:
|
||||
QCMakeCachePropertyList Properties;
|
||||
int NewCount;
|
||||
bool IsDirty;
|
||||
bool ModifiedValues;
|
||||
};
|
||||
|
||||
/// Qt delegate class for interaction (or other customization)
|
||||
|
|
Loading…
Reference in New Issue