summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@nokia.com>2012-03-12 16:56:25 +0100
committerEike Ziller <eike.ziller@nokia.com>2012-04-05 16:47:15 +0200
commit10438d2e9d74fe5ad38f2ccbaf1fbbe8316b4061 (patch)
treeea026b58c71f3fc87704b1d973493ddd343f058b /src/plugins/texteditor
parentf1c299a85e08c5ce16fc8dad371a11115687edf0 (diff)
downloadqt-creator-10438d2e9d74fe5ad38f2ccbaf1fbbe8316b4061.tar.gz
BaseTextMark: Support renaming files
Change-Id: I8d712f76fca5d8f5ecad70f1485228e21c00648d Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp5
-rw-r--r--src/plugins/texteditor/basetextmark.cpp56
-rw-r--r--src/plugins/texteditor/basetextmark.h8
-rw-r--r--src/plugins/texteditor/itextmark.h1
4 files changed, 66 insertions, 4 deletions
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 6bf18d8e75..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();
}
diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp
index 3c68e36e28..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,11 +48,17 @@ 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)) {
@@ -65,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,6 +89,46 @@ void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
}
}
+void BaseTextMarkRegistry::documentRenamed(Core::IDocument *document, const
+ QString &oldName, const QString &newName)
+{
+ 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;
+
+ 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;
+
+ 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)
: ITextMark(lineNumber), m_fileName(fileName)
{
@@ -93,3 +140,8 @@ BaseTextMark::~BaseTextMark()
// oha we are deleted
Internal::TextEditorPlugin::instance()->baseTextMarkRegistry()->remove(this);
}
+
+void BaseTextMark::updateFileName(const QString &fileName)
+{
+ m_fileName = fileName;
+}
diff --git a/src/plugins/texteditor/basetextmark.h b/src/plugins/texteditor/basetextmark.h
index 064b84d0c3..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,6 +62,9 @@ public:
BaseTextMark(const QString &fileName, int lineNumber);
virtual ~BaseTextMark();
+ /// called if the filename of the document changed
+ virtual void updateFileName(const QString &fileName);
+
// access to internal data
QString fileName() const { return m_fileName; }
@@ -79,8 +83,10 @@ public:
void remove(BaseTextMark *mark);
private slots:
void editorOpened(Core::IEditor *editor);
+ 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/itextmark.h b/src/plugins/texteditor/itextmark.h
index 19c8f4750b..79e0ca0131 100644
--- a/src/plugins/texteditor/itextmark.h
+++ b/src/plugins/texteditor/itextmark.h
@@ -103,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;