Commit bde1ebaa authored by dt's avatar dt
Browse files

Remove EditorManager::ensureEditorManagerVisible()

The function always switched to Edit Mode, which was the cause for
several bugs. Since openEditor() already does switch to the right mode,
the function is not really needed.

The following actions now respect the prefered mode of the editor:
"f file"-locator
The Open Documents list
Editor history navigation
parent 0e2a7608
......@@ -971,12 +971,7 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
if (!(flags & NoActivate)) {
setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
if (!(flags & NoModeSwitch)) {
const QString preferredMode = editor->preferredMode();
if (preferredMode.isEmpty() || preferredMode == Core::Constants::MODE_EDIT) {
ensureEditorManagerVisible();
} else {
ModeManager::instance()->activateMode(preferredMode);
}
switchToPreferedMode();
}
if (isVisible())
editor->widget()->setFocus();
......@@ -1255,10 +1250,22 @@ QStringList EditorManager::getOpenFileNames() const
QString(), &m_d->selectedFilter);
}
void EditorManager::ensureEditorManagerVisible()
/// Empty mode == figure out the correct mode from the editor
/// forcePrefered = true, switch to the mode even if the editor is visible in another mode
/// forcePrefered = false, only switch if it is not visible
void EditorManager::switchToPreferedMode()
{
if (!isVisible())
m_d->m_core->modeManager()->activateMode(Constants::MODE_EDIT);
QString preferedMode;
// Figure out prefered mode for editor
if (m_d->m_currentEditor)
preferedMode = m_d->m_currentEditor->preferredMode();
if (preferedMode.isEmpty())
preferedMode = Constants::MODE_EDIT;
if (m_d->m_core->modeManager()->currentMode()->id() != preferedMode)
m_d->m_core->modeManager()->activateMode(preferedMode);
}
IEditor *EditorManager::openEditorWithContents(const QString &editorId,
......@@ -1613,7 +1620,6 @@ void EditorManager::goBackInNavigationHistory()
{
currentEditorView()->goBackInNavigationHistory();
updateActions();
ensureEditorManagerVisible();
return;
}
......@@ -1621,7 +1627,6 @@ void EditorManager::goForwardInNavigationHistory()
{
currentEditorView()->goForwardInNavigationHistory();
updateActions();
ensureEditorManagerVisible();
}
OpenEditorsWindow *EditorManager::windowPopup() const
......@@ -1717,7 +1722,6 @@ bool EditorManager::restoreState(const QByteArray &state)
m_d->m_splitter->restoreState(splitterstates);
// splitting and stuff results in focus trouble, that's why we set the focus again after restoration
ensureEditorManagerVisible();
if (m_d->m_currentEditor) {
m_d->m_currentEditor->widget()->setFocus();
} else if (Core::Internal::SplitterOrView *view = currentSplitterOrView()) {
......
......@@ -126,7 +126,7 @@ public:
QStringList getOpenFileNames() const;
QString getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0) const;
void ensureEditorManagerVisible();
void switchToPreferedMode();
bool hasEditor(const QString &fileName) const;
QList<IEditor *> editorsForFileName(const QString &filename) const;
QList<IEditor *> editorsForFile(IFile *file) const;
......
......@@ -170,10 +170,8 @@ void CppToolsPlugin::switchHeaderSource()
Core::EditorManager *editorManager = Core::EditorManager::instance();
Core::IEditor *editor = editorManager->currentEditor();
QString otherFile = correspondingHeaderOrSource(editor->file()->fileName());
if (!otherFile.isEmpty()) {
if (!otherFile.isEmpty())
editorManager->openEditor(otherFile);
editorManager->ensureEditorManagerVisible();
}
}
QFileInfo CppToolsPlugin::findFile(const QDir &dir, const QString &name,
......
......@@ -679,7 +679,6 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
Core::IEditor *editor = m_core->editorManager()->openEditor(fileName, QLatin1String(Constants::GITSUBMITEDITOR_ID));
if (Git::Constants::debug)
qDebug() << Q_FUNC_INFO << fileName << editor;
m_core->editorManager()->ensureEditorManagerVisible();
GitSubmitEditor *submitEditor = qobject_cast<GitSubmitEditor*>(editor);
QTC_ASSERT(submitEditor, return 0);
// The actions are for some reason enabled by the context switching
......
......@@ -103,7 +103,6 @@ void FileSystemFilter::accept(FilterEntry selection) const
return;
}
m_editorManager->openEditor(selection.internalData.toString());
m_editorManager->ensureEditorManagerVisible();
}
bool FileSystemFilter::openConfigDialog(QWidget *parent, bool &needsRefresh)
......
......@@ -103,5 +103,4 @@ void OpenDocumentsFilter::accept(FilterEntry selection) const
return;
}
m_editorManager->openEditor(selection.internalData.toString());
m_editorManager->ensureEditorManagerVisible();
}
......@@ -599,8 +599,6 @@ void MercurialPlugin::showCommitWidget(const QList<QPair<QString, QString> > &st
return;
}
core->editorManager()->ensureEditorManagerVisible();
CommitEditor *commitEditor = qobject_cast<CommitEditor *>(editor);
if (!commitEditor) {
......
......@@ -674,7 +674,6 @@ Core::IEditor *PerforcePlugin::openPerforceSubmitEditor(const QString &fileName,
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
Core::IEditor *editor = editorManager->openEditor(fileName, Constants::PERFORCE_SUBMIT_EDITOR_ID);
editorManager->ensureEditorManagerVisible();
PerforceSubmitEditor *submitEditor = static_cast<PerforceSubmitEditor*>(editor);
submitEditor->restrictToProjectFiles(depotFileNames);
submitEditor->registerActions(m_undoAction, m_redoAction, m_submitCurrentLogAction, m_diffSelectedFiles);
......
......@@ -2116,7 +2116,6 @@ void ProjectExplorerPlugin::openFile()
QTC_ASSERT(d->m_currentNode, return)
Core::EditorManager *em = Core::EditorManager::instance();
em->openEditor(d->m_currentNode->path());
em->ensureEditorManagerVisible();
}
void ProjectExplorerPlugin::showInGraphicalShell()
......@@ -2312,7 +2311,6 @@ void ProjectExplorerPlugin::openEditorFromAction(QAction *action, const QString
}
em->openEditor(fileName, factory->id());
em->ensureEditorManagerVisible();
return;
}
if (qVariantCanConvert<Core::IExternalEditor *>(data)) {
......
......@@ -56,7 +56,6 @@ void ShowInEditorTaskHandler::handle(const ProjectExplorer::Task &task)
{
QFileInfo fi(task.file);
TextEditor::BaseTextEditor::openEditorAt(fi.canonicalFilePath(), task.line);
Core::EditorManager::instance()->ensureEditorManagerVisible();
}
QAction *ShowInEditorTaskHandler::createAction(QObject *parent)
......
......@@ -130,7 +130,7 @@ void DocumentWarningWidget::setError(const RewriterView::Error &error)
void DocumentWarningWidget::goToError()
{
m_designModeWidget->textEditor()->gotoLine(m_error.line(), m_error.column());
Core::EditorManager::instance()->ensureEditorManagerVisible();
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
}
// ---------- DesignModeWidget
......
......@@ -31,6 +31,8 @@
#include "itexteditor.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <QtCore/QVariant>
......@@ -61,10 +63,10 @@ void LineNumberFilter::accept(FilterEntry selection) const
ITextEditor *editor = currentTextEditor();
if (editor) {
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->ensureEditorManagerVisible();
editorManager->addCurrentPositionToNavigationHistory();
editor->gotoLine(selection.internalData.toInt());
editor->widget()->setFocus();
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
}
}
......
......@@ -36,6 +36,8 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/ifile.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/projectexplorer.h>
......@@ -634,7 +636,7 @@ void VCSBaseEditor::jumpToChangeFromDiff(QTextCursor cursor)
Core::EditorManager *em = Core::EditorManager::instance();
Core::IEditor *ed = em->openEditor(fileName);
em->ensureEditorManagerVisible();
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
if (TextEditor::ITextEditor *editor = qobject_cast<TextEditor::ITextEditor *>(ed))
editor->gotoLine(chunkStart + lineCount);
}
......
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