Commit 5dc0ac73 authored by Nikita Baryshnikov's avatar Nikita Baryshnikov

EditorManager: do not show endless errors

when there are removed files in navigation history. Steps to reproduce:
Open file in editor. Remove it outside the qtc. Activate qtc. "File Was
Removed" prompted - agree to remove it. Navigate back(alt left two
times). Qtc goes crazy with endless Error messages like a "Cannot open /
path/to/that/dead.file for reading: No such file or directory"

Change-Id: I10a4c178ba83a8dc769895830b6f76da2e676556
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 98abbd39
......@@ -48,6 +48,7 @@
#include <QDebug>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
......@@ -511,6 +512,13 @@ void EditorView::updateCurrentPositionInNavigationHistory()
location->state = QVariant(editor->saveState());
}
namespace {
static inline bool fileNameWasRemoved(const QString &fileName)
{
return !fileName.isEmpty() && !QFileInfo(fileName).exists();
}
} // End of anonymous namespace
void EditorView::goBackInNavigationHistory()
{
updateCurrentPositionInNavigationHistory();
......@@ -523,6 +531,10 @@ void EditorView::goBackInNavigationHistory()
EditorManager::IgnoreNavigationHistory);
}
if (!editor) {
if (fileNameWasRemoved(location.fileName)) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue;
}
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory);
if (!editor) {
......@@ -542,22 +554,30 @@ void EditorView::goForwardInNavigationHistory()
if (m_currentNavigationHistoryPosition >= m_navigationHistory.size()-1)
return;
++m_currentNavigationHistoryPosition;
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
IEditor *editor = 0;
if (location.document) {
editor = EditorManagerPrivate::activateEditorForDocument(this, location.document,
EditorManager::IgnoreNavigationHistory);
}
if (!editor) {
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory);
while (m_currentNavigationHistoryPosition < m_navigationHistory.size()) {
IEditor *editor = 0;
EditLocation location = m_navigationHistory.at(m_currentNavigationHistoryPosition);
if (location.document) {
editor = EditorManagerPrivate::activateEditorForDocument(this, location.document,
EditorManager::IgnoreNavigationHistory);
}
if (!editor) {
//TODO
qDebug() << Q_FUNC_INFO << "can't open file" << location.fileName;
return;
if (fileNameWasRemoved(location.fileName)) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue;
}
editor = EditorManagerPrivate::openEditor(this, location.fileName, location.id,
EditorManager::IgnoreNavigationHistory);
if (!editor) {
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
continue;
}
}
editor->restoreState(location.state.toByteArray());
break;
}
editor->restoreState(location.state.toByteArray());
if (m_currentNavigationHistoryPosition >= m_navigationHistory.size())
m_currentNavigationHistoryPosition = qMax<int>(m_navigationHistory.size() - 1, 0);
updateNavigatorActions();
}
......
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