Commit ff60b856 authored by Eike Ziller's avatar Eike Ziller Committed by hjk

EditorManager: Clean up public interface

By moving internally used methods to EditorManagerPrivate

Change-Id: I046ce92b8baffe4bcd2ea0529557a3ae69f74338
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 3d4caa39
......@@ -30,7 +30,7 @@
#include "readonlyfilesdialog.h"
#include "ui_readonlyfilesdialog.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/editormanager_p.h>
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
......@@ -275,7 +275,7 @@ int ReadOnlyFilesDialog::exec()
}
break;
case RO_SaveAs:
if (!EditorManager::saveDocumentAs(d->document)) {
if (!EditorManagerPrivate::saveDocumentAs(d->document)) {
failedToMakeWritable << buttongroup.fileName;
continue;
}
......
......@@ -37,6 +37,7 @@
#include <coreplugin/dialogs/readonlyfilesdialog.h>
#include <coreplugin/dialogs/saveitemsdialog.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/editormanager_p.h>
#include <coreplugin/editormanager/editorview.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
......@@ -617,7 +618,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
}
}
foreach (IDocument *document, documentsToSave) {
if (!EditorManager::saveDocument(document)) {
if (!EditorManagerPrivate::saveDocument(document)) {
if (cancelled)
*cancelled = true;
notSaved.append(document);
......@@ -913,7 +914,7 @@ void DocumentManager::checkForReload()
d->m_blockActivated = true;
IDocument::ReloadSetting defaultBehavior = EditorManager::reloadSetting();
IDocument::ReloadSetting defaultBehavior = EditorManagerPrivate::reloadSetting();
Utils::ReloadPromptAnswer previousReloadAnswer = Utils::ReloadCurrent;
Utils::FileDeletedPromptAnswer previousDeletedAnswer = Utils::FileDeletedSave;
......@@ -1421,7 +1422,7 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
QList<IEditor *> editorsOpenForFile
= DocumentModel::editorsForFilePath(entry.fileName);
foreach (IEditor *openEditor, editorsOpenForFile) {
Internal::EditorView *view = EditorManager::viewForEditor(openEditor);
Internal::EditorView *view = EditorManagerPrivate::viewForEditor(openEditor);
if (view && view->currentEditor() == openEditor) // visible
views.append(view);
}
......@@ -1431,15 +1432,15 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
if (views.isEmpty()) {
EditorManager::openEditor(entry.fileName, entry.editorFactory->id());
} else {
if (Internal::EditorView *currentView = EditorManager::currentEditorView()) {
if (Internal::EditorView *currentView = EditorManagerPrivate::currentEditorView()) {
if (views.removeOne(currentView))
views.prepend(currentView); // open editor in current view first
}
EditorManager::OpenEditorFlags flags;
foreach (Internal::EditorView *view, views) {
IEditor *editor =
EditorManager::openEditor(view, entry.fileName, entry.editorFactory->id(),
flags);
EditorManagerPrivate::openEditor(view, entry.fileName,
entry.editorFactory->id(), flags);
// Do not change the current editor after opening the first one. That
// * prevents multiple updates of focus etc which are not necessary
// * lets us control which editor is made current by putting the current editor view
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -66,6 +66,7 @@ enum MakeWritableResult {
namespace Internal {
class EditorClosingCoreListener;
class EditorManagerPrivate;
class EditorView;
class MainWindow;
class OpenEditorsViewFactory;
......@@ -115,30 +116,23 @@ public:
static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0,
const QByteArray &contents = QByteArray(),
OpenEditorFlags flags = NoFlags);
static IEditor *openEditor(Internal::EditorView *view, const QString &fileName,
Id id = Id(), OpenEditorFlags flags = NoFlags, bool *newEditor = 0);
static bool openExternalEditor(const QString &fileName, Id editorId);
static QStringList getOpenFileNames();
static Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0);
static IDocument *currentDocument();
static IEditor *currentEditor();
static Internal::EditorView *currentEditorView();
static QList<IEditor *> visibleEditors();
static void activateEditor(IEditor *editor, OpenEditorFlags flags = 0);
static void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = 0);
static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = 0);
static IEditor *activateEditorForDocument(Internal::EditorView *view, IDocument *document, OpenEditorFlags flags = 0);
static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
static void closeEditor(DocumentModel::Entry *entry);
static void closeOtherEditors(IDocument *document);
static Internal::EditorView *viewForEditor(IEditor *editor);
static void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
static void cutForwardNavigationHistory();
......@@ -147,35 +141,19 @@ public:
static bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
static void closeEditor(IEditor *editor, bool askAboutModifiedEditors = true);
static MakeWritableResult makeFileWritable(IDocument *document);
static QByteArray saveState();
static bool restoreState(const QByteArray &state);
static bool hasSplitter();
static void saveSettings();
static void readSettings();
static Internal::OpenEditorsWindow *windowPopup();
static void showPopupOrSelectDocument();
static void showEditorStatusBar(const QString &id,
const QString &infoText,
const QString &buttonText = QString(),
QObject *object = 0, const char *member = 0);
static void hideEditorStatusBar(const QString &id);
static EditorFactoryList editorFactories(const MimeType &mimeType, bool bestMatchOnly = true);
static ExternalEditorList externalEditors(const MimeType &mimeType, bool bestMatchOnly = true);
static void setReloadSetting(IDocument::ReloadSetting behavior);
static IDocument::ReloadSetting reloadSetting();
static void setAutoSaveEnabled(bool enabled);
static bool autoSaveEnabled();
static void setAutoSaveInterval(int interval);
static int autoSaveInterval();
static bool isAutoSaveFile(const QString &fileName);
static QTextCodec *defaultTextCodec();
......@@ -201,92 +179,22 @@ signals:
void findOnFileSystemRequest(const QString &path);
public slots:
static bool closeAllEditors(bool askAboutModifiedEditors = true);
static void closeAllEditorsExceptVisible();
static bool saveDocument(Core::IDocument *documentParam = 0);
static bool saveDocumentAs(Core::IDocument *documentParam = 0);
static void saveDocument();
static void saveDocumentAs();
static void revertToSaved();
static void revertToSaved(IDocument *document);
static bool closeAllEditors(bool askAboutModifiedEditors = true);
static void closeEditor();
static void closeOtherEditors();
static void doEscapeKeyFocusMoveMagic();
private slots:
static void gotoNextDocHistory();
static void gotoPreviousDocHistory();
static void handleContextChange(const QList<Core::IContext *> &context);
static void updateActions();
static void makeCurrentEditorWritable();
static void vcsOpenCurrentEditor();
static void updateWindowTitle();
void handleDocumentStateChange();
static void autoSave();
static void saveDocumentFromContextMenu();
static void saveDocumentAsFromContextMenu();
static void revertToSavedFromContextMenu();
static void closeEditorFromContextMenu();
static void closeOtherEditorsFromContextMenu();
static void showInGraphicalShell();
static void openTerminal();
static void findInDirectory();
static void rootDestroyed(QObject *root);
static void setCurrentEditorFromContextChange();
static void gotoNextSplit();
public slots:
static void goBackInNavigationHistory();
static void goForwardInNavigationHistory();
static void split(Qt::Orientation orientation);
static void split();
static void splitSideBySide();
static void splitNewWindow();
static void removeCurrentSplit();
static void removeAllSplits();
static void gotoOtherSplit();
static void goBackInNavigationHistory();
static void goForwardInNavigationHistory();
private:
explicit EditorManager(QObject *parent);
~EditorManager();
static void init();
static IEditor *createEditor(Id id = Id(), const QString &fileName = QString());
static void addEditor(IEditor *editor);
static void removeEditor(IEditor *editor);
static void restoreEditorState(IEditor *editor);
static IEditor *placeEditor(Internal::EditorView *view, IEditor *editor);
static IEditor *duplicateEditor(IEditor *editor);
static IEditor *activateEditor(Internal::EditorView *view, IEditor *editor, OpenEditorFlags flags = NoFlags);
static void activateEditorForEntry(Internal::EditorView *view, DocumentModel::Entry *entry,
OpenEditorFlags flags = NoFlags);
static void activateView(Internal::EditorView *view);
static int visibleDocumentsCount();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static void setCurrentView(Internal::EditorView *view);
static Internal::SplitterOrView *findRoot(const Internal::EditorView *view, int *rootIndex = 0);
static void closeView(Internal::EditorView *view);
static void emptyView(Internal::EditorView *view);
static void splitNewWindow(Internal::EditorView *view);
static IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0);
static void addDocumentToRecentFiles(IDocument *document);
static void updateAutoSave();
static void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
static void updateMakeWritableWarning();
static void setupSaveActions(IDocument *document, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
friend class Core::Internal::MainWindow;
friend class Core::Internal::SplitterOrView;
friend class Core::Internal::EditorView;
friend class Core::EditorToolBar;
};
} // namespace Core
......
......@@ -32,10 +32,12 @@
#include "idocument.h"
#include "documentmodel.h"
#include "editormanager.h"
#include "editorview.h"
#include "ieditor.h"
#include <QList>
#include <QObject>
#include <QPointer>
#include <QString>
#include <QVariant>
......@@ -46,19 +48,125 @@ class QTimer;
QT_END_NAMESPACE
namespace Core {
class EditorManager;
namespace Internal {
class EditorClosingCoreListener;
class MainWindow;
class OpenEditorsViewFactory;
class OpenEditorsWindow;
class EditorManagerPrivate
class EditorManagerPrivate : public QObject
{
Q_OBJECT
friend class Core::EditorManager;
public:
static QWidget *rootWidget();
static EditorView *currentEditorView();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static IEditor *openEditor(EditorView *view,
const QString &fileName,
Id editorId = Id(),
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags,
bool *newEditor = 0);
static IEditor *duplicateEditor(IEditor *editor);
static IEditor *activateEditor(EditorView *view, IEditor *editor,
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags);
static IEditor *activateEditorForDocument(EditorView *view, IDocument *document,
EditorManager::OpenEditorFlags flags = 0);
static void activateEditorForEntry(EditorView *view, DocumentModel::Entry *entry,
EditorManager::OpenEditorFlags flags = EditorManager::NoFlags);
static EditorView *viewForEditor(IEditor *editor);
static void setCurrentView(EditorView *view);
static MakeWritableResult makeFileWritable(IDocument *document);
static void doEscapeKeyFocusMoveMagic();
static Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = 0);
static void saveSettings();
static void readSettings();
static void setReloadSetting(IDocument::ReloadSetting behavior);
static IDocument::ReloadSetting reloadSetting();
static void setAutoSaveEnabled(bool enabled);
static bool autoSaveEnabled();
static void setAutoSaveInterval(int interval);
static int autoSaveInterval();
static void splitNewWindow(Internal::EditorView *view);
static void closeView(Internal::EditorView *view);
static void emptyView(Internal::EditorView *view);
static void updateActions();
public slots:
static bool saveDocument(Core::IDocument *document);
static bool saveDocumentAs(Core::IDocument *document);
static void makeCurrentEditorWritable();
static void vcsOpenCurrentEditor();
static void split(Qt::Orientation orientation);
static void removeAllSplits();
static void gotoNextSplit();
void handleDocumentStateChange();
static void rootDestroyed(QObject *root);
private slots:
static void gotoNextDocHistory();
static void gotoPreviousDocHistory();
static void autoSave();
static void handleContextChange(const QList<Core::IContext *> &context);
static void saveDocumentFromContextMenu();
static void saveDocumentAsFromContextMenu();
static void revertToSavedFromContextMenu();
static void closeEditorFromContextMenu();
static void closeOtherEditorsFromContextMenu();
static void closeAllEditorsExceptVisible();
static void revertToSaved(IDocument *document);
static void showInGraphicalShell();
static void openTerminal();
static void findInDirectory();
static void split();
static void splitNewWindow();
static void removeCurrentSplit();
static void setCurrentEditorFromContextChange();
private:
static OpenEditorsWindow *windowPopup();
static void showPopupOrSelectDocument();
static IEditor *createEditor(Id editorId = Id(), const QString &fileName = QString());
static void addEditor(IEditor *editor);
static void removeEditor(IEditor *editor);
static IEditor *placeEditor(EditorView *view, IEditor *editor);
static void activateView(EditorView *view);
static void restoreEditorState(IEditor *editor);
static int visibleDocumentsCount();
static SplitterOrView *findRoot(const EditorView *view, int *rootIndex = 0);
static IEditor *pickUnusedEditor(Internal::EditorView **foundView = 0);
static void addDocumentToRecentFiles(IDocument *document);
static void updateAutoSave();
static void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
static void updateMakeWritableWarning();
static void setupSaveActions(IDocument *document, QAction *saveAction,
QAction *saveAsAction, QAction *revertToSavedAction);
static void updateWindowTitle();
private:
explicit EditorManagerPrivate(QObject *parent);
~EditorManagerPrivate();
static QWidget *rootWidget();
void init();
QList<EditLocation> m_globalHistory;
QList<SplitterOrView *> m_root;
......
......@@ -28,7 +28,9 @@
****************************************************************************/
#include "editorview.h"
#include "editormanager.h"
#include "editormanager_p.h"
#include "documentmodel.h"
#include <coreplugin/editortoolbar.h>
......@@ -229,7 +231,7 @@ void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &histo
void EditorView::paintEvent(QPaintEvent *)
{
EditorView *editorView = EditorManager::currentEditorView();
EditorView *editorView = EditorManagerPrivate::currentEditorView();
if (editorView != this)
return;
......@@ -254,7 +256,7 @@ void EditorView::mousePressEvent(QMouseEvent *e)
void EditorView::focusInEvent(QFocusEvent *)
{
EditorManager::setCurrentView(this);
EditorManagerPrivate::setCurrentView(this);
}
void EditorView::addEditor(IEditor *editor)
......@@ -306,39 +308,39 @@ IEditor *EditorView::currentEditor() const
void EditorView::listSelectionActivated(int index)
{
EditorManager::activateEditorForEntry(this, DocumentModel::entryAtRow(index));
EditorManagerPrivate::activateEditorForEntry(this, DocumentModel::entryAtRow(index));
}
void EditorView::splitHorizontally()
{
if (m_parentSplitterOrView)
m_parentSplitterOrView->split(Qt::Vertical);
EditorManager::updateActions();
EditorManagerPrivate::updateActions();
}
void EditorView::splitVertically()
{
if (m_parentSplitterOrView)
m_parentSplitterOrView->split(Qt::Horizontal);
EditorManager::updateActions();
EditorManagerPrivate::updateActions();
}
void EditorView::splitNewWindow()
{
EditorManager::splitNewWindow(this);
EditorManagerPrivate::splitNewWindow(this);
}
void EditorView::closeSplit()
{
EditorManager::closeView(this);
EditorManager::updateActions();
EditorManagerPrivate::closeView(this);
EditorManagerPrivate::updateActions();
}
void EditorView::openDroppedFiles(const QStringList &files)
{
const int count = files.size();
for (int i = 0; i < count; ++i) {
EditorManager::openEditor(this, files.at(i), Id(),
EditorManagerPrivate::openEditor(this, files.at(i), Id(),
i < count - 1 ? EditorManager::DoNotChangeCurrentEditor
| EditorManager::DoNotMakeVisible
: EditorManager::NoFlags);
......@@ -486,11 +488,11 @@ void EditorView::goBackInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor = 0;
if (location.document) {
editor = EditorManager::activateEditorForDocument(this, location.document,
editor = EditorManagerPrivate::activateEditorForDocument(this, location.document,
EditorManager::IgnoreNavigationHistory);
}
if (!editor) {
editor = EditorManager::openEditor(this, location.fileName, location.id,
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory);
if (!editor) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
......@@ -512,11 +514,12 @@ void EditorView::goForwardInNavigationHistory()
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor = 0;
if (location.document) {
editor = EditorManager::activateEditorForDocument(this, location.document,
editor = EditorManagerPrivate::activateEditorForDocument(this, location.document,
EditorManager::IgnoreNavigationHistory);
}
if (!editor) {
editor = EditorManager::openEditor(this, location.fileName, location.id, EditorManager::IgnoreNavigationHistory);
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory);
if (!editor) {
//TODO
qDebug() << Q_FUNC_INFO << "can't open file" << location.fileName;
......@@ -555,7 +558,7 @@ SplitterOrView::~SplitterOrView()
delete m_layout;
m_layout = 0;
if (m_view)
EditorManager::emptyView(m_view);
EditorManagerPrivate::emptyView(m_view);
delete m_view;
m_view = 0;
delete m_splitter;
......@@ -630,7 +633,7 @@ void SplitterOrView::split(Qt::Orientation orientation)
SplitterOrView *view = 0;
SplitterOrView *otherView = 0;
IEditor *duplicate = e && e->duplicateSupported() ? EditorManager::duplicateEditor(e) : 0;
IEditor *duplicate = e && e->duplicateSupported() ? EditorManagerPrivate::duplicateEditor(e) : 0;
m_splitter->addWidget((view = new SplitterOrView(duplicate)));
m_splitter->addWidget((otherView = new SplitterOrView(editorView)));
......@@ -648,9 +651,9 @@ void SplitterOrView::split(Qt::Orientation orientation)
}
if (e)
EditorManager::activateEditor(otherView->view(), e);
EditorManagerPrivate::activateEditor(otherView->view(), e);
else
EditorManager::setCurrentView(otherView->view());
EditorManagerPrivate::setCurrentView(otherView->view());
}
void SplitterOrView::unsplitAll()
......@@ -665,7 +668,7 @@ void SplitterOrView::unsplitAll()
}
}
EditorView *currentView = EditorManager::currentEditorView();
EditorView *currentView = EditorManagerPrivate::currentEditorView();
if (currentView) {
currentView->parentSplitterOrView()->takeView();
currentView->setParentSplitterOrView(this);
......@@ -692,7 +695,7 @@ void SplitterOrView::unsplitAll()
void SplitterOrView::unsplitAll_helper()
{
if (m_view)
EditorManager::emptyView(m_view);
EditorManagerPrivate::emptyView(m_view);
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i)))
......@@ -726,7 +729,7 @@ void SplitterOrView::unsplit()
m_view->addEditor(e);
m_view->setCurrentEditor(e);
}
EditorManager::emptyView(childView);
EditorManagerPrivate::emptyView(childView);
} else {
m_view = childSplitterOrView->takeView();
m_view->setParentSplitterOrView(this);
......@@ -749,7 +752,7 @@ void SplitterOrView::unsplit()
m_layout->setCurrentWidget(m_view);
}
delete oldSplitter;
EditorManager::setCurrentView(findFirstView());
EditorManagerPrivate::setCurrentView(findFirstView());
}
......@@ -812,20 +815,22 @@ void SplitterOrView::restoreState(const QByteArray &state)
stream >> fileName >> id >> editorState;
if (!QFile::exists(fileName))
return;
IEditor *e = EditorManager::openEditor(view(), fileName, Id::fromString(id), Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor);
IEditor *e = EditorManagerPrivate::openEditor(view(), fileName, Id::fromString(id),
Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor);
if (!e) {
DocumentModel::Entry *entry = DocumentModel::firstRestoredEntry();
if (entry)
EditorManager::activateEditorForEntry(view(), entry, Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::DoNotChangeCurrentEditor);
if (entry) {
EditorManagerPrivate::activateEditorForEntry(view(), entry,
EditorManager::IgnoreNavigationHistory | EditorManager::DoNotChangeCurrentEditor);
}
}
if (e) {
e->restoreState(editorState);
if (mode == "currenteditor")
EditorManager::setCurrentEditor(e);
EditorManagerPrivate::setCurrentEditor(e);
}
}
}
......@@ -28,8 +28,10 @@
****************************************************************************/
#include "openeditorswindow.h"
#include "documentmodel.h"
#include "editormanager.h"
#include "editormanager_p.h"
#include "editorview.h"
#include <coreplugin/idocument.h>
......@@ -196,7 +198,7 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
return;
if (IDocument *document = item->data(0, Qt::UserRole).value<IDocument*>()) {
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
EditorManager::activateEditorForDocument(view, document);
EditorManagerPrivate::activateEditorForDocument(view, document);
} else {
if (!EditorManager::openEditor(
item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) {
......
......@@ -34,6 +34,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/editormanager_p.h>
#include <coreplugin/editormanager/documentmodel.h>
#include <coreplugin/actionmanager/actionmanager.h>
......@@ -339,7 +340,7 @@ void EditorToolBar::listContextMenu(QPoint pos)
void EditorToolBar::makeEditorWritable()
{
if (IDocument *current = EditorManager::currentDocument())
EditorManager::makeFileWritable(current);
Internal::EditorManagerPrivate::makeFileWritable(current);
}