forked from qt-creator/qt-creator
Editors: Get rid of keeping separate lists of "duplicated" editors.
And use documents for the list of currently open documents, instead of using a set of "original" editors that needed to be separately managed. Change-Id: I3379ca44f03646399d3ecb0e775d7f1fd81a6bcf Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -507,9 +507,9 @@ EditorToolBar *EditorManager::createToolBar(QWidget *parent)
|
|||||||
|
|
||||||
void EditorManager::removeEditor(IEditor *editor)
|
void EditorManager::removeEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
bool isDuplicate = d->m_editorModel->isDuplicate(editor);
|
bool lastOneForDocument = false;
|
||||||
d->m_editorModel->removeEditor(editor);
|
d->m_editorModel->removeEditor(editor, &lastOneForDocument);
|
||||||
if (!isDuplicate)
|
if (lastOneForDocument)
|
||||||
DocumentManager::removeDocument(editor->document());
|
DocumentManager::removeDocument(editor->document());
|
||||||
ICore::removeContextObject(editor);
|
ICore::removeContextObject(editor);
|
||||||
}
|
}
|
||||||
@@ -660,21 +660,17 @@ void EditorManager::emptyView(Core::Internal::EditorView *view)
|
|||||||
|
|
||||||
QList<IEditor *> editors = view->editors();
|
QList<IEditor *> editors = view->editors();
|
||||||
foreach (IEditor *editor, editors) {
|
foreach (IEditor *editor, editors) {
|
||||||
if (!d->m_editorModel->isDuplicate(editor)) {
|
if (d->m_editorModel->editorsForDocument(editor->document()).size() == 1) {
|
||||||
QList<IEditor *> duplicates = d->m_editorModel->duplicatesFor(editor);
|
// it's the only editor for that file
|
||||||
if (!duplicates.isEmpty()) {
|
// so we need to keep it around (--> in the editor model)
|
||||||
d->m_editorModel->makeOriginal(duplicates.first());
|
if (currentEditor() == editor) {
|
||||||
} else {
|
// we don't want a current editor that is not open in a view
|
||||||
// it's the only editor for that file and it's not a duplicate,
|
setCurrentView(view);
|
||||||
// so we need to keep it around (--> in the editor model)
|
setCurrentEditor(0);
|
||||||
if (currentEditor() == editor) {
|
|
||||||
// we don't want a current editor that is not open in a view
|
|
||||||
setCurrentEditor(0);
|
|
||||||
}
|
|
||||||
editors.removeAll(editor);
|
|
||||||
view->removeEditor(editor);
|
|
||||||
continue; // don't close the editor
|
|
||||||
}
|
}
|
||||||
|
editors.removeAll(editor);
|
||||||
|
view->removeEditor(editor);
|
||||||
|
continue; // don't close the editor
|
||||||
}
|
}
|
||||||
emit editorAboutToClose(editor);
|
emit editorAboutToClose(editor);
|
||||||
removeEditor(editor);
|
removeEditor(editor);
|
||||||
@@ -743,33 +739,6 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor*>
|
|
||||||
EditorManager::editorsForDocuments(QList<IDocument*> documents) const
|
|
||||||
{
|
|
||||||
const QList<IEditor *> editors = openedEditors();
|
|
||||||
QSet<IEditor *> found;
|
|
||||||
foreach (IDocument *document, documents) {
|
|
||||||
foreach (IEditor *editor, editors) {
|
|
||||||
if (editor->document() == document && !found.contains(editor))
|
|
||||||
found << editor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<IDocument *> EditorManager::documentsForEditors(QList<IEditor *> editors) const
|
|
||||||
{
|
|
||||||
QSet<IEditor *> handledEditors;
|
|
||||||
QList<IDocument *> documents;
|
|
||||||
foreach (IEditor *editor, editors) {
|
|
||||||
if (!handledEditors.contains(editor)) {
|
|
||||||
documents << editor->document();
|
|
||||||
handledEditors.insert(editor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return documents;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
||||||
{
|
{
|
||||||
d->m_editorModel->removeAllRestoredEditors();
|
d->m_editorModel->removeAllRestoredEditors();
|
||||||
@@ -780,19 +749,21 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeOtherEditors(IEditor *editor)
|
void EditorManager::closeOtherEditors(IDocument *document)
|
||||||
{
|
{
|
||||||
d->m_editorModel->removeAllRestoredEditors();
|
d->m_editorModel->removeAllRestoredEditors();
|
||||||
QList<IEditor*> editors = openedEditors();
|
QList<IEditor *> editorsToClose;
|
||||||
editors.removeAll(editor);
|
foreach (IEditor *editor, openedEditors())
|
||||||
closeEditors(editors, true);
|
if (editor->document() != document)
|
||||||
|
editorsToClose << editor;
|
||||||
|
closeEditors(editorsToClose, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeOtherEditors()
|
void EditorManager::closeOtherEditors()
|
||||||
{
|
{
|
||||||
IEditor *current = currentEditor();
|
IEditor *current = currentEditor();
|
||||||
QTC_ASSERT(current, return);
|
QTC_ASSERT(current, return);
|
||||||
closeOtherEditors(current);
|
closeOtherEditors(current->document());
|
||||||
}
|
}
|
||||||
|
|
||||||
// SLOT connected to action
|
// SLOT connected to action
|
||||||
@@ -822,9 +793,9 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, OpenEditors
|
|||||||
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 = entry ? entry->editor : 0;
|
IDocument *document = entry ? entry->document : 0;
|
||||||
|
|
||||||
setupSaveActions(editor,
|
setupSaveActions(document,
|
||||||
d->m_saveCurrentEditorContextAction,
|
d->m_saveCurrentEditorContextAction,
|
||||||
d->m_saveAsCurrentEditorContextAction,
|
d->m_saveAsCurrentEditorContextAction,
|
||||||
d->m_revertToSavedCurrentEditorContextAction);
|
d->m_revertToSavedCurrentEditorContextAction);
|
||||||
@@ -955,36 +926,36 @@ void EditorManager::doEscapeKeyFocusMoveMagic()
|
|||||||
|
|
||||||
void EditorManager::saveDocumentFromContextMenu()
|
void EditorManager::saveDocumentFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||||
if (editor)
|
if (document)
|
||||||
saveDocument(editor->document());
|
saveDocument(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::saveDocumentAsFromContextMenu()
|
void EditorManager::saveDocumentAsFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||||
if (editor)
|
if (document)
|
||||||
saveDocumentAs(editor->document());
|
saveDocumentAs(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::revertToSavedFromContextMenu()
|
void EditorManager::revertToSavedFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||||
if (editor)
|
if (document)
|
||||||
revertToSaved(editor);
|
revertToSaved(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeEditorFromContextMenu()
|
void EditorManager::closeEditorFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||||
if (editor)
|
if (document)
|
||||||
closeEditor(editor);
|
closeEditors(d->m_editorModel->editorsForDocument(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeOtherEditorsFromContextMenu()
|
void EditorManager::closeOtherEditorsFromContextMenu()
|
||||||
{
|
{
|
||||||
IEditor *editor = d->m_contextMenuEntry ? d->m_contextMenuEntry->editor : 0;
|
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : 0;
|
||||||
closeOtherEditors(editor);
|
closeOtherEditors(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::showInGraphicalShell()
|
void EditorManager::showInGraphicalShell()
|
||||||
@@ -1068,8 +1039,8 @@ void EditorManager::closeEditor(OpenEditorsModel::Entry *entry)
|
|||||||
{
|
{
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return;
|
return;
|
||||||
if (entry->editor)
|
if (entry->document)
|
||||||
closeEditor(entry->editor);
|
closeEditors(d->m_editorModel->editorsForDocument(entry->document));
|
||||||
else
|
else
|
||||||
d->m_editorModel->removeEntry(entry);
|
d->m_editorModel->removeEntry(entry);
|
||||||
}
|
}
|
||||||
@@ -1082,14 +1053,13 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
EditorView *currentView = currentEditorView();
|
EditorView *currentView = currentEditorView();
|
||||||
|
|
||||||
bool closingFailed = false;
|
bool closingFailed = false;
|
||||||
QList<IEditor*> acceptedEditors;
|
QSet<IEditor*> acceptedEditors;
|
||||||
|
QSet<IDocument *> acceptedDocuments;
|
||||||
//ask all core listeners to check whether the editor can be closed
|
//ask all core listeners to check whether the editor can be closed
|
||||||
const QList<ICoreListener *> listeners =
|
const QList<ICoreListener *> listeners =
|
||||||
ExtensionSystem::PluginManager::getObjects<ICoreListener>();
|
ExtensionSystem::PluginManager::getObjects<ICoreListener>();
|
||||||
foreach (IEditor *editor, editorsToClose) {
|
foreach (IEditor *editor, editorsToClose) {
|
||||||
bool editorAccepted = true;
|
bool editorAccepted = true;
|
||||||
if (d->m_editorModel->isDuplicate(editor))
|
|
||||||
editor = d->m_editorModel->originalForDuplicate(editor);
|
|
||||||
foreach (ICoreListener *listener, listeners) {
|
foreach (ICoreListener *listener, listeners) {
|
||||||
if (!listener->editorAboutToClose(editor)) {
|
if (!listener->editorAboutToClose(editor)) {
|
||||||
editorAccepted = false;
|
editorAccepted = false;
|
||||||
@@ -1097,21 +1067,24 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (editorAccepted)
|
if (editorAccepted) {
|
||||||
acceptedEditors.append(editor);
|
acceptedEditors += d->m_editorModel->editorsForDocument(editor->document()).toSet();
|
||||||
|
acceptedDocuments.insert(editor->document());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (acceptedEditors.isEmpty())
|
if (acceptedEditors.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
//ask whether to save modified files
|
//ask whether to save modified files
|
||||||
if (askAboutModifiedEditors) {
|
if (askAboutModifiedEditors) {
|
||||||
bool cancelled = false;
|
bool cancelled = false;
|
||||||
QList<IDocument*> list = DocumentManager::saveModifiedDocuments(documentsForEditors(acceptedEditors), &cancelled);
|
QList<IDocument*> list = DocumentManager::saveModifiedDocuments(acceptedDocuments.toList(), &cancelled);
|
||||||
if (cancelled)
|
if (cancelled)
|
||||||
return false;
|
return false;
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
closingFailed = true;
|
closingFailed = true;
|
||||||
QSet<IEditor*> skipSet = editorsForDocuments(list).toSet();
|
acceptedDocuments.subtract(list.toSet());
|
||||||
acceptedEditors = acceptedEditors.toSet().subtract(skipSet).toList();
|
QSet<IEditor*> skipSet = d->m_editorModel->editorsForDocuments(list).toSet();
|
||||||
|
acceptedEditors = acceptedEditors.subtract(skipSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (acceptedEditors.isEmpty())
|
if (acceptedEditors.isEmpty())
|
||||||
@@ -1120,12 +1093,6 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
// close Editor History list
|
// close Editor History list
|
||||||
windowPopup()->setVisible(false);
|
windowPopup()->setVisible(false);
|
||||||
|
|
||||||
// add duplicates
|
|
||||||
QList<IEditor *> duplicates;
|
|
||||||
foreach (IEditor *editor, acceptedEditors)
|
|
||||||
duplicates += d->m_editorModel->duplicatesFor(editor);
|
|
||||||
acceptedEditors += duplicates;
|
|
||||||
|
|
||||||
QList<EditorView*> closedViews;
|
QList<EditorView*> closedViews;
|
||||||
|
|
||||||
// remove the editors
|
// remove the editors
|
||||||
@@ -1168,14 +1135,18 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
activateEditorForEntry(view, entry, flags);
|
activateEditorForEntry(view, entry, flags);
|
||||||
} else {
|
} else {
|
||||||
const QList<IEditor *> editors = d->m_editorModel->editors();
|
// no "restored" ones, so any entry left should have a document
|
||||||
if (!editors.isEmpty())
|
const QList<OpenEditorsModel::Entry *> documents = d->m_editorModel->entries();
|
||||||
activateEditor(view, editors.last(), flags);
|
if (!documents.isEmpty()) {
|
||||||
|
IDocument *document = documents.last()->document;
|
||||||
|
if (document)
|
||||||
|
activateEditorForDocument(view, document, flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit editorsClosed(acceptedEditors);
|
emit editorsClosed(acceptedEditors.toList());
|
||||||
|
|
||||||
foreach (IEditor *editor, acceptedEditors) {
|
foreach (IEditor *editor, acceptedEditors) {
|
||||||
delete editor;
|
delete editor;
|
||||||
@@ -1197,50 +1168,6 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
return !closingFailed;
|
return !closingFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::closeDuplicate(Core::IEditor *editor)
|
|
||||||
{
|
|
||||||
|
|
||||||
IEditor *original = editor;
|
|
||||||
if (d->m_editorModel->isDuplicate(editor))
|
|
||||||
original= d->m_editorModel->originalForDuplicate(editor);
|
|
||||||
QList<IEditor *> duplicates = d->m_editorModel->duplicatesFor(original);
|
|
||||||
|
|
||||||
if (duplicates.isEmpty()) {
|
|
||||||
closeEditor(editor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (original== editor)
|
|
||||||
d->m_editorModel->makeOriginal(duplicates.first());
|
|
||||||
|
|
||||||
EditorView *currentView = currentEditorView();
|
|
||||||
|
|
||||||
emit editorAboutToClose(editor);
|
|
||||||
|
|
||||||
if (EditorView *view = viewForEditor(editor)) {
|
|
||||||
removeEditor(editor);
|
|
||||||
view->removeEditor(editor);
|
|
||||||
|
|
||||||
IEditor *newCurrent = view->currentEditor();
|
|
||||||
if (!newCurrent)
|
|
||||||
newCurrent = pickUnusedEditor();
|
|
||||||
if (newCurrent) {
|
|
||||||
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
|
||||||
} else {
|
|
||||||
OpenEditorsModel::Entry *entry = d->m_editorModel->firstRestoredEditor();
|
|
||||||
if (entry)
|
|
||||||
activateEditorForEntry(view, entry, DoNotChangeCurrentEditor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
emit editorsClosed(QList<IEditor*>() << editor);
|
|
||||||
delete editor;
|
|
||||||
if (currentView) {
|
|
||||||
if (IEditor *currentEditor = currentView->currentEditor())
|
|
||||||
activateEditor(currentView, currentEditor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::IEditor *EditorManager::pickUnusedEditor() const
|
Core::IEditor *EditorManager::pickUnusedEditor() const
|
||||||
{
|
{
|
||||||
foreach (IEditor *editor, openedEditors()) {
|
foreach (IEditor *editor, openedEditors()) {
|
||||||
@@ -1265,9 +1192,9 @@ void EditorManager::activateEditorForEntry(Internal::EditorView *view, OpenEdito
|
|||||||
setCurrentEditor(0);
|
setCurrentEditor(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IEditor *editor = entry->editor;
|
IDocument *document = entry->document;
|
||||||
if (editor) {
|
if (document) {
|
||||||
activateEditor(view, editor, flags);
|
activateEditorForDocument(view, document, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1298,6 +1225,7 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
|
|||||||
bool duplicateSupported = editor->duplicateSupported();
|
bool duplicateSupported = editor->duplicateSupported();
|
||||||
if (EditorView *sourceView = viewForEditor(editor)) {
|
if (EditorView *sourceView = viewForEditor(editor)) {
|
||||||
if (editor != sourceView->currentEditor() || !duplicateSupported) {
|
if (editor != sourceView->currentEditor() || !duplicateSupported) {
|
||||||
|
// pull the IEditor over to the new view
|
||||||
sourceView->removeEditor(editor);
|
sourceView->removeEditor(editor);
|
||||||
view->addEditor(editor);
|
view->addEditor(editor);
|
||||||
view->setCurrentEditor(editor);
|
view->setCurrentEditor(editor);
|
||||||
@@ -1309,7 +1237,6 @@ Core::IEditor *EditorManager::placeEditor(Core::Internal::EditorView *view, Core
|
|||||||
} else if (duplicateSupported) {
|
} else if (duplicateSupported) {
|
||||||
editor = duplicateEditor(editor);
|
editor = duplicateEditor(editor);
|
||||||
Q_ASSERT(editor);
|
Q_ASSERT(editor);
|
||||||
d->m_editorModel->makeOriginal(editor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
view->addEditor(editor);
|
view->addEditor(editor);
|
||||||
@@ -1475,14 +1402,15 @@ IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName
|
|||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
|
void EditorManager::addEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
ICore::addContextObject(editor);
|
ICore::addContextObject(editor);
|
||||||
|
|
||||||
d->m_editorModel->addEditor(editor, isDuplicate);
|
bool isNewDocument = false;
|
||||||
if (!isDuplicate) {
|
d->m_editorModel->addEditor(editor, &isNewDocument);
|
||||||
|
if (isNewDocument) {
|
||||||
const bool isTemporary = editor->isTemporary();
|
const bool isTemporary = editor->isTemporary();
|
||||||
const bool addWatcher = !isTemporary;
|
const bool addWatcher = !isTemporary;
|
||||||
DocumentManager::addDocument(editor->document(), addWatcher);
|
DocumentManager::addDocument(editor->document(), addWatcher);
|
||||||
@@ -2035,14 +1963,14 @@ void EditorManager::updateMakeWritableWarning()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::setupSaveActions(IEditor *editor, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction)
|
void EditorManager::setupSaveActions(IDocument *document, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction)
|
||||||
{
|
{
|
||||||
saveAction->setEnabled(editor != 0 && editor->document()->isModified());
|
saveAction->setEnabled(document != 0 && document->isModified());
|
||||||
saveAsAction->setEnabled(editor != 0 && editor->document()->isSaveAsAllowed());
|
saveAsAction->setEnabled(document != 0 && document->isSaveAsAllowed());
|
||||||
revertToSavedAction->setEnabled(editor != 0
|
revertToSavedAction->setEnabled(document != 0
|
||||||
&& !editor->document()->filePath().isEmpty() && editor->document()->isModified());
|
&& !document->filePath().isEmpty() && document->isModified());
|
||||||
|
|
||||||
const QString documentName = editor ? editor->document()->displayName() : QString();
|
const QString documentName = document ? document->displayName() : QString();
|
||||||
QString quotedName;
|
QString quotedName;
|
||||||
|
|
||||||
if (!documentName.isEmpty()) {
|
if (!documentName.isEmpty()) {
|
||||||
@@ -2056,11 +1984,12 @@ void EditorManager::setupSaveActions(IEditor *editor, QAction *saveAction, QActi
|
|||||||
void EditorManager::updateActions()
|
void EditorManager::updateActions()
|
||||||
{
|
{
|
||||||
IEditor *curEditor = currentEditor();
|
IEditor *curEditor = currentEditor();
|
||||||
|
IDocument *curDocument = curEditor ? curEditor->document() : 0;
|
||||||
int openedCount = d->m_editorModel->openDocumentCount();
|
int openedCount = d->m_editorModel->openDocumentCount();
|
||||||
|
|
||||||
if (curEditor) {
|
if (curDocument) {
|
||||||
if (HostOsInfo::isMacHost())
|
if (HostOsInfo::isMacHost())
|
||||||
window()->setWindowModified(curEditor->document()->isModified());
|
window()->setWindowModified(curDocument->isModified());
|
||||||
updateMakeWritableWarning();
|
updateMakeWritableWarning();
|
||||||
} else /* curEditor */ if (HostOsInfo::isMacHost()) {
|
} else /* curEditor */ if (HostOsInfo::isMacHost()) {
|
||||||
window()->setWindowModified(false);
|
window()->setWindowModified(false);
|
||||||
@@ -2070,11 +1999,11 @@ void EditorManager::updateActions()
|
|||||||
setCloseSplitEnabled(root, root->isSplitter());
|
setCloseSplitEnabled(root, root->isSplitter());
|
||||||
|
|
||||||
QString quotedName;
|
QString quotedName;
|
||||||
if (curEditor)
|
if (curDocument)
|
||||||
quotedName = QLatin1Char('"') + curEditor->document()->displayName() + QLatin1Char('"');
|
quotedName = QLatin1Char('"') + curDocument->displayName() + QLatin1Char('"');
|
||||||
setupSaveActions(curEditor, d->m_saveAction, d->m_saveAsAction, d->m_revertToSavedAction);
|
setupSaveActions(curDocument, d->m_saveAction, d->m_saveAsAction, d->m_revertToSavedAction);
|
||||||
|
|
||||||
d->m_closeCurrentEditorAction->setEnabled(curEditor != 0);
|
d->m_closeCurrentEditorAction->setEnabled(curDocument);
|
||||||
d->m_closeCurrentEditorAction->setText(tr("Close %1").arg(quotedName));
|
d->m_closeCurrentEditorAction->setText(tr("Close %1").arg(quotedName));
|
||||||
d->m_closeAllEditorsAction->setEnabled(openedCount > 0);
|
d->m_closeAllEditorsAction->setEnabled(openedCount > 0);
|
||||||
d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
|
d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
|
||||||
@@ -2139,9 +2068,10 @@ QList<IEditor*> EditorManager::visibleEditors() const
|
|||||||
return editors;
|
return editors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO code using this should probably better use OpenEditorsModel
|
||||||
QList<IEditor*> EditorManager::openedEditors() const
|
QList<IEditor*> EditorManager::openedEditors() const
|
||||||
{
|
{
|
||||||
return d->m_editorModel->editors();
|
return d->m_editorModel->oneEditorForEachDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenEditorsModel *EditorManager::openedEditorsModel() const
|
OpenEditorsModel *EditorManager::openedEditorsModel() const
|
||||||
@@ -2232,15 +2162,22 @@ QByteArray EditorManager::saveState() const
|
|||||||
QList<OpenEditorsModel::Entry *> entries = d->m_editorModel->entries();
|
QList<OpenEditorsModel::Entry *> entries = d->m_editorModel->entries();
|
||||||
int entriesCount = 0;
|
int entriesCount = 0;
|
||||||
foreach (OpenEditorsModel::Entry *entry, entries) {
|
foreach (OpenEditorsModel::Entry *entry, entries) {
|
||||||
|
// TODO: isTemporary should move to IDocument
|
||||||
|
IEditor *editor = entry->document
|
||||||
|
? d->m_editorModel->editorsForDocument(entry->document).first()
|
||||||
|
: 0;
|
||||||
// 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 (!editor || !editor->isTemporary())
|
||||||
++entriesCount;
|
++entriesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << entriesCount;
|
stream << entriesCount;
|
||||||
|
|
||||||
foreach (OpenEditorsModel::Entry *entry, entries) {
|
foreach (OpenEditorsModel::Entry *entry, entries) {
|
||||||
if (!entry->editor || !entry->editor->isTemporary())
|
IEditor *editor = entry->document
|
||||||
|
? d->m_editorModel->editorsForDocument(entry->document).first()
|
||||||
|
: 0;
|
||||||
|
if (!editor || !editor->isTemporary())
|
||||||
stream << entry->fileName() << entry->displayName() << entry->id();
|
stream << entry->fileName() << entry->displayName() << entry->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2352,17 +2289,18 @@ void EditorManager::readSettings()
|
|||||||
|
|
||||||
void EditorManager::revertToSaved()
|
void EditorManager::revertToSaved()
|
||||||
{
|
{
|
||||||
revertToSaved(currentEditor());
|
IEditor *editor = currentEditor();
|
||||||
|
revertToSaved(editor ? editor->document() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::revertToSaved(Core::IEditor *editor)
|
void EditorManager::revertToSaved(Core::IDocument *document)
|
||||||
{
|
{
|
||||||
if (!editor)
|
if (!document)
|
||||||
return;
|
return;
|
||||||
const QString fileName = editor->document()->filePath();
|
const QString fileName = document->filePath();
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
if (editor->document()->isModified()) {
|
if (document->isModified()) {
|
||||||
QMessageBox msgBox(QMessageBox::Question, tr("Revert to Saved"),
|
QMessageBox msgBox(QMessageBox::Question, tr("Revert to Saved"),
|
||||||
tr("You will lose your current changes if you proceed reverting %1.").arg(QDir::toNativeSeparators(fileName)),
|
tr("You will lose your current changes if you proceed reverting %1.").arg(QDir::toNativeSeparators(fileName)),
|
||||||
QMessageBox::Yes|QMessageBox::No, ICore::mainWindow());
|
QMessageBox::Yes|QMessageBox::No, ICore::mainWindow());
|
||||||
@@ -2375,7 +2313,7 @@ void EditorManager::revertToSaved(Core::IEditor *editor)
|
|||||||
|
|
||||||
}
|
}
|
||||||
QString errorString;
|
QString errorString;
|
||||||
if (!editor->document()->reload(&errorString, IDocument::FlagReload, IDocument::TypeContents))
|
if (!document->reload(&errorString, IDocument::FlagReload, IDocument::TypeContents))
|
||||||
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errorString);
|
QMessageBox::critical(ICore::mainWindow(), tr("File Error"), errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2444,7 +2382,7 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
|
|||||||
IEditor *duplicate = editor->duplicate(0);
|
IEditor *duplicate = editor->duplicate(0);
|
||||||
duplicate->restoreState(editor->saveState());
|
duplicate->restoreState(editor->saveState());
|
||||||
emit editorCreated(duplicate, duplicate->document()->filePath());
|
emit editorCreated(duplicate, duplicate->document()->filePath());
|
||||||
addEditor(duplicate, true);
|
addEditor(duplicate);
|
||||||
return duplicate;
|
return duplicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,9 +136,8 @@ public:
|
|||||||
|
|
||||||
OpenEditorsModel *openedEditorsModel() const;
|
OpenEditorsModel *openedEditorsModel() const;
|
||||||
void closeEditor(OpenEditorsModel::Entry *entry);
|
void closeEditor(OpenEditorsModel::Entry *entry);
|
||||||
void closeOtherEditors(IEditor *editor);
|
void closeOtherEditors(IDocument *document);
|
||||||
|
|
||||||
QList<IEditor*> editorsForDocuments(QList<IDocument *> documents) const;
|
|
||||||
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray());
|
||||||
void cutForwardNavigationHistory();
|
void cutForwardNavigationHistory();
|
||||||
|
|
||||||
@@ -203,7 +202,7 @@ public slots:
|
|||||||
bool saveDocument(Core::IDocument *documentParam = 0);
|
bool saveDocument(Core::IDocument *documentParam = 0);
|
||||||
bool saveDocumentAs(Core::IDocument *documentParam = 0);
|
bool saveDocumentAs(Core::IDocument *documentParam = 0);
|
||||||
void revertToSaved();
|
void revertToSaved();
|
||||||
void revertToSaved(Core::IEditor *editor);
|
void revertToSaved(IDocument *document);
|
||||||
void closeEditor();
|
void closeEditor();
|
||||||
void closeOtherEditors();
|
void closeOtherEditors();
|
||||||
void doEscapeKeyFocusMoveMagic();
|
void doEscapeKeyFocusMoveMagic();
|
||||||
@@ -251,9 +250,8 @@ private:
|
|||||||
virtual ~EditorManager();
|
virtual ~EditorManager();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
QList<IDocument *> documentsForEditors(QList<IEditor *> editors) const;
|
|
||||||
static IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
|
static IEditor *createEditor(const Id &id = Id(), const QString &fileName = QString());
|
||||||
void addEditor(IEditor *editor, bool isDuplicate = false);
|
void addEditor(IEditor *editor);
|
||||||
void removeEditor(IEditor *editor);
|
void removeEditor(IEditor *editor);
|
||||||
|
|
||||||
void restoreEditorState(IEditor *editor);
|
void restoreEditorState(IEditor *editor);
|
||||||
@@ -273,7 +271,6 @@ private:
|
|||||||
static Internal::SplitterOrView *findRoot(const Internal::EditorView *view, int *rootIndex = 0);
|
static Internal::SplitterOrView *findRoot(const Internal::EditorView *view, int *rootIndex = 0);
|
||||||
|
|
||||||
void closeEditor(IEditor *editor);
|
void closeEditor(IEditor *editor);
|
||||||
void closeDuplicate(IEditor *editor);
|
|
||||||
void closeView(Internal::EditorView *view);
|
void closeView(Internal::EditorView *view);
|
||||||
void emptyView(Internal::EditorView *view);
|
void emptyView(Internal::EditorView *view);
|
||||||
static void splitNewWindow(Internal::EditorView *view);
|
static void splitNewWindow(Internal::EditorView *view);
|
||||||
@@ -282,7 +279,7 @@ private:
|
|||||||
void updateAutoSave();
|
void updateAutoSave();
|
||||||
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
|
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
|
||||||
void updateMakeWritableWarning();
|
void updateMakeWritableWarning();
|
||||||
void setupSaveActions(IEditor *editor, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
|
void setupSaveActions(IDocument *document, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
|
||||||
|
|
||||||
friend class Core::Internal::MainWindow;
|
friend class Core::Internal::MainWindow;
|
||||||
friend class Core::Internal::SplitterOrView;
|
friend class Core::Internal::SplitterOrView;
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ 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_documents;
|
||||||
QList<IEditor *> m_duplicateEditors;
|
QMap<IDocument *, QList<IEditor *> > m_editors;
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenEditorsModelPrivate::OpenEditorsModelPrivate() :
|
OpenEditorsModelPrivate::OpenEditorsModelPrivate() :
|
||||||
@@ -56,7 +56,7 @@ OpenEditorsModelPrivate::OpenEditorsModelPrivate() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpenEditorsModel::Entry::Entry() :
|
OpenEditorsModel::Entry::Entry() :
|
||||||
editor(0)
|
document(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,16 +81,16 @@ QIcon OpenEditorsModel::unlockedIcon() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString OpenEditorsModel::Entry::fileName() const {
|
QString OpenEditorsModel::Entry::fileName() const {
|
||||||
return editor ? editor->document()->filePath() : m_fileName;
|
return document ? document->filePath() : m_fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OpenEditorsModel::Entry::displayName() const {
|
QString OpenEditorsModel::Entry::displayName() const {
|
||||||
return editor ? editor->document()->displayName() : m_displayName;
|
return document ? document->displayName() : m_displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Id OpenEditorsModel::Entry::id() const
|
Id OpenEditorsModel::Entry::id() const
|
||||||
{
|
{
|
||||||
return editor ? editor->id() : m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::columnCount(const QModelIndex &parent) const
|
int OpenEditorsModel::columnCount(const QModelIndex &parent) const
|
||||||
@@ -103,31 +103,32 @@ int OpenEditorsModel::columnCount(const QModelIndex &parent) const
|
|||||||
int OpenEditorsModel::rowCount(const QModelIndex &parent) const
|
int OpenEditorsModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid())
|
if (!parent.isValid())
|
||||||
return d->m_editors.count() + 1/*<no document>*/;
|
return d->m_documents.count() + 1/*<no document>*/;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor *> OpenEditorsModel::editors() const
|
// TODO remove
|
||||||
|
QList<IEditor *> OpenEditorsModel::oneEditorForEachDocument() const
|
||||||
{
|
{
|
||||||
QList<IEditor *> result;
|
QList<IEditor *> result;
|
||||||
foreach (const Entry *entry, d->m_editors)
|
QMapIterator<IDocument *, QList<IEditor *> > it(d->m_editors);
|
||||||
if (entry->editor)
|
while (it.hasNext())
|
||||||
result += entry->editor;
|
result << it.next().value().first();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::addEditor(IEditor *editor, bool isDuplicate)
|
void OpenEditorsModel::addEditor(IEditor *editor, bool *isNewDocument)
|
||||||
{
|
{
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isDuplicate) {
|
QList<IEditor *> &editorList = d->m_editors[editor->document()];
|
||||||
d->m_duplicateEditors.append(editor);
|
if (isNewDocument)
|
||||||
return;
|
*isNewDocument = editorList.isEmpty();
|
||||||
}
|
editorList << editor;
|
||||||
|
|
||||||
Entry *entry = new Entry;
|
Entry *entry = new Entry;
|
||||||
entry->editor = editor;
|
entry->document = editor->document();
|
||||||
|
entry->m_id = editor->id();
|
||||||
addEntry(entry);
|
addEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +143,9 @@ void OpenEditorsModel::addRestoredEditor(const QString &fileName, const QString
|
|||||||
|
|
||||||
OpenEditorsModel::Entry *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_documents.count(); ++i)
|
||||||
if (!d->m_editors.at(i)->editor)
|
if (!d->m_documents.at(i)->document)
|
||||||
return d->m_editors.at(i);
|
return d->m_documents.at(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,43 +153,34 @@ void OpenEditorsModel::addEntry(Entry *entry)
|
|||||||
{
|
{
|
||||||
QString fileName = entry->fileName();
|
QString fileName = entry->fileName();
|
||||||
|
|
||||||
|
// replace a non-loaded entry (aka 'restored') if possible
|
||||||
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->document && d->m_documents.at(previousIndex)->document == 0) {
|
||||||
d->m_editors[previousIndex] = entry;
|
d->m_documents[previousIndex] = entry;
|
||||||
connect(entry->editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
|
connect(entry->document, 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_documents.count(); ++index) {
|
||||||
if (displayName < d->m_editors.at(index)->displayName())
|
if (displayName < d->m_documents.at(index)->displayName())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int row = index + 1/*<no document>*/;
|
int row = index + 1/*<no document>*/;
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
d->m_editors.insert(index, entry);
|
d->m_documents.insert(index, entry);
|
||||||
if (entry->editor)
|
if (entry->document)
|
||||||
connect(entry->editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
|
connect(entry->document, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::findDocument(IDocument *document) const
|
int OpenEditorsModel::findDocument(IDocument *document) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i) {
|
for (int i = 0; i < d->m_documents.count(); ++i)
|
||||||
IEditor *editor = d->m_editors.at(i)->editor;
|
if (d->m_documents.at(i)->document == document)
|
||||||
if (editor && editor->document() == document)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int OpenEditorsModel::findEditor(IEditor *editor) const
|
|
||||||
{
|
|
||||||
for (int i = 0; i < d->m_editors.count(); ++i)
|
|
||||||
if (d->m_editors.at(i)->editor == editor)
|
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -197,8 +189,8 @@ 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_documents.count(); ++i) {
|
||||||
if (d->m_editors.at(i)->fileName() == filename)
|
if (d->m_documents.at(i)->fileName() == filename)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -206,116 +198,107 @@ int OpenEditorsModel::findFileName(const QString &filename) const
|
|||||||
|
|
||||||
void OpenEditorsModel::removeEntry(OpenEditorsModel::Entry *entry)
|
void OpenEditorsModel::removeEntry(OpenEditorsModel::Entry *entry)
|
||||||
{
|
{
|
||||||
int index = d->m_editors.indexOf(entry);
|
QTC_ASSERT(!entry->document, return); // we wouldn't know what to do with the associated editors
|
||||||
removeEditor(index);
|
int index = d->m_documents.indexOf(entry);
|
||||||
|
removeDocument(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(IEditor *editor)
|
void OpenEditorsModel::removeEditor(IEditor *editor, bool *lastOneForDocument)
|
||||||
{
|
{
|
||||||
d->m_duplicateEditors.removeAll(editor);
|
if (lastOneForDocument)
|
||||||
removeEditor(findEditor(editor));
|
*lastOneForDocument = false;
|
||||||
|
QTC_ASSERT(editor, return);
|
||||||
|
IDocument *document = editor->document();
|
||||||
|
QTC_ASSERT(d->m_editors.contains(document), return);
|
||||||
|
d->m_editors[document].removeAll(editor);
|
||||||
|
if (d->m_editors.value(document).isEmpty()) {
|
||||||
|
if (lastOneForDocument)
|
||||||
|
*lastOneForDocument = true;
|
||||||
|
d->m_editors.remove(document);
|
||||||
|
removeDocument(findDocument(document));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(const QString &fileName)
|
void OpenEditorsModel::removeDocument(const QString &fileName)
|
||||||
{
|
{
|
||||||
removeEditor(findFileName(fileName));
|
int index = findFileName(fileName);
|
||||||
|
QTC_ASSERT(!d->m_documents.at(index)->document, return); // we wouldn't know what to do with the associated editors
|
||||||
|
removeDocument(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeEditor(int idx)
|
void OpenEditorsModel::removeDocument(int idx)
|
||||||
{
|
{
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return;
|
return;
|
||||||
QTC_ASSERT(idx < d->m_editors.size(), return);
|
QTC_ASSERT(idx < d->m_documents.size(), return);
|
||||||
IEditor *editor = d->m_editors.at(idx)->editor;
|
IDocument *document = d->m_documents.at(idx)->document;
|
||||||
int row = idx + 1/*<no document>*/;
|
int row = idx + 1/*<no document>*/;
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
d->m_editors.removeAt(idx);
|
d->m_documents.removeAt(idx);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
if (editor)
|
if (document)
|
||||||
disconnect(editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
|
disconnect(document, SIGNAL(changed()), this, SLOT(itemChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::removeAllRestoredEditors()
|
void OpenEditorsModel::removeAllRestoredEditors()
|
||||||
{
|
{
|
||||||
for (int i = d->m_editors.count()-1; i >= 0; --i) {
|
for (int i = d->m_documents.count()-1; i >= 0; --i) {
|
||||||
if (!d->m_editors.at(i)->editor) {
|
if (!d->m_documents.at(i)->document) {
|
||||||
int row = i + 1/*<no document>*/;
|
int row = i + 1/*<no document>*/;
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
d->m_editors.removeAt(i);
|
d->m_documents.removeAt(i);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenEditorsModel::isDuplicate(IEditor *editor) const
|
QList<IEditor *> OpenEditorsModel::editorsForDocument(IDocument *document) const
|
||||||
{
|
{
|
||||||
return editor && d->m_duplicateEditors.contains(editor);
|
return d->m_editors.value(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEditor *OpenEditorsModel::originalForDuplicate(IEditor *duplicate) const
|
QList<IEditor *> OpenEditorsModel::editorsForDocuments(const QList<IDocument *> &documents) const
|
||||||
{
|
|
||||||
IDocument *document = duplicate->document();
|
|
||||||
foreach (const Entry *e, d->m_editors)
|
|
||||||
if (e->editor && e->editor->document() == document)
|
|
||||||
return e->editor;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<IEditor *> OpenEditorsModel::duplicatesFor(IEditor *editor) const
|
|
||||||
{
|
{
|
||||||
QList<IEditor *> result;
|
QList<IEditor *> result;
|
||||||
IDocument *document = editor->document();
|
foreach (IDocument *document, documents)
|
||||||
foreach (IEditor *e, d->m_duplicateEditors)
|
result += d->m_editors.value(document);
|
||||||
if (e->document() == document)
|
|
||||||
result += e;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::makeOriginal(IEditor *duplicate)
|
int OpenEditorsModel::indexOfDocument(IDocument *document) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(duplicate && isDuplicate(duplicate));
|
if (!document)
|
||||||
IEditor *original = originalForDuplicate(duplicate);
|
|
||||||
Q_ASSERT(original);
|
|
||||||
int i = findEditor(original);
|
|
||||||
d->m_editors[i]->editor = duplicate;
|
|
||||||
d->m_duplicateEditors.removeOne(duplicate);
|
|
||||||
d->m_duplicateEditors.append(original);
|
|
||||||
}
|
|
||||||
|
|
||||||
int OpenEditorsModel::indexOfEditor(IEditor *editor) const
|
|
||||||
{
|
|
||||||
if (!editor)
|
|
||||||
return -1;
|
return -1;
|
||||||
return findEditor(editor);
|
return findDocument(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
if (column < 0 || column > 1 || row < 0 || row >= d->m_editors.count() + 1/*<no document>*/)
|
if (column < 0 || column > 1 || row < 0 || row >= d->m_documents.count() + 1/*<no document>*/)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
return createIndex(row, column);
|
return createIndex(row, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenEditorsModel::Entry *OpenEditorsModel::entryAtRow(int row) const
|
OpenEditorsModel::Entry *OpenEditorsModel::entryAtRow(int row) const
|
||||||
{
|
{
|
||||||
int editorIndex = row - 1/*<no document>*/;
|
int entryIndex = row - 1/*<no document>*/;
|
||||||
if (editorIndex < 0)
|
if (entryIndex < 0)
|
||||||
return 0;
|
return 0;
|
||||||
return d->m_editors[editorIndex];
|
return d->m_documents[entryIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::openDocumentCount() const
|
int OpenEditorsModel::openDocumentCount() const
|
||||||
{
|
{
|
||||||
return d->m_editors.count();
|
return d->m_documents.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
|
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();
|
||||||
int editorIndex = index.row() - 1/*<no document>*/;
|
int entryIndex = index.row() - 1/*<no document>*/;
|
||||||
if (editorIndex < 0) {
|
if (entryIndex < 0) {
|
||||||
// <no document> entry
|
// <no document> entry
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
@@ -326,19 +309,19 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const Entry *e = d->m_editors.at(editorIndex);
|
const Entry *e = d->m_documents.at(entryIndex);
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return (e->editor && e->editor->document()->isModified())
|
return (e->document && e->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->document) {
|
||||||
showLock = e->editor->document()->filePath().isEmpty()
|
showLock = e->document->filePath().isEmpty()
|
||||||
? false
|
? false
|
||||||
: e->editor->document()->isFileReadOnly();
|
: e->document->isFileReadOnly();
|
||||||
} else {
|
} else {
|
||||||
showLock = !QFileInfo(e->m_fileName).isWritable();
|
showLock = !QFileInfo(e->m_fileName).isWritable();
|
||||||
}
|
}
|
||||||
@@ -348,23 +331,17 @@ QVariant OpenEditorsModel::data(const QModelIndex &index, int role) const
|
|||||||
return e->fileName().isEmpty()
|
return e->fileName().isEmpty()
|
||||||
? e->displayName()
|
? e->displayName()
|
||||||
: QDir::toNativeSeparators(e->fileName());
|
: QDir::toNativeSeparators(e->fileName());
|
||||||
case Qt::UserRole:
|
|
||||||
return qVariantFromValue(e->editor);
|
|
||||||
case Qt::UserRole + 1:
|
|
||||||
return e->fileName();
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
return QVariant::fromValue(e->editor ? Core::Id(e->editor->id()) : e->id());
|
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
int OpenEditorsModel::rowOfEditor(IEditor *editor) const
|
int OpenEditorsModel::rowOfDocument(IDocument *document) const
|
||||||
{
|
{
|
||||||
if (!editor)
|
if (!document)
|
||||||
return 0 /*<no document>*/;
|
return 0 /*<no document>*/;
|
||||||
return findEditor(originalForDuplicate(editor)) + 1/*<no document>*/;
|
return findDocument(document) + 1/*<no document>*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenEditorsModel::itemChanged()
|
void OpenEditorsModel::itemChanged()
|
||||||
@@ -380,7 +357,7 @@ void OpenEditorsModel::itemChanged()
|
|||||||
|
|
||||||
QList<OpenEditorsModel::Entry *> OpenEditorsModel::entries() const
|
QList<OpenEditorsModel::Entry *> OpenEditorsModel::entries() const
|
||||||
{
|
{
|
||||||
return d->m_editors;
|
return d->m_documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
|
|
||||||
struct CORE_EXPORT Entry {
|
struct CORE_EXPORT Entry {
|
||||||
Entry();
|
Entry();
|
||||||
IEditor *editor;
|
IDocument *document;
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
Id id() const;
|
Id id() const;
|
||||||
@@ -72,38 +72,34 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Entry *entryAtRow(int row) const;
|
Entry *entryAtRow(int row) const;
|
||||||
int rowOfEditor(IEditor *editor) const;
|
int rowOfDocument(IDocument *document) const;
|
||||||
|
|
||||||
int openDocumentCount() 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;
|
QList<Entry *> entries() const;
|
||||||
|
|
||||||
|
QList<IEditor *> editorsForDocument(IDocument *document) const;
|
||||||
|
QList<IEditor *> editorsForDocuments(const QList<IDocument *> &documents) const;
|
||||||
|
QList<IEditor *> oneEditorForEachDocument() const;
|
||||||
|
int indexOfDocument(IDocument *document) const;
|
||||||
|
|
||||||
|
// editor manager related methods, nobody else should call it
|
||||||
|
void addEditor(IEditor *editor, bool *isNewDocument);
|
||||||
|
void addRestoredEditor(const QString &fileName, const QString &displayName, const Id &id);
|
||||||
|
Entry *firstRestoredEditor() const;
|
||||||
void removeEntry(Entry *entry);
|
void removeEntry(Entry *entry);
|
||||||
void removeEditor(IEditor *editor);
|
void removeEditor(IEditor *editor, bool *lastOneForDocument);
|
||||||
void removeEditor(const QString &fileName);
|
void removeDocument(const QString &fileName);
|
||||||
|
|
||||||
void removeAllRestoredEditors();
|
void removeAllRestoredEditors();
|
||||||
|
|
||||||
QList<IEditor *> editors() const;
|
|
||||||
bool isDuplicate(IEditor *editor) const;
|
|
||||||
QList<IEditor *> duplicatesFor(IEditor *editor) const;
|
|
||||||
IEditor *originalForDuplicate(IEditor *duplicate) const;
|
|
||||||
void makeOriginal(IEditor *duplicate);
|
|
||||||
int indexOfEditor(IEditor *editor) const;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itemChanged();
|
void itemChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addEntry(Entry *entry);
|
void addEntry(Entry *entry);
|
||||||
int findDocument(IDocument *document) const;
|
int findDocument(IDocument *document) const;
|
||||||
int findEditor(IEditor *editor) const;
|
|
||||||
int findFileName(const QString &filename) const;
|
int findFileName(const QString &filename) const;
|
||||||
void removeEditor(int idx);
|
void removeDocument(int idx);
|
||||||
|
|
||||||
OpenEditorsModelPrivate *d;
|
OpenEditorsModelPrivate *d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "openeditorsview.h"
|
#include "openeditorsview.h"
|
||||||
#include "editormanager.h"
|
#include "editormanager.h"
|
||||||
|
#include "ieditor.h"
|
||||||
#include "openeditorsmodel.h"
|
#include "openeditorsmodel.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -126,8 +127,9 @@ OpenEditorsWidget::~OpenEditorsWidget()
|
|||||||
|
|
||||||
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
|
void OpenEditorsWidget::updateCurrentItem(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
|
IDocument *document = editor ? editor->document() : 0;
|
||||||
EditorManager *em = EditorManager::instance();
|
EditorManager *em = EditorManager::instance();
|
||||||
QModelIndex index = m_model->index(em->openedEditorsModel()->indexOfEditor(editor), 0);
|
QModelIndex index = m_model->index(em->openedEditorsModel()->indexOfDocument(document), 0);
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ void OpenEditorsWindow::setEditors(const QList<EditLocation> &globalHistory, Edi
|
|||||||
|
|
||||||
// add purely restored editors which are not initialised yet
|
// add purely restored editors which are not initialised yet
|
||||||
foreach (OpenEditorsModel::Entry *entry, model->entries()) {
|
foreach (OpenEditorsModel::Entry *entry, model->entries()) {
|
||||||
if (entry->editor)
|
if (entry->document)
|
||||||
continue;
|
continue;
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
QString title = entry->displayName();
|
QString title = entry->displayName();
|
||||||
@@ -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()->openedEditorsModel()->removeEditor(item->toolTip(0));
|
EditorManager::instance()->openedEditorsModel()->removeDocument(item->toolTip(0));
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,7 +290,8 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
|||||||
|
|
||||||
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
void EditorToolBar::setCurrentEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfEditor(editor));
|
IDocument *document = editor ? editor->document() : 0;
|
||||||
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(document));
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -303,7 +304,7 @@ 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->rowOfEditor(newSelection));
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(newSelection->document()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorToolBar::changeActiveEditor(int row)
|
void EditorToolBar::changeActiveEditor(int row)
|
||||||
@@ -375,7 +376,7 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfEditor(editor));
|
d->m_editorList->setCurrentIndex(d->m_editorsListModel->rowOfDocument(editor->document()));
|
||||||
|
|
||||||
if (editor->document()->filePath().isEmpty()) {
|
if (editor->document()->filePath().isEmpty()) {
|
||||||
d->m_lockButton->setIcon(QIcon());
|
d->m_lockButton->setIcon(QIcon());
|
||||||
|
|||||||
@@ -1999,7 +1999,9 @@ int FakeVimPluginPrivate::currentFile() const
|
|||||||
{
|
{
|
||||||
OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel();
|
OpenEditorsModel *model = EditorManager::instance()->openedEditorsModel();
|
||||||
IEditor *editor = EditorManager::currentEditor();
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
return model->indexOfEditor(editor);
|
if (!editor)
|
||||||
|
return -1;
|
||||||
|
return model->indexOfDocument(editor->document());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::switchToFile(int n)
|
void FakeVimPluginPrivate::switchToFile(int n)
|
||||||
|
|||||||
Reference in New Issue
Block a user