Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
19badfab
Commit
19badfab
authored
Oct 31, 2020
by
Alexander Lohnau
💬
Browse files
Make KRunner activity aware
parent
416c4b8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
krunner/view.cpp
View file @
19badfab
...
...
@@ -50,8 +50,7 @@
View
::
View
(
QWindow
*
)
:
PlasmaQuick
::
Dialog
(),
m_offset
(
.5
),
m_floating
(
false
),
m_retainPriorSearch
(
false
)
m_floating
(
false
)
{
setClearBeforeRendering
(
true
);
setColor
(
QColor
(
Qt
::
transparent
));
...
...
@@ -158,24 +157,6 @@ void View::loadConfig()
{
setFreeFloating
(
m_config
.
readEntry
(
"FreeFloating"
,
false
));
setPinned
(
m_config
.
readEntry
(
"Pinned"
,
false
));
m_historyEnabled
=
m_config
.
readEntry
(
"HistoryEnabled"
,
true
);
QStringList
history
;
if
(
m_historyEnabled
)
{
history
=
m_config
.
readEntry
(
"history"
,
QStringList
());
}
if
(
m_history
!=
history
)
{
m_history
=
history
;
emit
historyChanged
();
}
bool
retainPriorSearch
=
m_config
.
readEntry
(
"RetainPriorSearch"
,
true
);
if
(
retainPriorSearch
!=
m_retainPriorSearch
)
{
m_retainPriorSearch
=
retainPriorSearch
;
if
(
!
m_retainPriorSearch
)
{
m_qmlObj
->
rootObject
()
->
setProperty
(
"query"
,
QString
());
}
Q_EMIT
retainPriorSearchChanged
();
}
}
bool
View
::
event
(
QEvent
*
event
)
...
...
@@ -377,70 +358,6 @@ bool View::canConfigure() const
return
KAuthorized
::
authorizeControlModule
(
QStringLiteral
(
"kcm_plasmasearch.desktop"
));
}
QStringList
View
::
history
()
const
{
return
m_history
;
}
void
View
::
addToHistory
(
const
QString
&
item
)
{
if
(
!
m_historyEnabled
)
{
return
;
}
if
(
item
.
isEmpty
())
{
return
;
}
if
(
item
==
QLatin1String
(
"SESSIONS"
))
{
return
;
}
// Mimic shell behavior of not storing lines starting with a space
if
(
item
.
at
(
0
).
isSpace
())
{
return
;
}
// Avoid removing the same item from the front and prepending it again
if
(
!
m_history
.
isEmpty
()
&&
m_history
.
constFirst
()
==
item
)
{
return
;
}
if
(
!
KAuthorized
::
authorize
(
QStringLiteral
(
"lineedit_text_completion"
)))
{
return
;
}
m_history
.
removeOne
(
item
);
m_history
.
prepend
(
item
);
while
(
m_history
.
count
()
>
50
)
{
// make configurable?
m_history
.
removeLast
();
}
emit
historyChanged
();
writeHistory
();
m_config
.
sync
();
}
void
View
::
removeFromHistory
(
int
index
)
{
if
(
index
<
0
||
index
>=
m_history
.
count
())
{
return
;
}
m_history
.
removeAt
(
index
);
emit
historyChanged
();
writeHistory
();
}
void
View
::
writeHistory
()
{
if
(
!
m_historyEnabled
)
{
return
;
}
m_config
.
writeEntry
(
"history"
,
m_history
);
}
void
View
::
setVisible
(
bool
visible
)
{
m_requestedVisible
=
visible
;
...
...
@@ -452,10 +369,6 @@ void View::setVisible(bool visible)
}
}
bool
View
::
retainPriorSearch
()
const
{
return
m_retainPriorSearch
;
}
bool
View
::
pinned
()
const
{
return
m_pinned
;
...
...
krunner/view.h
View file @
19badfab
...
...
@@ -48,8 +48,6 @@ class View : public PlasmaQuick::Dialog
Q_CLASSINFO
(
"D-Bus Interface"
,
"org.kde.krunner.App"
)
Q_PROPERTY
(
bool
canConfigure
READ
canConfigure
CONSTANT
)
Q_PROPERTY
(
QStringList
history
READ
history
NOTIFY
historyChanged
)
Q_PROPERTY
(
bool
retainPriorSearch
READ
retainPriorSearch
NOTIFY
retainPriorSearchChanged
)
Q_PROPERTY
(
bool
pinned
READ
pinned
WRITE
setPinned
NOTIFY
pinnedChanged
)
public:
...
...
@@ -64,17 +62,10 @@ public:
bool
canConfigure
()
const
;
QStringList
history
()
const
;
Q_INVOKABLE
void
addToHistory
(
const
QString
&
item
);
Q_INVOKABLE
void
removeFromHistory
(
int
index
);
bool
retainPriorSearch
()
const
;
bool
pinned
()
const
;
void
setPinned
(
bool
pinned
);
Q_SIGNALS:
void
historyChanged
();
void
retainPriorSearchChanged
();
void
pinnedChanged
();
protected:
...
...
@@ -109,9 +100,6 @@ private:
qreal
m_offset
;
bool
m_floating
:
1
;
bool
m_requestedVisible
=
false
;
QStringList
m_history
;
bool
m_retainPriorSearch
;
bool
m_historyEnabled
;
bool
m_pinned
=
false
;
};
...
...
lookandfeel/contents/runcommand/RunCommand.qml
View file @
19badfab
...
...
@@ -29,7 +29,7 @@ ColumnLayout {
property
string
query
property
string
runner
property
bool
showHistory
:
false
property
string
priorSearch
property
alias
runnerManager
:
results
.
runnerManager
LayoutMirroring.enabled
:
Qt
.
application
.
layoutDirection
===
Qt
.
RightToLeft
LayoutMirroring.childrenInherit
:
true
...
...
@@ -44,16 +44,16 @@ ColumnLayout {
if
(
runnerWindow
.
visible
)
{
queryField
.
forceActiveFocus
();
listView
.
currentIndex
=
-
1
if
(
runner
Window
.
retainPriorSearch
)
{
if
(
runner
Manager
.
retainPriorSearch
)
{
// If we manually specified a query(D-Bus invocation) we don't want to retain the prior search
if
(
!
query
)
{
queryField
.
text
=
priorSearch
queryField
.
text
=
runnerManager
.
priorSearch
queryField
.
select
(
root
.
query
.
length
,
0
)
}
}
}
else
{
if
(
runner
Window
.
retainPriorSearch
)
{
priorSearch
=
root
.
query
if
(
runner
Manager
.
retainPriorSearch
)
{
runnerManager
.
priorSearch
=
root
.
query
}
root
.
runner
=
""
root
.
query
=
""
...
...
@@ -62,6 +62,18 @@ ColumnLayout {
}
}
Connections
{
target
:
root
function
onShowHistoryChanged
()
{
if
(
showHistory
)
{
// we store 50 entries in the history but only show 20 in the UI so it doesn't get too huge
listView
.
model
=
runnerManager
.
history
.
slice
(
0
,
20
)
}
else
{
listView
.
model
=
[]
}
}
}
RowLayout
{
Layout.alignment
:
Qt
.
AlignTop
PlasmaComponents3.ToolButton
{
...
...
@@ -139,20 +151,12 @@ ColumnLayout {
onTextChanged
:
{
root
.
query
=
queryField
.
text
if
(
allowCompletion
&&
length
>
0
)
{
var
history
=
runnerWindow
.
history
// search the first item in the history rather than the shortest matching one
// this way more recently used entries take precedence over older ones (Bug 358985)
for
(
var
i
=
0
,
j
=
history
.
length
;
i
<
j
;
++
i
)
{
var
item
=
history
[
i
]
if
(
item
.
toLowerCase
().
indexOf
(
text
.
toLowerCase
())
===
0
)
{
var
oldText
=
text
text
=
text
+
item
.
substr
(
oldText
.
length
)
select
(
text
.
length
,
oldText
.
length
)
break
}
if
(
allowCompletion
&&
length
>
0
&&
runnerManager
.
historyEnabled
)
{
var
oldText
=
text
var
suggestedText
=
runnerManager
.
getHistorySuggestion
(
text
);
if
(
suggestedText
.
length
>
0
)
{
text
=
suggestedText
select
(
text
.
length
,
oldText
.
length
)
}
}
}
...
...
@@ -200,7 +204,7 @@ ColumnLayout {
colorGroup
:
PlasmaCore
.
Theme
.
ButtonColorGroup
}
elementId
:
"
down-arrow
"
visible
:
queryField
.
length
===
0
&&
runner
Window
.
history
.
length
>
0
visible
:
queryField
.
length
===
0
&&
runner
Manager
.
history
Enabled
MouseArea
{
anchors.fill
:
parent
...
...
@@ -256,7 +260,6 @@ ColumnLayout {
}
onActivated
:
{
runnerWindow
.
addToHistory
(
queryString
)
runnerWindow
.
visible
=
false
}
...
...
@@ -281,8 +284,7 @@ ColumnLayout {
highlight
:
PlasmaComponents.Highlight
{}
highlightMoveDuration
:
0
activeFocusOnTab
:
true
// we store 50 entries in the history but only show 20 in the UI so it doesn't get too huge
model
:
root
.
showHistory
?
runnerWindow
.
history
.
slice
(
0
,
20
)
:
[]
model
:
[]
delegate
:
Milou.ResultDelegate
{
id
:
resultDelegate
width
:
listView
.
width
...
...
@@ -332,7 +334,7 @@ ColumnLayout {
Keys.onDownPressed
:
incrementCurrentIndex
()
function
runCurrentIndex
(
event
)
{
var
entry
=
runner
Window
.
history
[
currentIndex
]
var
entry
=
runner
Manager
.
history
[
currentIndex
]
if
(
entry
)
{
// If user presses Shift+Return to invoke an action, invoke the first runner action
if
(
event
&&
event
.
modifiers
===
Qt
.
ShiftModifier
...
...
@@ -350,7 +352,8 @@ ColumnLayout {
if
(
actionIndex
===
0
)
{
// QStringList changes just reset the model, so we'll remember the index and set it again
var
currentIndex
=
listView
.
currentIndex
runnerWindow
.
removeFromHistory
(
currentIndex
)
runnerManager
.
removeFromHistory
(
currentIndex
)
model
=
runnerManager
.
history
listView
.
currentIndex
=
currentIndex
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment