Commit 793d1cba authored by con's avatar con
Browse files

Start on some cleanup of EditorManager API and usage.

parent 12f2a0fb
......@@ -832,7 +832,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
} else {
QModelIndex idx = m_d->m_editorModel->firstRestoredEditor();
if (idx.isValid())
activateEditor(idx, view, NoActivate);
activateEditorForIndex(view, idx, NoActivate);
}
}
......@@ -889,7 +889,7 @@ void EditorManager::closeDuplicate(Core::IEditor *editor)
} else {
QModelIndex idx = m_d->m_editorModel->firstRestoredEditor();
if (idx.isValid())
activateEditor(idx, view, NoActivate);
activateEditorForIndex(view, idx, NoActivate);
}
}
......@@ -911,16 +911,23 @@ Core::IEditor *EditorManager::pickUnusedEditor() const
return 0;
}
Core::IEditor *EditorManager::activateEditor(const QModelIndex &index, Internal::EditorView *view, OpenEditorFlags flags)
void EditorManager::activateEditorForIndex(const QModelIndex &index, OpenEditorFlags flags)
{
activateEditorForIndex(currentEditorView(), index, flags);
}
void EditorManager::activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags flags)
{
Q_ASSERT(view);
IEditor *editor = index.data(Qt::UserRole).value<IEditor*>();
if (editor) {
return activateEditor(view, editor, flags);
activateEditor(view, editor, flags);
return;
}
QString fileName = index.data(Qt::UserRole + 1).toString();
QString id = index.data(Qt::UserRole + 2).toString();
return openEditor(view, fileName, id, flags);
openEditor(view, fileName, id, flags);
}
Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core::IEditor *editor)
......@@ -954,16 +961,17 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
return editor;
}
Core::IEditor *EditorManager::activateEditor(Core::IEditor *editor, OpenEditorFlags flags)
void EditorManager::activateEditor(Core::IEditor *editor, OpenEditorFlags flags)
{
return activateEditor(0, editor, flags);
EditorView *view = m_d->m_splitter->findView(editor)->view();
// TODO an IEditor doesn't have to belong to a view, which makes this method a bit funny
if (!view)
view = currentEditorView();
activateEditor(view, editor, flags);
}
Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags)
{
if (!view)
view = currentEditorView();
Q_ASSERT(view);
if (!editor) {
......@@ -985,13 +993,15 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
return editor;
}
Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IFile *file, OpenEditorFlags flags)
Core::IEditor *EditorManager::activateEditorForFile(Core::Internal::EditorView *view, Core::IFile *file, OpenEditorFlags flags)
{
Q_ASSERT(view);
const QList<IEditor*> editors = editorsForFile(file);
if (editors.isEmpty())
return 0;
return activateEditor(view, editors.first(), flags);
activateEditor(view, editors.first(), flags);
return editors.first();
}
/* For something that has a 'QStringList mimeTypes' (IEditorFactory
......@@ -1162,7 +1172,7 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId,
OpenEditorFlags flags, bool *newEditor)
{
return openEditor(0, fileName, editorId, flags, newEditor);
return openEditor(currentEditorView(), fileName, editorId, flags, newEditor);
}
int extractLineNumber(QString *fileName)
......
......@@ -47,7 +47,6 @@ QT_END_NAMESPACE
namespace Core {
class EditorGroup;
class IContext;
class ICore;
class IEditor;
......@@ -131,7 +130,6 @@ public:
QStringList getOpenFileNames() const;
QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
void switchToPreferedMode();
bool hasEditor(const QString &fileName) const;
QList<IEditor *> editorsForFileName(const QString &filename) const;
QList<IEditor *> editorsForFile(IFile *file) const;
......@@ -140,9 +138,9 @@ public:
QList<IEditor *> visibleEditors() const;
QList<IEditor*> openedEditors() const;
IEditor *activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
IEditor *activateEditor(const QModelIndex &index, Internal::EditorView *view = 0, OpenEditorFlags = 0);
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
void activateEditorForIndex(const QModelIndex &index, OpenEditorFlags = 0);
IEditor *activateEditorForFile(Core::Internal::EditorView *view, Core::IFile*file, OpenEditorFlags flags = 0);
OpenEditorsModel *openedEditorsModel() const;
void closeEditor(const QModelIndex &index);
......@@ -162,8 +160,6 @@ public:
bool restoreState(const QByteArray &state);
bool hasSplitter() const;
IEditor *restoreEditor(QString fileName, QString editorId, EditorGroup *group);
void saveSettings();
void readSettings();
......@@ -257,6 +253,7 @@ private:
void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
void setCurrentView(Core::Internal::SplitterOrView *view);
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
void activateEditorForIndex(Internal::EditorView *view, const QModelIndex &index, OpenEditorFlags = 0);
IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
const QString &editorId = QString(),
OpenEditorFlags flags = 0,
......@@ -270,6 +267,7 @@ private:
Core::Internal::EditorView *currentEditorView() const;
IEditor *pickUnusedEditor() const;
void addFileToRecentFiles(IFile *file);
void switchToPreferedMode();
static EditorManager *m_instance;
EditorManagerPrivate *m_d;
......
......@@ -279,13 +279,8 @@ IEditor *EditorView::currentEditor() const
void EditorView::listSelectionActivated(int index)
{
EditorManager *em = CoreImpl::instance()->editorManager();
QAbstractItemModel *model = EditorManager::instance()->openedEditorsModel();
if (IEditor *editor = model->data(model->index(index, 0), Qt::UserRole).value<IEditor*>()) {
em->activateEditor(this, editor, Core::EditorManager::ModeSwitch);
} else {
em->activateEditor(model->index(index, 0), this, Core::EditorManager::ModeSwitch);
}
EditorManager::instance()->activateEditorForIndex(this, model->index(index, 0), Core::EditorManager::ModeSwitch);
}
void EditorView::setCurrentEditor(IEditor *editor)
......@@ -451,7 +446,7 @@ void EditorView::goBackInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor;
if (location.file) {
editor = em->activateEditor(this, location.file,
editor = em->activateEditorForFile(this, location.file,
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
} else {
editor = em->openEditor(this, location.fileName, location.id,
......@@ -477,7 +472,7 @@ void EditorView::goForwardInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor;
if (location.file) {
editor = em->activateEditor(this, location.file,
editor = em->activateEditorForFile(this, location.file,
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
} else {
editor = em->openEditor(this, location.fileName, location.id, EditorManager::IgnoreNavigationHistory);
......@@ -861,7 +856,7 @@ void SplitterOrView::restoreState(const QByteArray &state)
if (!e) {
QModelIndex idx = em->openedEditorsModel()->firstRestoredEditor();
if (idx.isValid())
em->activateEditor(idx, view(), Core::EditorManager::IgnoreNavigationHistory
em->activateEditorForIndex(view(), idx, Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::NoActivate);
}
......
......@@ -193,7 +193,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
{
m_ui.editorList->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
EditorManager::instance()->activateEditor(index, 0, EditorManager::ModeSwitch);
EditorManager::instance()->activateEditorForIndex(index, EditorManager::ModeSwitch);
}
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
......
......@@ -281,7 +281,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
return;
if (IFile *file = item->data(0, Qt::UserRole).value<IFile*>()) {
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
EditorManager::instance()->activateEditor(view, file, Core::EditorManager::ModeSwitch);
EditorManager::instance()->activateEditorForFile(view, file, Core::EditorManager::ModeSwitch);
} else {
EditorManager::instance()->openEditor(item->toolTip(0), item->data(0, Qt::UserRole+2).toByteArray(),
Core::EditorManager::ModeSwitch);
......
......@@ -280,21 +280,7 @@ void EditorToolBar::changeActiveEditor(int row)
{
EditorManager *em = ICore::instance()->editorManager();
QAbstractItemModel *model = d->m_editorList->model();
const QModelIndex modelIndex = model->index(row, 0);
IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>();
if (editor) {
if (editor != em->currentEditor())
em->activateEditor(editor);
} else {
//em->activateEditor(model->index(index, 0), this);
QString fileName = model->data(modelIndex, Qt::UserRole + 1).toString();
QByteArray kind = model->data(modelIndex, Qt::UserRole + 2).toByteArray();
editor = em->openEditor(fileName, kind);
}
if (editor) {
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
}
em->activateEditorForIndex(model->index(row, 0), EditorManager::ModeSwitch);
}
void EditorToolBar::listContextMenu(QPoint pos)
......
......@@ -55,8 +55,6 @@ Q_DECLARE_METATYPE(Core::FileManager*)
Q_DECLARE_METATYPE(Core::IFile*)
Q_DECLARE_METATYPE(QList<Core::IFile*>)
Q_DECLARE_METATYPE(QList<Core::IEditor*>)
Q_DECLARE_METATYPE(Core::EditorGroup*)
Q_DECLARE_METATYPE(QList<Core::EditorGroup*>)
Q_DECLARE_METATYPE(Core::EditorManager*)
Q_DECLARE_METATYPE(Core::ICore*)
......
......@@ -246,8 +246,6 @@ ScriptManager::QScriptEnginePtr ScriptManagerPrivate::ensureEngineInitialized()
qScriptRegisterSequenceMetaType<QList<Core::IEditor *> >(m_engine.data());
qScriptRegisterSequenceMetaType<QList<Core::EditorGroup *> >(m_engine.data());
// CLASSIC: registerInterfaceWithDefaultPrototype<Core::MessageManager, MessageManagerPrototype>(m_engine);
// Message box conveniences
......
......@@ -344,10 +344,9 @@ void CodepasterPlugin::finishFetch(const QString &titleDescription,
tempFile = TemporaryFilePtr();
m_fetchedSnippets.push_back(fileName);
// Open editor with title.
Core::IEditor* editor = EditorManager::instance()->openEditor(fileName);
Core::IEditor* editor = EditorManager::instance()->openEditor(fileName, QString(), EditorManager::ModeSwitch);
QTC_ASSERT(editor, return)
editor->setDisplayName(titleDescription);
EditorManager::instance()->activateEditor(editor, Core::EditorManager::ModeSwitch);
}
Q_EXPORT_PLUGIN(CodepasterPlugin)
......@@ -1386,7 +1386,7 @@ void FakeVimPluginPrivate::switchToFile(int n)
n = n % size;
if (n < 0)
n += size;
editorManager()->activateEditor(model->index(n, 0), 0);
editorManager()->activateEditorForIndex(model->index(n, 0));
}
CommandMap &FakeVimExCommandsPage::exCommandMap()
......
......@@ -67,10 +67,7 @@ QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::Fil
QString fileName = editorEntry.fileName();
QString displayName = editorEntry.displayName();
if (regexp.exactMatch(displayName)) {
if (fileName.isEmpty()) {
if (editorEntry.editor)
value.append(FilterEntry(this, displayName, qVariantFromValue(editorEntry.editor)));
} else {
if (!fileName.isEmpty()) {
QFileInfo fi(fileName);
FilterEntry fiEntry(this, fi.fileName(), fileName);
fiEntry.extraInfo = QDir::toNativeSeparators(fi.path());
......@@ -87,7 +84,9 @@ void OpenDocumentsFilter::refreshInternally()
m_editors.clear();
foreach (IEditor *editor, m_editorManager->openedEditors()) {
OpenEditorsModel::Entry entry;
entry.editor = editor;
// don't work on IEditor directly, since that will be useless with split windows
entry.m_displayName = editor->displayName();
entry.m_fileName = editor->file()->fileName();
m_editors.append(entry);
}
m_editors += m_editorManager->openedEditorsModel()->restoredEditors();
......@@ -101,10 +100,5 @@ void OpenDocumentsFilter::refresh(QFutureInterface<void> &future)
void OpenDocumentsFilter::accept(FilterEntry selection) const
{
IEditor *editor = selection.internalData.value<IEditor *>();
if (editor) {
m_editorManager->activateEditor(editor, Core::EditorManager::ModeSwitch);
return;
}
m_editorManager->openEditor(selection.internalData.toString(), QString(), Core::EditorManager::ModeSwitch);
}
......@@ -49,12 +49,7 @@ RefactoringChanges::RefactoringChanges()
RefactoringChanges::~RefactoringChanges()
{
if (!m_fileToOpen.isEmpty()) {
BaseTextEditor *editor = editorForFile(m_fileToOpen, true);
editor->gotoLine(m_lineToOpen, m_columnToOpen);
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->activateEditor(editor->editableInterface(),
Core::EditorManager::ModeSwitch);
BaseTextEditor::openEditorAt(m_fileToOpen, m_lineToOpen, m_columnToOpen);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment