forked from qt-creator/qt-creator
historycompleter: make key explicit
Change-Id: I1560e379639a02a2decf46c4e6b015bd6042c6b7 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -44,6 +44,8 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
static QSettings *theSettings = 0;
|
||||||
|
|
||||||
class HistoryCompleterPrivate : public QAbstractListModel
|
class HistoryCompleterPrivate : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -61,7 +63,6 @@ public:
|
|||||||
QString historyKey;
|
QString historyKey;
|
||||||
HistoryCompleter *completer;
|
HistoryCompleter *completer;
|
||||||
QWidget *lastSeenWidget;
|
QWidget *lastSeenWidget;
|
||||||
QSettings *settings;
|
|
||||||
int maxLines;
|
int maxLines;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,20 +115,19 @@ HistoryCompleterPrivate::HistoryCompleterPrivate(HistoryCompleter *parent)
|
|||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, completer(parent)
|
, completer(parent)
|
||||||
, lastSeenWidget(0)
|
, lastSeenWidget(0)
|
||||||
, settings(0)
|
|
||||||
, maxLines(30)
|
, maxLines(30)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryCompleterPrivate::fetchHistory()
|
void HistoryCompleterPrivate::fetchHistory()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(settings, return);
|
QTC_ASSERT(theSettings, return);
|
||||||
if (!completer->widget()) {
|
if (!completer->widget()) {
|
||||||
list.clear();
|
list.clear();
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list = settings->value(historyKey).toStringList();
|
list = theSettings->value(historyKey).toStringList();
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &
|
|||||||
{
|
{
|
||||||
beginRemoveRows (parent, row, row + count);
|
beginRemoveRows (parent, row, row + count);
|
||||||
list.removeAt(row);
|
list.removeAt(row);
|
||||||
settings->setValue(historyKey, list);
|
theSettings->setValue(historyKey, list);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -178,6 +178,7 @@ void HistoryCompleterPrivate::clearHistory()
|
|||||||
|
|
||||||
void HistoryCompleterPrivate::saveEntry(const QString &str)
|
void HistoryCompleterPrivate::saveEntry(const QString &str)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(theSettings, return);
|
||||||
if (str.isEmpty())
|
if (str.isEmpty())
|
||||||
return;
|
return;
|
||||||
if (list.contains(str))
|
if (list.contains(str))
|
||||||
@@ -195,7 +196,7 @@ void HistoryCompleterPrivate::saveEntry(const QString &str)
|
|||||||
list.prepend(str);
|
list.prepend(str);
|
||||||
list = list.mid(0, maxLines);
|
list = list.mid(0, maxLines);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
settings->setValue(historyKey, list);
|
theSettings->setValue(historyKey, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
|
bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
|
||||||
@@ -207,26 +208,21 @@ bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
|
|||||||
return QAbstractListModel::eventFilter(obj,event);
|
return QAbstractListModel::eventFilter(obj,event);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryCompleter::HistoryCompleter(QSettings *settings, QObject *parent, const QString &historyKey)
|
HistoryCompleter::HistoryCompleter(QObject *parent, const QString &historyKey)
|
||||||
: QCompleter(parent)
|
: QCompleter(parent)
|
||||||
, d(new HistoryCompleterPrivate(this))
|
, d(new HistoryCompleterPrivate(this))
|
||||||
{
|
{
|
||||||
QTC_ASSERT(settings, return);
|
QTC_ASSERT(!historyKey.isEmpty(), return);
|
||||||
d->settings = settings;
|
|
||||||
// make an assumption to allow pressing of the down
|
// make an assumption to allow pressing of the down
|
||||||
// key, before the first model run:
|
// key, before the first model run:
|
||||||
// parent is likely the lineedit
|
// parent is likely the lineedit
|
||||||
if (historyKey.isEmpty())
|
|
||||||
d->historyKey = parent->objectName();
|
|
||||||
else
|
|
||||||
d->historyKey = historyKey;
|
|
||||||
|
|
||||||
if (d->historyKey.isEmpty())
|
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
|
||||||
return;
|
|
||||||
d->historyKey = QLatin1String("CompleterHistory/") + d->historyKey;
|
|
||||||
|
|
||||||
parent->installEventFilter(d);
|
parent->installEventFilter(d);
|
||||||
d->list = d->settings->value(d->historyKey).toStringList();
|
QTC_ASSERT(theSettings, return);
|
||||||
|
d->list = theSettings->value(d->historyKey).toStringList();
|
||||||
|
|
||||||
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
|
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
|
||||||
if (l && d->list.count())
|
if (l && d->list.count())
|
||||||
@@ -269,4 +265,9 @@ void HistoryCompleter::saveHistory()
|
|||||||
d->saveEntry(completionPrefix());
|
d->saveEntry(completionPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryCompleter::setSettings(QSettings *settings)
|
||||||
|
{
|
||||||
|
Internal::theSettings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -48,13 +48,14 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HistoryCompleter(QSettings *settings, QObject *parent,
|
HistoryCompleter(QObject *parent, const QString &historyKey);
|
||||||
const QString &historyKey = QString());
|
|
||||||
~HistoryCompleter();
|
~HistoryCompleter();
|
||||||
int historySize() const;
|
int historySize() const;
|
||||||
int maximalHistorySize() const;
|
int maximalHistorySize() const;
|
||||||
void setMaximalHistorySize(int numberOfEntries);
|
void setMaximalHistorySize(int numberOfEntries);
|
||||||
|
|
||||||
|
static void setSettings(QSettings *settings);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void clearHistory();
|
void clearHistory();
|
||||||
void saveHistory();
|
void saveHistory();
|
||||||
|
@@ -296,9 +296,8 @@ void CMakeRunPage::initWidgets()
|
|||||||
|
|
||||||
// Run CMake Line (with arguments)
|
// Run CMake Line (with arguments)
|
||||||
m_argumentsLineEdit = new QLineEdit(this);
|
m_argumentsLineEdit = new QLineEdit(this);
|
||||||
m_argumentsLineEdit->setObjectName(QLatin1String("CMakeArgumentsLineEdit"));
|
|
||||||
m_argumentsLineEdit->setCompleter(
|
m_argumentsLineEdit->setCompleter(
|
||||||
new Utils::HistoryCompleter(Core::ICore::settings(), m_argumentsLineEdit));
|
new Utils::HistoryCompleter(m_argumentsLineEdit, QLatin1String("CMakeArgumentsLineEdit")));
|
||||||
|
|
||||||
connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake()));
|
connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake()));
|
||||||
fl->addRow(tr("Arguments:"), m_argumentsLineEdit);
|
fl->addRow(tr("Arguments:"), m_argumentsLineEdit);
|
||||||
|
@@ -82,6 +82,7 @@
|
|||||||
#include <coreplugin/icorelistener.h>
|
#include <coreplugin/icorelistener.h>
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
#include <coreplugin/settingsdatabase.h>
|
#include <coreplugin/settingsdatabase.h>
|
||||||
|
#include <utils/historycompleter.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
@@ -175,6 +176,8 @@ MainWindow::MainWindow() :
|
|||||||
(void) new DocumentManager(this);
|
(void) new DocumentManager(this);
|
||||||
OutputPaneManager::create();
|
OutputPaneManager::create();
|
||||||
|
|
||||||
|
Utils::HistoryCompleter::setSettings(m_settings);
|
||||||
|
|
||||||
setWindowTitle(tr("Qt Creator"));
|
setWindowTitle(tr("Qt Creator"));
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
QApplication::setWindowIcon(QIcon(QLatin1String(Constants::ICON_QTLOGO_128)));
|
QApplication::setWindowIcon(QIcon(QLatin1String(Constants::ICON_QTLOGO_128)));
|
||||||
|
@@ -210,22 +210,21 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
|
|||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
setWindowTitle(tr("Start Debugger"));
|
setWindowTitle(tr("Start Debugger"));
|
||||||
|
|
||||||
QSettings *settings = ICore::settings();
|
|
||||||
|
|
||||||
d->localExecutablePathChooser = new PathChooser(this);
|
d->localExecutablePathChooser = new PathChooser(this);
|
||||||
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
|
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
|
||||||
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
|
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
|
||||||
d->localExecutablePathChooser->lineEdit()->setCompleter(
|
d->localExecutablePathChooser->lineEdit()->setCompleter(
|
||||||
new HistoryCompleter(settings, d->localExecutablePathChooser->lineEdit()));
|
new HistoryCompleter(d->localExecutablePathChooser->lineEdit(), QLatin1String("LocalExecutable")));
|
||||||
|
|
||||||
d->arguments = new QLineEdit(this);
|
d->arguments = new QLineEdit(this);
|
||||||
d->arguments->setCompleter(new HistoryCompleter(settings, d->arguments));
|
d->arguments->setCompleter(
|
||||||
|
new HistoryCompleter(d->arguments, QLatin1String("CommandlineArguments")));
|
||||||
|
|
||||||
d->workingDirectory = new PathChooser(this);
|
d->workingDirectory = new PathChooser(this);
|
||||||
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
||||||
d->workingDirectory->lineEdit()->setCompleter(
|
d->workingDirectory->lineEdit()->setCompleter(
|
||||||
new HistoryCompleter(settings, d->workingDirectory->lineEdit()));
|
new HistoryCompleter(d->workingDirectory->lineEdit(), QLatin1String("WorkingDirectory")));
|
||||||
|
|
||||||
d->runInTerminalCheckBox = new QCheckBox(this);
|
d->runInTerminalCheckBox = new QCheckBox(this);
|
||||||
|
|
||||||
@@ -667,25 +666,24 @@ public:
|
|||||||
StartRemoteEngineDialog::StartRemoteEngineDialog(QWidget *parent)
|
StartRemoteEngineDialog::StartRemoteEngineDialog(QWidget *parent)
|
||||||
: QDialog(parent), d(new StartRemoteEngineDialogPrivate)
|
: QDialog(parent), d(new StartRemoteEngineDialogPrivate)
|
||||||
{
|
{
|
||||||
QSettings *settings = ICore::settings();
|
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
setWindowTitle(tr("Start Remote Engine"));
|
setWindowTitle(tr("Start Remote Engine"));
|
||||||
|
|
||||||
d->host = new QLineEdit(this);
|
d->host = new QLineEdit(this);
|
||||||
d->host->setText(QString());
|
d->host->setText(QString());
|
||||||
d->host->setCompleter(new HistoryCompleter(settings, d->host));
|
d->host->setCompleter(new HistoryCompleter(d->host, QLatin1String("HostName")));
|
||||||
|
|
||||||
d->username = new QLineEdit(this);
|
d->username = new QLineEdit(this);
|
||||||
d->username->setCompleter(new HistoryCompleter(settings, d->username));
|
d->username->setCompleter(new HistoryCompleter(d->username, QLatin1String("UserName")));
|
||||||
|
|
||||||
d->password = new QLineEdit(this);
|
d->password = new QLineEdit(this);
|
||||||
d->password->setEchoMode(QLineEdit::Password);
|
d->password->setEchoMode(QLineEdit::Password);
|
||||||
|
|
||||||
d->enginePath = new QLineEdit(this);
|
d->enginePath = new QLineEdit(this);
|
||||||
d->enginePath->setCompleter(new HistoryCompleter(settings, d->enginePath));
|
d->enginePath->setCompleter(new HistoryCompleter(d->enginePath, QLatin1String("EnginePath")));
|
||||||
|
|
||||||
d->inferiorPath = new QLineEdit(this);
|
d->inferiorPath = new QLineEdit(this);
|
||||||
d->inferiorPath->setCompleter(new HistoryCompleter(settings, d->inferiorPath));
|
d->inferiorPath->setCompleter(new HistoryCompleter(d->inferiorPath, QLatin1String("InferiorPath")));
|
||||||
|
|
||||||
d->buttonBox = new QDialogButtonBox(this);
|
d->buttonBox = new QDialogButtonBox(this);
|
||||||
d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||||
|
@@ -343,9 +343,7 @@ LogWindow::LogWindow(QWidget *parent)
|
|||||||
m_commandLabel = new QLabel(tr("Command:"), this);
|
m_commandLabel = new QLabel(tr("Command:"), this);
|
||||||
m_commandEdit = new QLineEdit(this);
|
m_commandEdit = new QLineEdit(this);
|
||||||
m_commandEdit->setFrame(false);
|
m_commandEdit->setFrame(false);
|
||||||
m_commandEdit->setObjectName(QLatin1String("DebuggerInput"));
|
m_commandEdit->setCompleter(new Utils::HistoryCompleter(m_commandEdit, QLatin1String("DebuggerInput")));
|
||||||
m_commandEdit->setCompleter(new Utils::HistoryCompleter(
|
|
||||||
Core::ICore::settings(), m_commandEdit));
|
|
||||||
QHBoxLayout *commandBox = new QHBoxLayout;
|
QHBoxLayout *commandBox = new QHBoxLayout;
|
||||||
commandBox->addWidget(m_commandLabel);
|
commandBox->addWidget(m_commandLabel);
|
||||||
commandBox->addWidget(m_commandEdit);
|
commandBox->addWidget(m_commandEdit);
|
||||||
|
Reference in New Issue
Block a user