Commit 10438d2e authored by Daniel Teske's avatar Daniel Teske Committed by Eike Ziller

BaseTextMark: Support renaming files

Change-Id: I8d712f76fca5d8f5ecad70f1485228e21c00648d
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent f1c299a8
......@@ -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;
......
......@@ -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;
......
......@@ -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)
......
......@@ -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);
......
......@@ -116,6 +116,7 @@ signals:
void aboutToReload();
void reloaded();
void fileNameChanged(const QString &oldName, const QString &newName);
private:
QString m_autoSaveName;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......@@ -48,6 +48,7 @@ public:
~BreakpointMarker();
void removedFromEditor();
void updateLineNumber(int lineNumber);
void updateFileName(const QString &fileName);
private:
BreakpointModelId m_id;
......
......@@ -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();
}
......
......@@ -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();
}
......
......@@ -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);
......
......@@ -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 setCategoryVisibility(const Core::Id &categoryId, bool visible);
......@@ -65,6 +66,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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)),
......@@ -385,6 +387,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);
......
......@@ -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 clearTasks(const Core::Id &categoryId);
......
......@@ -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();
}
......
......@@ -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();
}
......
......@@ -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;
}
......@@ -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;
};
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment