forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/3.2'
Conflicts: qtcreator.pri qtcreator.qbs src/plugins/coreplugin/editormanager/editormanager.cpp src/plugins/projectexplorer/editorconfiguration.cpp src/plugins/projectexplorer/projectfilewizardextension.cpp src/plugins/qmakeandroidsupport/createandroidmanifestwizard.cpp Change-Id: I8de0f6fcdd8d214fbc14e79f74cb0206e6e2c6c1
This commit is contained in:
@@ -611,6 +611,7 @@ void DiffEditor::showDiffEditor(QWidget *newEditor)
|
||||
|
||||
writeCurrentDiffEditorSetting(m_currentEditor);
|
||||
updateDiffEditorSwitcher();
|
||||
widget()->setFocusProxy(m_currentEditor);
|
||||
}
|
||||
|
||||
QWidget *DiffEditor::readLegacyCurrentDiffEditorSetting()
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ DiffEditorDocument::DiffEditorDocument() :
|
||||
m_controller(new DiffEditorController(this))
|
||||
{
|
||||
setId(Constants::DIFF_EDITOR_ID);
|
||||
setMimeType(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
|
||||
setTemporary(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,9 @@ void SimpleDiffEditorReloader::reload()
|
||||
QList<FileData> fileDataList;
|
||||
fileDataList << fileData;
|
||||
|
||||
controller()->requestSaveState();
|
||||
controller()->setDiffFiles(fileDataList);
|
||||
controller()->requestRestoreState();
|
||||
|
||||
reloadFinished();
|
||||
}
|
||||
@@ -297,6 +299,25 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
||||
|
||||
///////////
|
||||
|
||||
rows.clear();
|
||||
rows << RowData(_("ABCD"));
|
||||
rows << RowData(_(""), TextLineData::Separator);
|
||||
rows << RowData(_(""), TextLineData::Separator);
|
||||
chunk.rows = rows;
|
||||
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
||||
"-ABCD\n"
|
||||
"-\n"
|
||||
"+ABCD\n"
|
||||
"\\ No newline at end of file\n");
|
||||
|
||||
QTest::newRow("Two last EOLs removed") << chunk
|
||||
<< fileName
|
||||
<< fileName
|
||||
<< true
|
||||
<< patchText;
|
||||
|
||||
///////////
|
||||
|
||||
rows.clear();
|
||||
rows << RowData(_("ABCD"));
|
||||
rows << RowData(TextLineData::Separator, _(""));
|
||||
@@ -418,6 +439,26 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
||||
<< fileName
|
||||
<< false
|
||||
<< patchText;
|
||||
|
||||
///////////
|
||||
|
||||
rows.clear();
|
||||
rows << RowData(_("ABCD"));
|
||||
rows << RowData(TextLineData::Separator, _(""));
|
||||
rows << RowData(_(""), _("EFGH"));
|
||||
chunk.rows = rows;
|
||||
patchText = header + _("@@ -1,1 +1,3 @@\n"
|
||||
" ABCD\n"
|
||||
"+\n"
|
||||
"+EFGH\n"
|
||||
"\\ No newline at end of file\n");
|
||||
|
||||
QTest::newRow("Blank line followed by No newline")
|
||||
<< chunk
|
||||
<< fileName
|
||||
<< fileName
|
||||
<< true
|
||||
<< patchText;
|
||||
}
|
||||
|
||||
void DiffEditor::Internal::DiffEditorPlugin::testMakePatch()
|
||||
@@ -748,6 +789,37 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
|
||||
QTest::newRow("2 chunks - first ends with blank line") << patch
|
||||
<< fileDataList4;
|
||||
|
||||
//////////////
|
||||
|
||||
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
||||
"index 1234567..9876543 100644\n"
|
||||
"--- a/file foo.txt\n"
|
||||
"+++ b/file foo.txt\n"
|
||||
"@@ -1,1 +1,3 @@ void DiffEditor::ctor()\n"
|
||||
" ABCD\n"
|
||||
"+\n"
|
||||
"+EFGH\n"
|
||||
"\\ No newline at end of file\n");
|
||||
|
||||
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
||||
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
||||
fileData1.fileOperation = FileData::ChangeFile;
|
||||
chunkData1.leftStartingLineNumber = 0;
|
||||
chunkData1.rightStartingLineNumber = 0;
|
||||
rows1.clear();
|
||||
rows1 << RowData(_("ABCD"));
|
||||
rows1 << RowData(TextLineData::Separator, _(""));
|
||||
rows1 << RowData(_(""), _("EFGH"));
|
||||
chunkData1.rows = rows1;
|
||||
fileData1.chunks.clear();
|
||||
fileData1.chunks << chunkData1;
|
||||
|
||||
QList<FileData> fileDataList5;
|
||||
fileDataList5 << fileData1;
|
||||
|
||||
QTest::newRow("Blank line followed by No newline") << patch
|
||||
<< fileDataList5;
|
||||
}
|
||||
|
||||
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
|
||||
|
||||
@@ -362,15 +362,33 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
||||
int rightLineCount = 0;
|
||||
QList<TextLineData> leftBuffer, rightBuffer;
|
||||
|
||||
int lastEqualRow = -1;
|
||||
int rowToBeSplit = -1;
|
||||
|
||||
if (lastChunk) {
|
||||
for (int i = chunkData.rows.count(); i > 0; i--) {
|
||||
if (chunkData.rows.at(i - 1).equal) {
|
||||
if (i != chunkData.rows.count())
|
||||
lastEqualRow = i - 1;
|
||||
// Detect the case when the last equal line is followed by
|
||||
// only separators on left or on right. In that case
|
||||
// the last equal line needs to be split.
|
||||
const int rowCount = chunkData.rows.count();
|
||||
int i = 0;
|
||||
for (i = rowCount; i > 0; i--) {
|
||||
const RowData &rowData = chunkData.rows.at(i - 1);
|
||||
if (rowData.leftLine.textLineType != TextLineData::Separator
|
||||
|| rowData.rightLine.textLineType != TextLineData::TextLine)
|
||||
break;
|
||||
}
|
||||
}
|
||||
const int leftSeparator = i;
|
||||
for (i = rowCount; i > 0; i--) {
|
||||
const RowData &rowData = chunkData.rows.at(i - 1);
|
||||
if (rowData.rightLine.textLineType != TextLineData::Separator
|
||||
|| rowData.leftLine.textLineType != TextLineData::TextLine)
|
||||
break;
|
||||
}
|
||||
const int rightSeparator = i;
|
||||
const int commonSeparator = qMin(leftSeparator, rightSeparator);
|
||||
if (commonSeparator > 0
|
||||
&& commonSeparator < rowCount
|
||||
&& chunkData.rows.at(commonSeparator - 1).equal)
|
||||
rowToBeSplit = commonSeparator - 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= chunkData.rows.count(); i++) {
|
||||
@@ -379,7 +397,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
||||
: RowData(TextLineData(TextLineData::Separator)); // dummy,
|
||||
// ensure we process buffers to the end.
|
||||
// rowData will be equal
|
||||
if (rowData.equal && i != lastEqualRow) {
|
||||
if (rowData.equal && i != rowToBeSplit) {
|
||||
if (leftBuffer.count()) {
|
||||
for (int j = 0; j < leftBuffer.count(); j++) {
|
||||
const QString line = makePatchLine(QLatin1Char('-'),
|
||||
@@ -439,7 +457,9 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
||||
+ QString::number(chunkData.rightStartingLineNumber + 1)
|
||||
+ QLatin1Char(',')
|
||||
+ QString::number(rightLineCount)
|
||||
+ QLatin1String(" @@\n");
|
||||
+ QLatin1String(" @@")
|
||||
+ chunkData.contextInfo
|
||||
+ QLatin1Char('\n');
|
||||
|
||||
diffText.prepend(chunkLine);
|
||||
|
||||
@@ -530,8 +550,6 @@ static QList<RowData> readLines(const QString &patch,
|
||||
Diff &last = diffList.last();
|
||||
if (last.text.isEmpty())
|
||||
break;
|
||||
if (last.text.at(0) == newLine) // there is a new line
|
||||
break;
|
||||
|
||||
if (last.command == Diff::Equal) {
|
||||
if (noNewLineInEqual >= 0)
|
||||
@@ -690,7 +708,7 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
// @@ -leftPos[,leftCount] +rightPos[,rightCount] @@
|
||||
"@@ -(\\d+)(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@"
|
||||
// optional hint (e.g. function name)
|
||||
"(?:\\ +[^\\n]*)?"
|
||||
"(\\ +[^\\n]*)?"
|
||||
// end of line (need to be followed by text line)
|
||||
"(?:\\n))"));
|
||||
|
||||
@@ -706,6 +724,7 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
const QString captured = capturedTexts.at(1);
|
||||
const int leftStartingPos = capturedTexts.at(2).toInt();
|
||||
const int rightStartingPos = capturedTexts.at(3).toInt();
|
||||
const QString contextInfo = capturedTexts.at(4);
|
||||
if (endOfLastChunk > 0) {
|
||||
const QString lines = patch.mid(endOfLastChunk,
|
||||
pos - endOfLastChunk);
|
||||
@@ -722,6 +741,7 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
ChunkData chunkData;
|
||||
chunkData.leftStartingLineNumber = leftStartingPos - 1;
|
||||
chunkData.rightStartingLineNumber = rightStartingPos - 1;
|
||||
chunkData.contextInfo = contextInfo;
|
||||
chunkDataList.append(chunkData);
|
||||
} while ((pos = chunkRegExp.indexIn(patch, pos)) != -1);
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ public:
|
||||
bool contextChunk;
|
||||
int leftStartingLineNumber;
|
||||
int rightStartingLineNumber;
|
||||
QString contextInfo;
|
||||
};
|
||||
|
||||
class DIFFEDITOR_EXPORT FileData {
|
||||
|
||||
@@ -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();
|
||||
@@ -836,6 +856,7 @@ SideBySideDiffEditorWidget::SideBySideDiffEditorWidget(QWidget *parent)
|
||||
QVBoxLayout *l = new QVBoxLayout(this);
|
||||
l->setMargin(0);
|
||||
l->addWidget(m_splitter);
|
||||
setFocusProxy(m_rightEditor);
|
||||
|
||||
clear(tr("No controller"));
|
||||
}
|
||||
@@ -856,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)));
|
||||
@@ -871,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)));
|
||||
@@ -936,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;
|
||||
@@ -1151,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;
|
||||
@@ -613,7 +638,9 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
||||
+ QString::number(chunkData.rightStartingLineNumber+ 1)
|
||||
+ QLatin1Char(',')
|
||||
+ QString::number(rightLineCount)
|
||||
+ QLatin1String(" @@\n");
|
||||
+ QLatin1String(" @@")
|
||||
+ chunkData.contextInfo
|
||||
+ QLatin1Char('\n');
|
||||
|
||||
diffText.prepend(chunkLine);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user