forked from qt-creator/qt-creator
Editors: Don't use model index outside of model/view.
The model index is an internal detail of the model/view and shouldn't be used outside that context. Change-Id: I2c1f742fff427484f6ff244dd3e0d8428a7318d3 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -212,7 +212,7 @@ public:
|
|||||||
QAction *m_closeOtherEditorsContextAction;
|
QAction *m_closeOtherEditorsContextAction;
|
||||||
QAction *m_openGraphicalShellAction;
|
QAction *m_openGraphicalShellAction;
|
||||||
QAction *m_openTerminalAction;
|
QAction *m_openTerminalAction;
|
||||||
QModelIndex m_contextMenuEditorIndex;
|
OpenEditorsModel::Entry *m_contextMenuEntry;
|
||||||
|
|
||||||
Internal::OpenEditorsWindow *m_windowPopup;
|
Internal::OpenEditorsWindow *m_windowPopup;
|
||||||
Internal::EditorClosingCoreListener *m_coreListener;
|
Internal::EditorClosingCoreListener *m_coreListener;
|
||||||
@@ -812,16 +812,16 @@ static void assignAction(QAction *self, QAction *other)
|
|||||||
self->setIconVisibleInMenu(other->isIconVisibleInMenu());
|
self->setIconVisibleInMenu(other->isIconVisibleInMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, const QModelIndex &editorIndex)
|
void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(contextMenu, return);
|
QTC_ASSERT(contextMenu, return);
|
||||||
d->m_contextMenuEditorIndex = editorIndex;
|
d->m_contextMenuEntry = entry;
|
||||||
|
|
||||||
assignAction(d->m_saveCurrentEditorContextAction, ActionManager::command(Constants::SAVE)->action());
|
assignAction(d->m_saveCurrentEditorContextAction, ActionManager::command(Constants::SAVE)->action());
|
||||||
assignAction(d->m_saveAsCurrentEditorContextAction, ActionManager::command(Constants::SAVEAS)->action());
|
assignAction(d->m_saveAsCurrentEditorContextAction, ActionManager::command(Constants::SAVEAS)->action());
|
||||||
assignAction(d->m_revertToSavedCurrentEditorContextAction, ActionManager::command(Constants::REVERTTOSAVED)->action());
|
assignAction(d->m_revertToSavedCurrentEditorContextAction, ActionManager::command(Constants::REVERTTOSAVED)->action());
|
||||||
|
|
||||||
IEditor *editor = d->m_contextMenuEditorIndex.data(Qt::UserRole).value<Core::IEditor*>();
|
IEditor *editor = entry ? entry->editor : 0;
|
||||||
|
|
||||||
setupSaveActions(editor,
|
setupSaveActions(editor,
|
||||||
d->m_saveCurrentEditorContextAction,
|
d->m_saveCurrentEditorContextAction,
|
||||||
@@ -835,25 +835,26 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, const QMode
|
|||||||
|
|
||||||
contextMenu->addSeparator();
|
contextMenu->addSeparator();
|
||||||
|
|
||||||
d->m_closeCurrentEditorContextAction->setText(editorIndex.isValid()
|
d->m_closeCurrentEditorContextAction->setText(entry
|
||||||
? tr("Close \"%1\"").arg(editorIndex.data().toString())
|
? tr("Close \"%1\"").arg(entry->displayName())
|
||||||
: tr("Close Editor"));
|
: tr("Close Editor"));
|
||||||
d->m_closeOtherEditorsContextAction->setText(editorIndex.isValid()
|
d->m_closeOtherEditorsContextAction->setText(entry
|
||||||
? tr("Close All Except \"%1\"").arg(editorIndex.data().toString())
|
? tr("Close All Except \"%1\"").arg(entry->displayName())
|
||||||
: tr("Close Other Editors"));
|
: tr("Close Other Editors"));
|
||||||
d->m_closeCurrentEditorContextAction->setEnabled(editorIndex.isValid());
|
d->m_closeCurrentEditorContextAction->setEnabled(entry != 0);
|
||||||
d->m_closeOtherEditorsContextAction->setEnabled(editorIndex.isValid());
|
d->m_closeOtherEditorsContextAction->setEnabled(entry != 0);
|
||||||
d->m_closeAllEditorsContextAction->setEnabled(!openedEditors().isEmpty());
|
d->m_closeAllEditorsContextAction->setEnabled(!openedEditors().isEmpty());
|
||||||
contextMenu->addAction(d->m_closeCurrentEditorContextAction);
|
contextMenu->addAction(d->m_closeCurrentEditorContextAction);
|
||||||
contextMenu->addAction(d->m_closeAllEditorsContextAction);
|
contextMenu->addAction(d->m_closeAllEditorsContextAction);
|
||||||
contextMenu->addAction(d->m_closeOtherEditorsContextAction);
|
contextMenu->addAction(d->m_closeOtherEditorsContextAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::addNativeDirActions(QMenu *contextMenu, const QModelIndex &editorIndex)
|
void EditorManager::addNativeDirActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(contextMenu, return);
|
QTC_ASSERT(contextMenu, return);
|
||||||
d->m_openGraphicalShellAction->setEnabled(editorIndex.isValid());
|
bool enabled = entry && !entry->fileName().isEmpty();
|
||||||
d->m_openTerminalAction->setEnabled(editorIndex.isValid());
|
d->m_openGraphicalShellAction->setEnabled(enabled);
|
||||||
|
d->m_openTerminalAction->setEnabled(enabled);
|
||||||
contextMenu->addAction(d->m_openGraphicalShellAction);
|
contextMenu->addAction(d->m_openGraphicalShellAction);
|
||||||
contextMenu->addAction(d->m_openTerminalAction);
|
contextMenu->addAction(d->m_openTerminalAction);
|
||||||
}
|
}
|
||||||
@@ -953,45 +954,50 @@ void EditorManager::doEscapeKeyFocusMoveMagic()
|
|||||||
|
|
||||||
void EditorManager::saveDocumentFromContextMenu()
|
void EditorManager::saveDocumentFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEditorIndex.data(Qt::UserRole).value<Core::IEditor*>();
|
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
||||||
if (editor)
|
if (editor)
|
||||||
saveDocument(editor->document());
|
saveDocument(editor->document());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::saveDocumentAsFromContextMenu()
|
void EditorManager::saveDocumentAsFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEditorIndex.data(Qt::UserRole).value<Core::IEditor*>();
|
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
||||||
if (editor)
|
if (editor)
|
||||||
saveDocumentAs(editor->document());
|
saveDocumentAs(editor->document());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::revertToSavedFromContextMenu()
|
void EditorManager::revertToSavedFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEditorIndex.data(Qt::UserRole).value<Core::IEditor*>();
|
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
||||||
if (editor)
|
if (editor)
|
||||||
revertToSaved(editor);
|
revertToSaved(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeEditorFromContextMenu()
|
void EditorManager::closeEditorFromContextMenu()
|
||||||
{
|
{
|
||||||
closeEditor(d->m_contextMenuEditorIndex);
|
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
||||||
|
if (editor)
|
||||||
|
closeEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeOtherEditorsFromContextMenu()
|
void EditorManager::closeOtherEditorsFromContextMenu()
|
||||||
{
|
{
|
||||||
closeOtherEditors(d->m_contextMenuEditorIndex.data(Qt::UserRole).value<IEditor *>());
|
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
||||||
|
closeOtherEditors(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::showInGraphicalShell()
|
void EditorManager::showInGraphicalShell()
|
||||||
{
|
{
|
||||||
const QString path = d->m_contextMenuEditorIndex.data(Qt::UserRole + 1).toString();
|
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty())
|
||||||
Core::FileUtils::showInGraphicalShell(ICore::mainWindow(), path);
|
return;
|
||||||
|
Core::FileUtils::showInGraphicalShell(ICore::mainWindow(), d->m_contextMenuEntry->fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::openTerminal()
|
void EditorManager::openTerminal()
|
||||||
{
|
{
|
||||||
const QString path = QFileInfo(d->m_contextMenuEditorIndex.data(Qt::UserRole + 1).toString()).path();
|
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->fileName().isEmpty())
|
||||||
Core::FileUtils::openTerminal(path);
|
return;
|
||||||
|
Core::FileUtils::openTerminal(QFileInfo(d->m_contextMenuEntry->fileName()).path());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::rootDestroyed(QObject *root)
|
void EditorManager::rootDestroyed(QObject *root)
|
||||||
@@ -1057,13 +1063,14 @@ void EditorManager::closeEditor(Core::IEditor *editor)
|
|||||||
closeEditors(QList<IEditor *>() << editor);
|
closeEditors(QList<IEditor *>() << editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeEditor(const QModelIndex &index)
|
void EditorManager::closeEditor(OpenEditorsModel::Entry *entry)
|
||||||
{
|
{
|
||||||
IEditor *editor = index.data(Qt::UserRole).value<Core::IEditor*>();
|
if (!entry)
|
||||||
if (editor)
|
return;
|
||||||
closeEditor(editor);
|
if (entry->editor)
|
||||||
|
closeEditor(entry->editor);
|
||||||
else
|
else
|
||||||
d->m_editorModel->removeEditor(index);
|
d->m_editorModel->removeEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool askAboutModifiedEditors)
|
bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool askAboutModifiedEditors)
|
||||||
@@ -1143,20 +1150,26 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool currentViewHandled = false;
|
||||||
foreach (EditorView *view, closedViews) {
|
foreach (EditorView *view, closedViews) {
|
||||||
|
OpenEditorFlags flags;
|
||||||
|
if (view == currentView)
|
||||||
|
currentViewHandled = true;
|
||||||
|
else
|
||||||
|
flags = OpenEditorFlags(DoNotChangeCurrentEditor);
|
||||||
IEditor *newCurrent = view->currentEditor();
|
IEditor *newCurrent = view->currentEditor();
|
||||||
if (!newCurrent)
|
if (!newCurrent)
|
||||||
newCurrent = pickUnusedEditor();
|
newCurrent = pickUnusedEditor();
|
||||||
if (newCurrent) {
|
if (newCurrent) {
|
||||||
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
activateEditor(view, newCurrent, flags);
|
||||||
} else {
|
} else {
|
||||||
QModelIndex idx = d->m_editorModel->firstRestoredEditor();
|
OpenEditorsModel::Entry *entry = d->m_editorModel->firstRestoredEditor();
|
||||||
if (idx.isValid()) {
|
if (entry) {
|
||||||
activateEditorForIndex(view, idx, DoNotChangeCurrentEditor);
|
activateEditorForEntry(view, entry, flags);
|
||||||
} else {
|
} else {
|
||||||
const QList<IEditor *> editors = d->m_editorModel->editors();
|
const QList<IEditor *> editors = d->m_editorModel->editors();
|
||||||
if (!editors.isEmpty())
|
if (!editors.isEmpty())
|
||||||
activateEditor(view, editors.last(), DoNotChangeCurrentEditor);
|
activateEditor(view, editors.last(), flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1167,7 +1180,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
delete editor;
|
delete editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentView) {
|
if (currentView && !currentViewHandled) {
|
||||||
if (IEditor *editor = currentView->currentEditor())
|
if (IEditor *editor = currentView->currentEditor())
|
||||||
activateEditor(currentView, editor);
|
activateEditor(currentView, editor);
|
||||||
else
|
else
|
||||||
@@ -1213,9 +1226,9 @@ void EditorManager::closeDuplicate(Core::IEditor *editor)
|
|||||||
if (newCurrent) {
|
if (newCurrent) {
|
||||||
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
||||||
} else {
|
} else {
|
||||||
QModelIndex idx = d->m_editorModel->firstRestoredEditor();
|
OpenEditorsModel::Entry *entry = d->m_editorModel->firstRestoredEditor();
|
||||||
if (idx.isValid())
|
if (entry)
|
||||||
activateEditorForIndex(view, idx, DoNotChangeCurrentEditor);
|
activateEditorForEntry(view, entry, DoNotChangeCurrentEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1237,24 +1250,23 @@ Core::IEditor *EditorManager::pickUnusedEditor() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::activateEditorForIndex(const QModelIndex &index, OpenEditorFlags flags)
|
void EditorManager::activateEditorForEntry(OpenEditorsModel::Entry *entry, OpenEditorFlags flags)
|
||||||
{
|
{
|
||||||
activateEditorForIndex(currentEditorView(), index, flags);
|
activateEditorForEntry(currentEditorView(), entry, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags flags)
|
void EditorManager::activateEditorForEntry(Internal::EditorView *view, OpenEditorsModel::Entry *entry, OpenEditorFlags flags)
|
||||||
{
|
{
|
||||||
Q_ASSERT(view);
|
QTC_ASSERT(view, return);
|
||||||
IEditor *editor = index.data(Qt::UserRole).value<IEditor*>();
|
QTC_ASSERT(entry, return);
|
||||||
|
IEditor *editor = entry->editor;
|
||||||
if (editor) {
|
if (editor) {
|
||||||
activateEditor(view, editor, flags);
|
activateEditor(view, editor, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString fileName = index.data(Qt::UserRole + 1).toString();
|
if (!openEditor(view, entry->fileName(), entry->id(), flags))
|
||||||
Core::Id id = index.data(Qt::UserRole + 2).value<Core::Id>();
|
d->m_editorModel->removeEntry(entry);
|
||||||
if (!openEditor(view, fileName, id, flags))
|
|
||||||
d->m_editorModel->removeEditor(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::activateView(EditorView *view)
|
void EditorManager::activateView(EditorView *view)
|
||||||
@@ -2226,19 +2238,19 @@ QByteArray EditorManager::saveState() const
|
|||||||
|
|
||||||
stream << d->m_editorStates;
|
stream << d->m_editorStates;
|
||||||
|
|
||||||
QList<OpenEditorsModel::Entry> entries = d->m_editorModel->entries();
|
QList<OpenEditorsModel::Entry *> entries = d->m_editorModel->entries();
|
||||||
int entriesCount = 0;
|
int entriesCount = 0;
|
||||||
foreach (const OpenEditorsModel::Entry &entry, entries) {
|
foreach (OpenEditorsModel::Entry *entry, entries) {
|
||||||
// The editor may be 0 if it was not loaded yet: In that case it is not temporary
|
// The editor may be 0 if it was not loaded yet: In that case it is not temporary
|
||||||
if (!entry.editor || !entry.editor->isTemporary())
|
if (!entry->editor || !entry->editor->isTemporary())
|
||||||
++entriesCount;
|
++entriesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << entriesCount;
|
stream << entriesCount;
|
||||||
|
|
||||||
foreach (const OpenEditorsModel::Entry &entry, entries) {
|
foreach (OpenEditorsModel::Entry *entry, entries) {
|
||||||
if (!entry.editor || !entry.editor->isTemporary())
|
if (!entry->editor || !entry->editor->isTemporary())
|
||||||
stream << entry.fileName() << entry.displayName() << entry.id();
|
stream << entry->fileName() << entry->displayName() << entry->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << d->m_root.first()->saveState(); // TODO
|
stream << d->m_root.first()->saveState(); // TODO
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include "../core_global.h"
|
#include "../core_global.h"
|
||||||
|
|
||||||
|
#include "openeditorsmodel.h"
|
||||||
|
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
#include <coreplugin/idocument.h> // enumerations
|
#include <coreplugin/idocument.h> // enumerations
|
||||||
|
|
||||||
@@ -40,7 +42,6 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QModelIndex;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -63,8 +64,6 @@ enum MakeWritableResult {
|
|||||||
Failed
|
Failed
|
||||||
};
|
};
|
||||||
|
|
||||||
class OpenEditorsModel;
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
class EditorClosingCoreListener;
|
class EditorClosingCoreListener;
|
||||||
class EditorView;
|
class EditorView;
|
||||||
@@ -132,11 +131,11 @@ public:
|
|||||||
QList<IEditor*> openedEditors() const;
|
QList<IEditor*> openedEditors() const;
|
||||||
|
|
||||||
static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
|
static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
|
||||||
void activateEditorForIndex(const QModelIndex &index, OpenEditorFlags = 0);
|
void activateEditorForEntry(OpenEditorsModel::Entry *entry, OpenEditorFlags flags = 0);
|
||||||
IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
|
IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
|
||||||
|
|
||||||
OpenEditorsModel *openedEditorsModel() const;
|
OpenEditorsModel *openedEditorsModel() const;
|
||||||
void closeEditor(const QModelIndex &index);
|
void closeEditor(OpenEditorsModel::Entry *entry);
|
||||||
void closeOtherEditors(IEditor *editor);
|
void closeOtherEditors(IEditor *editor);
|
||||||
|
|
||||||
QList<IEditor*> editorsForDocuments(QList<IDocument *> documents) const;
|
QList<IEditor*> editorsForDocuments(QList<IDocument *> documents) const;
|
||||||
@@ -184,8 +183,8 @@ public:
|
|||||||
void setWindowTitleAddition(const QString &addition);
|
void setWindowTitleAddition(const QString &addition);
|
||||||
QString windowTitleAddition() const;
|
QString windowTitleAddition() const;
|
||||||
|
|
||||||
void addSaveAndCloseEditorActions(QMenu *contextMenu, const QModelIndex &editorIndex);
|
void addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry);
|
||||||
void addNativeDirActions(QMenu *contextMenu, const QModelIndex &editorIndex);
|
void addNativeDirActions(QMenu *contextMenu, OpenEditorsModel::Entry *entry);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentEditorChanged(Core::IEditor *editor);
|
void currentEditorChanged(Core::IEditor *editor);
|
||||||
@@ -259,7 +258,7 @@ private:
|
|||||||
IEditor *placeEditor(Internal::EditorView *view, IEditor *editor);
|
IEditor *placeEditor(Internal::EditorView *view, IEditor *editor);
|
||||||
IEditor *duplicateEditor(IEditor *editor);
|
IEditor *duplicateEditor(IEditor *editor);
|
||||||
IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0);
|
IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = 0);
|
||||||
void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
|
void activateEditorForEntry(Internal::EditorView *view, OpenEditorsModel::Entry *entry, OpenEditorFlags flags = 0);
|
||||||
void activateView(Internal::EditorView *view);
|
void activateView(Internal::EditorView *view);
|
||||||
IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
|
IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
|
||||||
const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
|
const Id &id = Id(), OpenEditorFlags flags = 0, bool *newEditor = 0);
|
||||||
|
|||||||
@@ -291,15 +291,15 @@ void EditorView::removeEditor(IEditor *editor)
|
|||||||
|
|
||||||
IEditor *EditorView::currentEditor() const
|
IEditor *EditorView::currentEditor() const
|
||||||
{
|
{
|
||||||
if (m_container->count() > 0)
|
if (m_editors.size() > 0)
|
||||||
return m_widgetEditorMap.value(m_container->currentWidget());
|
return m_widgetEditorMap.value(m_container->currentWidget());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorView::listSelectionActivated(int index)
|
void EditorView::listSelectionActivated(int index)
|
||||||
{
|
{
|
||||||
QAbstractItemModel *model = EditorManager::instance()->openedEditorsModel();
|
OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel();
|
||||||
EditorManager::instance()->activateEditorForIndex(this, model->index(index, 0));
|
EditorManager::instance()->activateEditorForEntry(this, model->entryAtRow(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorView::splitHorizontally()
|
void EditorView::splitHorizontally()
|
||||||
@@ -338,7 +338,7 @@ void EditorView::setParentSplitterOrView(SplitterOrView *splitterOrView)
|
|||||||
void EditorView::setCurrentEditor(IEditor *editor)
|
void EditorView::setCurrentEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
if (!editor || m_container->count() <= 0
|
if (!editor || m_container->count() <= 0
|
||||||
|| m_container->indexOf(editor->widget()) == -1) {
|
|| m_container->indexOf(editor->widget()) == -1) {
|
||||||
m_toolBar->updateEditorStatus(0);
|
m_toolBar->updateEditorStatus(0);
|
||||||
m_infoBarDisplay->setInfoBar(0);
|
m_infoBarDisplay->setInfoBar(0);
|
||||||
QTC_CHECK(m_container->count() == 0);
|
QTC_CHECK(m_container->count() == 0);
|
||||||
@@ -360,12 +360,12 @@ void EditorView::setCurrentEditor(IEditor *editor)
|
|||||||
|
|
||||||
int EditorView::editorCount() const
|
int EditorView::editorCount() const
|
||||||
{
|
{
|
||||||
return m_container->count();
|
return m_editors.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor *> EditorView::editors() const
|
QList<IEditor *> EditorView::editors() const
|
||||||
{
|
{
|
||||||
return m_widgetEditorMap.values();
|
return m_editors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorView::updateEditorHistory(IEditor *editor)
|
void EditorView::updateEditorHistory(IEditor *editor)
|
||||||
@@ -788,9 +788,9 @@ void SplitterOrView::restoreState(const QByteArray &state)
|
|||||||
| Core::EditorManager::DoNotChangeCurrentEditor);
|
| Core::EditorManager::DoNotChangeCurrentEditor);
|
||||||
|
|
||||||
if (!e) {
|
if (!e) {
|
||||||
QModelIndex idx = em->openedEditorsModel()->firstRestoredEditor();
|
OpenEditorsModel::Entry *entry = em->openedEditorsModel()->firstRestoredEditor();
|
||||||
if (idx.isValid())
|
if (entry)
|
||||||
em->activateEditorForIndex(view(), idx, Core::EditorManager::IgnoreNavigationHistory
|
em->activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory
|
||||||
| Core::EditorManager::DoNotChangeCurrentEditor);
|
| Core::EditorManager::DoNotChangeCurrentEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#include "ieditor.h"
|
#include "ieditor.h"
|
||||||
#include "idocument.h"
|
#include "idocument.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ struct OpenEditorsModelPrivate
|
|||||||
const QIcon m_lockedIcon;
|
const QIcon m_lockedIcon;
|
||||||
const QIcon m_unlockedIcon;
|
const QIcon m_unlockedIcon;
|
||||||
|
|
||||||
QList<OpenEditorsModel::Entry> m_editors;
|
QList<OpenEditorsModel::Entry *> m_editors;
|
||||||
QList<IEditor *> m_duplicateEditors;
|
QList<IEditor *> m_duplicateEditors;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,8 +95,9 @@ Id OpenEditorsModel::Entry::id() const
|
|||||||
|
|
||||||
int OpenEditorsModel::columnCount(const QModelIndex &parent) const
|
int OpenEditorsModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
if (!parent.isValid())
|
||||||
return 2;
|
return 2;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::rowCount(const QModelIndex &parent) const
|
int OpenEditorsModel::rowCount(const QModelIndex &parent) const
|
||||||
@@ -107,9 +110,9 @@ int OpenEditorsModel::rowCount(const QModelIndex &parent) const
|
|||||||
QList<IEditor *> OpenEditorsModel::editors() const
|
QList<IEditor *> OpenEditorsModel::editors() const
|
||||||
{
|
{
|
||||||
QList<IEditor *> result;
|
QList<IEditor *> result;
|
||||||
foreach (const Entry &entry, d->m_editors)
|
foreach (const Entry *entry, d->m_editors)
|
||||||
if (entry.editor)
|
if (entry->editor)
|
||||||
result += entry.editor;
|
result += entry->editor;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,52 +126,52 @@ void OpenEditorsModel::addEditor(IEditor *editor, bool isDuplicate)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry entry;
|
Entry *entry = new Entry;
|
||||||
entry.editor = editor;
|
entry->editor = editor;
|
||||||
addEntry(entry);
|
addEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id)
|
void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id)
|
||||||
{
|
{
|
||||||
Entry entry;
|
Entry *entry = new Entry;
|
||||||
entry.m_fileName = fileName;
|
entry->m_fileName = fileName;
|
||||||
entry.m_displayName = displayName;
|
entry->m_displayName = displayName;
|
||||||
entry.m_id = id;
|
entry->m_id = id;
|
||||||
addEntry(entry);
|
addEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex OpenEditorsModel::firstRestoredEditor() const
|
OpenEditorsModel::Entry *OpenEditorsModel::firstRestoredEditor() const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i)
|
for (int i = 0; i < d->m_editors.count(); ++i)
|
||||||
if (!d->m_editors.at(i).editor)
|
if (!d->m_editors.at(i)->editor)
|
||||||
return createIndex(i, 0);
|
return d->m_editors.at(i);
|
||||||
return QModelIndex();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::addEntry(const Entry &entry)
|
void OpenEditorsModel::addEntry(Entry *entry)
|
||||||
{
|
{
|
||||||
QString fileName = entry.fileName();
|
QString fileName = entry->fileName();
|
||||||
|
|
||||||
int previousIndex = findFileName(fileName);
|
int previousIndex = findFileName(fileName);
|
||||||
if (previousIndex >= 0) {
|
if (previousIndex >= 0) {
|
||||||
if (entry.editor && d->m_editors.at(previousIndex).editor == 0) {
|
if (entry->editor && d->m_editors.at(previousIndex)->editor == 0) {
|
||||||
d->m_editors[previousIndex] = entry;
|
d->m_editors[previousIndex] = entry;
|
||||||
connect(entry.editor, SIGNAL(changed()), this, SLOT(itemChanged()));
|
connect(entry->editor, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
QString displayName = entry.displayName();
|
QString displayName = entry->displayName();
|
||||||
for (index = 0; index < d->m_editors.count(); ++index) {
|
for (index = 0; index < d->m_editors.count(); ++index) {
|
||||||
if (displayName < d->m_editors.at(index).displayName())
|
if (displayName < d->m_editors.at(index)->displayName())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
int row = index + 1/*<no document>*/;
|
||||||
beginInsertRows(QModelIndex(), index, index);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
d->m_editors.insert(index, entry);
|
d->m_editors.insert(index, entry);
|
||||||
if (entry.editor)
|
if (entry->editor)
|
||||||
connect(entry.editor, SIGNAL(changed()), this, SLOT(itemChanged()));
|
connect(entry->editor, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +179,7 @@ void OpenEditorsModel::addEntry(const Entry &entry)
|
|||||||
int OpenEditorsModel::findEditor(IEditor *editor) const
|
int OpenEditorsModel::findEditor(IEditor *editor) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i)
|
for (int i = 0; i < d->m_editors.count(); ++i)
|
||||||
if (d->m_editors.at(i).editor == editor)
|
if (d->m_editors.at(i)->editor == editor)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -186,23 +189,24 @@ int OpenEditorsModel::findFileName(const QString &filename) const
|
|||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
return -1;
|
return -1;
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i) {
|
for (int i = 0; i < d->m_editors.count(); ++i) {
|
||||||
if (d->m_editors.at(i).fileName() == filename)
|
if (d->m_editors.at(i)->fileName() == filename)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenEditorsModel::removeEntry(OpenEditorsModel::Entry *entry)
|
||||||
|
{
|
||||||
|
int index = d->m_editors.indexOf(entry);
|
||||||
|
removeEditor(index);
|
||||||
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(IEditor *editor)
|
void OpenEditorsModel::removeEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
d->m_duplicateEditors.removeAll(editor);
|
d->m_duplicateEditors.removeAll(editor);
|
||||||
removeEditor(findEditor(editor));
|
removeEditor(findEditor(editor));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(const QModelIndex &index)
|
|
||||||
{
|
|
||||||
removeEditor(index.row());
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(const QString &fileName)
|
void OpenEditorsModel::removeEditor(const QString &fileName)
|
||||||
{
|
{
|
||||||
removeEditor(findFileName(fileName));
|
removeEditor(findFileName(fileName));
|
||||||
@@ -210,10 +214,11 @@ void OpenEditorsModel::removeEditor(const QString &fileName)
|
|||||||
|
|
||||||
void OpenEditorsModel::removeEditor(int idx)
|
void OpenEditorsModel::removeEditor(int idx)
|
||||||
{
|
{
|
||||||
if (idx < 0)
|
if (idx < 0 || idx >= d->m_editors.size())
|
||||||
return;
|
return;
|
||||||
IEditor *editor= d->m_editors.at(idx).editor;
|
IEditor *editor = d->m_editors.at(idx)->editor;
|
||||||
beginRemoveRows(QModelIndex(), idx, idx);
|
int row = idx;
|
||||||
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
d->m_editors.removeAt(idx);
|
d->m_editors.removeAt(idx);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
if (editor)
|
if (editor)
|
||||||
@@ -223,24 +228,15 @@ void OpenEditorsModel::removeEditor(int idx)
|
|||||||
void OpenEditorsModel::removeAllRestoredEditors()
|
void OpenEditorsModel::removeAllRestoredEditors()
|
||||||
{
|
{
|
||||||
for (int i = d->m_editors.count()-1; i >= 0; --i) {
|
for (int i = d->m_editors.count()-1; i >= 0; --i) {
|
||||||
if (!d->m_editors.at(i).editor) {
|
if (!d->m_editors.at(i)->editor) {
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
int row = i;
|
||||||
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
d->m_editors.removeAt(i);
|
d->m_editors.removeAt(i);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<OpenEditorsModel::Entry> OpenEditorsModel::restoredEditors() const
|
|
||||||
{
|
|
||||||
QList<Entry> result;
|
|
||||||
for (int i = d->m_editors.count()-1; i >= 0; --i) {
|
|
||||||
if (!d->m_editors.at(i).editor)
|
|
||||||
result.append(d->m_editors.at(i));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenEditorsModel::isDuplicate(IEditor *editor) const
|
bool OpenEditorsModel::isDuplicate(IEditor *editor) const
|
||||||
{
|
{
|
||||||
return editor && d->m_duplicateEditors.contains(editor);
|
return editor && d->m_duplicateEditors.contains(editor);
|
||||||
@@ -249,9 +245,9 @@ bool OpenEditorsModel::isDuplicate(IEditor *editor) const
|
|||||||
IEditor *OpenEditorsModel::originalForDuplicate(IEditor *duplicate) const
|
IEditor *OpenEditorsModel::originalForDuplicate(IEditor *duplicate) const
|
||||||
{
|
{
|
||||||
IDocument *document = duplicate->document();
|
IDocument *document = duplicate->document();
|
||||||
foreach (const Entry &e, d->m_editors)
|
foreach (const Entry *e, d->m_editors)
|
||||||
if (e.editor && e.editor->document() == document)
|
if (e->editor && e->editor->document() == document)
|
||||||
return e.editor;
|
return e->editor;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,13 +267,20 @@ void OpenEditorsModel::makeOriginal(IEditor *duplicate)
|
|||||||
IEditor *original = originalForDuplicate(duplicate);
|
IEditor *original = originalForDuplicate(duplicate);
|
||||||
Q_ASSERT(original);
|
Q_ASSERT(original);
|
||||||
int i = findEditor(original);
|
int i = findEditor(original);
|
||||||
d->m_editors[i].editor = duplicate;
|
d->m_editors[i]->editor = duplicate;
|
||||||
d->m_duplicateEditors.removeOne(duplicate);
|
d->m_duplicateEditors.removeOne(duplicate);
|
||||||
d->m_duplicateEditors.append(original);
|
d->m_duplicateEditors.append(original);
|
||||||
disconnect(original, SIGNAL(changed()), this, SLOT(itemChanged()));
|
disconnect(original, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
connect(duplicate, SIGNAL(changed()), this, SLOT(itemChanged()));
|
connect(duplicate, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int OpenEditorsModel::indexOfEditor(IEditor *editor) const
|
||||||
|
{
|
||||||
|
if (!editor)
|
||||||
|
return -1;
|
||||||
|
return findEditor(editor);
|
||||||
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::emitDataChanged(IEditor *editor)
|
void OpenEditorsModel::emitDataChanged(IEditor *editor)
|
||||||
{
|
{
|
||||||
int idx = findEditor(editor);
|
int idx = findEditor(editor);
|
||||||
@@ -295,6 +298,14 @@ QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &pare
|
|||||||
return createIndex(row, column);
|
return createIndex(row, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenEditorsModel::Entry *OpenEditorsModel::entryAtRow(int row) const
|
||||||
|
{
|
||||||
|
int editorIndex = row;
|
||||||
|
if (editorIndex < 0)
|
||||||
|
return 0;
|
||||||
|
return d->m_editors[editorIndex];
|
||||||
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::openDocumentCount() const
|
int OpenEditorsModel::openDocumentCount() const
|
||||||
{
|
{
|
||||||
return d->m_editors.count();
|
return d->m_editors.count();
|
||||||
@@ -304,51 +315,64 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole))
|
if (!index.isValid() || (index.column() != 0 && role < Qt::UserRole))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
Entry e = d->m_editors.at(index.row());
|
int editorIndex = index.row();
|
||||||
|
if (editorIndex < 0) {
|
||||||
|
// <no document> entry
|
||||||
|
switch (role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return tr("<no document>");
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
return tr("No document is selected.");
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const Entry *e = d->m_editors.at(editorIndex);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return (e.editor && e.editor->document()->isModified())
|
return (e->editor && e->editor->document()->isModified())
|
||||||
? e.displayName() + QLatin1Char('*')
|
? e->displayName() + QLatin1Char('*')
|
||||||
: e.displayName();
|
: e->displayName();
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
{
|
{
|
||||||
bool showLock = false;
|
bool showLock = false;
|
||||||
if (e.editor) {
|
if (e->editor) {
|
||||||
showLock = e.editor->document()->fileName().isEmpty()
|
showLock = e->editor->document()->fileName().isEmpty()
|
||||||
? false
|
? false
|
||||||
: e.editor->document()->isFileReadOnly();
|
: e->editor->document()->isFileReadOnly();
|
||||||
} else {
|
} else {
|
||||||
showLock = !QFileInfo(e.m_fileName).isWritable();
|
showLock = !QFileInfo(e->m_fileName).isWritable();
|
||||||
}
|
}
|
||||||
return showLock ? d->m_lockedIcon : QIcon();
|
return showLock ? d->m_lockedIcon : QIcon();
|
||||||
}
|
}
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
return e.fileName().isEmpty()
|
return e->fileName().isEmpty()
|
||||||
? e.displayName()
|
? e->displayName()
|
||||||
: QDir::toNativeSeparators(e.fileName());
|
: QDir::toNativeSeparators(e->fileName());
|
||||||
case Qt::UserRole:
|
case Qt::UserRole:
|
||||||
return qVariantFromValue(e.editor);
|
return qVariantFromValue(e->editor);
|
||||||
case Qt::UserRole + 1:
|
case Qt::UserRole + 1:
|
||||||
return e.fileName();
|
return e->fileName();
|
||||||
case Qt::UserRole + 2:
|
case Qt::UserRole + 2:
|
||||||
return QVariant::fromValue(e.editor ? Core::Id(e.editor->id()) : e.id());
|
return QVariant::fromValue(e->editor ? Core::Id(e->editor->id()) : e->id());
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex OpenEditorsModel::indexOf(IEditor *editor) const
|
int OpenEditorsModel::rowOfEditor(IEditor *editor) const
|
||||||
{
|
{
|
||||||
int idx = findEditor(originalForDuplicate(editor));
|
if (!editor)
|
||||||
return createIndex(idx, 0);
|
return -1;
|
||||||
|
return findEditor(originalForDuplicate(editor));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OpenEditorsModel::displayNameForDocument(IDocument *document) const
|
QString OpenEditorsModel::displayNameForDocument(IDocument *document) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i)
|
for (int i = 0; i < d->m_editors.count(); ++i)
|
||||||
if (d->m_editors.at(i).editor && d->m_editors.at(i).editor->document() == document)
|
if (d->m_editors.at(i)->editor && d->m_editors.at(i)->editor->document() == document)
|
||||||
return d->m_editors.at(i).editor->displayName();
|
return d->m_editors.at(i)->editor->displayName();
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,14 +381,9 @@ void OpenEditorsModel::itemChanged()
|
|||||||
emitDataChanged(qobject_cast<IEditor*>(sender()));
|
emitDataChanged(qobject_cast<IEditor*>(sender()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<OpenEditorsModel::Entry> OpenEditorsModel::entries() const
|
QList<OpenEditorsModel::Entry *> OpenEditorsModel::entries() const
|
||||||
{
|
{
|
||||||
return d->m_editors;
|
return d->m_editors;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *OpenEditorsModel::editorAt(int row) const
|
|
||||||
{
|
|
||||||
return d->m_editors.at(row).editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -60,12 +60,6 @@ public:
|
|||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
||||||
int openDocumentCount() const;
|
|
||||||
|
|
||||||
void addEditor(IEditor *editor, bool isDuplicate = false);
|
|
||||||
void addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id);
|
|
||||||
QModelIndex firstRestoredEditor() const;
|
|
||||||
|
|
||||||
struct CORE_EXPORT Entry {
|
struct CORE_EXPORT Entry {
|
||||||
Entry();
|
Entry();
|
||||||
IEditor *editor;
|
IEditor *editor;
|
||||||
@@ -76,24 +70,30 @@ public:
|
|||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
Id m_id;
|
Id m_id;
|
||||||
};
|
};
|
||||||
QList<Entry> entries() const;
|
|
||||||
|
|
||||||
IEditor *editorAt(int row) const;
|
Entry *entryAtRow(int row) const;
|
||||||
|
int rowOfEditor(IEditor *editor) const;
|
||||||
|
|
||||||
|
int openDocumentCount() const;
|
||||||
|
|
||||||
|
void addEditor(IEditor *editor, bool isDuplicate = false);
|
||||||
|
void addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id);
|
||||||
|
Entry *firstRestoredEditor() const;
|
||||||
|
|
||||||
|
QList<Entry *> entries() const;
|
||||||
|
|
||||||
|
void removeEntry(Entry *entry);
|
||||||
void removeEditor(IEditor *editor);
|
void removeEditor(IEditor *editor);
|
||||||
void removeEditor(const QModelIndex &index);
|
|
||||||
void removeEditor(const QString &fileName);
|
void removeEditor(const QString &fileName);
|
||||||
|
|
||||||
void removeAllRestoredEditors();
|
void removeAllRestoredEditors();
|
||||||
void emitDataChanged(IEditor *editor);
|
|
||||||
|
|
||||||
QList<IEditor *> editors() const;
|
QList<IEditor *> editors() const;
|
||||||
QList<Entry> restoredEditors() const;
|
|
||||||
bool isDuplicate(IEditor *editor) const;
|
bool isDuplicate(IEditor *editor) const;
|
||||||
QList<IEditor *> duplicatesFor(IEditor *editor) const;
|
QList<IEditor *> duplicatesFor(IEditor *editor) const;
|
||||||
IEditor *originalForDuplicate(IEditor *duplicate) const;
|
IEditor *originalForDuplicate(IEditor *duplicate) const;
|
||||||
void makeOriginal(IEditor *duplicate);
|
void makeOriginal(IEditor *duplicate);
|
||||||
QModelIndex indexOf(IEditor *editor) const;
|
int indexOfEditor(IEditor *editor) const;
|
||||||
|
|
||||||
QString displayNameForDocument(IDocument *document) const;
|
QString displayNameForDocument(IDocument *document) const;
|
||||||
|
|
||||||
@@ -101,10 +101,11 @@ private slots:
|
|||||||
void itemChanged();
|
void itemChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addEntry(const Entry &entry);
|
void addEntry(Entry *entry);
|
||||||
int findEditor(IEditor *editor) const;
|
int findEditor(IEditor *editor) const;
|
||||||
int findFileName(const QString &filename) const;
|
int findFileName(const QString &filename) const;
|
||||||
void removeEditor(int idx);
|
void removeEditor(int idx);
|
||||||
|
void emitDataChanged(IEditor *editor);
|
||||||
|
|
||||||
OpenEditorsModelPrivate *d;
|
OpenEditorsModelPrivate *d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -124,12 +124,13 @@ OpenEditorsWidget::~OpenEditorsWidget()
|
|||||||
|
|
||||||
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
|
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
if (!editor) {
|
EditorManager *em = EditorManager::instance();
|
||||||
|
QModelIndex index = model()->index(em->openedEditorsModel()->rowOfEditor(editor), 0);
|
||||||
|
if (!index.isValid()) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EditorManager *em = EditorManager::instance();
|
setCurrentIndex(index);
|
||||||
setCurrentIndex(em->openedEditorsModel()->indexOf(editor));
|
|
||||||
selectionModel()->select(currentIndex(),
|
selectionModel()->select(currentIndex(),
|
||||||
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||||
scrollTo(currentIndex());
|
scrollTo(currentIndex());
|
||||||
@@ -189,12 +190,14 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
|
|||||||
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
|
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||||
EditorManager::instance()->activateEditorForIndex(index);
|
EditorManager *em = EditorManager::instance();
|
||||||
|
em->activateEditorForEntry(em->openedEditorsModel()->entryAtRow(index.row()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
|
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
EditorManager::instance()->closeEditor(index);
|
EditorManager *em = EditorManager::instance();
|
||||||
|
em->closeEditor(em->openedEditorsModel()->entryAtRow(index.row()));
|
||||||
// work around selection changes
|
// work around selection changes
|
||||||
updateCurrentItem(EditorManager::currentEditor());
|
updateCurrentItem(EditorManager::currentEditor());
|
||||||
}
|
}
|
||||||
@@ -203,9 +206,11 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos)
|
|||||||
{
|
{
|
||||||
QMenu contextMenu;
|
QMenu contextMenu;
|
||||||
QModelIndex editorIndex = indexAt(pos);
|
QModelIndex editorIndex = indexAt(pos);
|
||||||
EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, editorIndex);
|
OpenEditorsModel::Entry *entry = EditorManager::instance()->openedEditorsModel()->entryAtRow(
|
||||||
|
editorIndex.row());
|
||||||
|
EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, entry);
|
||||||
contextMenu.addSeparator();
|
contextMenu.addSeparator();
|
||||||
EditorManager::instance()->addNativeDirActions(&contextMenu, editorIndex);
|
EditorManager::instance()->addNativeDirActions(&contextMenu, entry);
|
||||||
contextMenu.exec(mapToGlobal(pos));
|
contextMenu.exec(mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,15 +203,15 @@ void OpenEditorsWindow::setEditors(const QList<EditLocation> &globalHistory, Edi
|
|||||||
addHistoryItems(globalHistory, view, model, documentsDone);
|
addHistoryItems(globalHistory, view, model, documentsDone);
|
||||||
|
|
||||||
// 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 (OpenEditorsModel::Entry *entry, model->entries()) {
|
||||||
if (entry.editor)
|
if (entry->editor)
|
||||||
continue;
|
continue;
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
QString title = entry.displayName();
|
QString title = entry->displayName();
|
||||||
item->setIcon(0, m_emptyIcon);
|
item->setIcon(0, m_emptyIcon);
|
||||||
item->setText(0, title);
|
item->setText(0, title);
|
||||||
item->setToolTip(0, entry.fileName());
|
item->setToolTip(0, entry->fileName());
|
||||||
item->setData(0, Qt::UserRole+2, QVariant::fromValue(entry.id()));
|
item->setData(0, Qt::UserRole+2, QVariant::fromValue(entry->id()));
|
||||||
item->setTextAlignment(0, Qt::AlignLeft);
|
item->setTextAlignment(0, Qt::AlignLeft);
|
||||||
|
|
||||||
m_editorList->addTopLevelItem(item);
|
m_editorList->addTopLevelItem(item);
|
||||||
|
|||||||
@@ -290,13 +290,12 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
|||||||
|
|
||||||
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(editor, return);
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfEditor(editor));
|
||||||
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
|
|
||||||
|
|
||||||
// If we never added the toolbar from the editor, we will never change
|
// If we never added the toolbar from the editor, we will never change
|
||||||
// the editor, so there's no need to update the toolbar either.
|
// the editor, so there's no need to update the toolbar either.
|
||||||
if (!d->m_isStandalone)
|
if (!d->m_isStandalone)
|
||||||
updateToolBar(editor->toolBar());
|
updateToolBar(editor ? editor->toolBar() : 0);
|
||||||
|
|
||||||
updateEditorStatus(editor);
|
updateEditorStatus(editor);
|
||||||
}
|
}
|
||||||
@@ -304,28 +303,28 @@ void EditorToolBar::setCurrentEditor(IEditor *editor)
|
|||||||
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
|
void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
|
||||||
{
|
{
|
||||||
if (newSelection)
|
if (newSelection)
|
||||||
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(newSelection).row());
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfEditor(newSelection));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorToolBar::changeActiveEditor(int row)
|
void EditorToolBar::changeActiveEditor(int row)
|
||||||
{
|
{
|
||||||
EditorManager *em = ICore::editorManager();
|
EditorManager *em = EditorManager::instance();
|
||||||
QAbstractItemModel *model = d->m_editorList->model();
|
em->activateEditorForEntry(d->m_editorsListModel->entryAtRow(row));
|
||||||
em->activateEditorForIndex(model->index(row, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorToolBar::listContextMenu(QPoint pos)
|
void EditorToolBar::listContextMenu(QPoint pos)
|
||||||
{
|
{
|
||||||
QModelIndex index = d->m_editorsListModel->index(d->m_editorList->currentIndex(), 0);
|
OpenEditorsModel::Entry *entry = EditorManager::instance()
|
||||||
QString fileName = d->m_editorsListModel->data(index, Qt::UserRole + 1).toString();
|
->openedEditorsModel()->entryAtRow(d->m_editorList->currentIndex());
|
||||||
|
QString fileName = entry ? entry->fileName() : QString();
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
|
QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
EditorManager::instance()->addSaveAndCloseEditorActions(&menu, index);
|
EditorManager::instance()->addSaveAndCloseEditorActions(&menu, entry);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
EditorManager::instance()->addNativeDirActions(&menu, index);
|
EditorManager::instance()->addNativeDirActions(&menu, entry);
|
||||||
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
|
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
|
||||||
if (result == copyPath)
|
if (result == copyPath)
|
||||||
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
|
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
|
||||||
@@ -376,7 +375,7 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfEditor(editor));
|
||||||
|
|
||||||
if (editor->document()->fileName().isEmpty()) {
|
if (editor->document()->fileName().isEmpty()) {
|
||||||
d->m_lockButton->setIcon(QIcon());
|
d->m_lockButton->setIcon(QIcon());
|
||||||
|
|||||||
@@ -1999,19 +1999,19 @@ int FakeVimPluginPrivate::currentFile() const
|
|||||||
{
|
{
|
||||||
OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel();
|
OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel();
|
||||||
IEditor *editor = EditorManager::currentEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
return model->indexOf(editor).row();
|
return model->indexOfEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::switchToFile(int n)
|
void FakeVimPluginPrivate::switchToFile(int n)
|
||||||
{
|
{
|
||||||
EditorManager *editorManager = ICore::editorManager();
|
EditorManager *editorManager = ICore::editorManager();
|
||||||
OpenEditorsModel *model = editorManager->openedEditorsModel();
|
OpenEditorsModel *model = editorManager->openedEditorsModel();
|
||||||
int size = model->rowCount();
|
int size = model->openDocumentCount();
|
||||||
QTC_ASSERT(size, return);
|
QTC_ASSERT(size, return);
|
||||||
n = n % size;
|
n = n % size;
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n += size;
|
n += size;
|
||||||
editorManager->activateEditorForIndex(model->index(n, 0));
|
editorManager->activateEditorForEntry(model->entries().at(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExCommandMap &FakeVimExCommandsPage::exCommandMap()
|
ExCommandMap &FakeVimExCommandsPage::exCommandMap()
|
||||||
|
|||||||
@@ -87,14 +87,14 @@ QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::Fil
|
|||||||
void OpenDocumentsFilter::refreshInternally()
|
void OpenDocumentsFilter::refreshInternally()
|
||||||
{
|
{
|
||||||
m_editors.clear();
|
m_editors.clear();
|
||||||
foreach (IEditor *editor, m_editorManager->openedEditors()) {
|
foreach (OpenEditorsModel::Entry *e, EditorManager::instance()->openedEditorsModel()->entries()) {
|
||||||
OpenEditorsModel::Entry entry;
|
OpenEditorsModel::Entry entry;
|
||||||
// don't work on IEditor directly, since that will be useless with split windows
|
// create copy with only the information relevant to use
|
||||||
entry.m_displayName = editor->displayName();
|
// to avoid model deleting entries behind our back
|
||||||
entry.m_fileName = editor->document()->fileName();
|
entry.m_displayName = e->displayName();
|
||||||
|
entry.m_fileName = e->fileName();
|
||||||
m_editors.append(entry);
|
m_editors.append(entry);
|
||||||
}
|
}
|
||||||
m_editors += m_editorManager->openedEditorsModel()->restoredEditors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
|
void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ QT_END_NAMESPACE
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
class SideBar;
|
class SideBar;
|
||||||
class SideBarItem;
|
class SideBarItem;
|
||||||
class OpenEditorsModel;
|
|
||||||
class EditorToolBar;
|
class EditorToolBar;
|
||||||
class OutputPanePlaceHolder;
|
class OutputPanePlaceHolder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
|
|||||||
QMap<QString, QTextCodec *> openEditorEncodings = ITextEditor::openedTextEditorsEncodings();
|
QMap<QString, QTextCodec *> openEditorEncodings = ITextEditor::openedTextEditorsEncodings();
|
||||||
QStringList fileNames;
|
QStringList fileNames;
|
||||||
QList<QTextCodec *> codecs;
|
QList<QTextCodec *> codecs;
|
||||||
foreach (const Core::OpenEditorsModel::Entry &entry,
|
foreach (Core::OpenEditorsModel::Entry *entry,
|
||||||
Core::EditorManager::instance()->openedEditorsModel()->entries()) {
|
Core::EditorManager::instance()->openedEditorsModel()->entries()) {
|
||||||
QString fileName = entry.fileName();
|
QString fileName = entry->fileName();
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
fileNames.append(fileName);
|
fileNames.append(fileName);
|
||||||
QTextCodec *codec = openEditorEncodings.value(fileName);
|
QTextCodec *codec = openEditorEncodings.value(fileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user