forked from qt-creator/qt-creator
Hide some diff editor controls when diff editor is bound to a file.
Remove unnecessary anymore "ignoreWhitespace" argument from functions which read a patch file. Transfer the ownership of reloader into controller. Task-number: QTCREATORBUG-13250 Change-Id: I68183005b845d6ece9ea2be9888abc8597310426 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -322,12 +322,12 @@ QWidget *DiffEditor::toolBar()
|
||||
whitespaceButton->setText(tr("Ignore Whitespace"));
|
||||
whitespaceButton->setCheckable(true);
|
||||
whitespaceButton->setChecked(m_controller->isIgnoreWhitespace());
|
||||
m_toolBar->addWidget(whitespaceButton);
|
||||
m_whitespaceButtonAction = m_toolBar->addWidget(whitespaceButton);
|
||||
|
||||
QLabel *contextLabel = new QLabel(m_toolBar);
|
||||
contextLabel->setText(tr("Context Lines:"));
|
||||
contextLabel->setContentsMargins(6, 0, 6, 0);
|
||||
m_toolBar->addWidget(contextLabel);
|
||||
m_contextLabelAction = m_toolBar->addWidget(contextLabel);
|
||||
|
||||
QSpinBox *contextSpinBox = new QSpinBox(m_toolBar);
|
||||
contextSpinBox->setRange(1, 100);
|
||||
@@ -335,7 +335,7 @@ QWidget *DiffEditor::toolBar()
|
||||
contextSpinBox->setFrame(false);
|
||||
contextSpinBox->setSizePolicy(QSizePolicy::Minimum,
|
||||
QSizePolicy::Expanding); // Mac Qt5
|
||||
m_toolBar->addWidget(contextSpinBox);
|
||||
m_contextSpinBoxAction = m_toolBar->addWidget(contextSpinBox);
|
||||
|
||||
QToolButton *toggleDescription = new QToolButton(m_toolBar);
|
||||
toggleDescription->setIcon(
|
||||
@@ -497,6 +497,9 @@ void DiffEditor::slotDescriptionVisibilityChanged()
|
||||
|
||||
void DiffEditor::slotReloaderChanged(DiffEditorReloader *reloader)
|
||||
{
|
||||
m_whitespaceButtonAction->setVisible(reloader);
|
||||
m_contextLabelAction->setVisible(reloader);
|
||||
m_contextSpinBoxAction->setVisible(reloader);
|
||||
m_reloadAction->setVisible(reloader);
|
||||
}
|
||||
|
||||
|
@@ -104,6 +104,9 @@ private:
|
||||
DiffEditorGuiController *m_guiController;
|
||||
QToolBar *m_toolBar;
|
||||
QComboBox *m_entriesComboBox;
|
||||
QAction *m_whitespaceButtonAction;
|
||||
QAction *m_contextLabelAction;
|
||||
QAction *m_contextSpinBoxAction;
|
||||
QAction *m_toggleDescriptionAction;
|
||||
QAction *m_reloadAction;
|
||||
QToolButton *m_diffEditorSwitcher;
|
||||
|
@@ -64,7 +64,7 @@ DiffEditorController::DiffEditorController(QObject *parent)
|
||||
|
||||
DiffEditorController::~DiffEditorController()
|
||||
{
|
||||
|
||||
delete m_reloader;
|
||||
}
|
||||
|
||||
QString DiffEditorController::clearMessage() const
|
||||
@@ -137,20 +137,20 @@ DiffEditorReloader *DiffEditorController::reloader() const
|
||||
return m_reloader;
|
||||
}
|
||||
|
||||
// The ownership of reloader is passed to the controller
|
||||
void DiffEditorController::setReloader(DiffEditorReloader *reloader)
|
||||
{
|
||||
if (m_reloader == reloader)
|
||||
return; // nothing changes
|
||||
|
||||
if (m_reloader)
|
||||
m_reloader->setController(0);
|
||||
delete m_reloader;
|
||||
|
||||
m_reloader = reloader;
|
||||
|
||||
if (m_reloader)
|
||||
m_reloader->setController(this);
|
||||
|
||||
reloaderChanged(m_reloader);
|
||||
emit reloaderChanged(m_reloader);
|
||||
}
|
||||
|
||||
void DiffEditorController::clear()
|
||||
|
@@ -31,6 +31,8 @@
|
||||
#include "diffeditordocument.h"
|
||||
#include "diffeditorconstants.h"
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "diffeditormanager.h"
|
||||
#include "diffeditorreloader.h"
|
||||
#include "diffutils.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -83,6 +85,10 @@ bool DiffEditorDocument::save(QString *errorString, const QString &fileName, boo
|
||||
if (!ok)
|
||||
return false;
|
||||
|
||||
if (m_controller->reloader())
|
||||
m_controller->setReloader(0);
|
||||
|
||||
DiffEditorManager::removeDocument(this);
|
||||
const QFileInfo fi(fileName);
|
||||
setTemporary(false);
|
||||
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
||||
@@ -105,10 +111,7 @@ bool DiffEditorDocument::open(QString *errorString, const QString &fileName)
|
||||
return false;
|
||||
|
||||
bool ok = false;
|
||||
QList<FileData> fileDataList
|
||||
= DiffUtils::readPatch(patch,
|
||||
m_controller->isIgnoreWhitespace(),
|
||||
&ok);
|
||||
QList<FileData> fileDataList = DiffUtils::readPatch(patch, &ok);
|
||||
if (!ok) {
|
||||
*errorString = tr("Could not parse patch file \"%1\". "
|
||||
"The content is not of unified diff format.")
|
||||
|
@@ -115,5 +115,14 @@ DiffEditorDocument *DiffEditorManager::findOrCreate(const QString &documentId, c
|
||||
return document;
|
||||
}
|
||||
|
||||
void DiffEditorManager::removeDocument(DiffEditorDocument *document)
|
||||
{
|
||||
if (!instance()->documentToId.contains(document))
|
||||
return;
|
||||
const QString documentId = instance()->documentToId.value(document);
|
||||
instance()->documentToId.remove(document);
|
||||
instance()->idToDocument.remove(documentId);
|
||||
}
|
||||
|
||||
|
||||
} // namespace DiffEditor
|
||||
|
@@ -53,6 +53,7 @@ public:
|
||||
|
||||
static DiffEditorDocument *find(const QString &documentId);
|
||||
static DiffEditorDocument *findOrCreate(const QString &documentId, const QString &displayName);
|
||||
static void removeDocument(DiffEditorDocument *document);
|
||||
|
||||
private slots:
|
||||
void slotEditorsClosed(const QList<Core::IEditor *> &editors);
|
||||
|
@@ -54,8 +54,7 @@ class SimpleDiffEditorReloader : public DiffEditorReloader
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SimpleDiffEditorReloader(QObject *parent,
|
||||
const QString &leftFileName,
|
||||
SimpleDiffEditorReloader(const QString &leftFileName,
|
||||
const QString &rightFileName);
|
||||
|
||||
protected:
|
||||
@@ -66,11 +65,9 @@ private:
|
||||
QString m_rightFileName;
|
||||
};
|
||||
|
||||
SimpleDiffEditorReloader::SimpleDiffEditorReloader(QObject *parent,
|
||||
const QString &leftFileName,
|
||||
SimpleDiffEditorReloader::SimpleDiffEditorReloader(const QString &leftFileName,
|
||||
const QString &rightFileName)
|
||||
: DiffEditorReloader(parent),
|
||||
m_leftFileName(leftFileName),
|
||||
: m_leftFileName(leftFileName),
|
||||
m_rightFileName(rightFileName)
|
||||
{
|
||||
}
|
||||
@@ -206,7 +203,7 @@ void DiffEditorPlugin::diff()
|
||||
DiffEditorController *controller = document->controller();
|
||||
if (!controller->reloader()) {
|
||||
SimpleDiffEditorReloader *reloader =
|
||||
new SimpleDiffEditorReloader(controller, fileName1, fileName2);
|
||||
new SimpleDiffEditorReloader(fileName1, fileName2);
|
||||
controller->setReloader(reloader);
|
||||
}
|
||||
|
||||
@@ -475,7 +472,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch()
|
||||
QCOMPARE(result, patchText);
|
||||
|
||||
bool ok;
|
||||
QList<FileData> resultList = DiffUtils::readPatch(result, false, &ok);
|
||||
QList<FileData> resultList = DiffUtils::readPatch(result, &ok);
|
||||
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(resultList.count(), 1);
|
||||
@@ -905,7 +902,7 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
|
||||
QFETCH(QList<FileData>, fileDataList);
|
||||
|
||||
bool ok;
|
||||
QList<FileData> result = DiffUtils::readPatch(sourcePatch, false, &ok);
|
||||
QList<FileData> result = DiffUtils::readPatch(sourcePatch, &ok);
|
||||
|
||||
QVERIFY(ok);
|
||||
QCOMPARE(fileDataList.count(), result.count());
|
||||
|
@@ -33,9 +33,8 @@
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
DiffEditorReloader::DiffEditorReloader(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_controller(0),
|
||||
DiffEditorReloader::DiffEditorReloader()
|
||||
: m_controller(0),
|
||||
m_reloading(false)
|
||||
{
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ class DIFFEDITOR_EXPORT DiffEditorReloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiffEditorReloader(QObject *parent = 0);
|
||||
DiffEditorReloader();
|
||||
~DiffEditorReloader();
|
||||
|
||||
bool isReloading() const;
|
||||
|
@@ -517,7 +517,6 @@ QString DiffUtils::makePatch(const QList<FileData> &fileDataList)
|
||||
}
|
||||
|
||||
static QList<RowData> readLines(const QString &patch,
|
||||
bool ignoreWhitespace,
|
||||
bool lastChunk,
|
||||
bool *lastChunkAtTheEndOfFile,
|
||||
bool *ok)
|
||||
@@ -678,28 +677,16 @@ static QList<RowData> readLines(const QString &patch,
|
||||
QList<Diff> outputLeftDiffList;
|
||||
QList<Diff> outputRightDiffList;
|
||||
|
||||
if (ignoreWhitespace) {
|
||||
const QList<Diff> leftIntermediate =
|
||||
Differ::moveWhitespaceIntoEqualities(leftDiffList);
|
||||
const QList<Diff> rightIntermediate =
|
||||
Differ::moveWhitespaceIntoEqualities(rightDiffList);
|
||||
Differ::ignoreWhitespaceBetweenEqualities(leftIntermediate,
|
||||
rightIntermediate,
|
||||
&outputLeftDiffList,
|
||||
&outputRightDiffList);
|
||||
} else {
|
||||
Differ::diffBetweenEqualities(leftDiffList,
|
||||
rightDiffList,
|
||||
&outputLeftDiffList,
|
||||
&outputRightDiffList);
|
||||
}
|
||||
|
||||
return DiffUtils::calculateOriginalData(outputLeftDiffList,
|
||||
outputRightDiffList).rows;
|
||||
}
|
||||
|
||||
static QList<ChunkData> readChunks(const QString &patch,
|
||||
bool ignoreWhitespace,
|
||||
bool *lastChunkAtTheEndOfFile,
|
||||
bool *ok)
|
||||
{
|
||||
@@ -728,7 +715,6 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
const QString lines = patch.mid(endOfLastChunk,
|
||||
pos - endOfLastChunk);
|
||||
chunkDataList.last().rows = readLines(lines,
|
||||
ignoreWhitespace,
|
||||
false,
|
||||
lastChunkAtTheEndOfFile,
|
||||
&readOk);
|
||||
@@ -747,7 +733,6 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
if (endOfLastChunk > 0) {
|
||||
const QString lines = patch.mid(endOfLastChunk);
|
||||
chunkDataList.last().rows = readLines(lines,
|
||||
ignoreWhitespace,
|
||||
true,
|
||||
lastChunkAtTheEndOfFile,
|
||||
&readOk);
|
||||
@@ -761,7 +746,6 @@ static QList<ChunkData> readChunks(const QString &patch,
|
||||
}
|
||||
|
||||
static FileData readDiffHeaderAndChunks(const QString &headerAndChunks,
|
||||
bool ignoreWhitespace,
|
||||
bool *ok)
|
||||
{
|
||||
QString patch = headerAndChunks;
|
||||
@@ -789,7 +773,6 @@ static FileData readDiffHeaderAndChunks(const QString &headerAndChunks,
|
||||
fileData.rightFileInfo.fileName = rightFileRegExp.cap(1);
|
||||
|
||||
fileData.chunks = readChunks(patch,
|
||||
ignoreWhitespace,
|
||||
&fileData.lastChunkAtTheEndOfFile,
|
||||
&readOk);
|
||||
}
|
||||
@@ -811,7 +794,6 @@ static FileData readDiffHeaderAndChunks(const QString &headerAndChunks,
|
||||
}
|
||||
|
||||
static QList<FileData> readDiffPatch(const QString &patch,
|
||||
bool ignoreWhitespace,
|
||||
bool *ok)
|
||||
{
|
||||
const QRegExp diffRegExp(QLatin1String("(?:\\n|^)" // new line of the beginning of a patch
|
||||
@@ -844,7 +826,6 @@ static QList<FileData> readDiffPatch(const QString &patch,
|
||||
pos - lastPos);
|
||||
|
||||
const FileData fileData = readDiffHeaderAndChunks(headerAndChunks,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
|
||||
if (!readOk)
|
||||
@@ -861,7 +842,6 @@ static QList<FileData> readDiffPatch(const QString &patch,
|
||||
patch.count() - lastPos - 1);
|
||||
|
||||
const FileData fileData = readDiffHeaderAndChunks(headerAndChunks,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
|
||||
if (readOk)
|
||||
@@ -880,7 +860,6 @@ static QList<FileData> readDiffPatch(const QString &patch,
|
||||
|
||||
static FileData readGitHeaderAndChunks(const QString &headerAndChunks,
|
||||
const QString &fileName,
|
||||
bool ignoreWhitespace,
|
||||
bool *ok)
|
||||
{
|
||||
FileData fileData;
|
||||
@@ -944,7 +923,6 @@ static FileData readGitHeaderAndChunks(const QString &headerAndChunks,
|
||||
patch.remove(0, rightFileRegExp.matchedLength());
|
||||
|
||||
fileData.chunks = readChunks(patch,
|
||||
ignoreWhitespace,
|
||||
&fileData.lastChunkAtTheEndOfFile,
|
||||
&readOk);
|
||||
}
|
||||
@@ -966,7 +944,6 @@ static FileData readCopyRenameChunks(const QString ©RenameChunks,
|
||||
FileData::FileOperation fileOperation,
|
||||
const QString &leftFileName,
|
||||
const QString &rightFileName,
|
||||
bool ignoreWhitespace,
|
||||
bool *ok)
|
||||
{
|
||||
FileData fileData;
|
||||
@@ -1005,7 +982,6 @@ static FileData readCopyRenameChunks(const QString ©RenameChunks,
|
||||
patch.remove(0, rightFileRegExp.matchedLength());
|
||||
|
||||
fileData.chunks = readChunks(patch,
|
||||
ignoreWhitespace,
|
||||
&fileData.lastChunkAtTheEndOfFile,
|
||||
&readOk);
|
||||
}
|
||||
@@ -1024,7 +1000,7 @@ static FileData readCopyRenameChunks(const QString ©RenameChunks,
|
||||
return fileData;
|
||||
}
|
||||
|
||||
static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace, bool *ok)
|
||||
static QList<FileData> readGitPatch(const QString &patch, bool *ok)
|
||||
{
|
||||
const QRegExp simpleGitRegExp(QLatin1String("(?:\\n|^)diff --git a/([^\\n]+) b/\\1\\n")); // diff --git a/cap1 b/cap1
|
||||
|
||||
@@ -1074,14 +1050,12 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
|
||||
if (lastOperation == FileData::ChangeFile) {
|
||||
fileData = readGitHeaderAndChunks(headerAndChunks,
|
||||
lastLeftFileName,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
} else {
|
||||
fileData = readCopyRenameChunks(headerAndChunks,
|
||||
lastOperation,
|
||||
lastLeftFileName,
|
||||
lastRightFileName,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
}
|
||||
if (!readOk)
|
||||
@@ -1124,14 +1098,12 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
|
||||
|
||||
fileData = readGitHeaderAndChunks(headerAndChunks,
|
||||
lastLeftFileName,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
} else {
|
||||
fileData = readCopyRenameChunks(headerAndChunks,
|
||||
lastOperation,
|
||||
lastLeftFileName,
|
||||
lastRightFileName,
|
||||
ignoreWhitespace,
|
||||
&readOk);
|
||||
}
|
||||
if (readOk)
|
||||
@@ -1148,7 +1120,7 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
|
||||
return fileDataList;
|
||||
}
|
||||
|
||||
QList<FileData> DiffUtils::readPatch(const QString &patch, bool ignoreWhitespace, bool *ok)
|
||||
QList<FileData> DiffUtils::readPatch(const QString &patch, bool *ok)
|
||||
{
|
||||
bool readOk = false;
|
||||
|
||||
@@ -1161,9 +1133,9 @@ QList<FileData> DiffUtils::readPatch(const QString &patch, bool ignoreWhitespace
|
||||
if (pos != -1)
|
||||
croppedPatch = patch.left(pos + 1); // crop the ending for git format-patch
|
||||
|
||||
fileDataList = readGitPatch(croppedPatch, ignoreWhitespace, &readOk);
|
||||
fileDataList = readGitPatch(croppedPatch, &readOk);
|
||||
if (!readOk)
|
||||
fileDataList = readDiffPatch(croppedPatch, ignoreWhitespace, &readOk);
|
||||
fileDataList = readDiffPatch(croppedPatch, &readOk);
|
||||
|
||||
if (ok)
|
||||
*ok = readOk;
|
||||
|
@@ -148,7 +148,6 @@ public:
|
||||
bool lastChunk = false);
|
||||
static QString makePatch(const QList<FileData> &fileDataList);
|
||||
static QList<FileData> readPatch(const QString &patch,
|
||||
bool ignoreWhitespace,
|
||||
bool *ok = 0);
|
||||
};
|
||||
|
||||
|
@@ -331,8 +331,7 @@ void GitDiffHandler::slotTextualDiffOutputReceived(const QString &contents)
|
||||
|
||||
bool ok;
|
||||
QList<DiffEditor::FileData> fileDataList
|
||||
= DiffEditor::DiffUtils::readPatch(
|
||||
contents, m_controller->isIgnoreWhitespace(), &ok);
|
||||
= DiffEditor::DiffUtils::readPatch(contents, &ok);
|
||||
m_controller->setDiffFiles(fileDataList, m_workingDirectory);
|
||||
m_controller->requestRestoreState();
|
||||
deleteLater();
|
||||
@@ -368,7 +367,7 @@ public:
|
||||
DiffShow
|
||||
};
|
||||
|
||||
GitDiffEditorReloader(QObject *parent);
|
||||
GitDiffEditorReloader();
|
||||
void setWorkingDirectory(const QString &workingDir) {
|
||||
m_workingDirectory = workingDir;
|
||||
}
|
||||
@@ -408,9 +407,8 @@ private:
|
||||
QString m_displayName;
|
||||
};
|
||||
|
||||
GitDiffEditorReloader::GitDiffEditorReloader(QObject *parent)
|
||||
: DiffEditorReloader(parent),
|
||||
m_gitClient(GitPlugin::instance()->gitClient())
|
||||
GitDiffEditorReloader::GitDiffEditorReloader()
|
||||
: m_gitClient(GitPlugin::instance()->gitClient())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -831,7 +829,7 @@ GitDiffEditorReloader *GitClient::findOrCreateDiffEditor(const QString &document
|
||||
connect(controller, SIGNAL(expandBranchesRequested(QString)),
|
||||
this, SLOT(branchesForCommit(QString)));
|
||||
|
||||
reloader = new GitDiffEditorReloader(controller);
|
||||
reloader = new GitDiffEditorReloader();
|
||||
controller->setReloader(reloader);
|
||||
|
||||
reloader->setWorkingDirectory(workingDirectory);
|
||||
|
Reference in New Issue
Block a user