summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2010-05-28 14:06:57 +0200
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2010-05-28 15:44:59 +0200
commit76020b61527db086e7b13fdad63ee5b43ff5f2b8 (patch)
treebd36d90a798e86411d8bbb69c480c9c167a289ef /src
parenta36d4b9b57762e2998feda565868a22a4e88dfa6 (diff)
downloadqt-creator-76020b61527db086e7b13fdad63ee5b43ff5f2b8.tar.gz
Make sure bookmarks survive a document reload
While reloading a text document, the bookmarks got lost since their associated QTextBlocks were deleted. This patch makes sure that before reloading, the bookmarks are removed non-persistently in the same way as when closing a document, and that they are restored after the document was reloaded. Currently, no effort is made to update the location of the bookmarks based on the way the file changed. Task-number: QTCREATORBUG-1281 Reviewed-by: dt
Diffstat (limited to 'src')
-rw-r--r--src/plugins/bineditor/bineditorplugin.cpp4
-rw-r--r--src/plugins/bookmarks/bookmark.h2
-rw-r--r--src/plugins/coreplugin/ifile.h3
-rw-r--r--src/plugins/designer/formwindowfile.cpp2
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.cpp4
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp25
-rw-r--r--src/plugins/texteditor/basetextdocument.h5
-rw-r--r--src/plugins/texteditor/basetextmark.cpp68
-rw-r--r--src/plugins/texteditor/basetextmark.h8
9 files changed, 78 insertions, 43 deletions
diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp
index 432df20a97..3d9f02b52d 100644
--- a/src/plugins/bineditor/bineditorplugin.cpp
+++ b/src/plugins/bineditor/bineditorplugin.cpp
@@ -269,7 +269,9 @@ public:
if (type == TypePermissions) {
emit changed();
} else {
- open(m_fileName);
+ emit aboutToReload();
+ if (open(m_fileName))
+ emit reloaded();
}
}
diff --git a/src/plugins/bookmarks/bookmark.h b/src/plugins/bookmarks/bookmark.h
index efa2211dd3..aeb800a8b9 100644
--- a/src/plugins/bookmarks/bookmark.h
+++ b/src/plugins/bookmarks/bookmark.h
@@ -48,7 +48,7 @@ class Bookmark : public TextEditor::BaseTextMark
{
Q_OBJECT
public:
- Bookmark(const QString& fileName, int lineNumber, BookmarkManager *manager);
+ Bookmark(const QString &fileName, int lineNumber, BookmarkManager *manager);
QIcon icon() const;
diff --git a/src/plugins/coreplugin/ifile.h b/src/plugins/coreplugin/ifile.h
index 575cac9488..77a8412aac 100644
--- a/src/plugins/coreplugin/ifile.h
+++ b/src/plugins/coreplugin/ifile.h
@@ -92,6 +92,9 @@ public:
signals:
void changed();
+
+ void aboutToReload();
+ void reloaded();
};
} // namespace Core
diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp
index a130cc9d68..bbf3505940 100644
--- a/src/plugins/designer/formwindowfile.cpp
+++ b/src/plugins/designer/formwindowfile.cpp
@@ -133,7 +133,9 @@ void FormWindowFile::reload(ReloadFlag flag, ChangeType type)
if (type == TypePermissions) {
emit changed();
} else {
+ emit aboutToReload();
emit reload(m_fileName);
+ emit reloaded();
}
}
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp
index 75f9fb2265..b37169bf77 100644
--- a/src/plugins/resourceeditor/resourceeditorw.cpp
+++ b/src/plugins/resourceeditor/resourceeditorw.cpp
@@ -203,7 +203,9 @@ void ResourceEditorFile::reload(ReloadFlag flag, ChangeType type)
if (type == TypePermissions) {
emit changed();
} else {
- m_parent->open(m_parent->m_resourceEditor->fileName());
+ emit aboutToReload();
+ if (m_parent->open(m_parent->m_resourceEditor->fileName()))
+ emit reloaded();
}
}
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 8035f0291a..b25bafebd8 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -132,7 +132,7 @@ BaseTextDocument::BaseTextDocument()
m_fileIsReadOnly = false;
m_isBinaryData = false;
m_codec = QTextCodec::codecForLocale();
- QSettings* settings = Core::ICore::instance()->settings();
+ QSettings *settings = Core::ICore::instance()->settings();
if (QTextCodec *candidate = QTextCodec::codecForName(
settings->value(QLatin1String("General/DefaultFileEncoding")).toByteArray()))
m_codec = candidate;
@@ -142,12 +142,8 @@ BaseTextDocument::BaseTextDocument()
BaseTextDocument::~BaseTextDocument()
{
- QTextBlock block = m_document->begin();
- while (block.isValid()) {
- if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData()))
- data->documentClosing();
- block = block.next();
- }
+ documentClosing();
+
delete m_document;
m_document = 0;
}
@@ -324,6 +320,8 @@ void BaseTextDocument::reload(QTextCodec *codec)
void BaseTextDocument::reload()
{
emit aboutToReload();
+ documentClosing(); // removes text marks non-permanently
+
if (open(m_fileName))
emit reloaded();
}
@@ -373,9 +371,8 @@ void BaseTextDocument::cleanWhitespace(const QTextCursor &cursor)
copyCursor.endEditBlock();
}
-void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool cleanIndentation, bool inEntireDocument)
+void BaseTextDocument::cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument)
{
-
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
QTextBlock block = m_document->findBlock(cursor.selectionStart());
@@ -423,3 +420,13 @@ void BaseTextDocument::ensureFinalNewLine(QTextCursor& cursor)
cursor.insertText(QLatin1String("\n"));
}
}
+
+void BaseTextDocument::documentClosing()
+{
+ QTextBlock block = m_document->begin();
+ while (block.isValid()) {
+ if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData()))
+ data->documentClosing();
+ block = block.next();
+ }
+}
diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h
index 2958fc3805..cdf778feee 100644
--- a/src/plugins/texteditor/basetextdocument.h
+++ b/src/plugins/texteditor/basetextdocument.h
@@ -76,7 +76,7 @@ public:
inline const StorageSettings &storageSettings() const { return m_storageSettings; }
inline const TabSettings &tabSettings() const { return m_tabSettings; }
- DocumentMarker *documentMarker() const {return m_documentMarker; }
+ DocumentMarker *documentMarker() const { return m_documentMarker; }
//IFile
virtual bool save(const QString &fileName = QString());
@@ -116,8 +116,6 @@ public:
signals:
void titleChanged(QString title);
- void aboutToReload();
- void reloaded();
private:
QString m_fileName;
@@ -150,6 +148,7 @@ private:
void cleanWhitespace(QTextCursor& cursor, bool cleanIndentation, bool inEntireDocument);
void ensureFinalNewLine(QTextCursor& cursor);
+ void documentClosing();
};
} // namespace TextEditor
diff --git a/src/plugins/texteditor/basetextmark.cpp b/src/plugins/texteditor/basetextmark.cpp
index 17b238b641..fb425cb890 100644
--- a/src/plugins/texteditor/basetextmark.cpp
+++ b/src/plugins/texteditor/basetextmark.cpp
@@ -29,6 +29,8 @@
#include "basetextmark.h"
+#include "basetextdocument.h"
+
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>
@@ -37,18 +39,25 @@
using namespace TextEditor;
using namespace TextEditor::Internal;
-BaseTextMark::BaseTextMark()
- : m_markableInterface(0), m_internalMark(0), m_init(false)
-{
-}
-
BaseTextMark::BaseTextMark(const QString &filename, int line)
- : m_markableInterface(0), m_internalMark(0), m_fileName(filename), m_line(line), m_init(false)
+ : m_markableInterface(0)
+ , m_internalMark(0)
+ , m_fileName(filename)
+ , m_line(line)
+ , m_init(false)
{
// Why is this?
QTimer::singleShot(0, this, SLOT(init()));
}
+BaseTextMark::~BaseTextMark()
+{
+ // oha we are deleted
+ if (m_markableInterface)
+ m_markableInterface->removeMark(m_internalMark);
+ removeInternalMark();
+}
+
void BaseTextMark::init()
{
m_init = true;
@@ -73,39 +82,49 @@ void BaseTextMark::editorOpened(Core::IEditor *editor)
m_markableInterface = textEditor->markableInterface();
m_internalMark = new InternalMark(this);
- if (!m_markableInterface->addMark(m_internalMark, m_line)) {
- delete m_internalMark;
- m_internalMark = 0;
- m_markableInterface = 0;
+ if (m_markableInterface->addMark(m_internalMark, m_line)) {
+ // Handle reload of text documents, readding the mark as necessary
+ connect(textEditor->file(), SIGNAL(reloaded()),
+ this, SLOT(documentReloaded()), Qt::UniqueConnection);
+ } else {
+ removeInternalMark();
}
}
}
}
+void BaseTextMark::documentReloaded()
+{
+ if (m_markableInterface)
+ return;
+
+ BaseTextDocument *doc = qobject_cast<BaseTextDocument*>(sender());
+ if (!doc)
+ return;
+
+ m_markableInterface = doc->documentMarker();
+ m_internalMark = new InternalMark(this);
+
+ if (!m_markableInterface->addMark(m_internalMark, m_line))
+ removeInternalMark();
+}
+
void BaseTextMark::childRemovedFromEditor(InternalMark *mark)
{
Q_UNUSED(mark)
// m_internalMark was removed from the editor
- delete m_internalMark;
- m_markableInterface = 0;
- m_internalMark = 0;
+ removeInternalMark();
removedFromEditor();
}
void BaseTextMark::documentClosingFor(InternalMark *mark)
{
Q_UNUSED(mark)
- // the document is closing
- delete m_internalMark;
- m_markableInterface = 0;
- m_internalMark = 0;
+ removeInternalMark();
}
-BaseTextMark::~BaseTextMark()
+void BaseTextMark::removeInternalMark()
{
- // oha we are deleted
- if (m_markableInterface)
- m_markableInterface->removeMark(m_internalMark);
delete m_internalMark;
m_internalMark = 0;
m_markableInterface = 0;
@@ -128,13 +147,10 @@ void BaseTextMark::moveMark(const QString & /* filename */, int /* line */)
m_init = true;
}
-
if (m_markableInterface)
m_markableInterface->removeMark(m_internalMark);
- m_markableInterface = 0;
- // This is only necessary since m_internalMark is created in ediorOpened
- delete m_internalMark;
- m_internalMark = 0;
+ // This is only necessary since m_internalMark is created in editorOpened
+ removeInternalMark();
foreach (Core::IEditor *editor, em->openedEditors())
editorOpened(editor);
diff --git a/src/plugins/texteditor/basetextmark.h b/src/plugins/texteditor/basetextmark.h
index 244dd0009d..ad40b7571f 100644
--- a/src/plugins/texteditor/basetextmark.h
+++ b/src/plugins/texteditor/basetextmark.h
@@ -45,8 +45,8 @@ class TEXTEDITOR_EXPORT BaseTextMark : public QObject
{
friend class Internal::InternalMark;
Q_OBJECT
+
public:
- BaseTextMark();
BaseTextMark(const QString &filename, int line);
~BaseTextMark();
@@ -69,12 +69,16 @@ public:
int lineNumber() const { return m_line; }
void moveMark(const QString &filename, int line);
+
private slots:
- void editorOpened(Core::IEditor *editor);
void init();
+ void editorOpened(Core::IEditor *editor);
+ void documentReloaded();
+
private:
void childRemovedFromEditor(Internal::InternalMark *mark);
void documentClosingFor(Internal::InternalMark *mark);
+ void removeInternalMark();
ITextMarkable *m_markableInterface;
Internal::InternalMark *m_internalMark;