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