forked from qt-creator/qt-creator
Remove code duplication in open editors window
Change-Id: I9007e1171fa6d519df8cf62978bbd2936d901876 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
David Schulz
parent
111392f6c5
commit
00885ca9a5
@@ -196,63 +196,12 @@ void OpenEditorsWindow::centerOnItem(int selectedIndex)
|
|||||||
void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenEditorsModel *model)
|
void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenEditorsModel *model)
|
||||||
{
|
{
|
||||||
m_editorList->clear();
|
m_editorList->clear();
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
QSet<IDocument*> documentsDone;
|
QSet<IDocument*> documentsDone;
|
||||||
foreach (const EditLocation &hi, view->editorHistory()) {
|
addHistoryItems(view->editorHistory(), view, model, documentsDone);
|
||||||
if (hi.document.isNull() || documentsDone.contains(hi.document))
|
|
||||||
continue;
|
|
||||||
QString title = model->displayNameForDocument(hi.document);
|
|
||||||
QTC_ASSERT(!title.isEmpty(), continue);
|
|
||||||
documentsDone.insert(hi.document.data());
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
||||||
if (hi.document->isModified())
|
|
||||||
title += tr("*");
|
|
||||||
item->setIcon(0, !hi.document->fileName().isEmpty() && hi.document->isFileReadOnly()
|
|
||||||
? model->lockedIcon() : m_emptyIcon);
|
|
||||||
item->setText(0, title);
|
|
||||||
item->setToolTip(0, hi.document->fileName());
|
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.document.data()));
|
|
||||||
item->setData(0, Qt::UserRole+1, QVariant::fromValue(view));
|
|
||||||
item->setTextAlignment(0, Qt::AlignLeft);
|
|
||||||
|
|
||||||
m_editorList->addTopLevelItem(item);
|
|
||||||
|
|
||||||
if (first){
|
|
||||||
m_editorList->setCurrentItem(item);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add missing editors from the main view
|
// add missing editors from the main view
|
||||||
if (mainView != view) {
|
if (mainView != view)
|
||||||
foreach (const EditLocation &hi, mainView->editorHistory()) {
|
addHistoryItems(mainView->editorHistory(), view, model, documentsDone);
|
||||||
if (hi.document.isNull() || documentsDone.contains(hi.document))
|
|
||||||
continue;
|
|
||||||
documentsDone.insert(hi.document.data());
|
|
||||||
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
||||||
|
|
||||||
QString title = model->displayNameForDocument(hi.document);
|
|
||||||
if (hi.document->isModified())
|
|
||||||
title += tr("*");
|
|
||||||
item->setIcon(0, !hi.document->fileName().isEmpty() && hi.document->isFileReadOnly()
|
|
||||||
? model->lockedIcon() : m_emptyIcon);
|
|
||||||
item->setText(0, title);
|
|
||||||
item->setToolTip(0, hi.document->fileName());
|
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.document.data()));
|
|
||||||
item->setData(0, Qt::UserRole+1, QVariant::fromValue(view));
|
|
||||||
item->setData(0, Qt::UserRole+2, QVariant::fromValue(hi.id));
|
|
||||||
item->setTextAlignment(0, Qt::AlignLeft);
|
|
||||||
|
|
||||||
m_editorList->addTopLevelItem(item);
|
|
||||||
|
|
||||||
if (first){
|
|
||||||
m_editorList->setCurrentItem(item);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add purely restored editors which are not initialised yet
|
// add purely restored editors which are not initialised yet
|
||||||
foreach (const OpenEditorsModel::Entry &entry, model->entries()) {
|
foreach (const OpenEditorsModel::Entry &entry, model->entries()) {
|
||||||
@@ -300,3 +249,31 @@ void OpenEditorsWindow::ensureCurrentVisible()
|
|||||||
m_editorList->scrollTo(m_editorList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
m_editorList->scrollTo(m_editorList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, EditorView *view,
|
||||||
|
OpenEditorsModel *model, QSet<IDocument *> &documentsDone)
|
||||||
|
{
|
||||||
|
foreach (const EditLocation &hi, history) {
|
||||||
|
if (hi.document.isNull() || documentsDone.contains(hi.document))
|
||||||
|
continue;
|
||||||
|
documentsDone.insert(hi.document.data());
|
||||||
|
QString title = model->displayNameForDocument(hi.document);
|
||||||
|
QTC_ASSERT(!title.isEmpty(), continue);
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
|
if (hi.document->isModified())
|
||||||
|
title += tr("*");
|
||||||
|
item->setIcon(0, !hi.document->fileName().isEmpty() && hi.document->isFileReadOnly()
|
||||||
|
? model->lockedIcon() : m_emptyIcon);
|
||||||
|
item->setText(0, title);
|
||||||
|
item->setToolTip(0, hi.document->fileName());
|
||||||
|
item->setData(0, Qt::UserRole, QVariant::fromValue(hi.document.data()));
|
||||||
|
item->setData(0, Qt::UserRole+1, QVariant::fromValue(view));
|
||||||
|
item->setTextAlignment(0, Qt::AlignLeft);
|
||||||
|
|
||||||
|
m_editorList->addTopLevelItem(item);
|
||||||
|
|
||||||
|
if (m_editorList->topLevelItemCount() == 1){
|
||||||
|
m_editorList->setCurrentItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,8 +30,11 @@
|
|||||||
#ifndef OPENEDITORSWINDOW_H
|
#ifndef OPENEDITORSWINDOW_H
|
||||||
#define OPENEDITORSWINDOW_H
|
#define OPENEDITORSWINDOW_H
|
||||||
|
|
||||||
|
#include "editorview.h"
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
@@ -40,13 +43,13 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
class IDocument;
|
||||||
class IEditor;
|
class IEditor;
|
||||||
class OpenEditorsModel;
|
class OpenEditorsModel;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class EditorHistoryItem;
|
class EditorHistoryItem;
|
||||||
class EditorView;
|
|
||||||
|
|
||||||
class OpenEditorsWindow : public QFrame
|
class OpenEditorsWindow : public QFrame
|
||||||
{
|
{
|
||||||
@@ -74,6 +77,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void updateItem(QTreeWidgetItem *item, IEditor *editor);
|
static void updateItem(QTreeWidgetItem *item, IEditor *editor);
|
||||||
|
void addHistoryItems(const QList<EditLocation> &history, EditorView *view,
|
||||||
|
OpenEditorsModel *model, QSet<IDocument*> &documentsDone);
|
||||||
void ensureCurrentVisible();
|
void ensureCurrentVisible();
|
||||||
bool isCentering();
|
bool isCentering();
|
||||||
void centerOnItem(int selectedIndex);
|
void centerOnItem(int selectedIndex);
|
||||||
|
|||||||
Reference in New Issue
Block a user