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() ...@@ -378,69 +378,61 @@ QWidget *DiffEditor::toolBar()
void DiffEditor::documentHasChanged() void DiffEditor::documentHasChanged()
{ {
int index = 0; Guard guard(&m_ignoreChanges);
{ const QList<FileData> diffFileList = m_document->diffFiles();
Guard guard(&m_ignoreChanges);
const QList<FileData> diffFileList = m_document->diffFiles(); updateDescription();
currentView()->setDiff(diffFileList, m_document->baseDirectory());
updateDescription();
currentView()->setDiff(diffFileList, m_document->baseDirectory()); m_entriesComboBox->clear();
const int count = diffFileList.count();
m_entriesComboBox->clear(); for (int i = 0; i < count; i++) {
const int count = diffFileList.count(); const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
for (int i = 0; i < count; i++) { const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo; const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName();
const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo; const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName();
const QString leftShortFileName = Utils::FileName::fromString(leftEntry.fileName).fileName(); QString itemText;
const QString rightShortFileName = Utils::FileName::fromString(rightEntry.fileName).fileName(); QString itemToolTip;
QString itemText; if (leftEntry.fileName == rightEntry.fileName) {
QString itemToolTip; itemText = leftShortFileName;
if (leftEntry.fileName == rightEntry.fileName) {
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; itemText = leftShortFileName;
} else {
itemText = tr("%1 vs. %2")
.arg(leftShortFileName,
rightShortFileName);
}
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) { if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
itemToolTip = leftEntry.fileName; itemToolTip = tr("%1 vs. %2")
} else { .arg(leftEntry.fileName,
itemToolTip = tr("[%1] vs. [%2] %3") rightEntry.fileName);
.arg(leftEntry.typeInfo,
rightEntry.typeInfo,
leftEntry.fileName);
}
} else { } else {
if (leftShortFileName == rightShortFileName) { itemToolTip = tr("[%1] %2 vs. [%3] %4")
itemText = leftShortFileName; .arg(leftEntry.typeInfo,
} else { leftEntry.fileName,
itemText = tr("%1 vs. %2") rightEntry.typeInfo,
.arg(leftShortFileName, rightEntry.fileName);
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);
}
} }
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() void DiffEditor::toggleDescription()
...@@ -521,9 +513,28 @@ void DiffEditor::reloadHasFinished(bool success) ...@@ -521,9 +513,28 @@ void DiffEditor::reloadHasFinished(bool success)
if (!currentView()) if (!currentView())
return; return;
m_currentFileChunk = qMakePair(QString(), QString());
currentView()->endOperation(success); 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() void DiffEditor::updateEntryToolTip()
......
...@@ -100,9 +100,10 @@ DiffEditorController *DiffEditorController::controller(Core::IDocument *document ...@@ -100,9 +100,10 @@ DiffEditorController *DiffEditorController::controller(Core::IDocument *document
} }
void DiffEditorController::setDiffFiles(const QList<FileData> &diffFileList, 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) void DiffEditorController::setDescription(const QString &description)
...@@ -169,6 +170,11 @@ void DiffEditorController::forceContextLineCount(int lines) ...@@ -169,6 +170,11 @@ void DiffEditorController::forceContextLineCount(int lines)
m_document->forceContextLineCount(lines); m_document->forceContextLineCount(lines);
} }
Core::IDocument *DiffEditorController::document() const
{
return m_document;
}
/** /**
* @brief Request the diff data to be re-read. * @brief Request the diff data to be re-read.
*/ */
......
...@@ -79,9 +79,11 @@ protected: ...@@ -79,9 +79,11 @@ protected:
virtual void reloadFinished(bool success); virtual void reloadFinished(bool success);
void setDiffFiles(const QList<FileData> &diffFileList, void setDiffFiles(const QList<FileData> &diffFileList,
const QString &baseDirectory = QString()); const QString &baseDirectory = QString(),
const QString &startupFile = QString());
void setDescription(const QString &description); void setDescription(const QString &description);
void forceContextLineCount(int lines); void forceContextLineCount(int lines);
Core::IDocument *document() const;
private: private:
void requestMoreInformation(); void requestMoreInformation();
......
...@@ -122,10 +122,12 @@ QString DiffEditorDocument::makePatch(int fileIndex, int chunkIndex, bool revert ...@@ -122,10 +122,12 @@ QString DiffEditorDocument::makePatch(int fileIndex, int chunkIndex, bool revert
lastChunk && fileData.lastChunkAtTheEndOfFile); 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_diffFiles = data;
m_baseDirectory = directory; m_baseDirectory = directory;
m_startupFile = startupFile;
emit documentChanged(); emit documentChanged();
} }
...@@ -139,6 +141,11 @@ QString DiffEditorDocument::baseDirectory() const ...@@ -139,6 +141,11 @@ QString DiffEditorDocument::baseDirectory() const
return m_baseDirectory; return m_baseDirectory;
} }
QString DiffEditorDocument::startupFile() const
{
return m_startupFile;
}
void DiffEditorDocument::setDescription(const QString &description) void DiffEditorDocument::setDescription(const QString &description)
{ {
if (m_description == description) if (m_description == description)
......
...@@ -54,9 +54,11 @@ public: ...@@ -54,9 +54,11 @@ public:
QString makePatch(int fileIndex, int chunkIndex, bool revert, bool addPrefix = false) const; 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; QList<FileData> diffFiles() const;
QString baseDirectory() const; QString baseDirectory() const;
QString startupFile() const;
void setDescription(const QString &description); void setDescription(const QString &description);
QString description() const; QString description() const;
...@@ -99,6 +101,7 @@ private: ...@@ -99,6 +101,7 @@ private:
DiffEditorController *m_controller; DiffEditorController *m_controller;
QList<FileData> m_diffFiles; QList<FileData> m_diffFiles;
QString m_baseDirectory; QString m_baseDirectory;
QString m_startupFile;
QString m_description; QString m_description;
int m_contextLineCount; int m_contextLineCount;
bool m_isContextLineCountForced; bool m_isContextLineCountForced;
......
...@@ -126,7 +126,7 @@ private slots: ...@@ -126,7 +126,7 @@ private slots:
virtual void processOutput(const QString &output); virtual void processOutput(const QString &output);
protected: protected:
void processDiff(const QString &output); void processDiff(const QString &output, const QString &startupFile = QString());
QStringList addConfigurationArguments(const QStringList &args) const; QStringList addConfigurationArguments(const QStringList &args) const;
GitClient *gitClient() const; GitClient *gitClient() const;
QStringList addHeadWhenCommandInProgress() const; QStringList addHeadWhenCommandInProgress() const;
...@@ -171,13 +171,13 @@ void BaseController::runCommand(const QList<QStringList> &args, QTextCodec *code ...@@ -171,13 +171,13 @@ void BaseController::runCommand(const QList<QStringList> &args, QTextCodec *code
m_command->execute(); m_command->execute();
} }
void BaseController::processDiff(const QString &output) void BaseController::processDiff(const QString &output, const QString &startupFile)
{ {
m_command.clear(); m_command.clear();
bool ok; bool ok;
QList<FileData> fileDataList = DiffUtils::readPatch(output, &ok); QList<FileData> fileDataList = DiffUtils::readPatch(output, &ok);
setDiffFiles(fileDataList, m_directory); setDiffFiles(fileDataList, m_directory, startupFile);
} }
QStringList BaseController::addConfigurationArguments(const QStringList &args) const QStringList BaseController::addConfigurationArguments(const QStringList &args) const
...@@ -381,11 +381,10 @@ void ShowController::reload() ...@@ -381,11 +381,10 @@ void ShowController::reload()
void ShowController::processOutput(const QString &output) void ShowController::processOutput(const QString &output)
{ {
QTC_ASSERT(m_state != Idle, return); QTC_ASSERT(m_state != Idle, return);
if (m_state == GettingDescription) { if (m_state == GettingDescription)
setDescription(gitClient()->extendedShowDescription(m_directory, output)); setDescription(gitClient()->extendedShowDescription(m_directory, output));
} else if (m_state == GettingDiff) { else if (m_state == GettingDiff)
processDiff(output); processDiff(output, VcsBasePlugin::source(document()));
}
} }
void ShowController::reloadFinished(bool success) 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