Commit ddef496c authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Improve the display a bit, and add component name to display

parent df1f3b2e
......@@ -9,12 +9,12 @@ CommandModel::CommandModel(QObject *parent)
{
}
void CommandModel::refresh(QList<QAction *> actions)
void CommandModel::refresh(QVector<QPair<QString, QAction*>> actionList)
{
QVector<Item> temp;
temp.reserve(actions.size());
for (auto action : actions) {
temp.push_back({action, 0});
temp.reserve(actionList.size());
for (auto action : actionList) {
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:
......
......@@ -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(QList<QAction*> actions);
void refresh(QVector<QPair<QString, QAction*>> actionList);
int rowCount(const QModelIndex & parent = QModelIndex()) const override
{
......
......@@ -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<QAction *> actions)
void KateCommandBar::updateBar(QList<KActionCollection *> actionCollections)
{
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();
......
......@@ -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<QAction*> actions);
void updateBar(QList<KActionCollection*> actions);
void updateViewGeometry();
......
......@@ -1219,14 +1219,14 @@ void KateMainWindow::slotQuickOpen()
void KateMainWindow::slotCommandBarOpen()
{
QList<QAction*> acts;
QList<KActionCollection*> actionCollections;
auto clients = guiFactory()->clients();
for (auto c : clients) {
acts.append(c->actionCollection()->actions());
actionCollections.append(c->actionCollection());
}
m_commandBar->updateBar(acts);
m_commandBar->updateBar(actionCollections);
centralWidget()->setFocusProxy(m_commandBar);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment