Commit d8d7acbe authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Git: Scroll to active file on Show invoked from file log

Change-Id: I0935bf8b8b30ee78716a14ee0a88c21b9caf62dc
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@theqtcompany.com>
parent f735c8da
......@@ -378,69 +378,61 @@ QWidget *DiffEditor::toolBar()
void DiffEditor::documentHasChanged()
{
int index = 0;
{
Guard guard(&m_ignoreChanges);
const QList<FileData> diffFileList = m_document->diffFiles();
updateDescription();
currentView()->setDiff(diffFileList, m_document->baseDirectory());
m_entriesComboBox->clear();
const int count = diffFileList.count();
for (int i = 0; i < count; i++) {
const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName();
const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName();
QString itemText;
QString itemToolTip;
if (leftEntry.fileName == rightEntry.fileName) {
Guard guard(&m_ignoreChanges);
const QList<FileData> diffFileList = m_document->diffFiles();
updateDescription();
currentView()->setDiff(diffFileList, m_document->baseDirectory());
m_entriesComboBox->clear();
const int count = diffFileList.count();
for (int i = 0; i < count; i++) {
const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName();
const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName();
QString itemText;
QString itemToolTip;
if (leftEntry.fileName == rightEntry.fileName) {
itemText = leftShortFileName;
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
itemToolTip = leftEntry.fileName;
} else {
itemToolTip = tr("[%1] vs. [%2] %3")
.arg(leftEntry.typeInfo,
rightEntry.typeInfo,
leftEntry.fileName);
}
} else {
if (leftShortFileName == rightShortFileName) {
itemText = leftShortFileName;
} else {
itemText = tr("%1 vs. %2")
.arg(leftShortFileName,
rightShortFileName);
}
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
itemToolTip = leftEntry.fileName;
} else {
itemToolTip = tr("[%1] vs. [%2] %3")
.arg(leftEntry.typeInfo,
rightEntry.typeInfo,
leftEntry.fileName);
}
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
itemToolTip = tr("%1 vs. %2")
.arg(leftEntry.fileName,
rightEntry.fileName);
} else {
if (leftShortFileName == rightShortFileName) {
itemText = leftShortFileName;
} else {
itemText = tr("%1 vs. %2")
.arg(leftShortFileName,
rightShortFileName);
}
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
itemToolTip = tr("%1 vs. %2")
.arg(leftEntry.fileName,
rightEntry.fileName);
} else {
itemToolTip = tr("[%1] %2 vs. [%3] %4")
.arg(leftEntry.typeInfo,
leftEntry.fileName,
rightEntry.typeInfo,
rightEntry.fileName);
}
itemToolTip = tr("[%1] %2 vs. [%3] %4")
.arg(leftEntry.typeInfo,
leftEntry.fileName,
rightEntry.typeInfo,
rightEntry.fileName);
}
if (m_currentFileChunk.first == leftEntry.fileName
&& m_currentFileChunk.second == rightEntry.fileName)
index = i;
m_entriesComboBox->addItem(itemText);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
leftEntry.fileName, Qt::UserRole);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
rightEntry.fileName, Qt::UserRole + 1);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
itemToolTip, Qt::ToolTipRole);
}
m_entriesComboBox->addItem(itemText);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
leftEntry.fileName, Qt::UserRole);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
rightEntry.fileName, Qt::UserRole + 1);
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
itemToolTip, Qt::ToolTipRole);
}
setCurrentDiffFileIndex(m_entriesComboBox->count() > 0 ? index : -1);
}
void DiffEditor::toggleDescription()
......@@ -521,9 +513,28 @@ void DiffEditor::reloadHasFinished(bool success)
if (!currentView())
return;
m_currentFileChunk = qMakePair(QString(), QString());
currentView()->endOperation(success);
int index = -1;
const QString startupFile = m_document->startupFile();
const QList<FileData> diffFileList = m_document->diffFiles();
const int count = diffFileList.count();
for (int i = 0; i < count; i++) {
const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
if ((m_currentFileChunk.first.isEmpty()
&& m_currentFileChunk.second.isEmpty()
&& startupFile.endsWith(rightEntry.fileName))
|| (m_currentFileChunk.first == leftEntry.fileName
&& m_currentFileChunk.second == rightEntry.fileName)) {
index = i;
break;
}
}
m_currentFileChunk = qMakePair(QString(), QString());
if (index >= 0)
setCurrentDiffFileIndex(index);
}
void DiffEditor::updateEntryToolTip()
......
......@@ -100,9 +100,10 @@ DiffEditorController *DiffEditorController::controller(Core::IDocument *document
}
void DiffEditorController::setDiffFiles(const QList<FileData> &diffFileList,
const QString &workingDirectory)
const QString &workingDirectory,
const QString &startupFile)
{
m_document->setDiffFiles(diffFileList, workingDirectory);
m_document->setDiffFiles(diffFileList, workingDirectory, startupFile);
}
void DiffEditorController::setDescription(const QString &description)
......@@ -169,6 +170,11 @@ void DiffEditorController::forceContextLineCount(int lines)
m_document->forceContextLineCount(lines);
}
Core::IDocument *DiffEditorController::document() const
{
return m_document;
}
/**
* @brief Request the diff data to be re-read.
*/
......
......@@ -79,9 +79,11 @@ protected:
virtual void reloadFinished(bool success);
void setDiffFiles(const QList<FileData> &diffFileList,
const QString &baseDirectory = QString());
const QString &baseDirectory = QString(),
const QString &startupFile = QString());
void setDescription(const QString &description);
void forceContextLineCount(int lines);
Core::IDocument *document() const;
private:
void requestMoreInformation();
......
......@@ -122,10 +122,12 @@ QString DiffEditorDocument::makePatch(int fileIndex, int chunkIndex, bool revert
lastChunk && fileData.lastChunkAtTheEndOfFile);
}
void DiffEditorDocument::setDiffFiles(const QList<FileData> &data, const QString &directory)
void DiffEditorDocument::setDiffFiles(const QList<FileData> &data, const QString &directory,
const QString &startupFile)
{
m_diffFiles = data;
m_baseDirectory = directory;
m_startupFile = startupFile;
emit documentChanged();
}
......@@ -139,6 +141,11 @@ QString DiffEditorDocument::baseDirectory() const
return m_baseDirectory;
}
QString DiffEditorDocument::startupFile() const
{
return m_startupFile;
}
void DiffEditorDocument::setDescription(const QString &description)
{
if (m_description == description)
......
......@@ -54,9 +54,11 @@ public:
QString makePatch(int fileIndex, int chunkIndex, bool revert, bool addPrefix = false) const;
void setDiffFiles(const QList<FileData> &data, const QString &directory);
void setDiffFiles(const QList<FileData> &data, const QString &directory,
const QString &startupFile = QString());
QList<FileData> diffFiles() const;
QString baseDirectory() const;
QString startupFile() const;
void setDescription(const QString &description);
QString description() const;
......@@ -99,6 +101,7 @@ private:
DiffEditorController *m_controller;
QList<FileData> m_diffFiles;
QString m_baseDirectory;
QString m_startupFile;
QString m_description;
int m_contextLineCount;
bool m_isContextLineCountForced;
......
......@@ -126,7 +126,7 @@ private slots:
virtual void processOutput(const QString &output);
protected:
void processDiff(const QString &output);
void processDiff(const QString &output, const QString &startupFile = QString());
QStringList addConfigurationArguments(const QStringList &args) const;
GitClient *gitClient() const;
QStringList addHeadWhenCommandInProgress() const;
......@@ -171,13 +171,13 @@ void BaseController::runCommand(const QList<QStringList> &args, QTextCodec *code
m_command->execute();
}
void BaseController::processDiff(const QString &output)
void BaseController::processDiff(const QString &output, const QString &startupFile)
{
m_command.clear();
bool ok;
QList<FileData> fileDataList = DiffUtils::readPatch(output, &ok);
setDiffFiles(fileDataList, m_directory);
setDiffFiles(fileDataList, m_directory, startupFile);
}
QStringList BaseController::addConfigurationArguments(const QStringList &args) const
......@@ -381,11 +381,10 @@ void ShowController::reload()
void ShowController::processOutput(const QString &output)
{
QTC_ASSERT(m_state != Idle, return);
if (m_state == GettingDescription) {
if (m_state == GettingDescription)
setDescription(gitClient()->extendedShowDescription(m_directory, output));
} else if (m_state == GettingDiff) {
processDiff(output);
}
else if (m_state == GettingDiff)
processDiff(output, VcsBasePlugin::source(document()));
}
void ShowController::reloadFinished(bool success)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment