Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
ddef496c
Commit
ddef496c
authored
Jan 18, 2021
by
Waqar Ahmed
Committed by
Christoph Cullmann
Jan 18, 2021
Browse files
Improve the display a bit, and add component name to display
parent
df1f3b2e
Changes
5
Hide whitespace changes
Inline
Side-by-side
kate/commandmodel.cpp
View file @
ddef496c
...
...
@@ -9,12 +9,12 @@ CommandModel::CommandModel(QObject *parent)
{
}
void
CommandModel
::
refresh
(
Q
List
<
QAction
*>
action
s
)
void
CommandModel
::
refresh
(
Q
Vector
<
QPair
<
QString
,
QAction
*
>
>
action
List
)
{
QVector
<
Item
>
temp
;
temp
.
reserve
(
action
s
.
size
());
for
(
auto
action
:
action
s
)
{
temp
.
push_back
({
action
,
0
});
temp
.
reserve
(
action
List
.
size
());
for
(
auto
action
:
action
List
)
{
temp
.
push_back
({
action
.
first
,
action
.
second
,
0
});
}
beginResetModel
();
...
...
@@ -34,7 +34,7 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const
{
case
Qt
::
DisplayRole
:
if
(
col
==
0
)
return
KLocalizedString
::
removeAcceleratorMarker
(
entry
.
action
->
text
());
return
QString
(
entry
.
component
+
QStringLiteral
(
": "
)
+
KLocalizedString
::
removeAcceleratorMarker
(
entry
.
action
->
text
())
)
;
else
return
entry
.
action
->
shortcut
().
toString
();
case
Qt
::
DecorationRole
:
...
...
kate/commandmodel.h
View file @
ddef496c
...
...
@@ -10,6 +10,7 @@ class CommandModel : public QAbstractTableModel
{
struct
Item
{
QString
component
;
QAction
*
action
;
int
score
;
};
...
...
@@ -20,7 +21,7 @@ public:
enum
Role
{
Score
=
Qt
::
UserRole
+
1
};
void
refresh
(
Q
List
<
QAction
*>
action
s
);
void
refresh
(
Q
Vector
<
QPair
<
QString
,
QAction
*>
>
action
List
);
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
{
...
...
kate/katecommandbar.cpp
View file @
ddef496c
...
...
@@ -15,6 +15,8 @@
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <KActionCollection>
#include <kfts_fuzzy_match.h>
class
CommandBarFilterModel
:
public
QSortFilterProxyModel
...
...
@@ -47,7 +49,7 @@ protected:
int
score
=
0
;
const
auto
idx
=
sourceModel
()
->
index
(
sourceRow
,
0
,
sourceParent
);
const
QString
actionName
=
idx
.
data
().
toString
();
const
auto
actionName
=
idx
.
data
().
toString
()
.
splitRef
(
QLatin1Char
(
':'
)).
at
(
1
)
;
const
bool
res
=
kfts
::
fuzzy_match
(
m_pattern
,
actionName
,
score
);
sourceModel
()
->
setData
(
idx
,
score
,
CommandModel
::
Score
);
return
res
;
...
...
@@ -72,11 +74,14 @@ public:
QTextDocument
doc
;
QString
str
=
index
.
data
().
toString
();
const
auto
strs
=
index
.
data
().
toString
().
split
(
QLatin1Char
(
':'
));
QString
str
=
strs
.
at
(
1
);
const
QString
nameColor
=
option
.
palette
.
color
(
QPalette
::
Link
).
name
();
kfts
::
to_fuzzy_matched_display_string
(
m_filterString
,
str
,
QStringLiteral
(
"<b style=
\"
color:%1;
\"
>"
).
arg
(
nameColor
),
QStringLiteral
(
"</b>"
));
doc
.
setHtml
(
QStringLiteral
(
"<span>"
)
+
str
+
QStringLiteral
(
"</span>"
));
const
QString
component
=
QStringLiteral
(
"<span style=
\"
color: gray;
\"
>"
)
+
strs
.
at
(
0
)
+
QStringLiteral
(
": </span>"
);
doc
.
setHtml
(
component
+
str
);
doc
.
setDocumentMargin
(
2
);
painter
->
save
();
...
...
@@ -164,9 +169,16 @@ KateCommandBar::KateCommandBar(QWidget *parent)
setHidden
(
true
);
}
void
KateCommandBar
::
updateBar
(
QList
<
Q
Action
*>
a
ctions
)
void
KateCommandBar
::
updateBar
(
QList
<
K
Action
Collection
*>
actionColle
ctions
)
{
m_model
->
refresh
(
actions
);
QVector
<
QPair
<
QString
,
QAction
*>>
actionList
;
for
(
const
auto
collection
:
actionCollections
)
{
for
(
const
auto
action
:
collection
->
actions
())
{
actionList
.
append
({
collection
->
componentDisplayName
(),
action
});
}
}
m_model
->
refresh
(
actionList
);
reselectFirst
();
updateViewGeometry
();
...
...
kate/katecommandbar.h
View file @
ddef496c
...
...
@@ -6,6 +6,7 @@ class QLineEdit;
class
CommandModel
;
class
QAction
;
class
CommandBarFilterModel
;
class
KActionCollection
;
class
KateCommandBar
:
public
QMenu
{
...
...
@@ -13,7 +14,7 @@ class KateCommandBar : public QMenu
public:
KateCommandBar
(
QWidget
*
parent
=
nullptr
);
void
updateBar
(
QList
<
QA
ction
*>
actions
);
void
updateBar
(
QList
<
KActionColle
ction
*>
actions
);
void
updateViewGeometry
();
...
...
kate/katemainwindow.cpp
View file @
ddef496c
...
...
@@ -1219,14 +1219,14 @@ void KateMainWindow::slotQuickOpen()
void
KateMainWindow
::
slotCommandBarOpen
()
{
QList
<
Q
Action
*>
act
s
;
QList
<
K
Action
Collection
*>
actionCollection
s
;
auto
clients
=
guiFactory
()
->
clients
();
for
(
auto
c
:
clients
)
{
acts
.
append
(
c
->
actionCollection
()
->
actions
()
);
act
ionCollection
s
.
append
(
c
->
actionCollection
());
}
m_commandBar
->
updateBar
(
acts
);
m_commandBar
->
updateBar
(
act
ionCollection
s
);
centralWidget
()
->
setFocusProxy
(
m_commandBar
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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