forked from qt-creator/qt-creator
DiffEditorPlugin: Various cleanups
Change-Id: Ic0c9c397067b899932bc39d938e63df36fa4caeb Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -46,6 +46,7 @@ static const char ignoreWhitespaceKeyC[] = "IgnoreWhitespace";
|
||||
|
||||
static const char diffViewKeyC[] = "DiffEditorType";
|
||||
|
||||
using namespace Core;
|
||||
using namespace TextEditor;
|
||||
|
||||
namespace DiffEditor {
|
||||
@@ -86,10 +87,10 @@ DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
auto context = new Core::IContext(this);
|
||||
auto context = new IContext(this);
|
||||
context->setWidget(this);
|
||||
context->setContext(Core::Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
|
||||
Core::ICore::addContextObject(context);
|
||||
context->setContext(Context(Constants::C_DIFF_EDITOR_DESCRIPTION));
|
||||
ICore::addContextObject(context);
|
||||
|
||||
textDocument()->setSyntaxHighlighter(new SyntaxHighlighter);
|
||||
}
|
||||
@@ -113,7 +114,7 @@ void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
||||
void DescriptionEditorWidget::setMarginSettings(const MarginSettings &ms)
|
||||
{
|
||||
Q_UNUSED(ms)
|
||||
TextEditorWidget::setMarginSettings(MarginSettings());
|
||||
TextEditorWidget::setMarginSettings({});
|
||||
}
|
||||
|
||||
void DescriptionEditorWidget::applyFontSettings()
|
||||
@@ -130,11 +131,11 @@ DiffEditor::DiffEditor()
|
||||
setDuplicateSupported(true);
|
||||
|
||||
// Widget:
|
||||
QSplitter *splitter = new Core::MiniSplitter(Qt::Vertical);
|
||||
QSplitter *splitter = new MiniSplitter(Qt::Vertical);
|
||||
|
||||
m_descriptionWidget = new DescriptionEditorWidget(splitter);
|
||||
m_descriptionWidget->setReadOnly(true);
|
||||
connect(m_descriptionWidget, &DescriptionEditorWidget::requestResize, this, [splitter](){
|
||||
connect(m_descriptionWidget, &DescriptionEditorWidget::requestResize, this, [splitter] {
|
||||
if (splitter->count() == 0)
|
||||
return;
|
||||
QList<int> sizes = splitter->sizes();
|
||||
@@ -189,16 +190,16 @@ DiffEditor::DiffEditor()
|
||||
m_whitespaceButtonAction = m_toolBar->addAction(tr("Ignore Whitespace"));
|
||||
m_whitespaceButtonAction->setCheckable(true);
|
||||
|
||||
m_toggleDescriptionAction = m_toolBar->addAction(Icons::TOP_BAR.icon(), QString());
|
||||
m_toggleDescriptionAction = m_toolBar->addAction(Icons::TOP_BAR.icon(), {});
|
||||
m_toggleDescriptionAction->setCheckable(true);
|
||||
|
||||
m_reloadAction = m_toolBar->addAction(Utils::Icons::RELOAD_TOOLBAR.icon(), tr("Reload Diff"));
|
||||
m_reloadAction->setToolTip(tr("Reload Diff"));
|
||||
|
||||
m_toggleSyncAction = m_toolBar->addAction(Utils::Icons::LINK_TOOLBAR.icon(), QString());
|
||||
m_toggleSyncAction = m_toolBar->addAction(Utils::Icons::LINK_TOOLBAR.icon(), {});
|
||||
m_toggleSyncAction->setCheckable(true);
|
||||
|
||||
m_viewSwitcherAction = m_toolBar->addAction(QIcon(), QString());
|
||||
m_viewSwitcherAction = m_toolBar->addAction(QIcon(), {});
|
||||
|
||||
connect(m_whitespaceButtonAction, &QAction::toggled,
|
||||
this, &DiffEditor::ignoreWhitespaceHasChanged);
|
||||
@@ -206,7 +207,7 @@ DiffEditor::DiffEditor()
|
||||
this, &DiffEditor::contextLineCountHasChanged);
|
||||
connect(m_toggleSyncAction, &QAction::toggled, this, &DiffEditor::toggleSync);
|
||||
connect(m_toggleDescriptionAction, &QAction::toggled, this, &DiffEditor::toggleDescription);
|
||||
connect(m_viewSwitcherAction, &QAction::triggered, this, [this]() { showDiffView(nextView()); });
|
||||
connect(m_viewSwitcherAction, &QAction::triggered, this, [this] { showDiffView(nextView()); });
|
||||
}
|
||||
|
||||
void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument> doc)
|
||||
@@ -225,7 +226,7 @@ void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument> doc)
|
||||
connect(m_document.data(), &DiffEditorDocument::reloadFinished,
|
||||
this, &DiffEditor::reloadHasFinished);
|
||||
|
||||
connect(m_reloadAction, &QAction::triggered, this, [this]() { m_document->reload(); });
|
||||
connect(m_reloadAction, &QAction::triggered, this, [this] { m_document->reload(); });
|
||||
connect(m_document.data(), &DiffEditorDocument::temporaryStateChanged,
|
||||
this, &DiffEditor::documentStateChanged);
|
||||
|
||||
@@ -250,9 +251,9 @@ DiffEditor::~DiffEditor()
|
||||
qDeleteAll(m_views);
|
||||
}
|
||||
|
||||
Core::IEditor *DiffEditor::duplicate()
|
||||
IEditor *DiffEditor::duplicate()
|
||||
{
|
||||
auto editor = new DiffEditor();
|
||||
auto editor = new DiffEditor;
|
||||
Utils::GuardLocker guard(editor->m_ignoreChanges);
|
||||
|
||||
editor->setDocument(m_document);
|
||||
@@ -270,7 +271,7 @@ Core::IEditor *DiffEditor::duplicate()
|
||||
return editor;
|
||||
}
|
||||
|
||||
Core::IDocument *DiffEditor::document() const
|
||||
IDocument *DiffEditor::document() const
|
||||
{
|
||||
return m_document.data();
|
||||
}
|
||||
@@ -421,7 +422,7 @@ void DiffEditor::prepareForReload()
|
||||
= qMakePair(m_entriesComboBox->itemData(m_currentDiffFileIndex, Qt::UserRole).toString(),
|
||||
m_entriesComboBox->itemData(m_currentDiffFileIndex, Qt::UserRole + 1).toString());
|
||||
} else {
|
||||
m_currentFileChunk = qMakePair(QString(), QString());
|
||||
m_currentFileChunk = {};
|
||||
}
|
||||
|
||||
{
|
||||
@@ -457,7 +458,7 @@ void DiffEditor::reloadHasFinished(bool success)
|
||||
}
|
||||
}
|
||||
|
||||
m_currentFileChunk = qMakePair(QString(), QString());
|
||||
m_currentFileChunk = {};
|
||||
if (index >= 0)
|
||||
setCurrentDiffFileIndex(index);
|
||||
}
|
||||
@@ -519,7 +520,7 @@ void DiffEditor::toggleSync()
|
||||
IDiffView *DiffEditor::loadSettings()
|
||||
{
|
||||
QTC_ASSERT(currentView(), return nullptr);
|
||||
QSettings *s = Core::ICore::settings();
|
||||
QSettings *s = ICore::settings();
|
||||
|
||||
// Read current settings:
|
||||
s->beginGroup(settingsGroupC);
|
||||
@@ -539,7 +540,7 @@ IDiffView *DiffEditor::loadSettings()
|
||||
|
||||
void DiffEditor::saveSetting(const QString &key, const QVariant &value) const
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
QSettings *s = ICore::settings();
|
||||
s->beginGroup(settingsGroupC);
|
||||
s->setValue(key, value);
|
||||
s->endGroup();
|
||||
|
@@ -63,7 +63,7 @@ Core::IDocument *DiffEditorController::findOrCreateDocument(const QString &vcsId
|
||||
{
|
||||
QString preferredDisplayName = displayName;
|
||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
|
||||
Constants::DIFF_EDITOR_ID, &preferredDisplayName, QByteArray(), vcsId);
|
||||
Constants::DIFF_EDITOR_ID, &preferredDisplayName, {}, vcsId);
|
||||
return editor ? editor->document() : nullptr;
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,7 @@ protected:
|
||||
|
||||
void setDiffFiles(const QList<FileData> &diffFileList,
|
||||
const Utils::FilePath &baseDirectory = {},
|
||||
const QString &startupFile = QString());
|
||||
const QString &startupFile = {});
|
||||
void setDescription(const QString &description);
|
||||
QString description() const;
|
||||
void forceContextLineCount(int lines);
|
||||
|
@@ -120,15 +120,12 @@ QString DiffEditorDocument::makePatch(int fileIndex, int chunkIndex,
|
||||
bool revert, bool addPrefix,
|
||||
const QString &overriddenFileName) const
|
||||
{
|
||||
if (fileIndex < 0 || chunkIndex < 0)
|
||||
return QString();
|
||||
|
||||
if (fileIndex >= m_diffFiles.count())
|
||||
return QString();
|
||||
if (fileIndex < 0 || chunkIndex < 0 || fileIndex >= m_diffFiles.count())
|
||||
return {};
|
||||
|
||||
const FileData &fileData = m_diffFiles.at(fileIndex);
|
||||
if (chunkIndex >= fileData.chunks.count())
|
||||
return QString();
|
||||
return {};
|
||||
|
||||
const ChunkData chunkData = filterChunk(fileData.chunks.at(chunkIndex), selection, revert);
|
||||
const bool lastChunk = (chunkIndex == fileData.chunks.count() - 1);
|
||||
@@ -257,12 +254,12 @@ bool DiffEditorDocument::save(QString *errorString, const FilePath &filePath, bo
|
||||
return false;
|
||||
|
||||
setController(nullptr);
|
||||
setDescription(QString());
|
||||
setDescription({});
|
||||
Core::EditorManager::clearUniqueId(this);
|
||||
|
||||
setTemporary(false);
|
||||
setFilePath(filePath.absoluteFilePath());
|
||||
setPreferredDisplayName(QString());
|
||||
setPreferredDisplayName({});
|
||||
emit temporaryStateChanged();
|
||||
|
||||
return true;
|
||||
@@ -393,8 +390,8 @@ void DiffEditorDocument::beginReload()
|
||||
m_state = Reloading;
|
||||
emit changed();
|
||||
QSignalBlocker blocker(this);
|
||||
setDiffFiles(QList<FileData>(), {});
|
||||
setDescription(QString());
|
||||
setDiffFiles({}, {});
|
||||
setDescription({});
|
||||
}
|
||||
|
||||
void DiffEditorDocument::endReload(bool success)
|
||||
|
@@ -35,10 +35,10 @@ public:
|
||||
const ChunkSelection &selection, bool revert);
|
||||
QString makePatch(int fileIndex, int chunkIndex, const ChunkSelection &selection,
|
||||
bool revert, bool addPrefix = false,
|
||||
const QString &overriddenFileName = QString()) const;
|
||||
const QString &overriddenFileName = {}) const;
|
||||
|
||||
void setDiffFiles(const QList<FileData> &data, const Utils::FilePath &directory,
|
||||
const QString &startupFile = QString());
|
||||
const QString &startupFile = {});
|
||||
QList<FileData> diffFiles() const;
|
||||
Utils::FilePath baseDirectory() const;
|
||||
void setBaseDirectory(const Utils::FilePath &directory);
|
||||
|
@@ -146,7 +146,7 @@ void DiffFilesController::cancelReload()
|
||||
{
|
||||
if (m_futureWatcher.future().isRunning()) {
|
||||
m_futureWatcher.future().cancel();
|
||||
m_futureWatcher.setFuture(QFuture<FileData>());
|
||||
m_futureWatcher.setFuture({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,7 +850,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch()
|
||||
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
{
|
||||
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"
|
||||
"index eab9e9b..082c135 100644\n"
|
||||
@@ -1189,11 +1189,11 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
" \n"
|
||||
;
|
||||
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("src/plugins/texteditor/basetextdocument.h"),
|
||||
DiffFileInfo("src/plugins/texteditor/textdocument.h")};
|
||||
fileData1.fileOperation = FileData::RenameFile;
|
||||
fileData2 = FileData();
|
||||
fileData2 = {};
|
||||
fileData2.fileInfo = {DiffFileInfo("src/plugins/texteditor/basetextdocumentlayout.cpp", "0121933"),
|
||||
DiffFileInfo("src/plugins/texteditor/textdocumentlayout.cpp", "01cc3a0")};
|
||||
fileData2.fileOperation = FileData::RenameFile;
|
||||
@@ -1224,7 +1224,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
"-Subproject commit eda76354077a427d692fee05479910de31040d3f\n"
|
||||
"+Subproject commit eda76354077a427d692fee05479910de31040d3f-dirty\n"
|
||||
;
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("src/shared/qbs"), DiffFileInfo("src/shared/qbs")};
|
||||
chunkData1.startingLineNumber = {0, 0};
|
||||
rows1.clear();
|
||||
@@ -1257,23 +1257,23 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
"Binary files /dev/null and b/demos/arthurplugin/flower.jpg differ\n"
|
||||
;
|
||||
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("demos/arthurplugin/arthurplugin.pro", "0000000"),
|
||||
DiffFileInfo("demos/arthurplugin/arthurplugin.pro", "c5132b4")};
|
||||
fileData1.fileOperation = FileData::NewFile;
|
||||
chunkData1 = ChunkData();
|
||||
chunkData1 = {};
|
||||
chunkData1.startingLineNumber = {-1, 0};
|
||||
rows1.clear();
|
||||
rows1 << RowData(TextLineData::Separator, _("XXX"));
|
||||
rows1 << RowData(TextLineData::Separator, TextLineData(TextLineData::TextLine));
|
||||
chunkData1.rows = rows1;
|
||||
fileData1.chunks << chunkData1;
|
||||
fileData2 = FileData();
|
||||
fileData2 = {};
|
||||
fileData2.fileInfo = {DiffFileInfo("demos/arthurplugin/bg1.jpg", "0000000"),
|
||||
DiffFileInfo("demos/arthurplugin/bg1.jpg", "dfc7cee")};
|
||||
fileData2.fileOperation = FileData::NewFile;
|
||||
fileData2.binaryFiles = true;
|
||||
fileData3 = FileData();
|
||||
fileData3 = {};
|
||||
fileData3.fileInfo = {DiffFileInfo("demos/arthurplugin/flower.jpg", "0000000"),
|
||||
DiffFileInfo("demos/arthurplugin/flower.jpg", "f8e022c")};
|
||||
fileData3.fileOperation = FileData::NewFile;
|
||||
@@ -1291,7 +1291,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
||||
"new mode 100755\n"
|
||||
;
|
||||
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("script.sh"), DiffFileInfo("script.sh")};
|
||||
fileData1.fileOperation = FileData::ChangeMode;
|
||||
|
||||
@@ -1310,7 +1310,7 @@ rename to new.sh
|
||||
)"
|
||||
;
|
||||
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("old.sh"), DiffFileInfo("new.sh")};
|
||||
fileData1.fileOperation = FileData::RenameFile;
|
||||
|
||||
@@ -1327,10 +1327,10 @@ rename to new.sh
|
||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(revision 0)\n"
|
||||
"@@ -0,0 +125 @@\n\n";
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("src/plugins/subversion/subversioneditor.cpp"),
|
||||
DiffFileInfo("src/plugins/subversion/subversioneditor.cpp")};
|
||||
chunkData1 = ChunkData();
|
||||
chunkData1 = {};
|
||||
chunkData1.startingLineNumber = {-1, 124};
|
||||
fileData1.chunks << chunkData1;
|
||||
QList<FileData> fileDataList21;
|
||||
@@ -1346,10 +1346,10 @@ rename to new.sh
|
||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
||||
"@@ -1,125 +0,0 @@\n\n";
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("src/plugins/subversion/subversioneditor.cpp"),
|
||||
DiffFileInfo("src/plugins/subversion/subversioneditor.cpp")};
|
||||
chunkData1 = ChunkData();
|
||||
chunkData1 = {};
|
||||
chunkData1.startingLineNumber = {0, -1};
|
||||
fileData1.chunks << chunkData1;
|
||||
QList<FileData> fileDataList22;
|
||||
@@ -1365,10 +1365,10 @@ rename to new.sh
|
||||
"--- src/plugins/subversion/subversioneditor.cpp\t(revision 42)\n"
|
||||
"+++ src/plugins/subversion/subversioneditor.cpp\t(working copy)\n"
|
||||
"@@ -120,7 +120,7 @@\n\n";
|
||||
fileData1 = FileData();
|
||||
fileData1 = {};
|
||||
fileData1.fileInfo = {DiffFileInfo("src/plugins/subversion/subversioneditor.cpp"),
|
||||
DiffFileInfo("src/plugins/subversion/subversioneditor.cpp")};
|
||||
chunkData1 = ChunkData();
|
||||
chunkData1 = {};
|
||||
chunkData1.startingLineNumber = {119, 119};
|
||||
fileData1.chunks << chunkData1;
|
||||
QList<FileData> fileDataList23;
|
||||
@@ -1425,7 +1425,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch_data()
|
||||
QTest::addColumn<ChunkSelection>("selection");
|
||||
QTest::addColumn<bool>("revert");
|
||||
|
||||
auto createChunk = []() {
|
||||
auto createChunk = [] {
|
||||
ChunkData chunk;
|
||||
chunk.contextInfo = "void DiffEditor::ctor()";
|
||||
chunk.contextChunk = false;
|
||||
|
@@ -164,7 +164,7 @@ void DiffEditorWidgetController::patch(bool revert, int fileIndex, int chunkInde
|
||||
if (patchBehaviour == DiffFileInfo::PatchFile) {
|
||||
const int strip = m_document->baseDirectory().isEmpty() ? -1 : 0;
|
||||
|
||||
const QString patch = m_document->makePatch(fileIndex, chunkIndex, ChunkSelection(), revert);
|
||||
const QString patch = m_document->makePatch(fileIndex, chunkIndex, {}, revert);
|
||||
|
||||
if (patch.isEmpty())
|
||||
return;
|
||||
@@ -190,7 +190,7 @@ void DiffEditorWidgetController::patch(bool revert, int fileIndex, int chunkInde
|
||||
const QString contentsCopyDir = QFileInfo(contentsCopyFileName).absolutePath();
|
||||
|
||||
const QString patch = m_document->makePatch(fileIndex, chunkIndex,
|
||||
ChunkSelection(), revert, false,
|
||||
{}, revert, false,
|
||||
QFileInfo(contentsCopyFileName).fileName());
|
||||
|
||||
if (patch.isEmpty())
|
||||
@@ -251,18 +251,12 @@ bool DiffEditorWidgetController::chunkExists(int fileIndex, int chunkIndex) cons
|
||||
|
||||
ChunkData DiffEditorWidgetController::chunkData(int fileIndex, int chunkIndex) const
|
||||
{
|
||||
if (!m_document)
|
||||
return ChunkData();
|
||||
|
||||
if (fileIndex < 0 || chunkIndex < 0)
|
||||
return ChunkData();
|
||||
|
||||
if (fileIndex >= m_contextFileData.count())
|
||||
return ChunkData();
|
||||
if (!m_document || fileIndex < 0 || chunkIndex < 0 || fileIndex >= m_contextFileData.count())
|
||||
return {};
|
||||
|
||||
const FileData fileData = m_contextFileData.at(fileIndex);
|
||||
if (chunkIndex >= fileData.chunks.count())
|
||||
return ChunkData();
|
||||
return {};
|
||||
|
||||
return fileData.chunks.at(chunkIndex);
|
||||
}
|
||||
@@ -328,8 +322,7 @@ void DiffEditorWidgetController::sendChunkToCodePaster(int fileIndex, int chunkI
|
||||
auto pasteService = ExtensionSystem::PluginManager::getObject<CodePaster::Service>();
|
||||
QTC_ASSERT(pasteService, return);
|
||||
|
||||
const QString patch = m_document->makePatch(fileIndex, chunkIndex,
|
||||
ChunkSelection(), false);
|
||||
const QString patch = m_document->makePatch(fileIndex, chunkIndex, {}, false);
|
||||
|
||||
if (patch.isEmpty())
|
||||
return;
|
||||
|
@@ -38,12 +38,8 @@ static QList<TextLineData> assemblyRows(const QList<TextLineData> &lines,
|
||||
static bool lastLinesEqual(const QList<TextLineData> &leftLines,
|
||||
const QList<TextLineData> &rightLines)
|
||||
{
|
||||
const bool leftLineEqual = !leftLines.isEmpty()
|
||||
? leftLines.last().text.isEmpty()
|
||||
: true;
|
||||
const bool rightLineEqual = !rightLines.isEmpty()
|
||||
? rightLines.last().text.isEmpty()
|
||||
: true;
|
||||
const bool leftLineEqual = leftLines.isEmpty() || leftLines.last().text.isEmpty();
|
||||
const bool rightLineEqual = rightLines.isEmpty() || rightLines.last().text.isEmpty();
|
||||
return leftLineEqual && rightLineEqual;
|
||||
}
|
||||
|
||||
@@ -207,10 +203,8 @@ ChunkData DiffUtils::calculateOriginalData(const QList<Diff> &leftDiffList,
|
||||
}
|
||||
}
|
||||
|
||||
QList<TextLineData> leftData = assemblyRows(leftLines,
|
||||
leftSpans);
|
||||
QList<TextLineData> rightData = assemblyRows(rightLines,
|
||||
rightSpans);
|
||||
QList<TextLineData> leftData = assemblyRows(leftLines, leftSpans);
|
||||
QList<TextLineData> rightData = assemblyRows(rightLines, rightSpans);
|
||||
|
||||
// fill ending separators
|
||||
for (int i = leftData.size(); i < rightData.size(); i++)
|
||||
@@ -334,7 +328,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
||||
bool lastChunk)
|
||||
{
|
||||
if (chunkData.contextChunk)
|
||||
return QString();
|
||||
return {};
|
||||
|
||||
QString diffText;
|
||||
int leftLineCount = 0;
|
||||
@@ -623,7 +617,7 @@ static QList<RowData> readLines(QStringView patch, bool lastChunk, bool *lastChu
|
||||
|| (noNewLineInInsert >= 0 && (noNewLineInInsert != lastInsert || lastEqual > lastInsert))) {
|
||||
if (ok)
|
||||
*ok = false;
|
||||
return QList<RowData>();
|
||||
return {};
|
||||
}
|
||||
|
||||
if (ok)
|
||||
@@ -712,7 +706,7 @@ static QStringView readLine(QStringView text, QStringView *remainingText, bool *
|
||||
const int indexOfFirstNewLine = text.indexOf(newLine);
|
||||
if (indexOfFirstNewLine < 0) {
|
||||
if (remainingText)
|
||||
*remainingText = QStringView();
|
||||
*remainingText = {};
|
||||
if (hasNewLine)
|
||||
*hasNewLine = false;
|
||||
return text;
|
||||
@@ -880,7 +874,7 @@ static FileData readDiffHeaderAndChunks(QStringView headerAndChunks, bool *ok)
|
||||
*ok = readOk;
|
||||
|
||||
if (!readOk)
|
||||
return FileData();
|
||||
return {};
|
||||
|
||||
return fileData;
|
||||
|
||||
@@ -914,7 +908,7 @@ static QList<FileData> readDiffPatch(QStringView patch, bool *ok, QFutureInterfa
|
||||
int lastPos = -1;
|
||||
do {
|
||||
if (jobController && jobController->isCanceled())
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
|
||||
int pos = diffMatch.capturedStart();
|
||||
if (lastPos >= 0) {
|
||||
@@ -948,7 +942,7 @@ static QList<FileData> readDiffPatch(QStringView patch, bool *ok, QFutureInterfa
|
||||
*ok = readOk;
|
||||
|
||||
if (!readOk)
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
|
||||
return fileDataList;
|
||||
}
|
||||
@@ -1044,7 +1038,7 @@ static bool detectIndexAndBinary(QStringView patch, FileData *fileData, QStringV
|
||||
|
||||
if (*remainingPatch == binaryLine) {
|
||||
fileData->binaryFiles = true;
|
||||
*remainingPatch = QStringView();
|
||||
*remainingPatch = {};
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1225,7 +1219,7 @@ static QList<FileData> readGitPatch(QStringView patch, bool *ok, QFutureInterfac
|
||||
const int count = startingPositions.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (jobController && jobController->isCanceled())
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
|
||||
const int diffStart = startingPositions.at(i);
|
||||
const int diffEnd = (i < count - 1)
|
||||
@@ -1251,7 +1245,7 @@ static QList<FileData> readGitPatch(QStringView patch, bool *ok, QFutureInterfac
|
||||
if (!readOk) {
|
||||
if (ok)
|
||||
*ok = readOk;
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
}
|
||||
|
||||
if (jobController)
|
||||
@@ -1263,7 +1257,7 @@ static QList<FileData> readGitPatch(QStringView patch, bool *ok, QFutureInterfac
|
||||
for (const auto &patchInfo : qAsConst(patches)) {
|
||||
if (jobController) {
|
||||
if (jobController->isCanceled())
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
jobController->setProgressValue(i++);
|
||||
}
|
||||
|
||||
@@ -1283,7 +1277,7 @@ static QList<FileData> readGitPatch(QStringView patch, bool *ok, QFutureInterfac
|
||||
*ok = readOk;
|
||||
|
||||
if (!readOk)
|
||||
return QList<FileData>();
|
||||
return {};
|
||||
|
||||
return fileDataList;
|
||||
}
|
||||
|
@@ -31,11 +31,11 @@ static QList<DiffSelection> subtractSelection(
|
||||
{
|
||||
// tha case that whole minuend is before the whole subtrahend
|
||||
if (minuendSelection.end >= 0 && minuendSelection.end <= subtrahendSelection.start)
|
||||
return QList<DiffSelection>() << minuendSelection;
|
||||
return {minuendSelection};
|
||||
|
||||
// the case that whole subtrahend is before the whole minuend
|
||||
if (subtrahendSelection.end >= 0 && subtrahendSelection.end <= minuendSelection.start)
|
||||
return QList<DiffSelection>() << minuendSelection;
|
||||
return {minuendSelection};
|
||||
|
||||
bool makeMinuendSubtrahendStart = false;
|
||||
bool makeSubtrahendMinuendEnd = false;
|
||||
|
@@ -39,7 +39,6 @@ public:
|
||||
SideDiffEditorWidget(QWidget *parent = nullptr);
|
||||
|
||||
void clearAll(const QString &message);
|
||||
void clearAllData();
|
||||
void saveState();
|
||||
using TextEditor::TextEditorWidget::restoreState;
|
||||
void restoreState();
|
||||
@@ -193,7 +192,7 @@ QString SideDiffEditorWidget::lineNumber(int blockNumber) const
|
||||
const auto it = m_data.m_lineNumbers.constFind(blockNumber);
|
||||
if (it != m_data.m_lineNumbers.constEnd())
|
||||
return QString::number(it.value());
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
int SideDiffEditorWidget::lineNumberDigits() const
|
||||
@@ -223,7 +222,7 @@ QString SideDiffEditorWidget::plainTextFromSelection(const QTextCursor &cursor)
|
||||
const int startPosition = cursor.selectionStart();
|
||||
const int endPosition = cursor.selectionEnd();
|
||||
if (startPosition == endPosition)
|
||||
return QString(); // no selection
|
||||
return {}; // no selection
|
||||
|
||||
const QTextBlock startBlock = document()->findBlock(startPosition);
|
||||
const QTextBlock endBlock = document()->findBlock(endPosition);
|
||||
@@ -344,16 +343,10 @@ int SideDiffData::chunkRowsCountForBlockNumber(int blockNumber) const
|
||||
void SideDiffEditorWidget::clearAll(const QString &message)
|
||||
{
|
||||
clear();
|
||||
clearAllData();
|
||||
setExtraSelections(TextEditorWidget::OtherSelection,
|
||||
QList<QTextEdit::ExtraSelection>());
|
||||
setPlainText(message);
|
||||
}
|
||||
|
||||
void SideDiffEditorWidget::clearAllData()
|
||||
{
|
||||
m_data = {};
|
||||
setSelections({});
|
||||
setExtraSelections(TextEditorWidget::OtherSelection, {});
|
||||
setPlainText(message);
|
||||
}
|
||||
|
||||
void SideDiffEditorWidget::scrollContentsBy(int dx, int dy)
|
||||
@@ -544,7 +537,7 @@ void SideDiffEditorWidget::paintEvent(QPaintEvent *e)
|
||||
m_drawCollapsedOffset,
|
||||
m_drawCollapsedClip);
|
||||
// reset the data for the drawing
|
||||
m_drawCollapsedBlock = QTextBlock();
|
||||
m_drawCollapsedBlock = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,8 +558,8 @@ void SideDiffEditorWidget::customDrawCollapsedBlockPopup(QPainter &painter,
|
||||
QRectF r = blockBoundingRect(b).translated(offset);
|
||||
|
||||
QTextLayout *layout = b.layout();
|
||||
for (int i = layout->lineCount()-1; i >= 0; --i)
|
||||
maxWidth = qMax(maxWidth, layout->lineAt(i).naturalTextWidth() + 2*margin);
|
||||
for (int i = layout->lineCount() - 1; i >= 0; --i)
|
||||
maxWidth = qMax(maxWidth, layout->lineAt(i).naturalTextWidth() + 2 * margin);
|
||||
|
||||
blockHeight += r.height();
|
||||
|
||||
@@ -585,9 +578,8 @@ void SideDiffEditorWidget::customDrawCollapsedBlockPopup(QPainter &painter,
|
||||
if (ifdefedOutFormat.hasProperty(QTextFormat::BackgroundBrush))
|
||||
brush = ifdefedOutFormat.background();
|
||||
painter.setBrush(brush);
|
||||
painter.drawRoundedRect(QRectF(offset.x(),
|
||||
offset.y(),
|
||||
maxWidth, blockHeight).adjusted(0, 0, 0, 0), 3, 3);
|
||||
painter.drawRoundedRect(QRectF(offset.x(), offset.y(), maxWidth, blockHeight)
|
||||
.adjusted(0, 0, 0, 0), 3, 3);
|
||||
painter.restore();
|
||||
|
||||
QTextBlock end = b;
|
||||
@@ -782,7 +774,7 @@ DiffEditorDocument *SideBySideDiffEditorWidget::diffDocument() const
|
||||
void SideBySideDiffEditorWidget::clear(const QString &message)
|
||||
{
|
||||
const GuardLocker locker(m_controller.m_ignoreChanges);
|
||||
setDiff(QList<FileData>());
|
||||
setDiff({});
|
||||
m_leftEditor->clearAll(message);
|
||||
m_rightEditor->clearAll(message);
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
void setLineNumber(int blockNumber, int lineNumber);
|
||||
void setFileInfo(int blockNumber, const DiffFileInfo &fileInfo);
|
||||
void setSkippedLines(int blockNumber, int skippedLines, const QString &contextInfo = QString()) {
|
||||
void setSkippedLines(int blockNumber, int skippedLines, const QString &contextInfo = {}) {
|
||||
m_skippedLines[blockNumber] = qMakePair(skippedLines, contextInfo);
|
||||
setSeparator(blockNumber, true);
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
void saveState();
|
||||
void restoreState();
|
||||
|
||||
void clear(const QString &message = QString());
|
||||
void clear(const QString &message = {});
|
||||
|
||||
signals:
|
||||
void currentDiffFileIndexChanged(int index);
|
||||
|
@@ -304,7 +304,7 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
||||
DiffSelections *selections)
|
||||
{
|
||||
if (chunkData.contextChunk)
|
||||
return QString();
|
||||
return {};
|
||||
|
||||
QString diffText;
|
||||
int leftLineCount = 0;
|
||||
@@ -341,8 +341,7 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
||||
'-',
|
||||
lineData.text,
|
||||
lastChunk,
|
||||
i == chunkData.rows.count()
|
||||
&& j == leftBuffer.count() - 1);
|
||||
i == chunkData.rows.count() && j == leftBuffer.count() - 1);
|
||||
|
||||
const int blockDelta = line.count('\n'); // no new line
|
||||
// could have been added
|
||||
@@ -351,10 +350,8 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
||||
|
||||
for (auto it = lineData.changedPositions.cbegin(),
|
||||
end = lineData.changedPositions.cend(); it != end; ++it) {
|
||||
const int startPos = it.key() < 0
|
||||
? 1 : it.key() + 1;
|
||||
const int endPos = it.value() < 0
|
||||
? it.value() : it.value() + 1;
|
||||
const int startPos = it.key() < 0 ? 1 : it.key() + 1;
|
||||
const int endPos = it.value() < 0 ? it.value() : it.value() + 1;
|
||||
(*selections)[*blockNumber + blockCount + 1].append(
|
||||
DiffSelection(startPos, endPos, input.m_leftCharFormat));
|
||||
}
|
||||
@@ -382,8 +379,7 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
||||
'+',
|
||||
lineData.text,
|
||||
lastChunk,
|
||||
i == chunkData.rows.count()
|
||||
&& j == rightBuffer.count() - 1);
|
||||
i == chunkData.rows.count() && j == rightBuffer.count() - 1);
|
||||
|
||||
const int blockDelta = line.count('\n'); // no new line
|
||||
// could have been added
|
||||
@@ -393,10 +389,8 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
||||
|
||||
for (auto it = lineData.changedPositions.cbegin(),
|
||||
end = lineData.changedPositions.cend(); it != end; ++it) {
|
||||
const int startPos = it.key() < 0
|
||||
? 1 : it.key() + 1;
|
||||
const int endPos = it.value() < 0
|
||||
? it.value() : it.value() + 1;
|
||||
const int startPos = it.key() < 0 ? 1 : it.key() + 1;
|
||||
const int endPos = it.value() < 0 ? it.value() : it.value() + 1;
|
||||
(*selections)[*blockNumber + blockCount + 1].append
|
||||
(DiffSelection(startPos, endPos, input.m_rightCharFormat));
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ public:
|
||||
using TextEditor::TextEditorWidget::restoreState;
|
||||
void restoreState();
|
||||
|
||||
void clear(const QString &message = QString());
|
||||
void clear(const QString &message = {});
|
||||
void setDisplaySettings(const TextEditor::DisplaySettings &ds) override;
|
||||
|
||||
signals:
|
||||
|
Reference in New Issue
Block a user