forked from qt-creator/qt-creator
DiffEditor: Modernize
* Use member init * Use nullptr * Use range-for * omit QLatin1{String|Char} where possible Change-Id: Ib231b747cdd9073b3d4fc6779b8e0afb2b404a31 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
André Hartmann
parent
53a151074a
commit
aae3056b33
@@ -191,7 +191,7 @@ void DescriptionEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
|||||||
bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor)
|
bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
m_currentCursor = cursor;
|
m_currentCursor = cursor;
|
||||||
return cursor.block().text() == QLatin1String(Constants::EXPAND_BRANCHES);
|
return cursor.block().text() == Constants::EXPAND_BRANCHES;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionEditorWidget::highlightCurrentContents()
|
void DescriptionEditorWidget::highlightCurrentContents()
|
||||||
@@ -210,28 +210,13 @@ void DescriptionEditorWidget::handleCurrentContents()
|
|||||||
{
|
{
|
||||||
m_currentCursor.select(QTextCursor::LineUnderCursor);
|
m_currentCursor.select(QTextCursor::LineUnderCursor);
|
||||||
m_currentCursor.removeSelectedText();
|
m_currentCursor.removeSelectedText();
|
||||||
m_currentCursor.insertText(QLatin1String("Branches: Expanding..."));
|
m_currentCursor.insertText("Branches: Expanding...");
|
||||||
emit requestBranchList();
|
emit requestBranchList();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////// DiffEditor //////////////////////////////////
|
///////////////////////////////// DiffEditor //////////////////////////////////
|
||||||
|
|
||||||
DiffEditor::DiffEditor()
|
DiffEditor::DiffEditor()
|
||||||
: m_document(0)
|
|
||||||
, m_descriptionWidget(0)
|
|
||||||
, m_stackedWidget(0)
|
|
||||||
, m_toolBar(0)
|
|
||||||
, m_entriesComboBox(0)
|
|
||||||
, m_contextSpinBox(0)
|
|
||||||
, m_toggleSyncAction(0)
|
|
||||||
, m_whitespaceButtonAction(0)
|
|
||||||
, m_toggleDescriptionAction(0)
|
|
||||||
, m_reloadAction(0)
|
|
||||||
, m_viewSwitcherAction(0)
|
|
||||||
, m_currentViewIndex(-1)
|
|
||||||
, m_currentDiffFileIndex(-1)
|
|
||||||
, m_sync(false)
|
|
||||||
, m_showDescription(true)
|
|
||||||
{
|
{
|
||||||
// Editor:
|
// Editor:
|
||||||
setDuplicateSupported(true);
|
setDuplicateSupported(true);
|
||||||
@@ -458,7 +443,7 @@ void DiffEditor::toggleDescription()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_showDescription = !m_showDescription;
|
m_showDescription = !m_showDescription;
|
||||||
saveSetting(QLatin1String(descriptionVisibleKeyC), m_showDescription);
|
saveSetting(descriptionVisibleKeyC, m_showDescription);
|
||||||
updateDescription();
|
updateDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +471,7 @@ void DiffEditor::contextLineCountHasChanged(int lines)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_document->setContextLineCount(lines);
|
m_document->setContextLineCount(lines);
|
||||||
saveSetting(QLatin1String(contextLineCountKeyC), lines);
|
saveSetting(contextLineCountKeyC, lines);
|
||||||
|
|
||||||
m_document->reload();
|
m_document->reload();
|
||||||
}
|
}
|
||||||
@@ -498,7 +483,7 @@ void DiffEditor::ignoreWhitespaceHasChanged()
|
|||||||
if (m_ignoreChanges.isLocked() || ignore == m_document->ignoreWhitespace())
|
if (m_ignoreChanges.isLocked() || ignore == m_document->ignoreWhitespace())
|
||||||
return;
|
return;
|
||||||
m_document->setIgnoreWhitespace(ignore);
|
m_document->setIgnoreWhitespace(ignore);
|
||||||
saveSetting(QLatin1String(ignoreWhitespaceKeyC), ignore);
|
saveSetting(ignoreWhitespaceKeyC, ignore);
|
||||||
|
|
||||||
m_document->reload();
|
m_document->reload();
|
||||||
}
|
}
|
||||||
@@ -605,7 +590,7 @@ void DiffEditor::toggleSync()
|
|||||||
|
|
||||||
QTC_ASSERT(currentView(), return);
|
QTC_ASSERT(currentView(), return);
|
||||||
m_sync = !m_sync;
|
m_sync = !m_sync;
|
||||||
saveSetting(QLatin1String(horizontalScrollBarSynchronizationKeyC), m_sync);
|
saveSetting(horizontalScrollBarSynchronizationKeyC, m_sync);
|
||||||
currentView()->setSync(m_sync);
|
currentView()->setSync(m_sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,12 +600,12 @@ IDiffView *DiffEditor::loadSettings()
|
|||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
|
|
||||||
// Read current settings:
|
// Read current settings:
|
||||||
s->beginGroup(QLatin1String(settingsGroupC));
|
s->beginGroup(settingsGroupC);
|
||||||
m_showDescription = s->value(QLatin1String(descriptionVisibleKeyC), true).toBool();
|
m_showDescription = s->value(descriptionVisibleKeyC, true).toBool();
|
||||||
m_sync = s->value(QLatin1String(horizontalScrollBarSynchronizationKeyC), true).toBool();
|
m_sync = s->value(horizontalScrollBarSynchronizationKeyC, true).toBool();
|
||||||
m_document->setIgnoreWhitespace(s->value(QLatin1String(ignoreWhitespaceKeyC), false).toBool());
|
m_document->setIgnoreWhitespace(s->value(ignoreWhitespaceKeyC, false).toBool());
|
||||||
m_document->setContextLineCount(s->value(QLatin1String(contextLineCountKeyC), 3).toInt());
|
m_document->setContextLineCount(s->value(contextLineCountKeyC, 3).toInt());
|
||||||
Core::Id id = Core::Id::fromSetting(s->value(QLatin1String(diffViewKeyC)));
|
Core::Id id = Core::Id::fromSetting(s->value(diffViewKeyC));
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
IDiffView *view = Utils::findOr(m_views, m_views.at(0),
|
IDiffView *view = Utils::findOr(m_views, m_views.at(0),
|
||||||
@@ -633,7 +618,7 @@ IDiffView *DiffEditor::loadSettings()
|
|||||||
void DiffEditor::saveSetting(const QString &key, const QVariant &value) const
|
void DiffEditor::saveSetting(const QString &key, const QVariant &value) const
|
||||||
{
|
{
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
s->beginGroup(QLatin1String(settingsGroupC));
|
s->beginGroup(settingsGroupC);
|
||||||
s->setValue(key, value);
|
s->setValue(key, value);
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
@@ -677,7 +662,7 @@ void DiffEditor::setupView(IDiffView *view)
|
|||||||
QTC_ASSERT(view, return);
|
QTC_ASSERT(view, return);
|
||||||
setCurrentView(view);
|
setCurrentView(view);
|
||||||
|
|
||||||
saveSetting(QLatin1String(diffViewKeyC), currentView()->id().toSetting());
|
saveSetting(diffViewKeyC, currentView()->id().toSetting());
|
||||||
|
|
||||||
{
|
{
|
||||||
Utils::GuardLocker guard(m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
|
@@ -93,14 +93,14 @@ private:
|
|||||||
void setupView(IDiffView *view);
|
void setupView(IDiffView *view);
|
||||||
|
|
||||||
QSharedPointer<DiffEditorDocument> m_document;
|
QSharedPointer<DiffEditorDocument> m_document;
|
||||||
DescriptionEditorWidget *m_descriptionWidget;
|
DescriptionEditorWidget *m_descriptionWidget = nullptr;
|
||||||
UnifiedView *m_unifiedView;
|
UnifiedView *m_unifiedView = nullptr;
|
||||||
SideBySideView *m_sideBySideView;
|
SideBySideView *m_sideBySideView = nullptr;
|
||||||
QStackedWidget *m_stackedWidget;
|
QStackedWidget *m_stackedWidget = nullptr;
|
||||||
QVector<IDiffView *> m_views;
|
QVector<IDiffView *> m_views;
|
||||||
QToolBar *m_toolBar;
|
QToolBar *m_toolBar = nullptr;
|
||||||
QComboBox *m_entriesComboBox;
|
QComboBox *m_entriesComboBox = nullptr;
|
||||||
QSpinBox *m_contextSpinBox;
|
QSpinBox *m_contextSpinBox = nullptr;
|
||||||
QAction *m_contextSpinBoxAction = nullptr;
|
QAction *m_contextSpinBoxAction = nullptr;
|
||||||
QAction *m_toggleSyncAction;
|
QAction *m_toggleSyncAction;
|
||||||
QAction *m_whitespaceButtonAction;
|
QAction *m_whitespaceButtonAction;
|
||||||
@@ -109,11 +109,11 @@ private:
|
|||||||
QAction *m_contextLabelAction = nullptr;
|
QAction *m_contextLabelAction = nullptr;
|
||||||
QAction *m_viewSwitcherAction;
|
QAction *m_viewSwitcherAction;
|
||||||
QPair<QString, QString> m_currentFileChunk;
|
QPair<QString, QString> m_currentFileChunk;
|
||||||
int m_currentViewIndex;
|
int m_currentViewIndex = -1;
|
||||||
int m_currentDiffFileIndex;
|
int m_currentDiffFileIndex = -1;
|
||||||
Utils::Guard m_ignoreChanges;
|
Utils::Guard m_ignoreChanges;
|
||||||
bool m_sync;
|
bool m_sync = false;
|
||||||
bool m_showDescription;
|
bool m_showDescription = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -39,10 +39,7 @@ namespace DiffEditor {
|
|||||||
|
|
||||||
DiffEditorController::DiffEditorController(Core::IDocument *document) :
|
DiffEditorController::DiffEditorController(Core::IDocument *document) :
|
||||||
QObject(document),
|
QObject(document),
|
||||||
m_document(qobject_cast<Internal::DiffEditorDocument *>(document)),
|
m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
||||||
m_isReloading(false),
|
|
||||||
m_diffFileIndex(-1),
|
|
||||||
m_chunkIndex(-1)
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_document, return);
|
QTC_ASSERT(m_document, return);
|
||||||
m_document->setController(this);
|
m_document->setController(this);
|
||||||
@@ -109,7 +106,7 @@ void DiffEditorController::setDescription(const QString &description)
|
|||||||
void DiffEditorController::branchesReceived(const QString &branches)
|
void DiffEditorController::branchesReceived(const QString &branches)
|
||||||
{
|
{
|
||||||
QString tmp = m_document->description();
|
QString tmp = m_document->description();
|
||||||
tmp.replace(QLatin1String(Constants::EXPAND_BRANCHES), branches);
|
tmp.replace(Constants::EXPAND_BRANCHES, branches);
|
||||||
m_document->setDescription(tmp);
|
m_document->setDescription(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -85,9 +85,9 @@ private:
|
|||||||
|
|
||||||
Internal::DiffEditorDocument *const m_document;
|
Internal::DiffEditorDocument *const m_document;
|
||||||
|
|
||||||
bool m_isReloading;
|
bool m_isReloading = false;
|
||||||
int m_diffFileIndex;
|
int m_diffFileIndex = -1;
|
||||||
int m_chunkIndex;
|
int m_chunkIndex = -1;
|
||||||
|
|
||||||
friend class Internal::DiffEditorDocument;
|
friend class Internal::DiffEditorDocument;
|
||||||
};
|
};
|
||||||
|
@@ -46,14 +46,10 @@ namespace DiffEditor {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
DiffEditorDocument::DiffEditorDocument() :
|
DiffEditorDocument::DiffEditorDocument() :
|
||||||
Core::BaseTextDocument(),
|
Core::BaseTextDocument()
|
||||||
m_controller(0),
|
|
||||||
m_contextLineCount(3),
|
|
||||||
m_isContextLineCountForced(false),
|
|
||||||
m_ignoreWhitespace(false)
|
|
||||||
{
|
{
|
||||||
setId(Constants::DIFF_EDITOR_ID);
|
setId(Constants::DIFF_EDITOR_ID);
|
||||||
setMimeType(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
|
setMimeType(Constants::DIFF_EDITOR_MIMETYPE);
|
||||||
setTemporary(true);
|
setTemporary(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +107,8 @@ QString DiffEditorDocument::makePatch(int fileIndex, int chunkIndex,
|
|||||||
|
|
||||||
QString leftPrefix, rightPrefix;
|
QString leftPrefix, rightPrefix;
|
||||||
if (addPrefix) {
|
if (addPrefix) {
|
||||||
leftPrefix = QLatin1String("a/");
|
leftPrefix = "a/";
|
||||||
rightPrefix = QLatin1String("b/");
|
rightPrefix = "b/";
|
||||||
}
|
}
|
||||||
return DiffUtils::makePatch(chunkData,
|
return DiffUtils::makePatch(chunkData,
|
||||||
leftPrefix + fileName,
|
leftPrefix + fileName,
|
||||||
@@ -287,10 +283,10 @@ QString DiffEditorDocument::fallbackSaveAsFileName() const
|
|||||||
|
|
||||||
const QString desc = description();
|
const QString desc = description();
|
||||||
if (!desc.isEmpty()) {
|
if (!desc.isEmpty()) {
|
||||||
QString name = QString::fromLatin1("0001-%1").arg(desc.left(desc.indexOf(QLatin1Char('\n'))));
|
QString name = QString::fromLatin1("0001-%1").arg(desc.left(desc.indexOf('\n')));
|
||||||
name = FileUtils::fileSystemFriendlyName(name);
|
name = FileUtils::fileSystemFriendlyName(name);
|
||||||
name.truncate(maxSubjectLength);
|
name.truncate(maxSubjectLength);
|
||||||
name.append(QLatin1String(".patch"));
|
name.append(".patch");
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
return QStringLiteral("0001.patch");
|
return QStringLiteral("0001.patch");
|
||||||
@@ -303,17 +299,17 @@ static void formatGitDescription(QString *description)
|
|||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
result.reserve(description->size());
|
result.reserve(description->size());
|
||||||
foreach (QString line, description->split(QLatin1Char('\n'))) {
|
const auto descriptionList = description->split('\n');
|
||||||
if (line.startsWith(QLatin1String("commit "))
|
for (QString line : descriptionList) {
|
||||||
|| line.startsWith(QLatin1String("Branches: <Expand>"))) {
|
if (line.startsWith("commit ") || line.startsWith("Branches: <Expand>"))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (line.startsWith(QLatin1String("Author: ")))
|
if (line.startsWith("Author: "))
|
||||||
line.replace(0, 8, QStringLiteral("From: "));
|
line.replace(0, 8, "From: ");
|
||||||
else if (line.startsWith(QLatin1String(" ")))
|
else if (line.startsWith(" "))
|
||||||
line.remove(0, 4);
|
line.remove(0, 4);
|
||||||
result.append(line);
|
result.append(line);
|
||||||
result.append(QLatin1Char('\n'));
|
result.append('\n');
|
||||||
}
|
}
|
||||||
*description = result;
|
*description = result;
|
||||||
}
|
}
|
||||||
@@ -328,7 +324,7 @@ QString DiffEditorDocument::plainText() const
|
|||||||
const QString diff = DiffUtils::makePatch(diffFiles(), formattingOptions);
|
const QString diff = DiffUtils::makePatch(diffFiles(), formattingOptions);
|
||||||
if (!diff.isEmpty()) {
|
if (!diff.isEmpty()) {
|
||||||
if (!result.isEmpty())
|
if (!result.isEmpty())
|
||||||
result += QLatin1Char('\n');
|
result += '\n';
|
||||||
result += diff;
|
result += diff;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -98,14 +98,14 @@ private:
|
|||||||
void endReload(bool success);
|
void endReload(bool success);
|
||||||
void setController(DiffEditorController *controller);
|
void setController(DiffEditorController *controller);
|
||||||
|
|
||||||
DiffEditorController *m_controller;
|
DiffEditorController *m_controller = nullptr;
|
||||||
QList<FileData> m_diffFiles;
|
QList<FileData> m_diffFiles;
|
||||||
QString m_baseDirectory;
|
QString m_baseDirectory;
|
||||||
QString m_startupFile;
|
QString m_startupFile;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
int m_contextLineCount;
|
int m_contextLineCount = 3;
|
||||||
bool m_isContextLineCountForced;
|
bool m_isContextLineCountForced = false;
|
||||||
bool m_ignoreWhitespace;
|
bool m_ignoreWhitespace = false;
|
||||||
State m_state = LoadOK;
|
State m_state = LoadOK;
|
||||||
|
|
||||||
friend class ::DiffEditor::DiffEditorController;
|
friend class ::DiffEditor::DiffEditorController;
|
||||||
|
@@ -31,11 +31,11 @@ namespace DiffEditor {
|
|||||||
namespace Icons {
|
namespace Icons {
|
||||||
|
|
||||||
const Utils::Icon TOP_BAR({
|
const Utils::Icon TOP_BAR({
|
||||||
{QLatin1String(":/diffeditor/images/topbar.png"), Utils::Theme::IconsBaseColor}});
|
{":/diffeditor/images/topbar.png", Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon UNIFIED_DIFF({
|
const Utils::Icon UNIFIED_DIFF({
|
||||||
{QLatin1String(":/diffeditor/images/unifieddiff.png"), Utils::Theme::IconsBaseColor}});
|
{":/diffeditor/images/unifieddiff.png", Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon SIDEBYSIDE_DIFF({
|
const Utils::Icon SIDEBYSIDE_DIFF({
|
||||||
{QLatin1String(":/diffeditor/images/sidebysidediff.png"), Utils::Theme::IconsBaseColor}});
|
{":/diffeditor/images/sidebysidediff.png", Utils::Theme::IconsBaseColor}});
|
||||||
|
|
||||||
} // namespace Icons
|
} // namespace Icons
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
@@ -251,7 +251,7 @@ QList<ReloadInput> DiffOpenFilesController::reloadInputList() const
|
|||||||
|
|
||||||
const QList<IDocument *> openedDocuments = DocumentModel::openedDocuments();
|
const QList<IDocument *> openedDocuments = DocumentModel::openedDocuments();
|
||||||
|
|
||||||
foreach (IDocument *doc, openedDocuments) {
|
for (IDocument *doc : openedDocuments) {
|
||||||
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(doc);
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(doc);
|
||||||
|
|
||||||
if (textDocument && textDocument->isModified()) {
|
if (textDocument && textDocument->isModified()) {
|
||||||
@@ -312,7 +312,7 @@ QList<ReloadInput> DiffModifiedFilesController::reloadInputList() const
|
|||||||
{
|
{
|
||||||
QList<ReloadInput> result;
|
QList<ReloadInput> result;
|
||||||
|
|
||||||
foreach (const QString fileName, m_fileNames) {
|
for (const QString &fileName : m_fileNames) {
|
||||||
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(
|
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||||
DocumentModel::documentForFilePath(fileName));
|
DocumentModel::documentForFilePath(fileName));
|
||||||
|
|
||||||
@@ -623,17 +623,17 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
QTest::addColumn<bool>("lastChunk");
|
QTest::addColumn<bool>("lastChunk");
|
||||||
QTest::addColumn<QString>("patchText");
|
QTest::addColumn<QString>("patchText");
|
||||||
|
|
||||||
const QString fileName = _("a.txt");
|
const QString fileName = "a.txt";
|
||||||
const QString header = _("--- ") + fileName + _("\n+++ ") + fileName + _("\n");
|
const QString header = "--- " + fileName + "\n+++ " + fileName + '\n';
|
||||||
|
|
||||||
QList<RowData> rows;
|
QList<RowData> rows;
|
||||||
rows << RowData(_("ABCD"), TextLineData::Separator);
|
rows << RowData(_("ABCD"), TextLineData::Separator);
|
||||||
rows << RowData(_("EFGH"));
|
rows << RowData(_("EFGH"));
|
||||||
ChunkData chunk;
|
ChunkData chunk;
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
QString patchText = header + _("@@ -1,2 +1,1 @@\n"
|
QString patchText = header + "@@ -1,2 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
" EFGH\n");
|
" EFGH\n";
|
||||||
QTest::newRow("Simple not a last chunk") << chunk
|
QTest::newRow("Simple not a last chunk") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -643,10 +643,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
///////////
|
///////////
|
||||||
|
|
||||||
// chunk the same here
|
// chunk the same here
|
||||||
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
patchText = header + "@@ -1,2 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
" EFGH\n"
|
" EFGH\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("Simple last chunk") << chunk
|
QTest::newRow("Simple last chunk") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -660,10 +660,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(_("ABCD"));
|
rows << RowData(_("ABCD"));
|
||||||
rows << RowData(_(""), TextLineData::Separator);
|
rows << RowData(_(""), TextLineData::Separator);
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
patchText = header + "@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+ABCD\n"
|
"+ABCD\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("EOL in last line removed") << chunk
|
QTest::newRow("EOL in last line removed") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -674,9 +674,9 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
///////////
|
///////////
|
||||||
|
|
||||||
// chunk the same here
|
// chunk the same here
|
||||||
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
patchText = header + "@@ -1,2 +1,1 @@\n"
|
||||||
" ABCD\n"
|
" ABCD\n"
|
||||||
"-\n");
|
"-\n";
|
||||||
|
|
||||||
QTest::newRow("Last empty line removed") << chunk
|
QTest::newRow("Last empty line removed") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -691,11 +691,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(_(""), TextLineData::Separator);
|
rows << RowData(_(""), TextLineData::Separator);
|
||||||
rows << RowData(_(""), TextLineData::Separator);
|
rows << RowData(_(""), TextLineData::Separator);
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,2 +1,1 @@\n"
|
patchText = header + "@@ -1,2 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"-\n"
|
"-\n"
|
||||||
"+ABCD\n"
|
"+ABCD\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("Two last EOLs removed") << chunk
|
QTest::newRow("Two last EOLs removed") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -709,10 +709,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(_("ABCD"));
|
rows << RowData(_("ABCD"));
|
||||||
rows << RowData(TextLineData::Separator, _(""));
|
rows << RowData(TextLineData::Separator, _(""));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
patchText = header + "@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"\\ No newline at end of file\n"
|
"\\ No newline at end of file\n"
|
||||||
"+ABCD\n");
|
"+ABCD\n";
|
||||||
|
|
||||||
QTest::newRow("EOL to last line added") << chunk
|
QTest::newRow("EOL to last line added") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -723,9 +723,9 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
///////////
|
///////////
|
||||||
|
|
||||||
// chunk the same here
|
// chunk the same here
|
||||||
patchText = header + _("@@ -1,1 +1,2 @@\n"
|
patchText = header + "@@ -1,1 +1,2 @@\n"
|
||||||
" ABCD\n"
|
" ABCD\n"
|
||||||
"+\n");
|
"+\n";
|
||||||
|
|
||||||
QTest::newRow("Last empty line added") << chunk
|
QTest::newRow("Last empty line added") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -738,9 +738,9 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows.clear();
|
rows.clear();
|
||||||
rows << RowData(_("ABCD"), _("EFGH"));
|
rows << RowData(_("ABCD"), _("EFGH"));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
patchText = header + "@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+EFGH\n");
|
"+EFGH\n";
|
||||||
|
|
||||||
QTest::newRow("Last line with a newline modified") << chunk
|
QTest::newRow("Last line with a newline modified") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -754,10 +754,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(_("ABCD"), _("EFGH"));
|
rows << RowData(_("ABCD"), _("EFGH"));
|
||||||
rows << RowData(_(""));
|
rows << RowData(_(""));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
patchText = header + "@@ -1,2 +1,2 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
" \n");
|
" \n";
|
||||||
QTest::newRow("Not a last line with a newline modified") << chunk
|
QTest::newRow("Not a last line with a newline modified") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -769,11 +769,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows.clear();
|
rows.clear();
|
||||||
rows << RowData(_("ABCD"), _("EFGH"));
|
rows << RowData(_("ABCD"), _("EFGH"));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
patchText = header + "@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"\\ No newline at end of file\n"
|
"\\ No newline at end of file\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("Last line without a newline modified") << chunk
|
QTest::newRow("Last line without a newline modified") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -784,9 +784,9 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
///////////
|
///////////
|
||||||
|
|
||||||
// chunk the same here
|
// chunk the same here
|
||||||
patchText = header + _("@@ -1,1 +1,1 @@\n"
|
patchText = header + "@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+EFGH\n");
|
"+EFGH\n";
|
||||||
QTest::newRow("Not a last line without a newline modified") << chunk
|
QTest::newRow("Not a last line without a newline modified") << chunk
|
||||||
<< fileName
|
<< fileName
|
||||||
<< fileName
|
<< fileName
|
||||||
@@ -799,11 +799,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(_("ABCD"), _("EFGH"));
|
rows << RowData(_("ABCD"), _("EFGH"));
|
||||||
rows << RowData(_("IJKL"));
|
rows << RowData(_("IJKL"));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
patchText = header + "@@ -1,2 +1,2 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
" IJKL\n"
|
" IJKL\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("Last but one line modified, last line without a newline")
|
QTest::newRow("Last but one line modified, last line without a newline")
|
||||||
<< chunk
|
<< chunk
|
||||||
@@ -815,10 +815,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
///////////
|
///////////
|
||||||
|
|
||||||
// chunk the same here
|
// chunk the same here
|
||||||
patchText = header + _("@@ -1,2 +1,2 @@\n"
|
patchText = header + "@@ -1,2 +1,2 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
" IJKL\n");
|
" IJKL\n";
|
||||||
|
|
||||||
QTest::newRow("Last but one line modified, last line with a newline")
|
QTest::newRow("Last but one line modified, last line with a newline")
|
||||||
<< chunk
|
<< chunk
|
||||||
@@ -834,11 +834,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data()
|
|||||||
rows << RowData(TextLineData::Separator, _(""));
|
rows << RowData(TextLineData::Separator, _(""));
|
||||||
rows << RowData(_(""), _("EFGH"));
|
rows << RowData(_(""), _("EFGH"));
|
||||||
chunk.rows = rows;
|
chunk.rows = rows;
|
||||||
patchText = header + _("@@ -1,1 +1,3 @@\n"
|
patchText = header + "@@ -1,1 +1,3 @@\n"
|
||||||
" ABCD\n"
|
" ABCD\n"
|
||||||
"+\n"
|
"+\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
QTest::newRow("Blank line followed by No newline")
|
QTest::newRow("Blank line followed by No newline")
|
||||||
<< chunk
|
<< chunk
|
||||||
@@ -894,7 +894,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
QTest::addColumn<QString>("sourcePatch");
|
QTest::addColumn<QString>("sourcePatch");
|
||||||
QTest::addColumn<QList<FileData> >("fileDataList");
|
QTest::addColumn<QList<FileData> >("fileDataList");
|
||||||
|
|
||||||
QString patch = _("diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp\n"
|
QString patch = "diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp\n"
|
||||||
"index eab9e9b..082c135 100644\n"
|
"index eab9e9b..082c135 100644\n"
|
||||||
"--- a/src/plugins/diffeditor/diffeditor.cpp\n"
|
"--- a/src/plugins/diffeditor/diffeditor.cpp\n"
|
||||||
"+++ b/src/plugins/diffeditor/diffeditor.cpp\n"
|
"+++ b/src/plugins/diffeditor/diffeditor.cpp\n"
|
||||||
@@ -972,11 +972,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
"-B\n"
|
"-B\n"
|
||||||
"+C\n"
|
"+C\n"
|
||||||
" D\n"
|
" D\n"
|
||||||
);
|
;
|
||||||
|
|
||||||
FileData fileData1;
|
FileData fileData1;
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffeditor.cpp"), _("eab9e9b"));
|
fileData1.leftFileInfo = DiffFileInfo("src/plugins/diffeditor/diffeditor.cpp", "eab9e9b");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/diffeditor/diffeditor.cpp"), _("082c135"));
|
fileData1.rightFileInfo = DiffFileInfo("src/plugins/diffeditor/diffeditor.cpp", "082c135");
|
||||||
ChunkData chunkData1;
|
ChunkData chunkData1;
|
||||||
chunkData1.leftStartingLineNumber = 186;
|
chunkData1.leftStartingLineNumber = 186;
|
||||||
chunkData1.rightStartingLineNumber = 186;
|
chunkData1.rightStartingLineNumber = 186;
|
||||||
@@ -1016,8 +1016,8 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
fileData2.chunks << chunkData2;
|
fileData2.chunks << chunkData2;
|
||||||
|
|
||||||
FileData fileData3;
|
FileData fileData3;
|
||||||
fileData3.leftFileInfo = DiffFileInfo(_("new"), _("0000000"));
|
fileData3.leftFileInfo = DiffFileInfo("new", "0000000");
|
||||||
fileData3.rightFileInfo = DiffFileInfo(_("new"), _("257cc56"));
|
fileData3.rightFileInfo = DiffFileInfo("new", "257cc56");
|
||||||
fileData3.fileOperation = FileData::NewFile;
|
fileData3.fileOperation = FileData::NewFile;
|
||||||
ChunkData chunkData3;
|
ChunkData chunkData3;
|
||||||
chunkData3.leftStartingLineNumber = -1;
|
chunkData3.leftStartingLineNumber = -1;
|
||||||
@@ -1030,8 +1030,8 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
fileData3.chunks << chunkData3;
|
fileData3.chunks << chunkData3;
|
||||||
|
|
||||||
FileData fileData4;
|
FileData fileData4;
|
||||||
fileData4.leftFileInfo = DiffFileInfo(_("deleted"), _("257cc56"));
|
fileData4.leftFileInfo = DiffFileInfo("deleted", "257cc56");
|
||||||
fileData4.rightFileInfo = DiffFileInfo(_("deleted"), _("0000000"));
|
fileData4.rightFileInfo = DiffFileInfo("deleted", "0000000");
|
||||||
fileData4.fileOperation = FileData::DeleteFile;
|
fileData4.fileOperation = FileData::DeleteFile;
|
||||||
ChunkData chunkData4;
|
ChunkData chunkData4;
|
||||||
chunkData4.leftStartingLineNumber = 0;
|
chunkData4.leftStartingLineNumber = 0;
|
||||||
@@ -1044,18 +1044,18 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
fileData4.chunks << chunkData4;
|
fileData4.chunks << chunkData4;
|
||||||
|
|
||||||
FileData fileData5;
|
FileData fileData5;
|
||||||
fileData5.leftFileInfo = DiffFileInfo(_("empty"), _("0000000"));
|
fileData5.leftFileInfo = DiffFileInfo("empty", "0000000");
|
||||||
fileData5.rightFileInfo = DiffFileInfo(_("empty"), _("e69de29"));
|
fileData5.rightFileInfo = DiffFileInfo("empty", "e69de29");
|
||||||
fileData5.fileOperation = FileData::NewFile;
|
fileData5.fileOperation = FileData::NewFile;
|
||||||
|
|
||||||
FileData fileData6;
|
FileData fileData6;
|
||||||
fileData6.leftFileInfo = DiffFileInfo(_("empty"), _("e69de29"));
|
fileData6.leftFileInfo = DiffFileInfo("empty", "e69de29");
|
||||||
fileData6.rightFileInfo = DiffFileInfo(_("empty"), _("0000000"));
|
fileData6.rightFileInfo = DiffFileInfo("empty", "0000000");
|
||||||
fileData6.fileOperation = FileData::DeleteFile;
|
fileData6.fileOperation = FileData::DeleteFile;
|
||||||
|
|
||||||
FileData fileData7;
|
FileData fileData7;
|
||||||
fileData7.leftFileInfo = DiffFileInfo(_("file a.txt"), _("1234567"));
|
fileData7.leftFileInfo = DiffFileInfo("file a.txt", "1234567");
|
||||||
fileData7.rightFileInfo = DiffFileInfo(_("file b.txt"), _("9876543"));
|
fileData7.rightFileInfo = DiffFileInfo("file b.txt", "9876543");
|
||||||
fileData7.fileOperation = FileData::CopyFile;
|
fileData7.fileOperation = FileData::CopyFile;
|
||||||
ChunkData chunkData7;
|
ChunkData chunkData7;
|
||||||
chunkData7.leftStartingLineNumber = 19;
|
chunkData7.leftStartingLineNumber = 19;
|
||||||
@@ -1068,13 +1068,13 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
fileData7.chunks << chunkData7;
|
fileData7.chunks << chunkData7;
|
||||||
|
|
||||||
FileData fileData8;
|
FileData fileData8;
|
||||||
fileData8.leftFileInfo = DiffFileInfo(_("file a.txt"));
|
fileData8.leftFileInfo = DiffFileInfo("file a.txt");
|
||||||
fileData8.rightFileInfo = DiffFileInfo(_("file b.txt"));
|
fileData8.rightFileInfo = DiffFileInfo("file b.txt");
|
||||||
fileData8.fileOperation = FileData::RenameFile;
|
fileData8.fileOperation = FileData::RenameFile;
|
||||||
|
|
||||||
FileData fileData9;
|
FileData fileData9;
|
||||||
fileData9.leftFileInfo = DiffFileInfo(_("file.txt"), _("1234567"));
|
fileData9.leftFileInfo = DiffFileInfo("file.txt", "1234567");
|
||||||
fileData9.rightFileInfo = DiffFileInfo(_("file.txt"), _("9876543"));
|
fileData9.rightFileInfo = DiffFileInfo("file.txt", "9876543");
|
||||||
fileData9.chunks << chunkData7;
|
fileData9.chunks << chunkData7;
|
||||||
QList<FileData> fileDataList1;
|
QList<FileData> fileDataList1;
|
||||||
fileDataList1 << fileData1 << fileData2 << fileData3 << fileData4 << fileData5
|
fileDataList1 << fileData1 << fileData2 << fileData3 << fileData4 << fileData5
|
||||||
@@ -1085,7 +1085,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
patch = "diff --git a/file foo.txt b/file foo.txt\n"
|
||||||
"index 1234567..9876543 100644\n"
|
"index 1234567..9876543 100644\n"
|
||||||
"--- a/file foo.txt\n"
|
"--- a/file foo.txt\n"
|
||||||
"+++ b/file foo.txt\n"
|
"+++ b/file foo.txt\n"
|
||||||
@@ -1093,10 +1093,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
" A\n"
|
" A\n"
|
||||||
" B\n"
|
" B\n"
|
||||||
" C\n"
|
" C\n"
|
||||||
"+\n");
|
"+\n";
|
||||||
|
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
fileData1.leftFileInfo = DiffFileInfo("file foo.txt", "1234567");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
fileData1.rightFileInfo = DiffFileInfo("file foo.txt", "9876543");
|
||||||
fileData1.fileOperation = FileData::ChangeFile;
|
fileData1.fileOperation = FileData::ChangeFile;
|
||||||
chunkData1.leftStartingLineNumber = 49;
|
chunkData1.leftStartingLineNumber = 49;
|
||||||
chunkData1.rightStartingLineNumber = 49;
|
chunkData1.rightStartingLineNumber = 49;
|
||||||
@@ -1117,17 +1117,17 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
patch = "diff --git a/file foo.txt b/file foo.txt\n"
|
||||||
"index 1234567..9876543 100644\n"
|
"index 1234567..9876543 100644\n"
|
||||||
"--- a/file foo.txt\n"
|
"--- a/file foo.txt\n"
|
||||||
"+++ b/file foo.txt\n"
|
"+++ b/file foo.txt\n"
|
||||||
"@@ -1,1 +1,1 @@\n"
|
"@@ -1,1 +1,1 @@\n"
|
||||||
"-ABCD\n"
|
"-ABCD\n"
|
||||||
"\\ No newline at end of file\n"
|
"\\ No newline at end of file\n"
|
||||||
"+ABCD\n");
|
"+ABCD\n";
|
||||||
|
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
fileData1.leftFileInfo = DiffFileInfo("file foo.txt", "1234567");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
fileData1.rightFileInfo = DiffFileInfo("file foo.txt", "9876543");
|
||||||
fileData1.fileOperation = FileData::ChangeFile;
|
fileData1.fileOperation = FileData::ChangeFile;
|
||||||
chunkData1.leftStartingLineNumber = 0;
|
chunkData1.leftStartingLineNumber = 0;
|
||||||
chunkData1.rightStartingLineNumber = 0;
|
chunkData1.rightStartingLineNumber = 0;
|
||||||
@@ -1144,7 +1144,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
QTest::newRow("Last newline added to a line without newline") << patch
|
QTest::newRow("Last newline added to a line without newline") << patch
|
||||||
<< fileDataList3;
|
<< fileDataList3;
|
||||||
|
|
||||||
patch = _("diff --git a/difftest.txt b/difftest.txt\n"
|
patch = "diff --git a/difftest.txt b/difftest.txt\n"
|
||||||
"index 1234567..9876543 100644\n"
|
"index 1234567..9876543 100644\n"
|
||||||
"--- a/difftest.txt\n"
|
"--- a/difftest.txt\n"
|
||||||
"+++ b/difftest.txt\n"
|
"+++ b/difftest.txt\n"
|
||||||
@@ -1160,10 +1160,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
" D\n"
|
" D\n"
|
||||||
"+E\n"
|
"+E\n"
|
||||||
"+F\n"
|
"+F\n"
|
||||||
);
|
;
|
||||||
|
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("difftest.txt"), _("1234567"));
|
fileData1.leftFileInfo = DiffFileInfo("difftest.txt", "1234567");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("difftest.txt"), _("9876543"));
|
fileData1.rightFileInfo = DiffFileInfo("difftest.txt", "9876543");
|
||||||
fileData1.fileOperation = FileData::ChangeFile;
|
fileData1.fileOperation = FileData::ChangeFile;
|
||||||
chunkData1.leftStartingLineNumber = 1;
|
chunkData1.leftStartingLineNumber = 1;
|
||||||
chunkData1.rightStartingLineNumber = 1;
|
chunkData1.rightStartingLineNumber = 1;
|
||||||
@@ -1195,7 +1195,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
patch = _("diff --git a/file foo.txt b/file foo.txt\n"
|
patch = "diff --git a/file foo.txt b/file foo.txt\n"
|
||||||
"index 1234567..9876543 100644\n"
|
"index 1234567..9876543 100644\n"
|
||||||
"--- a/file foo.txt\n"
|
"--- a/file foo.txt\n"
|
||||||
"+++ b/file foo.txt\n"
|
"+++ b/file foo.txt\n"
|
||||||
@@ -1203,10 +1203,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
" ABCD\n"
|
" ABCD\n"
|
||||||
"+\n"
|
"+\n"
|
||||||
"+EFGH\n"
|
"+EFGH\n"
|
||||||
"\\ No newline at end of file\n");
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567"));
|
fileData1.leftFileInfo = DiffFileInfo("file foo.txt", "1234567");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543"));
|
fileData1.rightFileInfo = DiffFileInfo("file foo.txt", "9876543");
|
||||||
fileData1.fileOperation = FileData::ChangeFile;
|
fileData1.fileOperation = FileData::ChangeFile;
|
||||||
chunkData1.leftStartingLineNumber = 0;
|
chunkData1.leftStartingLineNumber = 0;
|
||||||
chunkData1.rightStartingLineNumber = 0;
|
chunkData1.rightStartingLineNumber = 0;
|
||||||
@@ -1227,7 +1227,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// Based on 953cdb97
|
// Based on 953cdb97
|
||||||
patch = _("diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/textdocument.h\n"
|
patch = "diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/textdocument.h\n"
|
||||||
"similarity index 100%\n"
|
"similarity index 100%\n"
|
||||||
"rename from src/plugins/texteditor/basetextdocument.h\n"
|
"rename from src/plugins/texteditor/basetextdocument.h\n"
|
||||||
"rename to src/plugins/texteditor/textdocument.h\n"
|
"rename to src/plugins/texteditor/textdocument.h\n"
|
||||||
@@ -1245,15 +1245,15 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
"+Z\n"
|
"+Z\n"
|
||||||
" D\n"
|
" D\n"
|
||||||
" \n"
|
" \n"
|
||||||
);
|
;
|
||||||
|
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/texteditor/basetextdocument.h"));
|
fileData1.leftFileInfo = DiffFileInfo("src/plugins/texteditor/basetextdocument.h");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/texteditor/textdocument.h"));
|
fileData1.rightFileInfo = DiffFileInfo("src/plugins/texteditor/textdocument.h");
|
||||||
fileData1.fileOperation = FileData::RenameFile;
|
fileData1.fileOperation = FileData::RenameFile;
|
||||||
fileData2 = FileData();
|
fileData2 = FileData();
|
||||||
fileData2.leftFileInfo = DiffFileInfo(_("src/plugins/texteditor/basetextdocumentlayout.cpp"), _("0121933"));
|
fileData2.leftFileInfo = DiffFileInfo("src/plugins/texteditor/basetextdocumentlayout.cpp", "0121933");
|
||||||
fileData2.rightFileInfo = DiffFileInfo(_("src/plugins/texteditor/textdocumentlayout.cpp"), _("01cc3a0"));
|
fileData2.rightFileInfo = DiffFileInfo("src/plugins/texteditor/textdocumentlayout.cpp", "01cc3a0");
|
||||||
fileData2.fileOperation = FileData::RenameFile;
|
fileData2.fileOperation = FileData::RenameFile;
|
||||||
chunkData2.leftStartingLineNumber = 1;
|
chunkData2.leftStartingLineNumber = 1;
|
||||||
chunkData2.rightStartingLineNumber = 1;
|
chunkData2.rightStartingLineNumber = 1;
|
||||||
@@ -1276,16 +1276,16 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// Dirty submodule
|
// Dirty submodule
|
||||||
patch = _("diff --git a/src/shared/qbs b/src/shared/qbs\n"
|
patch = "diff --git a/src/shared/qbs b/src/shared/qbs\n"
|
||||||
"--- a/src/shared/qbs\n"
|
"--- a/src/shared/qbs\n"
|
||||||
"+++ b/src/shared/qbs\n"
|
"+++ b/src/shared/qbs\n"
|
||||||
"@@ -1 +1 @@\n"
|
"@@ -1 +1 @@\n"
|
||||||
"-Subproject commit eda76354077a427d692fee05479910de31040d3f\n"
|
"-Subproject commit eda76354077a427d692fee05479910de31040d3f\n"
|
||||||
"+Subproject commit eda76354077a427d692fee05479910de31040d3f-dirty\n"
|
"+Subproject commit eda76354077a427d692fee05479910de31040d3f-dirty\n"
|
||||||
);
|
;
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/shared/qbs"));
|
fileData1.leftFileInfo = DiffFileInfo("src/shared/qbs");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/shared/qbs"));
|
fileData1.rightFileInfo = DiffFileInfo("src/shared/qbs");
|
||||||
chunkData1.leftStartingLineNumber = 0;
|
chunkData1.leftStartingLineNumber = 0;
|
||||||
chunkData1.rightStartingLineNumber = 0;
|
chunkData1.rightStartingLineNumber = 0;
|
||||||
rows1.clear();
|
rows1.clear();
|
||||||
@@ -1301,7 +1301,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
<< fileDataList7;
|
<< fileDataList7;
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
patch = _("diff --git a/demos/arthurplugin/arthurplugin.pro b/demos/arthurplugin/arthurplugin.pro\n"
|
patch = "diff --git a/demos/arthurplugin/arthurplugin.pro b/demos/arthurplugin/arthurplugin.pro\n"
|
||||||
"new file mode 100644\n"
|
"new file mode 100644\n"
|
||||||
"index 0000000..c5132b4\n"
|
"index 0000000..c5132b4\n"
|
||||||
"--- /dev/null\n"
|
"--- /dev/null\n"
|
||||||
@@ -1316,11 +1316,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
"new file mode 100644\n"
|
"new file mode 100644\n"
|
||||||
"index 0000000..f8e022c\n"
|
"index 0000000..f8e022c\n"
|
||||||
"Binary files /dev/null and b/demos/arthurplugin/flower.jpg differ\n"
|
"Binary files /dev/null and b/demos/arthurplugin/flower.jpg differ\n"
|
||||||
);
|
;
|
||||||
|
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("demos/arthurplugin/arthurplugin.pro"), _("0000000"));
|
fileData1.leftFileInfo = DiffFileInfo("demos/arthurplugin/arthurplugin.pro", "0000000");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("demos/arthurplugin/arthurplugin.pro"), _("c5132b4"));
|
fileData1.rightFileInfo = DiffFileInfo("demos/arthurplugin/arthurplugin.pro", "c5132b4");
|
||||||
fileData1.fileOperation = FileData::NewFile;
|
fileData1.fileOperation = FileData::NewFile;
|
||||||
chunkData1 = ChunkData();
|
chunkData1 = ChunkData();
|
||||||
chunkData1.leftStartingLineNumber = -1;
|
chunkData1.leftStartingLineNumber = -1;
|
||||||
@@ -1331,13 +1331,13 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
chunkData1.rows = rows1;
|
chunkData1.rows = rows1;
|
||||||
fileData1.chunks << chunkData1;
|
fileData1.chunks << chunkData1;
|
||||||
fileData2 = FileData();
|
fileData2 = FileData();
|
||||||
fileData2.leftFileInfo = DiffFileInfo(_("demos/arthurplugin/bg1.jpg"), _("0000000"));
|
fileData2.leftFileInfo = DiffFileInfo("demos/arthurplugin/bg1.jpg", "0000000");
|
||||||
fileData2.rightFileInfo = DiffFileInfo(_("demos/arthurplugin/bg1.jpg"), _("dfc7cee"));
|
fileData2.rightFileInfo = DiffFileInfo("demos/arthurplugin/bg1.jpg", "dfc7cee");
|
||||||
fileData2.fileOperation = FileData::NewFile;
|
fileData2.fileOperation = FileData::NewFile;
|
||||||
fileData2.binaryFiles = true;
|
fileData2.binaryFiles = true;
|
||||||
fileData3 = FileData();
|
fileData3 = FileData();
|
||||||
fileData3.leftFileInfo = DiffFileInfo(_("demos/arthurplugin/flower.jpg"), _("0000000"));
|
fileData3.leftFileInfo = DiffFileInfo("demos/arthurplugin/flower.jpg", "0000000");
|
||||||
fileData3.rightFileInfo = DiffFileInfo(_("demos/arthurplugin/flower.jpg"), _("f8e022c"));
|
fileData3.rightFileInfo = DiffFileInfo("demos/arthurplugin/flower.jpg", "f8e022c");
|
||||||
fileData3.fileOperation = FileData::NewFile;
|
fileData3.fileOperation = FileData::NewFile;
|
||||||
fileData3.binaryFiles = true;
|
fileData3.binaryFiles = true;
|
||||||
|
|
||||||
@@ -1348,10 +1348,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
<< fileDataList8;
|
<< fileDataList8;
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
patch = _("diff --git a/script.sh b/script.sh\n"
|
patch = "diff --git a/script.sh b/script.sh\n"
|
||||||
"old mode 100644\n"
|
"old mode 100644\n"
|
||||||
"new mode 100755\n"
|
"new mode 100755\n"
|
||||||
);
|
;
|
||||||
|
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo("script.sh");
|
fileData1.leftFileInfo = DiffFileInfo("script.sh");
|
||||||
@@ -1366,14 +1366,14 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// Subversion New
|
// Subversion New
|
||||||
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
|
patch = "Index: src/plugins/subversion/subversioneditor.cpp\n"
|
||||||
"===================================================================\n"
|
"===================================================================\n"
|
||||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
||||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
"+++ src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
||||||
"@@ -0,0 +125 @@\n\n");
|
"@@ -0,0 +125 @@\n\n";
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.leftFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.rightFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
chunkData1 = ChunkData();
|
chunkData1 = ChunkData();
|
||||||
chunkData1.leftStartingLineNumber = -1;
|
chunkData1.leftStartingLineNumber = -1;
|
||||||
chunkData1.rightStartingLineNumber = 124;
|
chunkData1.rightStartingLineNumber = 124;
|
||||||
@@ -1386,14 +1386,14 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// Subversion Deleted
|
// Subversion Deleted
|
||||||
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
|
patch = "Index: src/plugins/subversion/subversioneditor.cpp\n"
|
||||||
"===================================================================\n"
|
"===================================================================\n"
|
||||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
||||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
||||||
"@@ -1,125 +0,0 @@\n\n");
|
"@@ -1,125 +0,0 @@\n\n";
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.leftFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.rightFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
chunkData1 = ChunkData();
|
chunkData1 = ChunkData();
|
||||||
chunkData1.leftStartingLineNumber = 0;
|
chunkData1.leftStartingLineNumber = 0;
|
||||||
chunkData1.rightStartingLineNumber = -1;
|
chunkData1.rightStartingLineNumber = -1;
|
||||||
@@ -1406,14 +1406,14 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// Subversion Normal
|
// Subversion Normal
|
||||||
patch = _("Index: src/plugins/subversion/subversioneditor.cpp\n"
|
patch = "Index: src/plugins/subversion/subversioneditor.cpp\n"
|
||||||
"===================================================================\n"
|
"===================================================================\n"
|
||||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
||||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
||||||
"@@ -120,7 +120,7 @@\n\n");
|
"@@ -120,7 +120,7 @@\n\n";
|
||||||
fileData1 = FileData();
|
fileData1 = FileData();
|
||||||
fileData1.leftFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.leftFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
fileData1.rightFileInfo = DiffFileInfo(_("src/plugins/subversion/subversioneditor.cpp"));
|
fileData1.rightFileInfo = DiffFileInfo("src/plugins/subversion/subversioneditor.cpp");
|
||||||
chunkData1 = ChunkData();
|
chunkData1 = ChunkData();
|
||||||
chunkData1.leftStartingLineNumber = 119;
|
chunkData1.leftStartingLineNumber = 119;
|
||||||
chunkData1.rightStartingLineNumber = 119;
|
chunkData1.rightStartingLineNumber = 119;
|
||||||
|
@@ -289,7 +289,7 @@ void DiffEditorWidgetController::slotSendChunkToCodePaster()
|
|||||||
if (patch.isEmpty())
|
if (patch.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pasteService->postText(patch, QLatin1String(Constants::DIFF_EDITOR_MIMETYPE));
|
pasteService->postText(patch, Constants::DIFF_EDITOR_MIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditorWidgetController::slotApplyChunk()
|
void DiffEditorWidgetController::slotApplyChunk()
|
||||||
|
@@ -81,7 +81,7 @@ private:
|
|||||||
void showProgress();
|
void showProgress();
|
||||||
void hideProgress();
|
void hideProgress();
|
||||||
|
|
||||||
QWidget *m_diffEditorWidget;
|
QWidget *m_diffEditorWidget = nullptr;
|
||||||
|
|
||||||
DiffEditorDocument *m_document = nullptr;
|
DiffEditorDocument *m_document = nullptr;
|
||||||
|
|
||||||
|
@@ -236,14 +236,14 @@ static int cleanupSemanticsScore(const QString &text1, const QString &text2)
|
|||||||
|
|
||||||
static bool isWhitespace(const QChar &c)
|
static bool isWhitespace(const QChar &c)
|
||||||
{
|
{
|
||||||
if (c == QLatin1Char(' ') || c == QLatin1Char('\t'))
|
if (c == ' ' || c == '\t')
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNewLine(const QChar &c)
|
static bool isNewLine(const QChar &c)
|
||||||
{
|
{
|
||||||
if (c == QLatin1Char('\n'))
|
if (c == '\n')
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -362,7 +362,7 @@ static QString encodeReducedWhitespace(const QString &input,
|
|||||||
QChar c = input.at(inputIndex);
|
QChar c = input.at(inputIndex);
|
||||||
|
|
||||||
if (isWhitespace(c)) {
|
if (isWhitespace(c)) {
|
||||||
output.append(QLatin1Char(' '));
|
output.append(' ');
|
||||||
codeMap->insert(outputIndex, QString(c));
|
codeMap->insert(outputIndex, QString(c));
|
||||||
++inputIndex;
|
++inputIndex;
|
||||||
|
|
||||||
@@ -564,7 +564,7 @@ static QString encodeExpandedWhitespace(const QString &leftEquality,
|
|||||||
if (leftWhitespaces.count() && rightWhitespaces.count()) {
|
if (leftWhitespaces.count() && rightWhitespaces.count()) {
|
||||||
const int replacementPosition = output.count();
|
const int replacementPosition = output.count();
|
||||||
const int replacementSize = qMax(leftWhitespaces.count(), rightWhitespaces.count());
|
const int replacementSize = qMax(leftWhitespaces.count(), rightWhitespaces.count());
|
||||||
const QString replacement(replacementSize, QLatin1Char(' '));
|
const QString replacement(replacementSize, ' ');
|
||||||
leftCodeMap->insert(replacementPosition,
|
leftCodeMap->insert(replacementPosition,
|
||||||
qMakePair(replacementSize, leftWhitespaces));
|
qMakePair(replacementSize, leftWhitespaces));
|
||||||
rightCodeMap->insert(replacementPosition,
|
rightCodeMap->insert(replacementPosition,
|
||||||
@@ -968,17 +968,14 @@ QString Diff::toString() const
|
|||||||
{
|
{
|
||||||
QString prettyText = text;
|
QString prettyText = text;
|
||||||
// Replace linebreaks with pretty char
|
// Replace linebreaks with pretty char
|
||||||
prettyText.replace(QLatin1Char('\n'), QLatin1Char('\xb6'));
|
prettyText.replace('\n', '\xb6');
|
||||||
return commandString(command) + QLatin1String(" \"")
|
return commandString(command) + " \"" + prettyText + "\"";
|
||||||
+ prettyText + QLatin1String("\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
Differ::Differ(QFutureInterfaceBase *jobController)
|
Differ::Differ(QFutureInterfaceBase *jobController)
|
||||||
: m_diffMode(Differ::LineMode),
|
: m_jobController(jobController)
|
||||||
m_currentDiffMode(Differ::LineMode),
|
|
||||||
m_jobController(jobController)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1288,7 +1285,7 @@ int Differ::findSubtextEnd(const QString &text,
|
|||||||
int subtextStart)
|
int subtextStart)
|
||||||
{
|
{
|
||||||
if (m_currentDiffMode == Differ::LineMode) {
|
if (m_currentDiffMode == Differ::LineMode) {
|
||||||
int subtextEnd = text.indexOf(QLatin1Char('\n'), subtextStart);
|
int subtextEnd = text.indexOf('\n', subtextStart);
|
||||||
if (subtextEnd == -1)
|
if (subtextEnd == -1)
|
||||||
subtextEnd = text.count() - 1;
|
subtextEnd = text.count() - 1;
|
||||||
return ++subtextEnd;
|
return ++subtextEnd;
|
||||||
|
@@ -109,8 +109,8 @@ private:
|
|||||||
QMap<QString, int> *lineToCode);
|
QMap<QString, int> *lineToCode);
|
||||||
int findSubtextEnd(const QString &text,
|
int findSubtextEnd(const QString &text,
|
||||||
int subTextStart);
|
int subTextStart);
|
||||||
DiffMode m_diffMode;
|
DiffMode m_diffMode = Differ::LineMode;
|
||||||
DiffMode m_currentDiffMode;
|
DiffMode m_currentDiffMode = Differ::LineMode;
|
||||||
QFutureInterfaceBase *m_jobController = nullptr;
|
QFutureInterfaceBase *m_jobController = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ static void handleDifference(const QString &text,
|
|||||||
QList<TextLineData> *lines,
|
QList<TextLineData> *lines,
|
||||||
int *lineNumber)
|
int *lineNumber)
|
||||||
{
|
{
|
||||||
const QStringList newLines = text.split(QLatin1Char('\n'));
|
const QStringList newLines = text.split('\n');
|
||||||
for (int line = 0; line < newLines.count(); ++line) {
|
for (int line = 0; line < newLines.count(); ++line) {
|
||||||
const int startPos = line > 0
|
const int startPos = line > 0
|
||||||
? -1
|
? -1
|
||||||
@@ -133,7 +133,7 @@ ChunkData DiffUtils::calculateOriginalData(const QList<Diff> &leftDiffList,
|
|||||||
: Diff(Diff::Equal);
|
: Diff(Diff::Equal);
|
||||||
|
|
||||||
if (leftDiff.command == Diff::Delete) {
|
if (leftDiff.command == Diff::Delete) {
|
||||||
if (j == rightDiffList.count() && lastLineEqual && leftDiff.text.startsWith(QLatin1Char('\n')))
|
if (j == rightDiffList.count() && lastLineEqual && leftDiff.text.startsWith('\n'))
|
||||||
equalLines.insert(leftLineNumber, rightLineNumber);
|
equalLines.insert(leftLineNumber, rightLineNumber);
|
||||||
// process delete
|
// process delete
|
||||||
handleDifference(leftDiff.text, &leftLines, &leftLineNumber);
|
handleDifference(leftDiff.text, &leftLines, &leftLineNumber);
|
||||||
@@ -143,7 +143,7 @@ ChunkData DiffUtils::calculateOriginalData(const QList<Diff> &leftDiffList,
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (rightDiff.command == Diff::Insert) {
|
if (rightDiff.command == Diff::Insert) {
|
||||||
if (i == leftDiffList.count() && lastLineEqual && rightDiff.text.startsWith(QLatin1Char('\n')))
|
if (i == leftDiffList.count() && lastLineEqual && rightDiff.text.startsWith('\n'))
|
||||||
equalLines.insert(leftLineNumber, rightLineNumber);
|
equalLines.insert(leftLineNumber, rightLineNumber);
|
||||||
// process insert
|
// process insert
|
||||||
handleDifference(rightDiff.text, &rightLines, &rightLineNumber);
|
handleDifference(rightDiff.text, &rightLines, &rightLineNumber);
|
||||||
@@ -154,8 +154,8 @@ ChunkData DiffUtils::calculateOriginalData(const QList<Diff> &leftDiffList,
|
|||||||
}
|
}
|
||||||
if (leftDiff.command == Diff::Equal && rightDiff.command == Diff::Equal) {
|
if (leftDiff.command == Diff::Equal && rightDiff.command == Diff::Equal) {
|
||||||
// process equal
|
// process equal
|
||||||
const QStringList newLeftLines = leftDiff.text.split(QLatin1Char('\n'));
|
const QStringList newLeftLines = leftDiff.text.split('\n');
|
||||||
const QStringList newRightLines = rightDiff.text.split(QLatin1Char('\n'));
|
const QStringList newRightLines = rightDiff.text.split('\n');
|
||||||
|
|
||||||
int line = 0;
|
int line = 0;
|
||||||
|
|
||||||
@@ -347,9 +347,9 @@ QString DiffUtils::makePatchLine(const QChar &startLineCharacter,
|
|||||||
|| addNoNewline; // no addNoNewline case
|
|| addNoNewline; // no addNoNewline case
|
||||||
|
|
||||||
if (addLine) {
|
if (addLine) {
|
||||||
line = startLineCharacter + textLine + QLatin1Char('\n');
|
line = startLineCharacter + textLine + '\n';
|
||||||
if (addNoNewline)
|
if (addNoNewline)
|
||||||
line += QLatin1String("\\ No newline at end of file\n");
|
line += "\\ No newline at end of file\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
@@ -404,7 +404,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
if (rowData.equal && i != rowToBeSplit) {
|
if (rowData.equal && i != rowToBeSplit) {
|
||||||
if (leftBuffer.count()) {
|
if (leftBuffer.count()) {
|
||||||
for (int j = 0; j < leftBuffer.count(); j++) {
|
for (int j = 0; j < leftBuffer.count(); j++) {
|
||||||
const QString line = makePatchLine(QLatin1Char('-'),
|
const QString line = makePatchLine('-',
|
||||||
leftBuffer.at(j).text,
|
leftBuffer.at(j).text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count()
|
i == chunkData.rows.count()
|
||||||
@@ -419,7 +419,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
}
|
}
|
||||||
if (rightBuffer.count()) {
|
if (rightBuffer.count()) {
|
||||||
for (int j = 0; j < rightBuffer.count(); j++) {
|
for (int j = 0; j < rightBuffer.count(); j++) {
|
||||||
const QString line = makePatchLine(QLatin1Char('+'),
|
const QString line = makePatchLine('+',
|
||||||
rightBuffer.at(j).text,
|
rightBuffer.at(j).text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count()
|
i == chunkData.rows.count()
|
||||||
@@ -433,7 +433,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
rightBuffer.clear();
|
rightBuffer.clear();
|
||||||
}
|
}
|
||||||
if (i < chunkData.rows.count()) {
|
if (i < chunkData.rows.count()) {
|
||||||
const QString line = makePatchLine(QLatin1Char(' '),
|
const QString line = makePatchLine(' ',
|
||||||
rowData.rightLine.text,
|
rowData.rightLine.text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count() - 1);
|
i == chunkData.rows.count() - 1);
|
||||||
@@ -453,17 +453,17 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString chunkLine = QLatin1String("@@ -")
|
const QString chunkLine = "@@ -"
|
||||||
+ QString::number(chunkData.leftStartingLineNumber + 1)
|
+ QString::number(chunkData.leftStartingLineNumber + 1)
|
||||||
+ QLatin1Char(',')
|
+ ','
|
||||||
+ QString::number(leftLineCount)
|
+ QString::number(leftLineCount)
|
||||||
+ QLatin1String(" +")
|
+ " +"
|
||||||
+ QString::number(chunkData.rightStartingLineNumber + 1)
|
+ QString::number(chunkData.rightStartingLineNumber + 1)
|
||||||
+ QLatin1Char(',')
|
+ ','
|
||||||
+ QString::number(rightLineCount)
|
+ QString::number(rightLineCount)
|
||||||
+ QLatin1String(" @@")
|
+ " @@"
|
||||||
+ chunkData.contextInfo
|
+ chunkData.contextInfo
|
||||||
+ QLatin1Char('\n');
|
+ '\n';
|
||||||
|
|
||||||
diffText.prepend(chunkLine);
|
diffText.prepend(chunkLine);
|
||||||
|
|
||||||
@@ -477,8 +477,8 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
{
|
{
|
||||||
QString diffText = makePatch(chunkData, lastChunk);
|
QString diffText = makePatch(chunkData, lastChunk);
|
||||||
|
|
||||||
const QString rightFileInfo = QLatin1String("+++ ") + rightFileName + QLatin1Char('\n');
|
const QString rightFileInfo = "+++ " + rightFileName + '\n';
|
||||||
const QString leftFileInfo = QLatin1String("--- ") + leftFileName + QLatin1Char('\n');
|
const QString leftFileInfo = "--- " + leftFileName + '\n';
|
||||||
|
|
||||||
diffText.prepend(rightFileInfo);
|
diffText.prepend(rightFileInfo);
|
||||||
diffText.prepend(leftFileInfo);
|
diffText.prepend(leftFileInfo);
|
||||||
@@ -568,7 +568,7 @@ static QList<RowData> readLines(QStringRef patch,
|
|||||||
{
|
{
|
||||||
QList<Diff> diffList;
|
QList<Diff> diffList;
|
||||||
|
|
||||||
const QChar newLine = QLatin1Char('\n');
|
const QChar newLine = '\n';
|
||||||
|
|
||||||
int lastEqual = -1;
|
int lastEqual = -1;
|
||||||
int lastDelete = -1;
|
int lastDelete = -1;
|
||||||
@@ -588,7 +588,7 @@ static QList<RowData> readLines(QStringRef patch,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const QChar firstCharacter = line.at(0);
|
const QChar firstCharacter = line.at(0);
|
||||||
if (firstCharacter == QLatin1Char('\\')) { // no new line marker
|
if (firstCharacter == '\\') { // no new line marker
|
||||||
if (!lastChunk) // can only appear in last chunk of the file
|
if (!lastChunk) // can only appear in last chunk of the file
|
||||||
break;
|
break;
|
||||||
if (!diffList.isEmpty()) {
|
if (!diffList.isEmpty()) {
|
||||||
@@ -612,11 +612,11 @@ static QList<RowData> readLines(QStringRef patch,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Diff::Command command = Diff::Equal;
|
Diff::Command command = Diff::Equal;
|
||||||
if (firstCharacter == QLatin1Char(' ')) { // common line
|
if (firstCharacter == ' ') { // common line
|
||||||
command = Diff::Equal;
|
command = Diff::Equal;
|
||||||
} else if (firstCharacter == QLatin1Char('-')) { // deleted line
|
} else if (firstCharacter == '-') { // deleted line
|
||||||
command = Diff::Delete;
|
command = Diff::Delete;
|
||||||
} else if (firstCharacter == QLatin1Char('+')) { // inserted line
|
} else if (firstCharacter == '+') { // inserted line
|
||||||
command = Diff::Insert;
|
command = Diff::Insert;
|
||||||
} else { // no other character may exist as the first character
|
} else { // no other character may exist as the first character
|
||||||
if (lastChunk)
|
if (lastChunk)
|
||||||
@@ -1074,9 +1074,9 @@ static bool detectIndexAndBinary(QStringRef patch,
|
|||||||
const QString rightFileName = fileData->fileOperation == FileData::DeleteFile
|
const QString rightFileName = fileData->fileOperation == FileData::DeleteFile
|
||||||
? devNull : QLatin1String("b/") + fileData->rightFileInfo.fileName;
|
? devNull : QLatin1String("b/") + fileData->rightFileInfo.fileName;
|
||||||
|
|
||||||
const QString binaryLine = QLatin1String("Binary files ")
|
const QString binaryLine = "Binary files "
|
||||||
+ leftFileName + QLatin1String(" and ")
|
+ leftFileName + " and "
|
||||||
+ rightFileName + QLatin1String(" differ");
|
+ rightFileName + " differ";
|
||||||
|
|
||||||
if (*remainingPatch == binaryLine) {
|
if (*remainingPatch == binaryLine) {
|
||||||
fileData->binaryFiles = true;
|
fileData->binaryFiles = true;
|
||||||
@@ -1084,7 +1084,7 @@ static bool detectIndexAndBinary(QStringRef patch,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString leftStart = QLatin1String("--- ") + leftFileName;
|
const QString leftStart = "--- " + leftFileName;
|
||||||
QStringRef afterMinuses;
|
QStringRef afterMinuses;
|
||||||
// --- leftFileName
|
// --- leftFileName
|
||||||
const QStringRef minuses = readLine(*remainingPatch, &afterMinuses, &hasNewLine);
|
const QStringRef minuses = readLine(*remainingPatch, &afterMinuses, &hasNewLine);
|
||||||
@@ -1094,7 +1094,7 @@ static bool detectIndexAndBinary(QStringRef patch,
|
|||||||
if (!minuses.startsWith(leftStart))
|
if (!minuses.startsWith(leftStart))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QString rightStart = QLatin1String("+++ ") + rightFileName;
|
const QString rightStart = "+++ " + rightFileName;
|
||||||
QStringRef afterPluses;
|
QStringRef afterPluses;
|
||||||
// +++ rightFileName
|
// +++ rightFileName
|
||||||
const QStringRef pluses = readLine(afterMinuses, &afterPluses, &hasNewLine);
|
const QStringRef pluses = readLine(afterMinuses, &afterPluses, &hasNewLine);
|
||||||
|
@@ -63,10 +63,10 @@ public:
|
|||||||
Separator,
|
Separator,
|
||||||
Invalid
|
Invalid
|
||||||
};
|
};
|
||||||
TextLineData() : textLineType(Invalid) {}
|
TextLineData() {}
|
||||||
TextLineData(const QString &txt) : textLineType(TextLine), text(txt) {}
|
TextLineData(const QString &txt) : textLineType(TextLine), text(txt) {}
|
||||||
TextLineData(TextLineType t) : textLineType(t) {}
|
TextLineData(TextLineType t) : textLineType(t) {}
|
||||||
TextLineType textLineType;
|
TextLineType textLineType = Invalid;
|
||||||
QString text;
|
QString text;
|
||||||
/*
|
/*
|
||||||
* <start position, end position>
|
* <start position, end position>
|
||||||
@@ -79,24 +79,23 @@ public:
|
|||||||
|
|
||||||
class DIFFEDITOR_EXPORT RowData {
|
class DIFFEDITOR_EXPORT RowData {
|
||||||
public:
|
public:
|
||||||
RowData() : equal(false) {}
|
RowData() {}
|
||||||
RowData(const TextLineData &l)
|
RowData(const TextLineData &l)
|
||||||
: leftLine(l), rightLine(l), equal(true) {}
|
: leftLine(l), rightLine(l), equal(true) {}
|
||||||
RowData(const TextLineData &l, const TextLineData &r)
|
RowData(const TextLineData &l, const TextLineData &r)
|
||||||
: leftLine(l), rightLine(r), equal(false) {}
|
: leftLine(l), rightLine(r) {}
|
||||||
TextLineData leftLine;
|
TextLineData leftLine;
|
||||||
TextLineData rightLine;
|
TextLineData rightLine;
|
||||||
bool equal;
|
bool equal = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT ChunkData {
|
class DIFFEDITOR_EXPORT ChunkData {
|
||||||
public:
|
public:
|
||||||
ChunkData() : contextChunk(false),
|
ChunkData() {}
|
||||||
leftStartingLineNumber(0), rightStartingLineNumber(0) {}
|
|
||||||
QList<RowData> rows;
|
QList<RowData> rows;
|
||||||
bool contextChunk;
|
bool contextChunk = false;
|
||||||
int leftStartingLineNumber;
|
int leftStartingLineNumber = 0;
|
||||||
int rightStartingLineNumber;
|
int rightStartingLineNumber = 0;
|
||||||
QString contextInfo;
|
QString contextInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,23 +110,15 @@ public:
|
|||||||
RenameFile
|
RenameFile
|
||||||
};
|
};
|
||||||
|
|
||||||
FileData()
|
FileData() {}
|
||||||
: fileOperation(ChangeFile),
|
FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
|
||||||
binaryFiles(false),
|
|
||||||
lastChunkAtTheEndOfFile(false),
|
|
||||||
contextChunksIncluded(false) {}
|
|
||||||
FileData(const ChunkData &chunkData)
|
|
||||||
: fileOperation(ChangeFile),
|
|
||||||
binaryFiles(false),
|
|
||||||
lastChunkAtTheEndOfFile(false),
|
|
||||||
contextChunksIncluded(false) { chunks.append(chunkData); }
|
|
||||||
QList<ChunkData> chunks;
|
QList<ChunkData> chunks;
|
||||||
DiffFileInfo leftFileInfo;
|
DiffFileInfo leftFileInfo;
|
||||||
DiffFileInfo rightFileInfo;
|
DiffFileInfo rightFileInfo;
|
||||||
FileOperation fileOperation;
|
FileOperation fileOperation = ChangeFile;
|
||||||
bool binaryFiles;
|
bool binaryFiles = false;
|
||||||
bool lastChunkAtTheEndOfFile;
|
bool lastChunkAtTheEndOfFile = false;
|
||||||
bool contextChunksIncluded;
|
bool contextChunksIncluded = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DIFFEDITOR_EXPORT DiffUtils {
|
class DIFFEDITOR_EXPORT DiffUtils {
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
IDiffView::IDiffView(QObject *parent) : QObject(parent), m_supportsSync(false)
|
IDiffView::IDiffView(QObject *parent) : QObject(parent)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QIcon IDiffView::icon() const
|
QIcon IDiffView::icon() const
|
||||||
|
@@ -50,7 +50,7 @@ class IDiffView : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IDiffView(QObject *parent = 0);
|
explicit IDiffView(QObject *parent = nullptr);
|
||||||
|
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
QString toolTip() const;
|
QString toolTip() const;
|
||||||
@@ -82,7 +82,7 @@ private:
|
|||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
Core::Id m_id;
|
Core::Id m_id;
|
||||||
bool m_supportsSync;
|
bool m_supportsSync = false;
|
||||||
QString m_syncToolTip;
|
QString m_syncToolTip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -33,20 +33,20 @@ namespace Internal {
|
|||||||
class DiffSelection
|
class DiffSelection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DiffSelection() : start(-1), end(-1), format(0) {}
|
DiffSelection() {}
|
||||||
DiffSelection(QTextCharFormat *f) : start(-1), end(-1), format(f) {}
|
DiffSelection(QTextCharFormat *f) : format(f) {}
|
||||||
DiffSelection(int s, int e, QTextCharFormat *f) : start(s), end(e), format(f) {}
|
DiffSelection(int s, int e, QTextCharFormat *f) : start(s), end(e), format(f) {}
|
||||||
|
|
||||||
int start;
|
int start = -1;
|
||||||
int end;
|
int end = -1;
|
||||||
QTextCharFormat *format;
|
QTextCharFormat *format = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SelectableTextEditorWidget : public TextEditor::TextEditorWidget
|
class SelectableTextEditorWidget : public TextEditor::TextEditorWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SelectableTextEditorWidget(Core::Id id, QWidget *parent = 0);
|
SelectableTextEditorWidget(Core::Id id, QWidget *parent = nullptr);
|
||||||
~SelectableTextEditorWidget() override;
|
~SelectableTextEditorWidget() override;
|
||||||
void setSelections(const QMap<int, QList<DiffSelection> > &selections);
|
void setSelections(const QMap<int, QList<DiffSelection> > &selections);
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ class SideDiffEditorWidget : public SelectableTextEditorWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SideDiffEditorWidget(QWidget *parent = 0);
|
SideDiffEditorWidget(QWidget *parent = nullptr);
|
||||||
|
|
||||||
// block number, file info
|
// block number, file info
|
||||||
QMap<int, DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
QMap<int, DiffFileInfo> fileInfo() const { return m_fileInfo; }
|
||||||
@@ -100,7 +100,7 @@ signals:
|
|||||||
void foldChanged(int blockNumber, bool folded);
|
void foldChanged(int blockNumber, bool folded);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int extraAreaWidth(int *markWidthPtr = 0) const override {
|
int extraAreaWidth(int *markWidthPtr = nullptr) const override {
|
||||||
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
|
return SelectableTextEditorWidget::extraAreaWidth(markWidthPtr);
|
||||||
}
|
}
|
||||||
void applyFontSettings() override;
|
void applyFontSettings() override;
|
||||||
@@ -281,7 +281,7 @@ QString SideDiffEditorWidget::plainTextFromSelection(const QTextCursor &cursor)
|
|||||||
text = block.text().mid(startPosition - block.position());
|
text = block.text().mid(startPosition - block.position());
|
||||||
} else {
|
} else {
|
||||||
if (textInserted)
|
if (textInserted)
|
||||||
text += QLatin1Char('\n');
|
text += '\n';
|
||||||
if (block == endBlock)
|
if (block == endBlock)
|
||||||
text += block.text().leftRef(endPosition - block.position());
|
text += block.text().leftRef(endPosition - block.position());
|
||||||
else
|
else
|
||||||
@@ -394,9 +394,7 @@ void SideDiffEditorWidget::paintSeparator(QPainter &painter,
|
|||||||
|
|
||||||
painter.setPen(foreground);
|
painter.setPen(foreground);
|
||||||
|
|
||||||
const QString replacementText = QLatin1String(" {")
|
const QString replacementText = " {" + foldReplacementText(block) + "}; ";
|
||||||
+ foldReplacementText(block)
|
|
||||||
+ QLatin1String("}; ");
|
|
||||||
const int replacementTextWidth = fontMetrics().width(replacementText) + 24;
|
const int replacementTextWidth = fontMetrics().width(replacementText) + 24;
|
||||||
int x = replacementTextWidth + offset.x();
|
int x = replacementTextWidth + offset.x();
|
||||||
if (x < document()->documentMargin()
|
if (x < document()->documentMargin()
|
||||||
@@ -806,7 +804,7 @@ void SideBySideDiffEditorWidget::showDiff()
|
|||||||
|
|
||||||
QString leftTexts, rightTexts;
|
QString leftTexts, rightTexts;
|
||||||
int blockNumber = 0;
|
int blockNumber = 0;
|
||||||
QChar separator = QLatin1Char('\n');
|
QChar separator = '\n';
|
||||||
QHash<int, int> foldingIndent;
|
QHash<int, int> foldingIndent;
|
||||||
for (const FileData &contextFileData : m_controller.m_contextFileData) {
|
for (const FileData &contextFileData : m_controller.m_contextFileData) {
|
||||||
QString leftText, rightText;
|
QString leftText, rightText;
|
||||||
@@ -929,8 +927,8 @@ void SideBySideDiffEditorWidget::showDiff()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
leftText.replace(QLatin1Char('\r'), QLatin1Char(' '));
|
leftText.replace('\r', ' ');
|
||||||
rightText.replace(QLatin1Char('\r'), QLatin1Char(' '));
|
rightText.replace('\r', ' ');
|
||||||
leftTexts += leftText;
|
leftTexts += leftText;
|
||||||
rightTexts += rightText;
|
rightTexts += rightText;
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ class SideBySideDiffEditorWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SideBySideDiffEditorWidget(QWidget *parent = 0);
|
explicit SideBySideDiffEditorWidget(QWidget *parent = nullptr);
|
||||||
~SideBySideDiffEditorWidget();
|
~SideBySideDiffEditorWidget();
|
||||||
|
|
||||||
TextEditor::TextEditorWidget *leftEditorWidget() const;
|
TextEditor::TextEditorWidget *leftEditorWidget() const;
|
||||||
@@ -98,17 +98,17 @@ private:
|
|||||||
|
|
||||||
void showDiff();
|
void showDiff();
|
||||||
|
|
||||||
SideDiffEditorWidget *m_leftEditor;
|
SideDiffEditorWidget *m_leftEditor = nullptr;
|
||||||
SideDiffEditorWidget *m_rightEditor;
|
SideDiffEditorWidget *m_rightEditor = nullptr;
|
||||||
QSplitter *m_splitter;
|
QSplitter *m_splitter = nullptr;
|
||||||
|
|
||||||
DiffEditorWidgetController m_controller;
|
DiffEditorWidgetController m_controller;
|
||||||
|
|
||||||
bool m_horizontalSync = false;
|
bool m_horizontalSync = false;
|
||||||
|
|
||||||
QTextCharFormat m_spanLineFormat;
|
QTextCharFormat m_spanLineFormat;
|
||||||
Core::IContext *m_leftContext;
|
Core::IContext *m_leftContext = nullptr;
|
||||||
Core::IContext *m_rightContext;
|
Core::IContext *m_rightContext = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -229,15 +229,15 @@ QString UnifiedDiffEditorWidget::lineNumber(int blockNumber) const
|
|||||||
? QString::number(m_leftLineNumbers.value(blockNumber))
|
? QString::number(m_leftLineNumbers.value(blockNumber))
|
||||||
: QString();
|
: QString();
|
||||||
lineNumberString += QString(m_leftLineNumberDigits - leftLine.count(),
|
lineNumberString += QString(m_leftLineNumberDigits - leftLine.count(),
|
||||||
QLatin1Char(' ')) + leftLine;
|
' ') + leftLine;
|
||||||
|
|
||||||
lineNumberString += QLatin1Char('|');
|
lineNumberString += '|';
|
||||||
|
|
||||||
const QString rightLine = rightLineExists
|
const QString rightLine = rightLineExists
|
||||||
? QString::number(m_rightLineNumbers.value(blockNumber))
|
? QString::number(m_rightLineNumbers.value(blockNumber))
|
||||||
: QString();
|
: QString();
|
||||||
lineNumberString += QString(m_rightLineNumberDigits - rightLine.count(),
|
lineNumberString += QString(m_rightLineNumberDigits - rightLine.count(),
|
||||||
QLatin1Char(' ')) + rightLine;
|
' ') + rightLine;
|
||||||
}
|
}
|
||||||
return lineNumberString;
|
return lineNumberString;
|
||||||
}
|
}
|
||||||
@@ -327,13 +327,13 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
|||||||
for (int j = 0; j < leftBuffer.count(); j++) {
|
for (int j = 0; j < leftBuffer.count(); j++) {
|
||||||
const TextLineData &lineData = leftBuffer.at(j);
|
const TextLineData &lineData = leftBuffer.at(j);
|
||||||
const QString line = DiffUtils::makePatchLine(
|
const QString line = DiffUtils::makePatchLine(
|
||||||
QLatin1Char('-'),
|
'-',
|
||||||
lineData.text,
|
lineData.text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count()
|
i == chunkData.rows.count()
|
||||||
&& j == leftBuffer.count() - 1);
|
&& j == leftBuffer.count() - 1);
|
||||||
|
|
||||||
const int blockDelta = line.count(QLatin1Char('\n')); // no new line
|
const int blockDelta = line.count('\n'); // no new line
|
||||||
// could have been added
|
// could have been added
|
||||||
for (int k = 0; k < blockDelta; k++)
|
for (int k = 0; k < blockDelta; k++)
|
||||||
(*selections)[*blockNumber + blockCount + 1 + k].append(&m_controller.m_leftLineFormat);
|
(*selections)[*blockNumber + blockCount + 1 + k].append(&m_controller.m_leftLineFormat);
|
||||||
@@ -366,13 +366,13 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
|||||||
for (int j = 0; j < rightBuffer.count(); j++) {
|
for (int j = 0; j < rightBuffer.count(); j++) {
|
||||||
const TextLineData &lineData = rightBuffer.at(j);
|
const TextLineData &lineData = rightBuffer.at(j);
|
||||||
const QString line = DiffUtils::makePatchLine(
|
const QString line = DiffUtils::makePatchLine(
|
||||||
QLatin1Char('+'),
|
'+',
|
||||||
lineData.text,
|
lineData.text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count()
|
i == chunkData.rows.count()
|
||||||
&& j == rightBuffer.count() - 1);
|
&& j == rightBuffer.count() - 1);
|
||||||
|
|
||||||
const int blockDelta = line.count(QLatin1Char('\n')); // no new line
|
const int blockDelta = line.count('\n'); // no new line
|
||||||
// could have been added
|
// could have been added
|
||||||
|
|
||||||
for (int k = 0; k < blockDelta; k++)
|
for (int k = 0; k < blockDelta; k++)
|
||||||
@@ -403,7 +403,7 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
|||||||
rightBuffer.clear();
|
rightBuffer.clear();
|
||||||
}
|
}
|
||||||
if (i < chunkData.rows.count()) {
|
if (i < chunkData.rows.count()) {
|
||||||
const QString line = DiffUtils::makePatchLine(QLatin1Char(' '),
|
const QString line = DiffUtils::makePatchLine(' ',
|
||||||
rowData.rightLine.text,
|
rowData.rightLine.text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count() - 1);
|
i == chunkData.rows.count() - 1);
|
||||||
@@ -415,7 +415,7 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
|||||||
setRightLineNumber(*blockNumber + blockCount + 1,
|
setRightLineNumber(*blockNumber + blockCount + 1,
|
||||||
chunkData.rightStartingLineNumber
|
chunkData.rightStartingLineNumber
|
||||||
+ rightLineCount + 1);
|
+ rightLineCount + 1);
|
||||||
blockCount += line.count(QLatin1Char('\n'));
|
blockCount += line.count('\n');
|
||||||
++leftLineCount;
|
++leftLineCount;
|
||||||
++rightLineCount;
|
++rightLineCount;
|
||||||
}
|
}
|
||||||
@@ -432,17 +432,17 @@ QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString chunkLine = QLatin1String("@@ -")
|
const QString chunkLine = "@@ -"
|
||||||
+ QString::number(chunkData.leftStartingLineNumber + 1)
|
+ QString::number(chunkData.leftStartingLineNumber + 1)
|
||||||
+ QLatin1Char(',')
|
+ ','
|
||||||
+ QString::number(leftLineCount)
|
+ QString::number(leftLineCount)
|
||||||
+ QLatin1String(" +")
|
+ " +"
|
||||||
+ QString::number(chunkData.rightStartingLineNumber+ 1)
|
+ QString::number(chunkData.rightStartingLineNumber+ 1)
|
||||||
+ QLatin1Char(',')
|
+ ','
|
||||||
+ QString::number(rightLineCount)
|
+ QString::number(rightLineCount)
|
||||||
+ QLatin1String(" @@")
|
+ " @@"
|
||||||
+ chunkData.contextInfo
|
+ chunkData.contextInfo
|
||||||
+ QLatin1Char('\n');
|
+ '\n';
|
||||||
|
|
||||||
diffText.prepend(chunkLine);
|
diffText.prepend(chunkLine);
|
||||||
|
|
||||||
@@ -466,10 +466,8 @@ void UnifiedDiffEditorWidget::showDiff()
|
|||||||
QMap<int, QList<DiffSelection> > selections;
|
QMap<int, QList<DiffSelection> > selections;
|
||||||
|
|
||||||
for (const FileData &fileData : m_controller.m_contextFileData) {
|
for (const FileData &fileData : m_controller.m_contextFileData) {
|
||||||
const QString leftFileInfo = QLatin1String("--- ")
|
const QString leftFileInfo = "--- " + fileData.leftFileInfo.fileName + '\n';
|
||||||
+ fileData.leftFileInfo.fileName + QLatin1Char('\n');
|
const QString rightFileInfo = "+++ " + fileData.rightFileInfo.fileName + '\n';
|
||||||
const QString rightFileInfo = QLatin1String("+++ ")
|
|
||||||
+ fileData.rightFileInfo.fileName + QLatin1Char('\n');
|
|
||||||
setFileInfo(blockNumber, fileData.leftFileInfo, fileData.rightFileInfo);
|
setFileInfo(blockNumber, fileData.leftFileInfo, fileData.rightFileInfo);
|
||||||
foldingIndent.insert(blockNumber, 1);
|
foldingIndent.insert(blockNumber, 1);
|
||||||
selections[blockNumber].append(DiffSelection(&m_controller.m_fileLineFormat));
|
selections[blockNumber].append(DiffSelection(&m_controller.m_fileLineFormat));
|
||||||
@@ -486,11 +484,11 @@ void UnifiedDiffEditorWidget::showDiff()
|
|||||||
foldingIndent.insert(blockNumber, 2);
|
foldingIndent.insert(blockNumber, 2);
|
||||||
selections[blockNumber].append(DiffSelection(&m_controller.m_chunkLineFormat));
|
selections[blockNumber].append(DiffSelection(&m_controller.m_chunkLineFormat));
|
||||||
blockNumber++;
|
blockNumber++;
|
||||||
const QString binaryLine = QLatin1String("Binary files ")
|
const QString binaryLine = "Binary files "
|
||||||
+ fileData.leftFileInfo.fileName
|
+ fileData.leftFileInfo.fileName
|
||||||
+ QLatin1String(" and ")
|
+ " and "
|
||||||
+ fileData.rightFileInfo.fileName
|
+ fileData.rightFileInfo.fileName
|
||||||
+ QLatin1String(" differ\n");
|
+ " differ\n";
|
||||||
diffText += binaryLine;
|
diffText += binaryLine;
|
||||||
charNumber += binaryLine.count();
|
charNumber += binaryLine.count();
|
||||||
} else {
|
} else {
|
||||||
@@ -515,7 +513,7 @@ void UnifiedDiffEditorWidget::showDiff()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
diffText.replace(QLatin1Char('\r'), QLatin1Char(' '));
|
diffText.replace('\r', ' ');
|
||||||
const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange;
|
const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange;
|
||||||
m_controller.m_ignoreCurrentIndexChange = true;
|
m_controller.m_ignoreCurrentIndexChange = true;
|
||||||
setPlainText(diffText);
|
setPlainText(diffText);
|
||||||
|
@@ -48,7 +48,7 @@ class UnifiedDiffEditorWidget : public SelectableTextEditorWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
UnifiedDiffEditorWidget(QWidget *parent = 0);
|
UnifiedDiffEditorWidget(QWidget *parent = nullptr);
|
||||||
~UnifiedDiffEditorWidget();
|
~UnifiedDiffEditorWidget();
|
||||||
|
|
||||||
void setDocument(DiffEditorDocument *document);
|
void setDocument(DiffEditorDocument *document);
|
||||||
@@ -113,7 +113,7 @@ private:
|
|||||||
QMap<int, QPair<int, int> > m_chunkInfo;
|
QMap<int, QPair<int, int> > m_chunkInfo;
|
||||||
|
|
||||||
QByteArray m_state;
|
QByteArray m_state;
|
||||||
Core::IContext *m_context;
|
Core::IContext *m_context = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user