mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add initial support of tag suggestion
This commit is contained in:
parent
d520f55afc
commit
87406f70c4
@ -73,6 +73,7 @@ Item {
|
|||||||
|
|
||||||
AWTextEditor {
|
AWTextEditor {
|
||||||
id: textPattern
|
id: textPattern
|
||||||
|
backend: awKeys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,7 @@ QStringList AWKeyOperations::dictKeys() const
|
|||||||
for (auto item : m_graphicalItems->activeItems())
|
for (auto item : m_graphicalItems->activeItems())
|
||||||
allKeys.append(item->tag(QString("bar")));
|
allKeys.append(item->tag(QString("bar")));
|
||||||
// static keys
|
// static keys
|
||||||
QStringList staticKeys = QString(STATIC_KEYS).split(QChar(','));
|
allKeys.append(QString(STATIC_KEYS).split(QChar(',')));
|
||||||
std::for_each(staticKeys.cbegin(), staticKeys.cend(),
|
|
||||||
[&allKeys](const QString &key) { allKeys.append(key); });
|
|
||||||
|
|
||||||
// sort in valid order
|
// sort in valid order
|
||||||
allKeys.sort();
|
allKeys.sort();
|
||||||
|
@ -57,6 +57,7 @@ Item {
|
|||||||
|
|
||||||
AWTextEditor {
|
AWTextEditor {
|
||||||
id: textPattern
|
id: textPattern
|
||||||
|
backend: dpAdds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
QStringList allKeys;
|
||||||
allKeys.append(QString("mark"));
|
allKeys.append(QString("mark"));
|
||||||
allKeys.append(QString("name"));
|
allKeys.append(QString("name"));
|
||||||
allKeys.append(QString("number"));
|
allKeys.append(QString("number"));
|
||||||
allKeys.append(QString("total"));
|
allKeys.append(QString("total"));
|
||||||
|
|
||||||
return allKeys;
|
if (sorted)
|
||||||
|
allKeys.sort();
|
||||||
|
|
||||||
|
return allKeys.filter(QRegExp(regexp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ public:
|
|||||||
virtual ~DPAdds();
|
virtual ~DPAdds();
|
||||||
Q_INVOKABLE bool isDebugEnabled() const;
|
Q_INVOKABLE bool isDebugEnabled() const;
|
||||||
Q_INVOKABLE int currentDesktop() const;
|
Q_INVOKABLE int currentDesktop() const;
|
||||||
Q_INVOKABLE QStringList dictKeys(const bool = true,
|
Q_INVOKABLE QStringList dictKeys(const bool sorted = true,
|
||||||
const QString = QString()) const;
|
const QString regexp = QString()) const;
|
||||||
Q_INVOKABLE int numberOfDesktops() const;
|
Q_INVOKABLE int numberOfDesktops() const;
|
||||||
Q_INVOKABLE QString toolTipImage(const int desktop) const;
|
Q_INVOKABLE QString toolTipImage(const int desktop) const;
|
||||||
Q_INVOKABLE QString parsePattern(const QString pattern,
|
Q_INVOKABLE QString parsePattern(const QString pattern,
|
||||||
|
@ -16,12 +16,60 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import QtQuick.Controls 1.3 as QtControls
|
import QtQuick.Controls 2.0 as QtControls
|
||||||
|
|
||||||
|
|
||||||
QtControls.TextArea {
|
Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height * 4 / 5
|
height: parent.height * 4 / 5
|
||||||
|
|
||||||
|
property var backend
|
||||||
|
property alias text: textArea.text
|
||||||
|
|
||||||
|
QtControls.TextArea {
|
||||||
|
id: textArea
|
||||||
|
anchors.fill: parent
|
||||||
textFormat: TextEdit.PlainText
|
textFormat: TextEdit.PlainText
|
||||||
text: plasmoid.configuration.text
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user