Make document model static and add some document related methods

Change-Id: Ibcb863e67a2433529c9d2b6dec237f9d8b1d8d50
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2013-07-09 11:52:44 +02:00
parent 7b1941c792
commit 354cd410b0
25 changed files with 121 additions and 112 deletions
@@ -278,6 +278,11 @@ int DocumentModel::indexOfDocument(IDocument *document) const
return -1; return -1;
} }
QList<IDocument *> DocumentModel::openedDocuments() const
{
return d->m_editors.keys();
}
QModelIndex DocumentModel::index(int row, int column, const QModelIndex &parent) const QModelIndex DocumentModel::index(int row, int column, const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
@@ -77,6 +77,7 @@ public:
int documentCount() const; int documentCount() const;
QList<Entry *> documents() const; QList<Entry *> documents() const;
int indexOfDocument(IDocument *document) const; int indexOfDocument(IDocument *document) const;
QList<IDocument *> openedDocuments() const;
QList<IEditor *> editorsForDocument(IDocument *document) const; QList<IEditor *> editorsForDocument(IDocument *document) const;
QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents) const; QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents) const;
@@ -648,6 +648,11 @@ QList<IEditor *> EditorManager::editorsForDocument(IDocument *document) const
return found; return found;
} }
IDocument *EditorManager::currentDocument()
{
return d->m_currentEditor ? d->m_currentEditor->document() : 0;
}
IEditor *EditorManager::currentEditor() IEditor *EditorManager::currentEditor()
{ {
return d->m_currentEditor; return d->m_currentEditor;
@@ -761,9 +766,9 @@ void EditorManager::closeOtherEditors(IDocument *document)
void EditorManager::closeOtherEditors() void EditorManager::closeOtherEditors()
{ {
IEditor *current = currentEditor(); IDocument *current = currentDocument();
QTC_ASSERT(current, return); QTC_ASSERT(current, return);
closeOtherEditors(current->document()); closeOtherEditors(current);
} }
// SLOT connected to action // SLOT connected to action
@@ -1286,6 +1291,11 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
return editor; return editor;
} }
IEditor *EditorManager::activateEditorForDocument(IDocument *document, OpenEditorFlags flags)
{
return activateEditorForDocument(currentEditorView(), document, flags);
}
Core::IEditor *EditorManager::activateEditorForDocument(Core::Internal::EditorView *view, Core::IDocument *document, OpenEditorFlags flags) Core::IEditor *EditorManager::activateEditorForDocument(Core::Internal::EditorView *view, Core::IDocument *document, OpenEditorFlags flags)
{ {
Q_ASSERT(view); Q_ASSERT(view);
@@ -1705,8 +1715,8 @@ bool EditorManager::saveEditor(IEditor *editor)
bool EditorManager::saveDocument(IDocument *documentParam) bool EditorManager::saveDocument(IDocument *documentParam)
{ {
IDocument *document = documentParam; IDocument *document = documentParam;
if (!document && currentEditor()) if (!document && currentDocument())
document = currentEditor()->document(); document = currentDocument();
if (!document) if (!document)
return false; return false;
@@ -1784,8 +1794,8 @@ MakeWritableResult EditorManager::makeFileWritable(IDocument *document)
bool EditorManager::saveDocumentAs(IDocument *documentParam) bool EditorManager::saveDocumentAs(IDocument *documentParam)
{ {
IDocument *document = documentParam; IDocument *document = documentParam;
if (!document && currentEditor()) if (!document && currentDocument())
document = currentEditor()->document(); document = currentDocument();
if (!document) if (!document)
return false; return false;
@@ -1866,22 +1876,22 @@ void EditorManager::gotoPreviousDocHistory()
void EditorManager::makeCurrentEditorWritable() void EditorManager::makeCurrentEditorWritable()
{ {
if (IEditor* curEditor = currentEditor()) if (IDocument* doc = currentDocument())
makeFileWritable(curEditor->document()); makeFileWritable(doc);
} }
void EditorManager::vcsOpenCurrentEditor() void EditorManager::vcsOpenCurrentEditor()
{ {
IEditor *curEditor = currentEditor(); IDocument *document = currentDocument();
if (!curEditor) if (!document)
return; return;
const QString directory = QFileInfo(curEditor->document()->filePath()).absolutePath(); const QString directory = QFileInfo(document->filePath()).absolutePath();
IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory); IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory);
if (!versionControl || versionControl->openSupportMode() == IVersionControl::NoOpen) if (!versionControl || versionControl->openSupportMode() == IVersionControl::NoOpen)
return; return;
if (!versionControl->vcsOpen(curEditor->document()->filePath())) { if (!versionControl->vcsOpen(document->filePath())) {
QMessageBox::warning(ICore::mainWindow(), tr("Cannot Open File"), QMessageBox::warning(ICore::mainWindow(), tr("Cannot Open File"),
tr("Cannot open the file for editing with VCS.")); tr("Cannot open the file for editing with VCS."));
} }
@@ -1895,12 +1905,12 @@ void EditorManager::updateWindowTitle()
windowTitle.prepend(d->m_titleVcsTopic + dashSep); windowTitle.prepend(d->m_titleVcsTopic + dashSep);
if (!d->m_titleAddition.isEmpty()) if (!d->m_titleAddition.isEmpty())
windowTitle.prepend(d->m_titleAddition + dashSep); windowTitle.prepend(d->m_titleAddition + dashSep);
IEditor *curEditor = currentEditor(); IDocument *document = currentDocument();
if (curEditor) { if (document) {
QString editorName = curEditor->document()->displayName(); QString editorName = document->displayName();
if (!editorName.isEmpty()) if (!editorName.isEmpty())
windowTitle.prepend(editorName + dashSep); windowTitle.prepend(editorName + dashSep);
QString filePath = QFileInfo(curEditor->document()->filePath()).absoluteFilePath(); QString filePath = QFileInfo(document->filePath()).absoluteFilePath();
if (!filePath.isEmpty()) if (!filePath.isEmpty())
ICore::mainWindow()->setWindowFilePath(filePath); ICore::mainWindow()->setWindowFilePath(filePath);
} else { } else {
@@ -1912,11 +1922,10 @@ void EditorManager::updateWindowTitle()
void EditorManager::handleDocumentStateChange() void EditorManager::handleDocumentStateChange()
{ {
updateActions(); updateActions();
IDocument *document= qobject_cast<IDocument *>(sender()); IDocument *document = qobject_cast<IDocument *>(sender());
if (!document->isModified()) if (!document->isModified())
document->removeAutoSaveFile(); document->removeAutoSaveFile();
IEditor *currEditor = currentEditor(); if (currentDocument() == document) {
if (currEditor && currEditor->document() == document) {
updateWindowTitle(); updateWindowTitle();
emit currentDocumentStateChanged(); emit currentDocumentStateChanged();
} }
@@ -1924,15 +1933,16 @@ void EditorManager::handleDocumentStateChange()
void EditorManager::updateMakeWritableWarning() void EditorManager::updateMakeWritableWarning()
{ {
IEditor *curEditor = currentEditor(); IDocument *document = currentDocument();
bool ww = curEditor->document()->isModified() && curEditor->document()->isFileReadOnly(); QTC_ASSERT(document, return);
if (ww != curEditor->document()->hasWriteWarning()) { bool ww = document->isModified() && document->isFileReadOnly();
curEditor->document()->setWriteWarning(ww); if (ww != document->hasWriteWarning()) {
document->setWriteWarning(ww);
// Do this after setWriteWarning so we don't re-evaluate this part even // Do this after setWriteWarning so we don't re-evaluate this part even
// if we do not really show a warning. // if we do not really show a warning.
bool promptVCS = false; bool promptVCS = false;
const QString directory = QFileInfo(curEditor->document()->filePath()).absolutePath(); const QString directory = QFileInfo(document->filePath()).absolutePath();
IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory); IVersionControl *versionControl = ICore::vcsManager()->findVersionControlForDirectory(directory);
if (versionControl && versionControl->openSupportMode() != IVersionControl::NoOpen) { if (versionControl && versionControl->openSupportMode() != IVersionControl::NoOpen) {
if (versionControl->settingsFlags() & IVersionControl::AutoOpen) { if (versionControl->settingsFlags() & IVersionControl::AutoOpen) {
@@ -1950,15 +1960,15 @@ void EditorManager::updateMakeWritableWarning()
tr("<b>Warning:</b> This file was not opened in %1 yet.") tr("<b>Warning:</b> This file was not opened in %1 yet.")
.arg(versionControl->displayName())); .arg(versionControl->displayName()));
info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor())); info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor()));
curEditor->document()->infoBar()->addInfo(info); document->infoBar()->addInfo(info);
} else { } else {
InfoBarEntry info(Id(kMakeWritableWarning), InfoBarEntry info(Id(kMakeWritableWarning),
tr("<b>Warning:</b> You are changing a read-only file.")); tr("<b>Warning:</b> You are changing a read-only file."));
info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable())); info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable()));
curEditor->document()->infoBar()->addInfo(info); document->infoBar()->addInfo(info);
} }
} else { } else {
curEditor->document()->infoBar()->removeInfo(Id(kMakeWritableWarning)); document->infoBar()->removeInfo(Id(kMakeWritableWarning));
} }
} }
} }
@@ -1983,8 +1993,7 @@ void EditorManager::setupSaveActions(IDocument *document, QAction *saveAction, Q
void EditorManager::updateActions() void EditorManager::updateActions()
{ {
IEditor *curEditor = currentEditor(); IDocument *curDocument = currentDocument();
IDocument *curDocument = curEditor ? curEditor->document() : 0;
int openedCount = d->m_documentModel->documentCount(); int openedCount = d->m_documentModel->documentCount();
if (curDocument) { if (curDocument) {
@@ -2074,11 +2083,16 @@ QList<IEditor*> EditorManager::openedEditors() const
return d->m_documentModel->oneEditorForEachOpenedDocument(); return d->m_documentModel->oneEditorForEachOpenedDocument();
} }
DocumentModel *EditorManager::documentModel() const DocumentModel *EditorManager::documentModel()
{ {
return d->m_documentModel; return d->m_documentModel;
} }
void EditorManager::closeDocuments(const QList<IDocument *> &document, bool askAboutModifiedEditors)
{
m_instance->closeEditors(d->m_documentModel->editorsForDocuments(document), askAboutModifiedEditors);
}
void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState) void EditorManager::addCurrentPositionToNavigationHistory(IEditor *editor, const QByteArray &saveState)
{ {
currentEditorView()->addCurrentPositionToNavigationHistory(editor, saveState); currentEditorView()->addCurrentPositionToNavigationHistory(editor, saveState);
@@ -2289,8 +2303,7 @@ void EditorManager::readSettings()
void EditorManager::revertToSaved() void EditorManager::revertToSaved()
{ {
IEditor *editor = currentEditor(); revertToSaved(currentDocument());
revertToSaved(editor ? editor->document() : 0);
} }
void EditorManager::revertToSaved(Core::IDocument *document) void EditorManager::revertToSaved(Core::IDocument *document)
@@ -2535,9 +2548,9 @@ void EditorManager::updateVariable(const QByteArray &variable)
{ {
if (VariableManager::instance()->isFileVariable(variable, kCurrentDocumentPrefix)) { if (VariableManager::instance()->isFileVariable(variable, kCurrentDocumentPrefix)) {
QString value; QString value;
IEditor *curEditor = currentEditor(); IDocument *document = currentDocument();
if (curEditor) { if (document) {
QString fileName = curEditor->document()->filePath(); QString fileName = document->filePath();
if (!fileName.isEmpty()) if (!fileName.isEmpty())
value = VariableManager::fileVariableValue(variable, kCurrentDocumentPrefix, value = VariableManager::fileVariableValue(variable, kCurrentDocumentPrefix,
fileName); fileName);
@@ -126,15 +126,18 @@ public:
QList<IEditor *> editorsForFileName(const QString &filename) const; QList<IEditor *> editorsForFileName(const QString &filename) const;
QList<IEditor *> editorsForDocument(IDocument *document) const; QList<IEditor *> editorsForDocument(IDocument *document) const;
static IDocument *currentDocument();
static IEditor *currentEditor(); static IEditor *currentEditor();
QList<IEditor *> visibleEditors() const; QList<IEditor *> visibleEditors() const;
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 activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0); void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0);
IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0);
IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0); IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
DocumentModel *documentModel() const; static DocumentModel *documentModel();
static void closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
void closeEditor(DocumentModel::Entry *entry); void closeEditor(DocumentModel::Entry *entry);
void closeOtherEditors(IDocument *document); void closeOtherEditors(IDocument *document);
@@ -303,8 +303,8 @@ IEditor *EditorView::currentEditor() const
void EditorView::listSelectionActivated(int index) void EditorView::listSelectionActivated(int index)
{ {
DocumentModel *model = EditorManager::instance()->documentModel(); EditorManager::instance()->activateEditorForEntry(
EditorManager::instance()->activateEditorForEntry(this, model->documentAtRow(index)); this, EditorManager::documentModel()->documentAtRow(index));
} }
void EditorView::splitHorizontally() void EditorView::splitHorizontally()
@@ -786,7 +786,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
| Core::EditorManager::DoNotChangeCurrentEditor); | Core::EditorManager::DoNotChangeCurrentEditor);
if (!e) { if (!e) {
DocumentModel::Entry *entry = em->documentModel()->firstRestoredDocument(); DocumentModel::Entry *entry = EditorManager::documentModel()->firstRestoredDocument();
if (entry) if (entry)
em->activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory em->activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor); | Core::EditorManager::DoNotChangeCurrentEditor);
@@ -96,9 +96,8 @@ OpenEditorsWidget::OpenEditorsWidget()
setTextElideMode(Qt::ElideMiddle); setTextElideMode(Qt::ElideMiddle);
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
setAttribute(Qt::WA_MacShowFocusRect, false); setAttribute(Qt::WA_MacShowFocusRect, false);
EditorManager *em = EditorManager::instance();
m_model = new ProxyModel(this); m_model = new ProxyModel(this);
m_model->setSourceModel(em->documentModel()); m_model->setSourceModel(EditorManager::documentModel());
setModel(m_model); setModel(m_model);
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
@@ -110,7 +109,7 @@ OpenEditorsWidget::OpenEditorsWidget()
installEventFilter(this); installEventFilter(this);
viewport()->installEventFilter(this); viewport()->installEventFilter(this);
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), connect(EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentItem(Core::IEditor*))); this, SLOT(updateCurrentItem(Core::IEditor*)));
connect(this, SIGNAL(clicked(QModelIndex)), connect(this, SIGNAL(clicked(QModelIndex)),
this, SLOT(handleClicked(QModelIndex))); this, SLOT(handleClicked(QModelIndex)));
@@ -128,8 +127,7 @@ OpenEditorsWidget::~OpenEditorsWidget()
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor) void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
{ {
IDocument *document = editor ? editor->document() : 0; IDocument *document = editor ? editor->document() : 0;
EditorManager *em = EditorManager::instance(); QModelIndex index = m_model->index(EditorManager::documentModel()->indexOfDocument(document), 0);
QModelIndex index = m_model->index(em->documentModel()->indexOfDocument(document), 0);
if (!index.isValid()) { if (!index.isValid()) {
clearSelection(); clearSelection();
return; return;
@@ -194,14 +192,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 *em = EditorManager::instance(); EditorManager::instance()->activateEditorForEntry(
em->activateEditorForEntry(em->documentModel()->documentAtRow(m_model->mapToSource(index).row())); EditorManager::documentModel()->documentAtRow(m_model->mapToSource(index).row()));
} }
void OpenEditorsWidget::closeEditor(const QModelIndex &index) void OpenEditorsWidget::closeEditor(const QModelIndex &index)
{ {
EditorManager *em = EditorManager::instance(); EditorManager::instance()->closeEditor(
em->closeEditor(em->documentModel()->documentAtRow(m_model->mapToSource(index).row())); EditorManager::documentModel()->documentAtRow(m_model->mapToSource(index).row()));
// work around selection changes // work around selection changes
updateCurrentItem(EditorManager::currentEditor()); updateCurrentItem(EditorManager::currentEditor());
} }
@@ -210,7 +208,7 @@ void OpenEditorsWidget::contextMenuRequested(QPoint pos)
{ {
QMenu contextMenu; QMenu contextMenu;
QModelIndex editorIndex = indexAt(pos); QModelIndex editorIndex = indexAt(pos);
DocumentModel::Entry *entry = EditorManager::instance()->documentModel()->documentAtRow( DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow(
m_model->mapToSource(editorIndex).row()); m_model->mapToSource(editorIndex).row());
EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, entry); EditorManager::instance()->addSaveAndCloseEditorActions(&contextMenu, entry);
contextMenu.addSeparator(); contextMenu.addSeparator();
@@ -229,7 +229,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
} else { } else {
if (!EditorManager::openEditor( if (!EditorManager::openEditor(
item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) { item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) {
EditorManager::instance()->documentModel()->removeDocument(item->toolTip(0)); EditorManager::documentModel()->removeDocument(item->toolTip(0));
delete item; delete item;
} }
} }
+5 -5
View File
@@ -115,7 +115,7 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
d->m_lockButton->setAutoRaise(true); d->m_lockButton->setAutoRaise(true);
d->m_lockButton->setEnabled(false); d->m_lockButton->setEnabled(false);
d->m_editorsListModel = EditorManager::instance()->documentModel(); d->m_editorsListModel = EditorManager::documentModel();
connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked())); connect(d->m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked()));
connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked())); connect(d->m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked()));
@@ -315,8 +315,8 @@ void EditorToolBar::changeActiveEditor(int row)
void EditorToolBar::listContextMenu(QPoint pos) void EditorToolBar::listContextMenu(QPoint pos)
{ {
DocumentModel::Entry *entry = EditorManager::instance() DocumentModel::Entry *entry = EditorManager::documentModel()->documentAtRow(
->documentModel()->documentAtRow(d->m_editorList->currentIndex()); d->m_editorList->currentIndex());
QString fileName = entry ? entry->fileName() : QString(); QString fileName = entry ? entry->fileName() : QString();
if (fileName.isEmpty()) if (fileName.isEmpty())
return; return;
@@ -333,8 +333,8 @@ void EditorToolBar::listContextMenu(QPoint pos)
void EditorToolBar::makeEditorWritable() void EditorToolBar::makeEditorWritable()
{ {
if (IEditor *current = EditorManager::currentEditor()) if (IDocument *current = EditorManager::currentDocument())
EditorManager::instance()->makeFileWritable(current->document()); EditorManager::instance()->makeFileWritable(current);
} }
void EditorToolBar::setCanGoBack(bool canGoBack) void EditorToolBar::setCanGoBack(bool canGoBack)
+3 -3
View File
@@ -590,10 +590,10 @@ void ExternalToolRunner::run()
return; return;
} }
if (m_tool->modifiesCurrentDocument()) { if (m_tool->modifiesCurrentDocument()) {
if (IEditor *editor = EditorManager::currentEditor()) { if (IDocument *document = EditorManager::currentDocument()) {
m_expectedFileName = editor->document()->filePath(); m_expectedFileName = document->filePath();
bool cancelled = false; bool cancelled = false;
DocumentManager::saveModifiedDocuments(QList<IDocument *>() << editor->document(), &cancelled); DocumentManager::saveModifiedDocuments(QList<IDocument *>() << document, &cancelled);
if (cancelled) { if (cancelled) {
deleteLater(); deleteLater();
return; return;
+1 -3
View File
@@ -279,9 +279,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
const bool isVcsConfigured = versionControl->isConfigured(); const bool isVcsConfigured = versionControl->isConfigured();
if (!isVcsConfigured || d->m_unconfiguredVcs) { if (!isVcsConfigured || d->m_unconfiguredVcs) {
Id vcsWarning("VcsNotConfiguredWarning"); Id vcsWarning("VcsNotConfiguredWarning");
IDocument *curDocument = 0; IDocument *curDocument = EditorManager::currentDocument();
if (IEditor *curEditor = EditorManager::currentEditor())
curDocument = curEditor->document();
if (isVcsConfigured) { if (isVcsConfigured) {
if (curDocument && d->m_unconfiguredVcs == versionControl) { if (curDocument && d->m_unconfiguredVcs == versionControl) {
curDocument->infoBar()->removeInfo(vcsWarning); curDocument->infoBar()->removeInfo(vcsWarning);
+2 -2
View File
@@ -154,7 +154,7 @@ ExtensionSystem::IPlugin::ShutdownFlag CppToolsPlugin::aboutToShutdown()
void CppToolsPlugin::switchHeaderSource() void CppToolsPlugin::switchHeaderSource()
{ {
QString otherFile = correspondingHeaderOrSource( QString otherFile = correspondingHeaderOrSource(
Core::EditorManager::currentEditor()->document()->filePath()); Core::EditorManager::currentDocument()->filePath());
if (!otherFile.isEmpty()) if (!otherFile.isEmpty())
Core::EditorManager::openEditor(otherFile); Core::EditorManager::openEditor(otherFile);
} }
@@ -162,7 +162,7 @@ void CppToolsPlugin::switchHeaderSource()
void CppToolsPlugin::switchHeaderSourceInNextSplit() void CppToolsPlugin::switchHeaderSourceInNextSplit()
{ {
QString otherFile = correspondingHeaderOrSource( QString otherFile = correspondingHeaderOrSource(
Core::EditorManager::currentEditor()->document()->filePath()); Core::EditorManager::currentDocument()->filePath());
if (!otherFile.isEmpty()) if (!otherFile.isEmpty())
Core::EditorManager::openEditor(otherFile, Core::Id(), Core::EditorManager::OpenInOtherSplit); Core::EditorManager::openEditor(otherFile, Core::Id(), Core::EditorManager::OpenInOtherSplit);
} }
+5 -6
View File
@@ -864,12 +864,11 @@ void FormEditorW::print()
// Find out current existing editor file // Find out current existing editor file
static QString currentFile() static QString currentFile()
{ {
if (Core::IEditor *editor = Core::EditorManager::currentEditor()) if (const Core::IDocument *document = Core::EditorManager::currentDocument()) {
if (const Core::IDocument *document = editor->document()) { const QString fileName = document->filePath();
const QString fileName = document->filePath(); if (!fileName.isEmpty() && QFileInfo(fileName).isFile())
if (!fileName.isEmpty() && QFileInfo(fileName).isFile()) return fileName;
return fileName; }
}
return QString(); return QString();
} }
+3 -6
View File
@@ -1997,23 +1997,20 @@ void FakeVimPluginPrivate::highlightMatches(const QString &needle)
int FakeVimPluginPrivate::currentFile() const int FakeVimPluginPrivate::currentFile() const
{ {
DocumentModel *model = EditorManager::instance()->documentModel();
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
if (!editor) if (!editor)
return -1; return -1;
return model->indexOfDocument(editor->document()); return EditorManager::documentModel()->indexOfDocument(editor->document());
} }
void FakeVimPluginPrivate::switchToFile(int n) void FakeVimPluginPrivate::switchToFile(int n)
{ {
EditorManager *editorManager = ICore::editorManager(); int size = EditorManager::documentModel()->documentCount();
DocumentModel *model = editorManager->documentModel();
int size = model->documentCount();
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->activateEditorForEntry(model->documents().at(n)); EditorManager::instance()->activateEditorForEntry(EditorManager::documentModel()->documents().at(n));
} }
ExCommandMap &FakeVimExCommandsPage::exCommandMap() ExCommandMap &FakeVimExCommandsPage::exCommandMap()
+2 -2
View File
@@ -782,8 +782,8 @@ static inline QString msgParseFilesFailed()
static inline QString currentDocumentPath() static inline QString currentDocumentPath()
{ {
if (Core::IEditor *editor = Core::EditorManager::currentEditor()) if (Core::IDocument *document= Core::EditorManager::currentDocument())
return QFileInfo(editor->document()->filePath()).path(); return QFileInfo(document->filePath()).path();
return QString(); return QString();
} }
+1 -4
View File
@@ -993,10 +993,7 @@ void GitPlugin::updateVersionWarning()
unsigned version = m_gitClient->gitVersion(); unsigned version = m_gitClient->gitVersion();
if (!version || version >= minimumRequiredVersion) if (!version || version >= minimumRequiredVersion)
return; return;
Core::IEditor *curEditor = Core::EditorManager::currentEditor(); Core::IDocument *curDocument = Core::EditorManager::currentDocument();
if (!curEditor)
return;
Core::IDocument *curDocument = curEditor->document();
if (!curDocument) if (!curDocument)
return; return;
Core::InfoBar *infoBar = curDocument->infoBar(); Core::InfoBar *infoBar = curDocument->infoBar();
+3 -3
View File
@@ -58,9 +58,9 @@ QList<FilterEntry> FileSystemFilter::matchesFor(QFutureInterface<Locator::Filter
if (filePath.startsWith(QLatin1String("~/"))) { if (filePath.startsWith(QLatin1String("~/"))) {
directory.replace(0, 1, QDir::homePath()); directory.replace(0, 1, QDir::homePath());
} else { } else {
IEditor *editor = EditorManager::currentEditor(); IDocument *document= EditorManager::currentDocument();
if (editor && !editor->document()->filePath().isEmpty()) { if (document && !document->filePath().isEmpty()) {
QFileInfo info(editor->document()->filePath()); QFileInfo info(document->filePath());
directory.prepend(info.absolutePath() + QLatin1Char('/')); directory.prepend(info.absolutePath() + QLatin1Char('/'));
} }
} }
+1 -1
View File
@@ -87,7 +87,7 @@ QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::Fil
void OpenDocumentsFilter::refreshInternally() void OpenDocumentsFilter::refreshInternally()
{ {
m_editors.clear(); m_editors.clear();
foreach (DocumentModel::Entry *e, EditorManager::instance()->documentModel()->documents()) { foreach (DocumentModel::Entry *e, EditorManager::documentModel()->documents()) {
DocumentModel::Entry entry; DocumentModel::Entry entry;
// create copy with only the information relevant to use // create copy with only the information relevant to use
// to avoid model deleting entries behind our back // to avoid model deleting entries behind our back
@@ -1020,12 +1020,10 @@ void ProjectExplorerPlugin::loadAction()
// for your special convenience, we preselect a pro file if it is // for your special convenience, we preselect a pro file if it is
// the current file // the current file
if (Core::IEditor *editor = Core::EditorManager::currentEditor()) { if (const Core::IDocument *document = Core::EditorManager::currentDocument()) {
if (const Core::IDocument *document= editor->document()) { const QString fn = document->filePath();
const QString fn = document->filePath(); const bool isProject = d->m_profileMimeTypes.contains(document->mimeType());
const bool isProject = d->m_profileMimeTypes.contains(document->mimeType()); dir = isProject ? fn : QFileInfo(fn).absolutePath();
dir = isProject ? fn : QFileInfo(fn).absolutePath();
}
} }
QString filename = QFileDialog::getOpenFileName(0, tr("Load Project"), QString filename = QFileDialog::getOpenFileName(0, tr("Load Project"),
@@ -1827,8 +1825,8 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node
} }
d->m_currentProject = project; d->m_currentProject = project;
if (!node && Core::EditorManager::currentEditor()) { if (!node && Core::EditorManager::currentDocument()) {
connect(Core::EditorManager::currentEditor()->document(), SIGNAL(changed()), connect(Core::EditorManager::currentDocument(), SIGNAL(changed()),
this, SLOT(updateExternalFileWarning()), Qt::UniqueConnection); this, SLOT(updateExternalFileWarning()), Qt::UniqueConnection);
} }
if (projectChanged || d->m_currentNode != node) { if (projectChanged || d->m_currentNode != node) {
@@ -225,8 +225,8 @@ void QbsProjectManagerPlugin::updateBuildActions()
QString file; QString file;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
file = currentEditor->document()->filePath(); file = currentDocument->filePath();
ProjectExplorer::SessionManager *session = m_projectExplorer->session(); ProjectExplorer::SessionManager *session = m_projectExplorer->session();
ProjectExplorer::Node *node = session->nodeForFile(file); ProjectExplorer::Node *node = session->nodeForFile(file);
ProjectExplorer::Project *project ProjectExplorer::Project *project
@@ -296,8 +296,8 @@ void QbsProjectManagerPlugin::buildFile()
{ {
QString file; QString file;
QbsProject *project = 0; QbsProject *project = 0;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
file = currentEditor->document()->filePath(); file = currentDocument->filePath();
project = qobject_cast<QbsProject *>(m_projectExplorer->session()->projectForFile(file)); project = qobject_cast<QbsProject *>(m_projectExplorer->session()->projectForFile(file));
} }
@@ -319,8 +319,8 @@ void QbsProjectManagerPlugin::buildProduct()
{ {
QbsProject *project = 0; QbsProject *project = 0;
QbsProductNode *product = 0; QbsProductNode *product = 0;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
const QString file = currentEditor->document()->filePath(); const QString file = currentDocument->filePath();
ProjectExplorer::SessionManager *session = m_projectExplorer->session(); ProjectExplorer::SessionManager *session = m_projectExplorer->session();
project = qobject_cast<QbsProject *>(session->projectForFile(file)); project = qobject_cast<QbsProject *>(session->projectForFile(file));
+1 -1
View File
@@ -172,7 +172,7 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
void ShortCutManager::updateActions(Core::IEditor* currentEditor) void ShortCutManager::updateActions(Core::IEditor* currentEditor)
{ {
int openedCount = Core::ICore::editorManager()->documentModel()->documentCount(); int openedCount = Core::EditorManager::documentModel()->documentCount();
m_saveAction.setEnabled(currentEditor != 0 && currentEditor->document()->isModified()); m_saveAction.setEnabled(currentEditor != 0 && currentEditor->document()->isModified());
m_saveAsAction.setEnabled(currentEditor != 0 && currentEditor->document()->isSaveAsAllowed()); m_saveAsAction.setEnabled(currentEditor != 0 && currentEditor->document()->isSaveAsAllowed());
@@ -281,14 +281,14 @@ void QmlProjectRunConfiguration::updateEnabled()
{ {
bool qmlFileFound = false; bool qmlFileFound = false;
if (mainScriptSource() == FileInEditor) { if (mainScriptSource() == FileInEditor) {
Core::IEditor *editor = Core::EditorManager::currentEditor(); Core::IDocument *document= Core::EditorManager::currentDocument();
Core::MimeDatabase *db = ICore::mimeDatabase(); Core::MimeDatabase *db = ICore::mimeDatabase();
if (editor) { if (document) {
m_currentFileFilename = editor->document()->filePath(); m_currentFileFilename = document->filePath();
if (db->findByFile(mainScript()).type() == QLatin1String("application/x-qml")) if (db->findByFile(mainScript()).type() == QLatin1String("application/x-qml"))
qmlFileFound = true; qmlFileFound = true;
} }
if (!editor if (!document
|| db->findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) { || db->findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) {
// find a qml file with lowercase filename. This is slow, but only done // find a qml file with lowercase filename. This is slow, but only done
// in initialization/other border cases. // in initialization/other border cases.
@@ -326,8 +326,8 @@ void Qt4Manager::buildFileContextMenu()
void Qt4Manager::buildFile() void Qt4Manager::buildFile()
{ {
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
QString file = currentEditor->document()->filePath(); QString file = currentDocument->filePath();
ProjectExplorer::SessionManager *session = projectExplorer()->session(); ProjectExplorer::SessionManager *session = projectExplorer()->session();
ProjectExplorer::FileNode *node = qobject_cast<FileNode *>(session->nodeForFile(file)); ProjectExplorer::FileNode *node = qobject_cast<FileNode *>(session->nodeForFile(file));
ProjectExplorer::Project *project = session->projectForFile(file); ProjectExplorer::Project *project = session->projectForFile(file);
@@ -416,8 +416,8 @@ void Qt4ProjectManagerPlugin::updateBuildFileAction()
bool enabled = false; bool enabled = false;
QString file; QString file;
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) { if (Core::IDocument *currentDocument= Core::EditorManager::currentDocument()) {
file = currentEditor->document()->filePath(); file = currentDocument->filePath();
ProjectExplorer::SessionManager *session = m_projectExplorer->session(); ProjectExplorer::SessionManager *session = m_projectExplorer->session();
ProjectExplorer::Node *node = session->nodeForFile(file); ProjectExplorer::Node *node = session->nodeForFile(file);
ProjectExplorer::Project *project = session->projectForFile(file); ProjectExplorer::Project *project = session->projectForFile(file);
+1 -1
View File
@@ -68,7 +68,7 @@ Utils::FileIterator *FindInOpenFiles::files(const QStringList &nameFilters,
QStringList fileNames; QStringList fileNames;
QList<QTextCodec *> codecs; QList<QTextCodec *> codecs;
foreach (Core::DocumentModel::Entry *entry, foreach (Core::DocumentModel::Entry *entry,
Core::EditorManager::instance()->documentModel()->documents()) { Core::EditorManager::documentModel()->documents()) {
QString fileName = entry->fileName(); QString fileName = entry->fileName();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
fileNames.append(fileName); fileNames.append(fileName);
+3 -3
View File
@@ -233,11 +233,11 @@ void StateListener::slotStateChanged()
// temporary path prefix or does the file contains a hash, indicating a project // temporary path prefix or does the file contains a hash, indicating a project
// folder? // folder?
State state; State state;
Core::IEditor *currentEditor = Core::EditorManager::currentEditor(); Core::IDocument *currentDocument = Core::EditorManager::currentDocument();
if (!currentEditor || !currentEditor->document()) if (!currentDocument)
state.currentFile.clear(); state.currentFile.clear();
else else
state.currentFile = currentEditor->document()->filePath(); state.currentFile = currentDocument->filePath();
QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required. QScopedPointer<QFileInfo> currentFileInfo; // Instantiate QFileInfo only once if required.
if (!state.currentFile.isEmpty()) { if (!state.currentFile.isEmpty()) {
const bool isTempFile = state.currentFile.startsWith(QDir::tempPath()); const bool isTempFile = state.currentFile.startsWith(QDir::tempPath());