summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libs/utils/fancylineedit.cpp11
-rw-r--r--src/libs/utils/fancylineedit.h2
-rw-r--r--src/libs/utils/historycompleter.cpp19
-rw-r--r--src/libs/utils/historycompleter.h1
-rw-r--r--src/plugins/projectexplorer/devicesupport/deviceprocessesdialog.cpp3
5 files changed, 32 insertions, 4 deletions
diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp
index d5316dfdb8..f2b7684b5c 100644
--- a/src/libs/utils/fancylineedit.cpp
+++ b/src/libs/utils/fancylineedit.cpp
@@ -172,6 +172,13 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) :
FancyLineEdit::~FancyLineEdit()
{
+ if (d->m_historyCompleter) {
+ // When dialog with FancyLineEdit widget closed by <Escape>
+ // the QueuedConnection don't have enough time to call slot callback
+ // because edit widget and all of its connections are destroyed before
+ // QCoreApplicationPrivate::sendPostedEvents dispatch our queued signal.
+ d->m_historyCompleter->addEntry(text());
+ }
}
void FancyLineEdit::setButtonVisible(Side side, bool visible)
@@ -297,10 +304,12 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
return d->m_iconbutton[side]->hasAutoHide();
}
-void FancyLineEdit::setHistoryCompleter(const QString &historyKey)
+void FancyLineEdit::setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory)
{
QTC_ASSERT(!d->m_historyCompleter, return);
d->m_historyCompleter = new HistoryCompleter(historyKey, this);
+ if (restoreLastItemFromHistory)
+ setText(d->m_historyCompleter->historyItem());
QLineEdit::setCompleter(d->m_historyCompleter);
// Hitting <Return> in the popup first causes editingFinished()
diff --git a/src/libs/utils/fancylineedit.h b/src/libs/utils/fancylineedit.h
index 975da4d176..c50adfea30 100644
--- a/src/libs/utils/fancylineedit.h
+++ b/src/libs/utils/fancylineedit.h
@@ -114,7 +114,7 @@ public:
// Completion
// Enable a history completer with a history of entries.
- void setHistoryCompleter(const QString &historyKey);
+ void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false);
// Sets a completer that is not a history completer.
void setSpecialCompleter(QCompleter *completer);
diff --git a/src/libs/utils/historycompleter.cpp b/src/libs/utils/historycompleter.cpp
index d2e660861c..4cf055ae3c 100644
--- a/src/libs/utils/historycompleter.cpp
+++ b/src/libs/utils/historycompleter.cpp
@@ -59,6 +59,8 @@ public:
QStringList list;
QString historyKey;
+ bool isLastItemEmpty;
+ QString historyKeyIsLastItemEmpty;
int maxLines;
};
@@ -149,8 +151,11 @@ void HistoryCompleterPrivate::clearHistory()
void HistoryCompleterPrivate::addEntry(const QString &str)
{
const QString entry = str.trimmed();
- if (entry.isEmpty())
+ if (entry.isEmpty()) {
+ isLastItemEmpty = true;
+ theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
return;
+ }
int removeIndex = list.indexOf(entry);
beginResetModel();
if (removeIndex != -1)
@@ -159,6 +164,8 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
list = list.mid(0, maxLines - 1);
endResetModel();
theSettings->setValue(historyKey, list);
+ isLastItemEmpty = false;
+ theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
}
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
@@ -170,6 +177,9 @@ HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
d->list = theSettings->value(d->historyKey).toStringList();
+ d->historyKeyIsLastItemEmpty = QLatin1String("CompleterHistory/")
+ + historyKey + QLatin1String(".IsLastItemEmpty");
+ d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, false).toBool();
setModel(d);
setPopup(new HistoryLineView(d));
@@ -180,6 +190,13 @@ bool HistoryCompleter::removeHistoryItem(int index)
return d->removeRow(index);
}
+QString HistoryCompleter::historyItem() const
+{
+ if (historySize() == 0 || d->isLastItemEmpty)
+ return QString();
+ return d->list.at(0);
+}
+
HistoryCompleter::~HistoryCompleter()
{
delete d;
diff --git a/src/libs/utils/historycompleter.h b/src/libs/utils/historycompleter.h
index 47dd6286ae..641eaaec61 100644
--- a/src/libs/utils/historycompleter.h
+++ b/src/libs/utils/historycompleter.h
@@ -51,6 +51,7 @@ public:
static void setSettings(QSettings *settings);
HistoryCompleter(const QString &historyKey, QObject *parent = 0);
bool removeHistoryItem(int index);
+ QString historyItem() const;
private:
~HistoryCompleter();
diff --git a/src/plugins/projectexplorer/devicesupport/deviceprocessesdialog.cpp b/src/plugins/projectexplorer/devicesupport/deviceprocessesdialog.cpp
index fbb01fb4c1..52abe8be2c 100644
--- a/src/plugins/projectexplorer/devicesupport/deviceprocessesdialog.cpp
+++ b/src/plugins/projectexplorer/devicesupport/deviceprocessesdialog.cpp
@@ -139,7 +139,8 @@ DeviceProcessesDialogPrivate::DeviceProcessesDialogPrivate(KitChooser *chooser,
processFilterLineEdit = new FancyLineEdit(q);
processFilterLineEdit->setPlaceholderText(DeviceProcessesDialog::tr("Filter"));
processFilterLineEdit->setFocus(Qt::TabFocusReason);
- processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"));
+ processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"),
+ true /*restoreLastItemFromHistory*/);
processFilterLineEdit->setFiltering(true);
kitChooser->populate();