Commit b1802f4a authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

always sort views by usage

this will allow e.g. the KTextEditor implementation
to be able to access the proper most recently used
view without extra interfacing

naturally one will need to adapt the documentation
in the interface, but I think this is nicer than
to expose and extra sortedView thing, given the
sorting should not be that costly anyways
parent c7250255
Pipeline #125384 passed with stage
in 3 minutes and 22 seconds
......@@ -567,9 +567,8 @@ KTextEditor::View *KateViewManager::activeView()
}
// last attempt: pick MRU view
auto views = sortedViews();
if (!views.empty()) {
KTextEditor::View *v = views.front();
if (auto sortedViews = views(); !sortedViews.empty()) {
KTextEditor::View *v = sortedViews.front();
activateView(v);
m_activeViewRunning = false;
return v;
......
......@@ -246,23 +246,9 @@ public Q_SLOTS:
/**
* Get a list of all views.
* @return all views
* @return all views sorted by their last use, most recently used first
*/
QList<KTextEditor::View *> views() const
{
QList<KTextEditor::View *> ret;
ret.reserve(m_views.size());
std::transform(m_views.begin(), m_views.end(), std::back_inserter(ret), [](const std::pair<KTextEditor::View *, ViewData> &p) {
return p.first;
});
return ret;
}
/**
* get views in lru order
* @return views in lru order
*/
std::vector<KTextEditor::View *> sortedViews() const
{
std::vector<std::pair<KTextEditor::View *, qint64>> sorted;
......@@ -276,7 +262,7 @@ public Q_SLOTS:
});
// extract the views only and return
std::vector<KTextEditor::View *> ret;
QList<KTextEditor::View *> ret;
ret.reserve(sorted.size());
std::transform(sorted.begin(), sorted.end(), std::back_inserter(ret), [](const std::pair<KTextEditor::View *, qint64> &p) {
return p.first;
......
......@@ -304,9 +304,9 @@ bool KateQuickOpen::eventFilter(QObject *obj, QEvent *event)
void KateQuickOpen::reselectFirst()
{
int first = 0;
if (m_mainWindow->viewManager()->sortedViews().size() > 1 && m_model->rowCount() > 1 && m_inputLine->text().isEmpty()) {
if (m_mainWindow->viewManager()->views().size() > 1 && m_model->rowCount() > 1 && m_inputLine->text().isEmpty()) {
first = 1;
}
}
QModelIndex index = m_model->index(first, 0);
m_listView->setCurrentIndex(index);
......@@ -397,4 +397,4 @@ void KateQuickOpen::updateViewGeometry()
move(p + m_mainWindow->pos());
setFixedSize(viewMaxSize);
}
\ No newline at end of file
}
......@@ -81,7 +81,7 @@ QVariant KateQuickOpenModel::data(const QModelIndex &idx, int role) const
void KateQuickOpenModel::refresh(KateMainWindow *mainWindow)
{
QObject *projectView = mainWindow->pluginView(QStringLiteral("kateprojectplugin"));
const std::vector<KTextEditor::View *> sortedViews = mainWindow->viewManager()->sortedViews();
const auto sortedViews = mainWindow->viewManager()->views();
const QList<KTextEditor::Document *> openDocs = KateApp::self()->documentManager()->documentList();
const QStringList projectDocs = projectView
? (m_listMode == CurrentProject ? projectView->property("projectFiles") : projectView->property("allProjectsFiles")).toStringList()
......
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