add initial support of tag suggestion

This commit is contained in:
Evgenii Alekseev 2016-10-24 08:12:14 +03:00
parent d520f55afc
commit 87406f70c4
6 changed files with 65 additions and 11 deletions

View File

@ -73,6 +73,7 @@ Item {
AWTextEditor {
id: textPattern
backend: awKeys
}
}

View File

@ -155,9 +155,7 @@ QStringList AWKeyOperations::dictKeys() const
for (auto item : m_graphicalItems->activeItems())
allKeys.append(item->tag(QString("bar")));
// static keys
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
[&allKeys](const QString &key) { allKeys.append(key); });
allKeys.append(QString(STATIC_KEYS).split(QChar(',')));
// sort in valid order
allKeys.sort();

View File

@ -57,6 +57,7 @@ Item {
AWTextEditor {
id: textPattern
backend: dpAdds
}
}

View File

@ -72,15 +72,21 @@ int DPAdds::currentDesktop() const
}
QStringList DPAdds::dictKeys(const bool, const QString) const
QStringList DPAdds::dictKeys(const bool sorted, const QString regexp) const
{
qCDebug(LOG_DP) << "Should be sorted" << sorted << "and filter applied"
<< regexp;
QStringList allKeys;
allKeys.append(QString("mark"));
allKeys.append(QString("name"));
allKeys.append(QString("number"));
allKeys.append(QString("total"));
return allKeys;
if (sorted)
allKeys.sort();
return allKeys.filter(QRegExp(regexp));
}

View File

@ -45,8 +45,8 @@ public:
virtual ~DPAdds();
Q_INVOKABLE bool isDebugEnabled() const;
Q_INVOKABLE int currentDesktop() const;
Q_INVOKABLE QStringList dictKeys(const bool = true,
const QString = QString()) const;
Q_INVOKABLE QStringList dictKeys(const bool sorted = true,
const QString regexp = QString()) const;
Q_INVOKABLE int numberOfDesktops() const;
Q_INVOKABLE QString toolTipImage(const int desktop) const;
Q_INVOKABLE QString parsePattern(const QString pattern,

View File

@ -16,12 +16,60 @@
***************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls
import QtQuick.Controls 2.0 as QtControls
QtControls.TextArea {
Item {
width: parent.width
height: parent.height * 4 / 5
textFormat: TextEdit.PlainText
text: plasmoid.configuration.text
property var backend
property alias text: textArea.text
QtControls.TextArea {
id: textArea
anchors.fill: parent
textFormat: TextEdit.PlainText
QtControls.ToolTip {
id: tooltip
}
onTextChanged: {
var currentTag = getLastTag()
// exit if there are spaces or empty
if ((currentTag.indexOf(" ") != -1) || (currentTag.length == 0)) {
tooltip.visible = false
return
}
var tags = backend.dictKeys(true, "^" + currentTag).join('\n')
// exit if no suggestion found
if (tags.length == 0) {
tooltip.visible = false
return
}
// update tooltip and show it
tooltip.text = tags
changeTooltipPosition()
tooltip.visible = true
}
}
function changeTooltipPosition() {
tooltip.x = textArea. cursorRectangle.x
tooltip.y = textArea. cursorRectangle.y
}
function getLastTag() {
// get substring to analyze
var substring = textArea.getText(0, textArea.cursorPosition)
// find last position of index in the given substring
var signIndex = substring.lastIndexOf('$') + 1
if ((signIndex == 0) || (signIndex == textArea.cursorPosition))
return ""
// get current tag text
return substring.substr(signIndex)
}
}