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:
jkobus
2014-07-11 12:55:31 +02:00
committed by Jarek Kobus
parent b97c9d731e
commit 87b5db5562
7 changed files with 83 additions and 10 deletions

View File

@@ -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));
}