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

Remember last triggered actions in command bar

- For now it will only work for current session
- Only last 6 actions are remembered
parent 718d59f1
......@@ -19,7 +19,20 @@ void CommandModel::refresh(QVector<QPair<QString, QAction *>> actionList)
QVector<Item> temp;
temp.reserve(actionList.size());
for (auto action : actionList) {
temp.push_back({action.first, action.second, 0});
if (!action.second) {
continue;
}
temp.push_back({action.first, action.second, -1});
}
int score = 0;
for (const auto &actionName : m_lastTriggered) {
for (auto &item : temp) {
if (actionName == item.action->text()) {
item.score = score++;
break;
}
}
}
beginResetModel();
......@@ -65,3 +78,21 @@ QVariant CommandModel::data(const QModelIndex &index, int role) const
return {};
}
void CommandModel::actionTriggered(const QString &name)
{
if (m_lastTriggered.size() == 6) {
m_lastTriggered.pop_front();
}
m_lastTriggered.push_back(name);
}
QVector<QString> CommandModel::lastUsedActions()
{
return m_lastTriggered;
}
void CommandModel::setLastUsedActions(const QVector<QString> &actionNames)
{
m_lastTriggered = actionNames;
}
......@@ -55,8 +55,15 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
void actionTriggered(const QString &name);
QVector<QString> lastUsedActions();
void setLastUsedActions(const QVector<QString> &actionNames);
private:
QVector<Item> m_rows;
QVector<QString> m_lastTriggered;
};
#endif // COMMANDMODEL_H
......@@ -387,6 +387,7 @@ void KateCommandBar::slotReturnPressed()
m_lineEdit->clear();
return;
} else {
m_model->actionTriggered(act->text());
act->trigger();
}
}
......@@ -419,3 +420,13 @@ void KateCommandBar::updateViewGeometry()
this->setFixedSize(viewMaxSize);
}
void KateCommandBar::setLastUsedCmdBarActions(const QVector<QString> &actionNames)
{
return m_model->setLastUsedActions(actionNames);
}
QVector<QString> KateCommandBar::lastUsedCmdBarActions() const
{
return m_model->lastUsedActions();
}
......@@ -23,6 +23,9 @@ public:
void updateViewGeometry();
void setLastUsedCmdBarActions(const QVector<QString> &actionNames);
QVector<QString> lastUsedCmdBarActions() const;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
......
......@@ -1207,9 +1207,11 @@ void KateMainWindow::slotCommandBarOpen()
}
KateCommandBar commandBar(this);
commandBar.setLastUsedCmdBarActions(m_lastUsedCmdBarActions);
commandBar.updateBar(actionCollections, actionsCount);
centralWidget()->setFocusProxy(&commandBar);
commandBar.exec();
m_lastUsedCmdBarActions = commandBar.lastUsedCmdBarActions();
}
QWidget *KateMainWindow::createToolView(KTextEditor::Plugin *plugin,
......
......@@ -566,6 +566,8 @@ private:
QWidget *m_bottomViewBarContainer = nullptr;
KateContainerStackedLayout *m_bottomContainerStack = nullptr;
QVector<QString> m_lastUsedCmdBarActions;
class BarState
{
public:
......
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