Commit 87b5db55 authored by jkobus's avatar jkobus Committed by Jarek Kobus

Save / restore state in diff editor when reloading

Task-number: QTCREATORBUG-12650
Change-Id: I0bb25ed39f8a15dd5da798ebf0ce72898a2e3b3d
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent b97c9d73
......@@ -272,4 +272,14 @@ void DiffEditorController::requestChunkActions(QMenu *menu,
emit chunkActionsRequested(menu, diffFileIndex, chunkIndex);
}
void DiffEditorController::requestSaveState()
{
emit saveStateRequested();
}
void DiffEditorController::requestRestoreState()
{
emit restoreStateRequested();
}
} // namespace DiffEditor
......@@ -73,6 +73,8 @@ public slots:
void requestChunkActions(QMenu *menu,
int diffFileIndex,
int chunkIndex);
void requestSaveState();
void requestRestoreState();
void branchesForCommitReceived(const QString &output);
void expandBranchesRequested();
......@@ -87,6 +89,8 @@ signals:
void chunkActionsRequested(QMenu *menu,
int diffFileIndex,
int chunkIndex);
void saveStateRequested();
void restoreStateRequested();
void expandBranchesRequested(const QString &revision);
void reloaderChanged(DiffEditorReloader *reloader);
......
......@@ -132,7 +132,9 @@ void SimpleDiffEditorReloader::reload()
QList<FileData> fileDataList;
fileDataList << fileData;
controller()->requestSaveState();
controller()->setDiffFiles(fileDataList);
controller()->requestRestoreState();
reloadFinished();
}
......
......@@ -154,6 +154,8 @@ public:
public slots:
void setDisplaySettings(const DisplaySettings &ds);
void saveStateRequested();
void restoreStateRequested();
signals:
void jumpToOriginalFileRequested(int diffFileIndex,
......@@ -205,6 +207,7 @@ private:
QColor m_fileLineForeground;
QColor m_chunkLineForeground;
QColor m_textForeground;
QByteArray m_state;
// MultiHighlighter *m_highlighter;
};
......@@ -338,6 +341,23 @@ SideDiffEditorWidget::SideDiffEditorWidget(QWidget *parent)
// baseTextDocument()->setSyntaxHighlighter(m_highlighter);
}
void SideDiffEditorWidget::saveStateRequested()
{
if (!m_state.isNull())
return;
m_state = saveState();
}
void SideDiffEditorWidget::restoreStateRequested()
{
if (m_state.isNull())
return;
restoreState(m_state);
m_state.clear();
}
void SideDiffEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{
DisplaySettings settings = displaySettings();
......@@ -857,6 +877,14 @@ void SideBySideDiffEditorWidget::setDiffEditorGuiController(
this, SLOT(clearAll(QString)));
disconnect(m_controller, SIGNAL(diffFilesChanged(QList<FileData>,QString)),
this, SLOT(setDiff(QList<FileData>,QString)));
disconnect(m_controller, SIGNAL(saveStateRequested()),
m_leftEditor, SLOT(saveStateRequested()));
disconnect(m_controller, SIGNAL(saveStateRequested()),
m_rightEditor, SLOT(saveStateRequested()));
disconnect(m_controller, SIGNAL(restoreStateRequested()),
m_leftEditor, SLOT(restoreStateRequested()));
disconnect(m_controller, SIGNAL(restoreStateRequested()),
m_rightEditor, SLOT(restoreStateRequested()));
disconnect(m_guiController, SIGNAL(currentDiffFileIndexChanged(int)),
this, SLOT(setCurrentDiffFileIndex(int)));
......@@ -872,6 +900,14 @@ void SideBySideDiffEditorWidget::setDiffEditorGuiController(
this, SLOT(clearAll(QString)));
connect(m_controller, SIGNAL(diffFilesChanged(QList<FileData>,QString)),
this, SLOT(setDiff(QList<FileData>,QString)));
connect(m_controller, SIGNAL(saveStateRequested()),
m_leftEditor, SLOT(saveStateRequested()));
connect(m_controller, SIGNAL(saveStateRequested()),
m_rightEditor, SLOT(saveStateRequested()));
connect(m_controller, SIGNAL(restoreStateRequested()),
m_leftEditor, SLOT(restoreStateRequested()));
connect(m_controller, SIGNAL(restoreStateRequested()),
m_rightEditor, SLOT(restoreStateRequested()));
connect(m_guiController, SIGNAL(currentDiffFileIndexChanged(int)),
this, SLOT(setCurrentDiffFileIndex(int)));
......@@ -937,11 +973,6 @@ void SideBySideDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
void SideBySideDiffEditorWidget::showDiff()
{
// TODO: remember the line number of the line in the middle
const int verticalValue = m_leftEditor->verticalScrollBar()->value();
const int leftHorizontalValue = m_leftEditor->horizontalScrollBar()->value();
const int rightHorizontalValue = m_rightEditor->horizontalScrollBar()->value();
clear(tr("No difference"));
QMap<int, QList<DiffSelection> > leftFormats;
......@@ -1152,11 +1183,6 @@ void SideBySideDiffEditorWidget::showDiff()
}
m_foldingBlocker = false;
*/
m_leftEditor->verticalScrollBar()->setValue(verticalValue);
m_rightEditor->verticalScrollBar()->setValue(verticalValue);
m_leftEditor->horizontalScrollBar()->setValue(leftHorizontalValue);
m_rightEditor->horizontalScrollBar()->setValue(rightHorizontalValue);
// m_leftEditor->updateFoldingHighlight(QPoint(-1, -1));
// m_rightEditor->updateFoldingHighlight(QPoint(-1, -1));
}
......
......@@ -134,6 +134,10 @@ void UnifiedDiffEditorWidget::setDiffEditorGuiController(
this, SLOT(clearAll(QString)));
disconnect(m_controller, SIGNAL(diffFilesChanged(QList<FileData>,QString)),
this, SLOT(setDiff(QList<FileData>,QString)));
disconnect(m_controller, SIGNAL(saveStateRequested()),
this, SLOT(saveStateRequested()));
disconnect(m_controller, SIGNAL(restoreStateRequested()),
this, SLOT(restoreStateRequested()));
disconnect(m_guiController, SIGNAL(currentDiffFileIndexChanged(int)),
this, SLOT(setCurrentDiffFileIndex(int)));
......@@ -149,6 +153,10 @@ void UnifiedDiffEditorWidget::setDiffEditorGuiController(
this, SLOT(clearAll(QString)));
connect(m_controller, SIGNAL(diffFilesChanged(QList<FileData>,QString)),
this, SLOT(setDiff(QList<FileData>,QString)));
connect(m_controller, SIGNAL(saveStateRequested()),
this, SLOT(saveStateRequested()));
connect(m_controller, SIGNAL(restoreStateRequested()),
this, SLOT(restoreStateRequested()));
connect(m_guiController, SIGNAL(currentDiffFileIndexChanged(int)),
this, SLOT(setCurrentDiffFileIndex(int)));
......@@ -158,6 +166,23 @@ void UnifiedDiffEditorWidget::setDiffEditorGuiController(
}
}
void UnifiedDiffEditorWidget::saveStateRequested()
{
if (!m_state.isNull())
return;
m_state = saveState();
}
void UnifiedDiffEditorWidget::restoreStateRequested()
{
if (m_state.isNull())
return;
restoreState(m_state);
m_state.clear();
}
DiffEditorGuiController *UnifiedDiffEditorWidget::diffEditorGuiController() const
{
return m_guiController;
......
......@@ -87,6 +87,8 @@ private slots:
void slotSendChunkToCodePaster();
void slotApplyChunk();
void slotRevertChunk();
void saveStateRequested();
void restoreStateRequested();
private:
void setLeftLineNumber(int blockNumber, int lineNumber);
......@@ -139,6 +141,7 @@ private:
QTextCharFormat m_rightLineFormat;
QTextCharFormat m_leftCharFormat;
QTextCharFormat m_rightCharFormat;
QByteArray m_state;
};
} // namespace DiffEditor
......
......@@ -211,6 +211,7 @@ void GitDiffHandler::postCollectShowDescription(const QString &id)
return;
}
m_controller->saveStateRequested();
m_controller->clear(m_waitMessage);
VcsBase::Command *command = new VcsBase::Command(gitPath(),
m_workingDirectory,
......@@ -286,6 +287,7 @@ void GitDiffHandler::postCollectTextualDiffOutput(const QString &gitCommand, con
return;
}
m_controller->saveStateRequested();
m_controller->clear(m_waitMessage);
VcsBase::Command *command = new VcsBase::Command(gitPath(),
m_workingDirectory,
......@@ -313,6 +315,7 @@ void GitDiffHandler::slotTextualDiffOutputReceived(const QString &contents)
= DiffEditor::DiffUtils::readPatch(
contents, m_controller->isIgnoreWhitespace(), &ok);
m_controller->setDiffFiles(fileDataList, m_workingDirectory);
m_controller->restoreStateRequested();
deleteLater();
}
......
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