diff options
author | Eike Ziller <eike.ziller@nokia.com> | 2012-04-05 18:24:26 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@nokia.com> | 2012-04-05 18:24:26 +0200 |
commit | 9ec6e9f7e094eee2eb55c777332c33b7a99f11f0 (patch) | |
tree | 81066a933a52f1988f9cab7d574d2123803846d9 /src/plugins | |
parent | e6565936e0b820e073927b64a28f9b4c621dbeaa (diff) | |
parent | f521c9f0628fc89ddc41a1584d65369f9c07a2f3 (diff) | |
download | qt-creator-9ec6e9f7e094eee2eb55c777332c33b7a99f11f0.tar.gz |
Merge remote-tracking branch 'origin/2.5'
Diffstat (limited to 'src/plugins')
30 files changed, 260 insertions, 66 deletions
diff --git a/src/plugins/QtcPlugin.qbs b/src/plugins/QtcPlugin.qbs index 4f5d0b5194..8d4ca84bb1 100644 --- a/src/plugins/QtcPlugin.qbs +++ b/src/plugins/QtcPlugin.qbs @@ -3,7 +3,8 @@ import qbs.fileinfo 1.0 as FileInfo Product { type: ["dynamiclibrary", "pluginSpec"] - destination: "lib/qtcreator/plugins/Nokia" + property string provider: 'Nokia' + destination: "lib/qtcreator/plugins/" + provider targetName: { // see PluginSpecPrivate::loadLibrary() if (qbs.debugInformation) { diff --git a/src/plugins/bookmarks/bookmark.cpp b/src/plugins/bookmarks/bookmark.cpp index 4de678563d..45fb4bdee3 100644 --- a/src/plugins/bookmarks/bookmark.cpp +++ b/src/plugins/bookmarks/bookmark.cpp @@ -70,6 +70,16 @@ void Bookmark::updateBlock(const QTextBlock &block) } } +void Bookmark::updateFileName(const QString &fileName) +{ + m_fileName = fileName; + QFileInfo fi(fileName); + m_onlyFile = fi.fileName(); + m_path = fi.path(); + m_manager->updateBookmark(this); + BaseTextMark::updateFileName(fileName); +} + QString Bookmark::lineText() const { return m_lineText; diff --git a/src/plugins/bookmarks/bookmark.h b/src/plugins/bookmarks/bookmark.h index 62d55f7d1b..f26a66920f 100644 --- a/src/plugins/bookmarks/bookmark.h +++ b/src/plugins/bookmarks/bookmark.h @@ -54,6 +54,7 @@ public: void updateLineNumber(int lineNumber); void updateBlock(const QTextBlock &block); + void updateFileName(const QString &fileName); void removedFromEditor(); QString filePath() const; @@ -63,7 +64,7 @@ public: private: BookmarkManager *m_manager; - const QString m_fileName; + QString m_fileName; QString m_onlyFile; QString m_path; QString m_lineText; diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index 878c2fb612..9828859f9f 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -294,6 +294,7 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add foreach (IDocument *document, documents) { if (document && !d->m_documentsWithoutWatch.contains(document)) { connect(document, SIGNAL(destroyed(QObject*)), m_instance, SLOT(documentDestroyed(QObject*))); + connect(document, SIGNAL(fileNameChanged(QString,QString)), m_instance, SLOT(fileNameChanged(QString, QString))); d->m_documentsWithoutWatch.append(document); } } @@ -304,6 +305,7 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add if (document && !d->m_documentsWithWatch.contains(document)) { connect(document, SIGNAL(changed()), m_instance, SLOT(checkForNewFileName())); connect(document, SIGNAL(destroyed(QObject*)), m_instance, SLOT(documentDestroyed(QObject*))); + connect(document, SIGNAL(fileNameChanged(QString,QString)), m_instance, SLOT(fileNameChanged(QString, QString))); addFileInfo(document); } } @@ -398,7 +400,18 @@ void DocumentManager::renamedFile(const QString &from, const QString &to) addFileInfo(document); d->m_blockedIDocument = 0; } + emit m_instance->allDocumentsRenamed(from, to); } + +void DocumentManager::fileNameChanged(const QString &oldName, const QString &newName) +{ + IDocument *doc = qobject_cast<IDocument *>(sender()); + QTC_ASSERT(doc, return); + if (doc == d->m_blockedIDocument) + return; + emit m_instance->documentRenamed(doc, oldName, newName); +} + /*! \fn bool DocumentManager::addFile(IDocument *document, bool addWatcher) diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index 7f59e50ecd..23451720e2 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -148,9 +148,14 @@ signals: /* Used to notify e.g. the code model to update the given files. Does *not* lead to any editors to reload or any other editor manager actions. */ void filesChangedInternally(const QStringList &files); + /// emitted if all documents changed their name e.g. due to the file changing on disk + void allDocumentsRenamed(const QString &from, const QString &to); + /// emitted if one document changed its name e.g. due to save as + void documentRenamed(Core::IDocument *document, const QString &from, const QString &to); private slots: void documentDestroyed(QObject *obj); + void fileNameChanged(const QString &oldName, const QString &newName); void checkForNewFileName(); void checkForReload(); void changedFile(const QString &file); diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h index 8a2716d398..f3048276b1 100644 --- a/src/plugins/coreplugin/idocument.h +++ b/src/plugins/coreplugin/idocument.h @@ -116,6 +116,7 @@ signals: void aboutToReload(); void reloaded(); + void fileNameChanged(const QString &oldName, const QString &newName); private: QString m_autoSaveName; diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index 6e892b54b0..3ea1664955 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -1223,6 +1223,14 @@ void BreakHandler::gotoLocation(BreakpointModelId id) const } } +void BreakHandler::updateFileNameFromMarker(BreakpointModelId id, const QString &fileName) +{ + Iterator it = m_storage.find(id); + BREAK_ASSERT(it != m_storage.end(), return); + it->data.fileName = fileName; + emit layoutChanged(); +} + void BreakHandler::updateLineNumberFromMarker(BreakpointModelId id, int lineNumber) { Iterator it = m_storage.find(id); diff --git a/src/plugins/debugger/breakhandler.h b/src/plugins/debugger/breakhandler.h index 04475bc80d..d212b6d9ab 100644 --- a/src/plugins/debugger/breakhandler.h +++ b/src/plugins/debugger/breakhandler.h @@ -134,6 +134,7 @@ public: BreakpointState state(BreakpointModelId id) const; bool isEnabled(BreakpointModelId id) const; void setEnabled(BreakpointModelId id, bool on); + void updateFileNameFromMarker(BreakpointModelId id, const QString &fileName); void updateLineNumberFromMarker(BreakpointModelId id, int lineNumber); void setMarkerFileAndLine(BreakpointModelId id, const QString &fileName, int lineNumber); diff --git a/src/plugins/debugger/breakpointmarker.cpp b/src/plugins/debugger/breakpointmarker.cpp index 214184f9a6..6cac5a37c2 100644 --- a/src/plugins/debugger/breakpointmarker.cpp +++ b/src/plugins/debugger/breakpointmarker.cpp @@ -71,6 +71,12 @@ void BreakpointMarker::updateLineNumber(int lineNumber) breakHandler()->updateLineNumberFromMarker(m_id, lineNumber); } +void BreakpointMarker::updateFileName(const QString &fileName) +{ + BaseTextMark::updateFileName(fileName); + breakHandler()->updateFileNameFromMarker(m_id, fileName); +} + } // namespace Internal } // namespace Debugger diff --git a/src/plugins/debugger/breakpointmarker.h b/src/plugins/debugger/breakpointmarker.h index 4101e7414d..432f59b3cd 100644 --- a/src/plugins/debugger/breakpointmarker.h +++ b/src/plugins/debugger/breakpointmarker.h @@ -48,6 +48,7 @@ public: ~BreakpointMarker(); void removedFromEditor(); void updateLineNumber(int lineNumber); + void updateFileName(const QString &fileName); private: BreakpointModelId m_id; diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index 0b05e675ed..eea63511e8 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -104,9 +104,11 @@ bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSa return false; } + const QString oldFileName = m_fileName; m_fileName = fi.absoluteFilePath(); emit setDisplayName(fi.fileName()); m_formWindow->setDirty(false); + emit fileNameChanged(oldFileName, m_fileName); emit changed(); emit saved(); @@ -117,8 +119,10 @@ void FormWindowFile::rename(const QString &newName) { m_formWindow->setFileName(newName); QFileInfo fi(newName); + const QString oldFileName = m_fileName; m_fileName = fi.absoluteFilePath(); emit setDisplayName(fi.fileName()); + emit fileNameChanged(oldFileName, m_fileName); emit changed(); } diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp index c332af750f..d54cbdce6c 100644 --- a/src/plugins/imageviewer/imageviewerfile.cpp +++ b/src/plugins/imageviewer/imageviewerfile.cpp @@ -97,8 +97,10 @@ bool ImageViewerFile::save(QString *errorString, const QString &fileName, bool a void ImageViewerFile::rename(const QString &newName) { + const QString oldFilename = d->fileName; d->fileName = newName; d->editor->setDisplayName(QFileInfo(d->fileName).fileName()); + emit fileNameChanged(oldFilename, newName); emit changed(); } diff --git a/src/plugins/projectexplorer/taskhub.cpp b/src/plugins/projectexplorer/taskhub.cpp index 613911330f..39ce6a4bd1 100644 --- a/src/plugins/projectexplorer/taskhub.cpp +++ b/src/plugins/projectexplorer/taskhub.cpp @@ -48,6 +48,7 @@ public: bool clickable() const; void clicked(); + void updateFileName(const QString &fileName); void updateLineNumber(int lineNumber); void removedFromEditor(); bool visible() const; @@ -62,6 +63,12 @@ void TaskMark::updateLineNumber(int lineNumber) BaseTextMark::updateLineNumber(lineNumber); } +void TaskMark::updateFileName(const QString &fileName) +{ + ProjectExplorerPlugin::instance()->taskHub()->updateTaskFileName(m_id, fileName); + BaseTextMark::updateFileName(fileName); +} + void TaskMark::removedFromEditor() { ProjectExplorerPlugin::instance()->taskHub()->updateTaskLineNumber(m_id, -1); @@ -122,6 +129,11 @@ void TaskHub::removeTask(const Task &task) emit taskRemoved(task); } +void TaskHub::updateTaskFileName(unsigned int id, const QString &fileName) +{ + emit taskFileNameUpdated(id, fileName); +} + void TaskHub::updateTaskLineNumber(unsigned int id, int line) { emit taskLineNumberUpdated(id, line); diff --git a/src/plugins/projectexplorer/taskhub.h b/src/plugins/projectexplorer/taskhub.h index cdfce583d5..66370c30ff 100644 --- a/src/plugins/projectexplorer/taskhub.h +++ b/src/plugins/projectexplorer/taskhub.h @@ -52,6 +52,7 @@ public: void addTask(Task task); void clearTasks(const Core::Id &categoryId = Core::Id()); void removeTask(const Task &task); + void updateTaskFileName(unsigned int id, const QString &fileName); void updateTaskLineNumber(unsigned int id, int line); void taskMarkClicked(unsigned int id); void showTaskInEditor(unsigned int id); @@ -66,6 +67,7 @@ signals: void taskAdded(const ProjectExplorer::Task &task); void taskRemoved(const ProjectExplorer::Task &task); void tasksCleared(const Core::Id &categoryId); + void taskFileNameUpdated(unsigned int id, const QString &fileName); void taskLineNumberUpdated(unsigned int id, int line); void categoryVisibilityChanged(const Core::Id &categoryId, bool visible); void popupRequested(bool withFocus); diff --git a/src/plugins/projectexplorer/taskmodel.cpp b/src/plugins/projectexplorer/taskmodel.cpp index edf903ef44..94f2307f9f 100644 --- a/src/plugins/projectexplorer/taskmodel.cpp +++ b/src/plugins/projectexplorer/taskmodel.cpp @@ -156,6 +156,16 @@ int TaskModel::rowForId(unsigned int id) return it - m_tasks.constBegin(); } +void TaskModel::updateTaskFileName(unsigned int id, const QString &fileName) +{ + int i = rowForId(id); + QTC_ASSERT(i != -1, return) + if (m_tasks.at(i).taskId == id) { + m_tasks[i].file = Utils::FileName::fromString(fileName); + emit dataChanged(index(i, 0), index(i, 0)); + } +} + void TaskModel::updateTaskLineNumber(unsigned int id, int line) { int i = rowForId(id); diff --git a/src/plugins/projectexplorer/taskmodel.h b/src/plugins/projectexplorer/taskmodel.h index 017e489b6e..98e857af75 100644 --- a/src/plugins/projectexplorer/taskmodel.h +++ b/src/plugins/projectexplorer/taskmodel.h @@ -62,6 +62,7 @@ public: void addTask(const Task &task); void removeTask(const Task &task); void clearTasks(const Core::Id &categoryId = Core::Id()); + void updateTaskFileName(unsigned int id, const QString &fileName); void updateTaskLineNumber(unsigned int id, int line); int sizeOfFile(const QFont &font); diff --git a/src/plugins/projectexplorer/taskwindow.cpp b/src/plugins/projectexplorer/taskwindow.cpp index 2eeadf8b75..41dea75060 100644 --- a/src/plugins/projectexplorer/taskwindow.cpp +++ b/src/plugins/projectexplorer/taskwindow.cpp @@ -299,6 +299,8 @@ TaskWindow::TaskWindow(TaskHub *taskhub) : d(new TaskWindowPrivate) this, SLOT(removeTask(ProjectExplorer::Task))); connect(d->m_taskHub, SIGNAL(taskLineNumberUpdated(uint,int)), this, SLOT(updatedTaskLineNumber(uint,int))); + connect(d->m_taskHub, SIGNAL(taskFileNameUpdated(uint,QString)), + this, SLOT(updatedTaskFileName(uint,QString))); connect(d->m_taskHub, SIGNAL(tasksCleared(Core::Id)), this, SLOT(clearTasks(Core::Id))); connect(d->m_taskHub, SIGNAL(categoryVisibilityChanged(Core::Id,bool)), @@ -387,6 +389,12 @@ void TaskWindow::removeTask(const Task &task) navigateStateChanged(); } +void TaskWindow::updatedTaskFileName(unsigned int id, const QString &fileName) +{ + d->m_model->updateTaskFileName(id, fileName); + emit tasksChanged(); +} + void TaskWindow::updatedTaskLineNumber(unsigned int id, int line) { d->m_model->updateTaskLineNumber(id, line); diff --git a/src/plugins/projectexplorer/taskwindow.h b/src/plugins/projectexplorer/taskwindow.h index 6a077bfe63..1866d9c05a 100644 --- a/src/plugins/projectexplorer/taskwindow.h +++ b/src/plugins/projectexplorer/taskwindow.h @@ -89,6 +89,7 @@ private slots: void addCategory(const Core::Id &categoryId, const QString &displayName, bool visible); void addTask(const ProjectExplorer::Task &task); void removeTask(const ProjectExplorer::Task &task); + void updatedTaskFileName(unsigned int id, const QString &fileName); void updatedTaskLineNumber(unsigned int id, int line); void showTask(unsigned int id); void openTask(unsigned int id); diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 150a4a3ce8..33ded8d76b 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -194,7 +194,9 @@ bool ResourceEditorDocument::save(QString *errorString, const QString &name, boo void ResourceEditorDocument::rename(const QString &newName) { + const QString oldName = m_parent->m_resourceEditor->fileName(); m_parent->m_resourceEditor->setFileName(newName); + emit fileNameChanged(oldName, newName); // TODO Are there other cases where the ressource file name changes? emit changed(); } diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index 99b81191cc..22cb9fcd56 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -268,9 +268,10 @@ bool BaseTextDocument::save(QString *errorString, const QString &fileName, bool return true; const QFileInfo fi(fName); + const QString oldFileName = d->m_fileName; d->m_fileName = QDir::cleanPath(fi.absoluteFilePath()); - d->m_document->setModified(false); + emit fileNameChanged(oldFileName, d->m_fileName); emit titleChanged(fi.fileName()); emit changed(); return true; @@ -284,7 +285,9 @@ bool BaseTextDocument::shouldAutoSave() const void BaseTextDocument::rename(const QString &newName) { const QFileInfo fi(newName); + const QString oldFileName = d->m_fileName; d->m_fileName = QDir::cleanPath(fi.absoluteFilePath()); + emit fileNameChanged(oldFileName, d->m_fileName); emit titleChanged(fi.fileName()); emit changed(); } @@ -378,13 +381,17 @@ bool BaseTextDocument::reload(QString *errorString) emit aboutToReload(); BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout()); + TextMarks marks; if (documentLayout) - documentLayout->documentClosing(); // removes text marks non-permanently + marks = documentLayout->documentClosing(); // removes text marks non-permanently - if (!open(errorString, d->m_fileName, d->m_fileName)) - return false; - emit reloaded(); - return true; + bool success = open(errorString, d->m_fileName, d->m_fileName); + + if (documentLayout) + documentLayout->documentReloaded(marks); // readds text marks + if (success) + emit reloaded(); + return success; } bool BaseTextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) diff --git a/src/plugins/texteditor/basetextdocumentlayout.cpp b/src/plugins/texteditor/basetextdocumentlayout.cpp index 66ac014c9b..5378421834 100644 --- a/src/plugins/texteditor/basetextdocumentlayout.cpp +++ b/src/plugins/texteditor/basetextdocumentlayout.cpp @@ -53,6 +53,7 @@ public: void removeMark(ITextMark *mark); void updateMark(ITextMark *mark); + void removeMarkFromMarksCache(TextEditor::ITextMark *mark); private: double recalculateMaxMarkWidthFactor() const; @@ -72,6 +73,8 @@ DocumentMarker::~DocumentMarker() bool DocumentMarker::addMark(TextEditor::ITextMark *mark) { + if (mark->markableInterface()) + return false; QTC_ASSERT(mark->lineNumber() >= 1, return false); int blockNumber = mark->lineNumber() - 1; BaseTextDocumentLayout *documentLayout = @@ -90,6 +93,7 @@ bool DocumentMarker::addMark(TextEditor::ITextMark *mark) documentLayout->maxMarkWidthFactor = qMax(mark->widthFactor(), documentLayout->maxMarkWidthFactor); documentLayout->requestUpdate(); + mark->setMarkableInterface(this); return true; } return false; @@ -116,26 +120,38 @@ TextEditor::TextMarks DocumentMarker::marksAt(int line) const return TextMarks(); } +void DocumentMarker::removeMarkFromMarksCache(TextEditor::ITextMark *mark) +{ + BaseTextDocumentLayout *documentLayout = + qobject_cast<BaseTextDocumentLayout*>(document->documentLayout()); + QTC_ASSERT(documentLayout, return) + bool needUpdate = m_marksCache.removeOne(mark); + if (m_marksCache.isEmpty()) { + documentLayout->hasMarks = false; + needUpdate = true; + } + + if (needUpdate) { + documentLayout->maxMarkWidthFactor = recalculateMaxMarkWidthFactor(); + updateMark(0); + } +} + void DocumentMarker::removeMark(TextEditor::ITextMark *mark) { BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(document->documentLayout()); QTC_ASSERT(documentLayout, return) - bool needUpdate = false; QTextBlock block = document->begin(); while (block.isValid()) { if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) { - needUpdate |= data->removeMark(mark); + data->removeMark(mark); } block = block.next(); } - m_marksCache.removeAll(mark); - - if (needUpdate) { - documentLayout->maxMarkWidthFactor = recalculateMaxMarkWidthFactor(); - updateMark(0); - } + removeMarkFromMarksCache(mark); + mark->setMarkableInterface(0); } void DocumentMarker::updateMark(ITextMark *mark) @@ -159,6 +175,10 @@ TextBlockUserData::~TextBlockUserData() TextMarks marks = m_marks; m_marks.clear(); foreach (ITextMark *mrk, marks) { + TextEditor::Internal::DocumentMarker *documentMarker + = static_cast<TextEditor::Internal::DocumentMarker *>(mrk->markableInterface()); + documentMarker->removeMarkFromMarksCache(mrk); + mrk->setMarkableInterface(0); mrk->removedFromEditor(); } @@ -703,16 +723,37 @@ QSizeF BaseTextDocumentLayout::documentSize() const return size; } -void BaseTextDocumentLayout::documentClosing() +TextMarks BaseTextDocumentLayout::documentClosing() { + TextMarks marks; QTextBlock block = document()->begin(); while (block.isValid()) { if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) - data->documentClosing(); + marks.append(data->documentClosing()); block = block.next(); } + return marks; } +void BaseTextDocumentLayout::documentReloaded(TextMarks marks) +{ + foreach (ITextMark *mark, marks) { + int blockNumber = mark->lineNumber() - 1; + QTextBlock block = document()->findBlockByNumber(blockNumber); + if (block.isValid()) { + TextBlockUserData *userData = BaseTextDocumentLayout::userData(block); + userData->addMark(mark); + mark->setMarkableInterface(m_documentMarker); + mark->updateBlock(block); + } else { + TextEditor::Internal::DocumentMarker *documentMarker + = static_cast<TextEditor::Internal::DocumentMarker *>(m_documentMarker); + documentMarker->removeMarkFromMarksCache(mark); + mark->removedFromEditor(); + } + } + requestUpdate(); +} void BaseTextDocumentLayout::updateMarksLineNumber() { diff --git a/src/plugins/texteditor/basetextdocumentlayout.h b/src/plugins/texteditor/basetextdocumentlayout.h index 4f052a93b3..bed5b1863f 100644 --- a/src/plugins/texteditor/basetextdocumentlayout.h +++ b/src/plugins/texteditor/basetextdocumentlayout.h @@ -81,7 +81,13 @@ public: void addMark(ITextMark *mark); inline bool removeMark(ITextMark *mark) { return m_marks.removeAll(mark); } - inline void documentClosing() { m_marks.clear(); } + inline TextMarks documentClosing() { + TextMarks marks = m_marks; + foreach (ITextMark *mrk, m_marks) + mrk->setMarkableInterface(0); + m_marks.clear(); + return marks; + } inline void setFolded(bool b) { m_folded = b; } inline bool folded() const { return m_folded; } @@ -214,7 +220,8 @@ public: QSizeF documentSize() const; - void documentClosing(); + TextMarks documentClosing(); + void documentReloaded(TextMarks marks); void updateMarksLineNumber(); void updateMarksBlock(const QTextBlock &block); }; diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp index 9737314651..6f5898a532 100644 --- a/src/plugins/texteditor/basetextmark.cpp +++ b/src/plugins/texteditor/basetextmark.cpp @@ -36,6 +36,7 @@ #include "texteditorplugin.h" #include <coreplugin/editormanager/editormanager.h> +#include <coreplugin/documentmanager.h> #include <extensionsystem/pluginmanager.h> using namespace TextEditor; @@ -47,23 +48,23 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent) Core::EditorManager *em = Core::EditorManager::instance(); connect(em, SIGNAL(editorOpened(Core::IEditor*)), SLOT(editorOpened(Core::IEditor*))); + + Core::DocumentManager *dm = Core::DocumentManager::instance(); + connect(dm, SIGNAL(allDocumentsRenamed(QString,QString)), + this, SLOT(allDocumentsRenamed(QString,QString))); + connect(dm, SIGNAL(documentRenamed(Core::IDocument*,QString,QString)), + this, SLOT(documentRenamed(Core::IDocument*,QString,QString))); } void BaseTextMarkRegistry::add(BaseTextMark *mark) { - m_marks[Utils::FileName::fromString(mark->fileName())].append(mark); + m_marks[Utils::FileName::fromString(mark->fileName())].insert(mark); Core::EditorManager *em = Core::EditorManager::instance(); foreach (Core::IEditor *editor, em->editorsForFileName(mark->fileName())) { if (ITextEditor *textEditor = qobject_cast<ITextEditor *>(editor)) { - if (mark->m_markableInterface == 0) { // We aren't added to something - ITextMarkable *markableInterface = textEditor->markableInterface(); - if (markableInterface->addMark(mark)) { - mark->m_markableInterface = markableInterface; - // Handle reload of text documents, readding the mark as necessary - connect(textEditor->document(), SIGNAL(reloaded()), - this, SLOT(documentReloaded()), Qt::UniqueConnection); - break; - } + ITextMarkable *markableInterface = textEditor->markableInterface(); + if (markableInterface->addMark(mark)) { + break; } } } @@ -71,7 +72,7 @@ void BaseTextMarkRegistry::add(BaseTextMark *mark) void BaseTextMarkRegistry::remove(BaseTextMark *mark) { - m_marks[Utils::FileName::fromString(mark->fileName())].removeOne(mark); + m_marks[Utils::FileName::fromString(mark->fileName())].remove(mark); } void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor) @@ -82,35 +83,50 @@ void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor) if (!m_marks.contains(Utils::FileName::fromString(editor->document()->fileName()))) return; - // Handle reload of text documents, readding the mark as necessary - connect(textEditor->document(), SIGNAL(reloaded()), - this, SLOT(documentReloaded()), Qt::UniqueConnection); - foreach (BaseTextMark *mark, m_marks.value(Utils::FileName::fromString(editor->document()->fileName()))) { - if (mark->m_markableInterface == 0) { // We aren't added to something - ITextMarkable *markableInterface = textEditor->markableInterface(); - if (markableInterface->addMark(mark)) - mark->m_markableInterface = markableInterface; - } + ITextMarkable *markableInterface = textEditor->markableInterface(); + markableInterface->addMark(mark); } } -void BaseTextMarkRegistry::documentReloaded() +void BaseTextMarkRegistry::documentRenamed(Core::IDocument *document, const + QString &oldName, const QString &newName) { - BaseTextDocument *doc = qobject_cast<BaseTextDocument*>(sender()); - if (!doc) + TextEditor::BaseTextDocument *baseTextDocument + = qobject_cast<TextEditor::BaseTextDocument *>(document); + if (!document) + return; + Utils::FileName oldFileName = Utils::FileName::fromString(oldName); + Utils::FileName newFileName = Utils::FileName::fromString(newName); + if (!m_marks.contains(oldFileName)) return; - if (!m_marks.contains(Utils::FileName::fromString(doc->fileName()))) + QSet<BaseTextMark *> toBeMoved; + foreach (ITextMark *mark, baseTextDocument->documentMarker()->marks()) + if (BaseTextMark *baseTextMark = dynamic_cast<BaseTextMark *>(mark)) + toBeMoved.insert(baseTextMark); + + m_marks[oldFileName].subtract(toBeMoved); + m_marks[newFileName].unite(toBeMoved); + + foreach (BaseTextMark *mark, toBeMoved) + mark->updateFileName(newName); +} + +void BaseTextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QString &newName) +{ + Utils::FileName oldFileName = Utils::FileName::fromString(oldName); + Utils::FileName newFileName = Utils::FileName::fromString(newName); + if (!m_marks.contains(oldFileName)) return; - foreach (BaseTextMark *mark, m_marks.value(Utils::FileName::fromString(doc->fileName()))) { - if (mark->m_markableInterface) - return; - ITextMarkable *markableInterface = doc->documentMarker(); - if (markableInterface->addMark(mark)) - mark->m_markableInterface = markableInterface; - } + QSet<BaseTextMark *> oldFileNameMarks = m_marks.value(oldFileName); + + m_marks[newFileName].unite(oldFileNameMarks); + m_marks[oldFileName].clear(); + + foreach (BaseTextMark *mark, oldFileNameMarks) + mark->updateFileName(newName); } BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber) @@ -122,14 +138,10 @@ BaseTextMark::BaseTextMark(const QString &fileName, int lineNumber) BaseTextMark::~BaseTextMark() { // oha we are deleted - if (m_markableInterface) - m_markableInterface.data()->removeMark(this); - m_markableInterface.clear(); Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->remove(this); } -void BaseTextMark::updateMarker() +void BaseTextMark::updateFileName(const QString &fileName) { - if (m_markableInterface) - m_markableInterface.data()->updateMark(this); + m_fileName = fileName; } diff --git a/src/plugins/texteditor/basetextmark.h b/src/plugins/texteditor/basetextmark.h index 8426abcf9e..1b31724f2f 100644 --- a/src/plugins/texteditor/basetextmark.h +++ b/src/plugins/texteditor/basetextmark.h @@ -40,6 +40,7 @@ #include <QWeakPointer> #include <QHash> +#include <QSet> QT_BEGIN_NAMESPACE class QTextBlock; @@ -61,14 +62,13 @@ public: BaseTextMark(const QString &fileName, int lineNumber); virtual ~BaseTextMark(); - // call this if the icon has changed. - void updateMarker(); + /// called if the filename of the document changed + virtual void updateFileName(const QString &fileName); // access to internal data QString fileName() const { return m_fileName; } private: - QWeakPointer<ITextMarkable> m_markableInterface; QString m_fileName; }; @@ -83,9 +83,10 @@ public: void remove(BaseTextMark *mark); private slots: void editorOpened(Core::IEditor *editor); - void documentReloaded(); + void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName); + void allDocumentsRenamed(const QString &oldName, const QString &newName); private: - QHash<Utils::FileName, QList<BaseTextMark *> > m_marks; + QHash<Utils::FileName, QSet<BaseTextMark *> > m_marks; }; } diff --git a/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp index 043e2c0eed..744744a71d 100644 --- a/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp @@ -55,6 +55,11 @@ HighlightDefinition::HighlightDefinition() : HighlightDefinition::~HighlightDefinition() {} +bool HighlightDefinition::isValid() const +{ + return !m_initialContext.isEmpty(); +} + template <class Element, class Container> QSharedPointer<Element> HighlightDefinition:: GenericHelper::create(const QString &name, Container &container) diff --git a/src/plugins/texteditor/generichighlighter/highlightdefinition.h b/src/plugins/texteditor/generichighlighter/highlightdefinition.h index 029eaa7e5b..b178a2e476 100644 --- a/src/plugins/texteditor/generichighlighter/highlightdefinition.h +++ b/src/plugins/texteditor/generichighlighter/highlightdefinition.h @@ -51,6 +51,8 @@ public: HighlightDefinition(); ~HighlightDefinition(); + bool isValid() const; + QSharedPointer<KeywordList> createKeywordList(const QString &list); QSharedPointer<KeywordList> keywordList(const QString &list); diff --git a/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp index cc123bcf20..a259132291 100644 --- a/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp @@ -449,7 +449,7 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointer<Contex const QSharedPointer<HighlightDefinition> &externalDefinition = Manager::instance()->definition(id); - if (externalDefinition.isNull()) + if (externalDefinition.isNull() || !externalDefinition->isValid()) continue; sourceContext = externalDefinition->initialContext(); diff --git a/src/plugins/texteditor/itextmark.cpp b/src/plugins/texteditor/itextmark.cpp index a999b6367e..bf7030ce07 100644 --- a/src/plugins/texteditor/itextmark.cpp +++ b/src/plugins/texteditor/itextmark.cpp @@ -36,7 +36,9 @@ using namespace TextEditor; ITextMark::~ITextMark() { - + if (m_markableInterface) + m_markableInterface->removeMark(this); + m_markableInterface = 0; } int ITextMark::lineNumber() const @@ -65,6 +67,12 @@ void ITextMark::setIcon(const QIcon &icon) m_icon = icon; } +void ITextMark::updateMarker() +{ + if (m_markableInterface) + m_markableInterface->updateMark(this); +} + void ITextMark::setPriority(Priority priority) { m_priority = priority; @@ -92,3 +100,14 @@ bool ITextMark::clickable() const void ITextMark::clicked() {} + +ITextMarkable *ITextMark::markableInterface() const +{ + return m_markableInterface; +} + +void ITextMark::setMarkableInterface(ITextMarkable *markableInterface) +{ + m_markableInterface = markableInterface; +} + diff --git a/src/plugins/texteditor/itextmark.h b/src/plugins/texteditor/itextmark.h index 48be8b0992..79e0ca0131 100644 --- a/src/plugins/texteditor/itextmark.h +++ b/src/plugins/texteditor/itextmark.h @@ -50,11 +50,16 @@ QT_END_NAMESPACE namespace TextEditor { class ITextEditor; +class ITextMarkable; class TEXTEDITOR_EXPORT ITextMark { public: - ITextMark(int line) : m_lineNumber(line), m_priority(NormalPriority) {} + ITextMark(int line) + : m_markableInterface(0), + m_lineNumber(line), + m_priority(NormalPriority) + {} virtual ~ITextMark(); // determine order on markers on the same line. @@ -71,6 +76,8 @@ public: virtual void updateBlock(const QTextBlock &block); virtual void removedFromEditor(); void setIcon(const QIcon &icon); + // call this if the icon has changed. + void updateMarker(); Priority priority() const; void setPriority(Priority prioriy); virtual bool visible() const; @@ -78,7 +85,10 @@ public: virtual bool clickable() const; virtual void clicked(); + ITextMarkable *markableInterface() const; + void setMarkableInterface(ITextMarkable *markableInterface); private: + ITextMarkable *m_markableInterface; int m_lineNumber; QIcon m_icon; Priority m_priority; @@ -93,6 +103,7 @@ class TEXTEDITOR_EXPORT ITextMarkable : public QObject public: ITextMarkable(QObject *parent = 0) : QObject(parent) {} + virtual TextMarks marks() const = 0; virtual bool addMark(ITextMark *mark) = 0; virtual TextMarks marksAt(int line) const = 0; virtual void removeMark(ITextMark *mark) = 0; diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index d1abadb607..90a30a2381 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -180,7 +180,7 @@ void PlainTextEditorWidget::configure(const Core::MimeType &mimeType) m_isMissingSyntaxDefinition = false; const QSharedPointer<HighlightDefinition> &definition = Manager::instance()->definition(definitionId); - if (!definition.isNull()) { + if (!definition.isNull() && definition->isValid()) { highlighter->setDefaultContext(definition->initialContext()); m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces()); |