forked from qt-creator/qt-creator
Editors: Centralize creation of EditLocation for history
Change-Id: I05387ccf444351de4002b706f7c03027fdd9adaf Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -3444,18 +3444,7 @@ void EditorManager::addCurrentPositionToNavigationHistory(const QByteArray &save
|
|||||||
*/
|
*/
|
||||||
void EditorManager::setLastEditLocation(const IEditor* editor)
|
void EditorManager::setLastEditLocation(const IEditor* editor)
|
||||||
{
|
{
|
||||||
IDocument *document = editor->document();
|
d->m_globalLastEditLocation = EditLocation::forEditor(editor);
|
||||||
if (!document)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QByteArray &state = editor->saveState();
|
|
||||||
EditLocation location;
|
|
||||||
location.document = document;
|
|
||||||
location.filePath = document->filePath();
|
|
||||||
location.id = document->id();
|
|
||||||
location.state = state;
|
|
||||||
|
|
||||||
d->m_globalLastEditLocation = location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -262,20 +262,10 @@ bool EditorView::canGoBack() const
|
|||||||
|
|
||||||
void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &history)
|
void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &history)
|
||||||
{
|
{
|
||||||
if (!editor)
|
IDocument *document = editor ? editor->document() : nullptr;
|
||||||
return;
|
QTC_ASSERT(document, return);
|
||||||
IDocument *document = editor->document();
|
|
||||||
|
|
||||||
if (!document)
|
const auto location = EditLocation::forEditor(editor);
|
||||||
return;
|
|
||||||
|
|
||||||
QByteArray state = editor->saveState();
|
|
||||||
|
|
||||||
EditLocation location;
|
|
||||||
location.document = document;
|
|
||||||
location.filePath = document->filePath();
|
|
||||||
location.id = document->id();
|
|
||||||
location.state = state;
|
|
||||||
|
|
||||||
for (int i = 0; i < history.size(); ++i) {
|
for (int i = 0; i < history.size(); ++i) {
|
||||||
const EditLocation &item = history.at(i);
|
const EditLocation &item = history.at(i);
|
||||||
@@ -491,24 +481,11 @@ constexpr int navigationHistorySize = 100;
|
|||||||
void EditorView::addCurrentPositionToNavigationHistory(const QByteArray &saveState)
|
void EditorView::addCurrentPositionToNavigationHistory(const QByteArray &saveState)
|
||||||
{
|
{
|
||||||
IEditor *editor = currentEditor();
|
IEditor *editor = currentEditor();
|
||||||
if (!editor)
|
|
||||||
return;
|
|
||||||
IDocument *document = editor->document();
|
|
||||||
|
|
||||||
if (!document)
|
if (!editor || !editor->document())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QByteArray state;
|
const auto location = EditLocation::forEditor(editor, saveState);
|
||||||
if (saveState.isNull())
|
|
||||||
state = editor->saveState();
|
|
||||||
else
|
|
||||||
state = saveState;
|
|
||||||
|
|
||||||
EditLocation location;
|
|
||||||
location.document = document;
|
|
||||||
location.filePath = document->filePath();
|
|
||||||
location.id = document->id();
|
|
||||||
location.state = state;
|
|
||||||
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
|
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
|
||||||
m_navigationHistory.insert(m_currentNavigationHistoryPosition, location);
|
m_navigationHistory.insert(m_currentNavigationHistoryPosition, location);
|
||||||
++m_currentNavigationHistoryPosition;
|
++m_currentNavigationHistoryPosition;
|
||||||
@@ -552,7 +529,6 @@ void EditorView::updateCurrentPositionInNavigationHistory()
|
|||||||
if (!editor || !editor->document())
|
if (!editor || !editor->document())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IDocument *document = editor->document();
|
|
||||||
EditLocation *location;
|
EditLocation *location;
|
||||||
if (m_currentNavigationHistoryPosition < m_navigationHistory.size()) {
|
if (m_currentNavigationHistoryPosition < m_navigationHistory.size()) {
|
||||||
location = &m_navigationHistory[m_currentNavigationHistoryPosition];
|
location = &m_navigationHistory[m_currentNavigationHistoryPosition];
|
||||||
@@ -560,10 +536,7 @@ void EditorView::updateCurrentPositionInNavigationHistory()
|
|||||||
m_navigationHistory.append(EditLocation());
|
m_navigationHistory.append(EditLocation());
|
||||||
location = &m_navigationHistory[m_navigationHistory.size()-1];
|
location = &m_navigationHistory[m_navigationHistory.size()-1];
|
||||||
}
|
}
|
||||||
location->document = document;
|
*location = EditLocation::forEditor(editor);
|
||||||
location->filePath = document->filePath();
|
|
||||||
location->id = document->id();
|
|
||||||
location->state = editor->saveState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool fileNameWasRemoved(const FilePath &filePath)
|
static bool fileNameWasRemoved(const FilePath &filePath)
|
||||||
@@ -1033,4 +1006,22 @@ EditLocation EditLocation::load(const QByteArray &data)
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditLocation EditLocation::forEditor(const IEditor *editor, const QByteArray &saveState)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(editor, return EditLocation());
|
||||||
|
|
||||||
|
IDocument *document = editor->document();
|
||||||
|
QTC_ASSERT(document, return EditLocation());
|
||||||
|
|
||||||
|
const QByteArray &state = saveState.isEmpty() ? editor->saveState() : saveState;
|
||||||
|
|
||||||
|
EditLocation location;
|
||||||
|
location.document = document;
|
||||||
|
location.filePath = document->filePath();
|
||||||
|
location.id = document->id();
|
||||||
|
location.state = state;
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
} // Core::Internal
|
} // Core::Internal
|
||||||
|
@@ -40,6 +40,7 @@ class EditLocation
|
|||||||
public:
|
public:
|
||||||
QByteArray save() const;
|
QByteArray save() const;
|
||||||
static EditLocation load(const QByteArray &data);
|
static EditLocation load(const QByteArray &data);
|
||||||
|
static EditLocation forEditor(const IEditor *editor, const QByteArray &saveState = {});
|
||||||
|
|
||||||
QPointer<IDocument> document;
|
QPointer<IDocument> document;
|
||||||
Utils::FilePath filePath;
|
Utils::FilePath filePath;
|
||||||
|
Reference in New Issue
Block a user