diff options
| author | Jonathan Marten <[email protected]> | 2020-09-23 11:07:29 +0000 |
|---|---|---|
| committer | Jonathan Marten <[email protected]> | 2020-09-23 11:07:29 +0000 |
| commit | b02046c5484f9c5bb9b5146fc4d521e4da2103a3 (patch) | |
| tree | 35134dc746ba5471948c2cd45eedf501e2f04166 /src/dolphinpart.cpp | |
| parent | 06d629ec6e59c1956e050c304ea7058f2fec89aa (diff) | |
Select/Unselect dialogue: Retain a history of entries made there
It's a very useful facilitity, and having a history of entries and being
able to recall earlier ones makes it even more useful for repetitive
operations.
Diffstat (limited to 'src/dolphinpart.cpp')
| -rw-r--r-- | src/dolphinpart.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index ea3a649e1..5d4188151 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -491,13 +491,38 @@ void DolphinPart::slotUnselectItemsMatchingPattern() void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems) { - bool okClicked; - const QString pattern = QInputDialog::getText(m_view, title, text, QLineEdit::Normal, QStringLiteral("*"), &okClicked); + auto *dialog = new QInputDialog(m_view); + dialog->setAttribute(Qt::WA_DeleteOnClose, true); + dialog->setInputMode(QInputDialog::TextInput); + dialog->setWindowTitle(title); + dialog->setLabelText(text); - if (okClicked && !pattern.isEmpty()) { - const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern)); - m_view->selectItems(patternRegExp, selectItems); - } + const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog"); + dialog->setComboBoxEditable(true); + dialog->setComboBoxItems(group.readEntry("History", QStringList())); + + dialog->setTextValue(QStringLiteral("*")); + + connect(dialog, &QDialog::accepted, this, [=]() { + const QString pattern = dialog->textValue(); + if (!pattern.isEmpty()) { + QStringList items = dialog->comboBoxItems(); + items.removeAll(pattern); + items.prepend(pattern); + + // Need to evaluate this again here, because the captured value is const + // (even if the const were removed from 'const KConfigGroup group =' above). + KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog"); + // Limit the size of the saved history. + group.writeEntry("History", items.mid(0, 10)); + group.sync(); + + const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern)); + m_view->selectItems(patternRegExp, selectItems); + } + }); + + dialog->open(); } void DolphinPart::setCurrentViewMode(const QString& viewModeName) |
