cmake-gui: add completion for the names when adding cache entries
Up to 100 completion strings for the names of added variables are saved in the settings, so it will remember the variables you are usually adding. It also ensures that CMAKE_INSTALL_PREFIX is always there, since this is maybe the one which is set most often. Alex
This commit is contained in:
parent
08c59af4de
commit
b0d01c306b
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "AddCacheEntry.h"
|
#include "AddCacheEntry.h"
|
||||||
#include <QMetaProperty>
|
#include <QMetaProperty>
|
||||||
|
#include <QCompleter>
|
||||||
|
|
||||||
static const int NumTypes = 4;
|
static const int NumTypes = 4;
|
||||||
static const QString TypeStrings[NumTypes] =
|
static const QString TypeStrings[NumTypes] =
|
||||||
|
@ -20,7 +21,7 @@ static const QCMakeProperty::PropertyType Types[NumTypes] =
|
||||||
{ QCMakeProperty::BOOL, QCMakeProperty::PATH,
|
{ QCMakeProperty::BOOL, QCMakeProperty::PATH,
|
||||||
QCMakeProperty::FILEPATH, QCMakeProperty::STRING};
|
QCMakeProperty::FILEPATH, QCMakeProperty::STRING};
|
||||||
|
|
||||||
AddCacheEntry::AddCacheEntry(QWidget* p)
|
AddCacheEntry::AddCacheEntry(QWidget* p, const QStringList& completions)
|
||||||
: QWidget(p)
|
: QWidget(p)
|
||||||
{
|
{
|
||||||
this->setupUi(this);
|
this->setupUi(this);
|
||||||
|
@ -42,6 +43,7 @@ AddCacheEntry::AddCacheEntry(QWidget* p)
|
||||||
this->setTabOrder(path, filepath);
|
this->setTabOrder(path, filepath);
|
||||||
this->setTabOrder(filepath, string);
|
this->setTabOrder(filepath, string);
|
||||||
this->setTabOrder(string, this->Description);
|
this->setTabOrder(string, this->Description);
|
||||||
|
this->Name->setCompleter(new QCompleter(completions, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AddCacheEntry::name() const
|
QString AddCacheEntry::name() const
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include "QCMake.h"
|
#include "QCMake.h"
|
||||||
#include "ui_AddCacheEntry.h"
|
#include "ui_AddCacheEntry.h"
|
||||||
|
@ -23,7 +24,7 @@ class AddCacheEntry : public QWidget, public Ui::AddCacheEntry
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AddCacheEntry(QWidget* p);
|
AddCacheEntry(QWidget* p, const QStringList& completions);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
|
|
|
@ -68,6 +68,9 @@ CMakeSetupDialog::CMakeSetupDialog()
|
||||||
int w = settings.value("Width", 700).toInt();
|
int w = settings.value("Width", 700).toInt();
|
||||||
this->resize(w, h);
|
this->resize(w, h);
|
||||||
|
|
||||||
|
this->AddVariableCompletions = settings.value("AddVariableCompletionEntries",
|
||||||
|
QStringList("CMAKE_INSTALL_PREFIX")).toStringList();
|
||||||
|
|
||||||
QWidget* cont = new QWidget(this);
|
QWidget* cont = new QWidget(this);
|
||||||
this->setupUi(cont);
|
this->setupUi(cont);
|
||||||
this->Splitter->setStretchFactor(0, 3);
|
this->Splitter->setStretchFactor(0, 3);
|
||||||
|
@ -1008,7 +1011,7 @@ void CMakeSetupDialog::addCacheEntry()
|
||||||
dialog.resize(400, 200);
|
dialog.resize(400, 200);
|
||||||
dialog.setWindowTitle(tr("Add Cache Entry"));
|
dialog.setWindowTitle(tr("Add Cache Entry"));
|
||||||
QVBoxLayout* l = new QVBoxLayout(&dialog);
|
QVBoxLayout* l = new QVBoxLayout(&dialog);
|
||||||
AddCacheEntry* w = new AddCacheEntry(&dialog);
|
AddCacheEntry* w = new AddCacheEntry(&dialog, this->AddVariableCompletions);
|
||||||
QDialogButtonBox* btns = new QDialogButtonBox(
|
QDialogButtonBox* btns = new QDialogButtonBox(
|
||||||
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
||||||
Qt::Horizontal, &dialog);
|
Qt::Horizontal, &dialog);
|
||||||
|
@ -1021,6 +1024,26 @@ void CMakeSetupDialog::addCacheEntry()
|
||||||
{
|
{
|
||||||
QCMakeCacheModel* m = this->CacheValues->cacheModel();
|
QCMakeCacheModel* m = this->CacheValues->cacheModel();
|
||||||
m->insertProperty(w->type(), w->name(), w->description(), w->value(), false);
|
m->insertProperty(w->type(), w->name(), w->description(), w->value(), false);
|
||||||
|
|
||||||
|
// only add variable names to the completion which are new
|
||||||
|
if (!this->AddVariableCompletions.contains(w->name()))
|
||||||
|
{
|
||||||
|
this->AddVariableCompletions << w->name();
|
||||||
|
// limit to at most 100 completion items
|
||||||
|
if (this->AddVariableCompletions.size() > 100)
|
||||||
|
{
|
||||||
|
this->AddVariableCompletions.removeFirst();
|
||||||
|
}
|
||||||
|
// make sure CMAKE_INSTALL_PREFIX is always there
|
||||||
|
if (!this->AddVariableCompletions.contains("CMAKE_INSTALL_PREFIX"))
|
||||||
|
{
|
||||||
|
this->AddVariableCompletions << QString("CMAKE_INSTALL_PREFIX");
|
||||||
|
}
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup("Settings/StartPath");
|
||||||
|
settings.setValue("AddVariableCompletionEntries",
|
||||||
|
this->AddVariableCompletions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,8 @@ protected:
|
||||||
QTextCharFormat ErrorFormat;
|
QTextCharFormat ErrorFormat;
|
||||||
QTextCharFormat MessageFormat;
|
QTextCharFormat MessageFormat;
|
||||||
|
|
||||||
|
QStringList AddVariableCompletions;
|
||||||
|
|
||||||
QEventLoop LocalLoop;
|
QEventLoop LocalLoop;
|
||||||
|
|
||||||
float ProgressOffset;
|
float ProgressOffset;
|
||||||
|
|
Loading…
Reference in New Issue