forked from qt-creator/qt-creator
Add a toolbutton for switching diff view mode
Task-number: QTCREATORBUG-10035 Change-Id: I83cb7cec3f4ba484ab068f398a12096501017668 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -73,5 +73,7 @@
|
|||||||
<file>images/splitbutton_closetop.png</file>
|
<file>images/splitbutton_closetop.png</file>
|
||||||
<file>images/splitbutton_vertical.png</file>
|
<file>images/splitbutton_vertical.png</file>
|
||||||
<file>images/panel_manage_button.png</file>
|
<file>images/panel_manage_button.png</file>
|
||||||
|
<file>images/sidebysidediff.png</file>
|
||||||
|
<file>images/textdiff.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ const char ICON_CLOSE_SPLIT_TOP[] = ":/core/images/splitbutton_closetop.png";
|
|||||||
const char ICON_CLOSE_SPLIT_BOTTOM[] = ":/core/images/splitbutton_closebottom.png";
|
const char ICON_CLOSE_SPLIT_BOTTOM[] = ":/core/images/splitbutton_closebottom.png";
|
||||||
const char ICON_CLOSE_SPLIT_LEFT[] = ":/core/images/splitbutton_closeleft.png";
|
const char ICON_CLOSE_SPLIT_LEFT[] = ":/core/images/splitbutton_closeleft.png";
|
||||||
const char ICON_CLOSE_SPLIT_RIGHT[] = ":/core/images/splitbutton_closeright.png";
|
const char ICON_CLOSE_SPLIT_RIGHT[] = ":/core/images/splitbutton_closeright.png";
|
||||||
|
const char ICON_SIDE_BY_SIDE_DIFF[] = ":/core/images/sidebysidediff.png";
|
||||||
|
const char ICON_TEXT_DIFF[] = ":/core/images/textdiff.png";
|
||||||
const char ICON_FILTER[] = ":/core/images/filtericon.png";
|
const char ICON_FILTER[] = ":/core/images/filtericon.png";
|
||||||
const char ICON_LINK[] = ":/core/images/linkicon.png";
|
const char ICON_LINK[] = ":/core/images/linkicon.png";
|
||||||
const char ICON_QTLOGO_32[] = ":/core/images/logo/32/QtProject-qtcreator.png";
|
const char ICON_QTLOGO_32[] = ":/core/images/logo/32/QtProject-qtcreator.png";
|
||||||
|
|||||||
BIN
src/plugins/coreplugin/images/sidebysidediff.png
Normal file
BIN
src/plugins/coreplugin/images/sidebysidediff.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 257 B |
BIN
src/plugins/coreplugin/images/textdiff.png
Normal file
BIN
src/plugins/coreplugin/images/textdiff.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 258 B |
@@ -89,7 +89,7 @@ static QToolBar *createToolBar(const QWidget *someWidget)
|
|||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
QToolBar *toolBar = new QToolBar;
|
QToolBar *toolBar = new QToolBar;
|
||||||
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||||
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
toolBar->setIconSize(QSize(size, size));
|
toolBar->setIconSize(QSize(size, size));
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
#include <coreplugin/iversioncontrol.h>
|
#include <coreplugin/iversioncontrol.h>
|
||||||
|
#include <coreplugin/coreconstants.h>
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -84,6 +85,96 @@ namespace Internal {
|
|||||||
|
|
||||||
using VcsBase::VcsBasePlugin;
|
using VcsBase::VcsBasePlugin;
|
||||||
|
|
||||||
|
class GitDiffSwitcher : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum DiffType {
|
||||||
|
DiffRepository,
|
||||||
|
DiffFile,
|
||||||
|
DiffFileList,
|
||||||
|
DiffProjectList,
|
||||||
|
DiffBranch,
|
||||||
|
DiffShow
|
||||||
|
};
|
||||||
|
|
||||||
|
GitDiffSwitcher(Core::IEditor *parentEditor, GitClient *gitClient, GitClient::DiffEditorType switchToType)
|
||||||
|
: QObject(parentEditor),
|
||||||
|
m_gitClient(gitClient),
|
||||||
|
m_editorType(switchToType)
|
||||||
|
{
|
||||||
|
QIcon actionIcon = switchToType == GitClient::SideBySideDiffEditor
|
||||||
|
? QIcon(QLatin1String(Core::Constants::ICON_SIDE_BY_SIDE_DIFF))
|
||||||
|
: QIcon(QLatin1String(Core::Constants::ICON_TEXT_DIFF));
|
||||||
|
|
||||||
|
const QString actionToolTip = switchToType == GitClient::SideBySideDiffEditor
|
||||||
|
? tr("Switch to Side By Side Diff Editor")
|
||||||
|
: tr("Switch to Text Diff Editor");
|
||||||
|
|
||||||
|
QAction *switchAction = new QAction(actionIcon, actionToolTip, parentEditor);
|
||||||
|
parentEditor->toolBar()->addAction(switchAction);
|
||||||
|
connect(switchAction, SIGNAL(triggered()), this, SLOT(execute()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWorkingDirectory(const QString &workingDir) { m_workingDirectory = workingDir; }
|
||||||
|
void setDiffType(DiffType type) { m_diffType = type; }
|
||||||
|
void setFileName(const QString &fileName) { m_fileName = fileName; }
|
||||||
|
void setFileList(const QStringList &stagedFiles, const QStringList &unstagedFiles)
|
||||||
|
{
|
||||||
|
m_stagedFiles = stagedFiles;
|
||||||
|
m_unstagedFiles = unstagedFiles;
|
||||||
|
}
|
||||||
|
void setProjectList(const QStringList &projectFiles) { m_projectFiles = projectFiles; }
|
||||||
|
void setBranchName(const QString &branchName) { m_branchName = branchName; }
|
||||||
|
void setId(const QString &id) { m_id = id; }
|
||||||
|
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
|
||||||
|
void setBaseArguments(const QStringList &args) { m_baseArguments = args; }
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GitClient *m_gitClient;
|
||||||
|
QString m_workingDirectory;
|
||||||
|
DiffType m_diffType;
|
||||||
|
GitClient::DiffEditorType m_editorType;
|
||||||
|
QString m_fileName;
|
||||||
|
QStringList m_stagedFiles;
|
||||||
|
QStringList m_unstagedFiles;
|
||||||
|
QStringList m_projectFiles;
|
||||||
|
QString m_branchName;
|
||||||
|
QString m_id;
|
||||||
|
QString m_displayName;
|
||||||
|
QStringList m_baseArguments;
|
||||||
|
};
|
||||||
|
|
||||||
|
void GitDiffSwitcher::execute()
|
||||||
|
{
|
||||||
|
switch (m_diffType) {
|
||||||
|
case DiffRepository:
|
||||||
|
m_gitClient->diff(m_workingDirectory, QStringList(), QStringList(), m_editorType);
|
||||||
|
break;
|
||||||
|
case DiffFile:
|
||||||
|
m_gitClient->diff(m_workingDirectory, m_fileName, m_editorType);
|
||||||
|
break;
|
||||||
|
case DiffFileList:
|
||||||
|
m_gitClient->diff(m_workingDirectory, m_unstagedFiles, m_stagedFiles, m_editorType);
|
||||||
|
break;
|
||||||
|
case DiffProjectList:
|
||||||
|
m_gitClient->diff(m_workingDirectory, m_projectFiles, QStringList(), m_editorType);
|
||||||
|
break;
|
||||||
|
case DiffBranch:
|
||||||
|
m_gitClient->diffBranch(m_workingDirectory, m_baseArguments, m_branchName, m_editorType);
|
||||||
|
break;
|
||||||
|
case DiffShow:
|
||||||
|
m_gitClient->show(m_fileName, m_id, m_baseArguments, m_displayName, m_editorType);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class GitDiffHandler : public QObject
|
class GitDiffHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -873,28 +964,30 @@ VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *regis
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditor::DiffEditor *GitClient::findExistingOrOpenNewDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditor *GitClient::findExistingDiffEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue, const QString &titlePattern, const Core::Id editorId) const
|
const QString &dynamicPropertyValue) const
|
||||||
{
|
{
|
||||||
Core::IEditor *outputEditor = locateEditor(registerDynamicProperty, dynamicPropertyValue);
|
DiffEditor::DiffEditor *diffEditor = qobject_cast<DiffEditor::DiffEditor *>(
|
||||||
if (outputEditor) {
|
locateEditor(registerDynamicProperty, dynamicPropertyValue));
|
||||||
// Exists already
|
if (diffEditor) {
|
||||||
Core::EditorManager::activateEditor(outputEditor);
|
diffEditor->document()->setContents(m_msgWait.toUtf8());
|
||||||
outputEditor->document()->setContents(m_msgWait.toUtf8());
|
Core::EditorManager::activateEditor(diffEditor);
|
||||||
}
|
}
|
||||||
|
return diffEditor;
|
||||||
DiffEditor::DiffEditor *editor = qobject_cast<DiffEditor::DiffEditor *>(outputEditor);
|
|
||||||
if (!editor) {
|
|
||||||
QString title = titlePattern;
|
|
||||||
editor = qobject_cast<DiffEditor::DiffEditor *>(
|
|
||||||
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait.toUtf8()));
|
|
||||||
QTC_ASSERT(editor, return 0);
|
|
||||||
editor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
|
||||||
Core::EditorManager::activateEditor(editor);
|
|
||||||
}
|
|
||||||
return editor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiffEditor::DiffEditor *GitClient::createDiffEditor(const char *registerDynamicProperty,
|
||||||
|
const QString &dynamicPropertyValue, const QString &titlePattern, const Core::Id editorId) const
|
||||||
|
{
|
||||||
|
QString title = titlePattern;
|
||||||
|
DiffEditor::DiffEditor *diffEditor = qobject_cast<DiffEditor::DiffEditor *>(
|
||||||
|
Core::EditorManager::openEditorWithContents(editorId, &title, m_msgWait.toUtf8()));
|
||||||
|
QTC_ASSERT(diffEditor, return 0);
|
||||||
|
diffEditor->document()->setProperty(registerDynamicProperty, dynamicPropertyValue);
|
||||||
|
|
||||||
|
Core::EditorManager::activateEditor(diffEditor);
|
||||||
|
return diffEditor;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create an editor associated to VCS output of a source file/directory
|
/* Create an editor associated to VCS output of a source file/directory
|
||||||
* (using the file's codec). Makes use of a dynamic property to find an
|
* (using the file's codec). Makes use of a dynamic property to find an
|
||||||
@@ -942,19 +1035,30 @@ VcsBase::VcsBaseEditorWidget *GitClient::createVcsEditor(const Core::Id &id,
|
|||||||
|
|
||||||
void GitClient::diff(const QString &workingDirectory,
|
void GitClient::diff(const QString &workingDirectory,
|
||||||
const QStringList &unstagedFileNames,
|
const QStringList &unstagedFileNames,
|
||||||
const QStringList &stagedFileNames)
|
const QStringList &stagedFileNames,
|
||||||
|
DiffEditorType editorType)
|
||||||
{
|
{
|
||||||
const QString title = tr("Git Diff");
|
const QString title = tr("Git Diff");
|
||||||
const int timeout = settings()->intValue(GitSettings::timeoutKey);
|
const int timeout = settings()->intValue(GitSettings::timeoutKey);
|
||||||
|
const bool showSideBySideEditor = (editorType == DefaultDiffEditor
|
||||||
|
&& settings()->boolValue(GitSettings::useDiffEditorKey))
|
||||||
|
|| editorType == SideBySideDiffEditor;
|
||||||
|
Core::IEditor *newEditor = 0;
|
||||||
|
if (showSideBySideEditor) {
|
||||||
|
const char *propertyName = "sideBySideOriginalFileName";
|
||||||
|
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, workingDirectory);
|
||||||
|
if (!diffEditor) {
|
||||||
|
newEditor = diffEditor = createDiffEditor(propertyName,
|
||||||
|
workingDirectory,
|
||||||
|
title,
|
||||||
|
DiffEditor::Constants::DIFF_EDITOR_ID);
|
||||||
|
}
|
||||||
|
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
||||||
DiffEditor::DiffEditor *editor = findExistingOrOpenNewDiffEditor(
|
gitBinaryPath(),
|
||||||
"originalFileName",
|
workingDirectory,
|
||||||
workingDirectory,
|
processEnvironment(),
|
||||||
title,
|
timeout);
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
|
||||||
|
|
||||||
GitDiffHandler *handler = new GitDiffHandler(editor, gitBinaryPath(), workingDirectory, processEnvironment(), timeout);
|
|
||||||
|
|
||||||
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
// local repository diff
|
// local repository diff
|
||||||
@@ -968,32 +1072,41 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const QString binary = settings()->stringValue(GitSettings::binaryPathKey);
|
const QString binary = settings()->stringValue(GitSettings::binaryPathKey);
|
||||||
const Core::Id editorId = Git::Constants::GIT_DIFF_EDITOR_ID;
|
const char *propertyName = "originalFileName";
|
||||||
|
VcsBase::VcsBaseEditorWidget *vcsEditor = findExistingVCSEditor(propertyName, workingDirectory);
|
||||||
VcsBase::VcsBaseEditorWidget *editor = findExistingVCSEditor("originalFileName", workingDirectory);
|
if (!vcsEditor) {
|
||||||
if (!editor) {
|
|
||||||
GitCommitDiffArgumentsWidget *argWidget =
|
GitCommitDiffArgumentsWidget *argWidget =
|
||||||
new GitCommitDiffArgumentsWidget(this, workingDirectory,
|
new GitCommitDiffArgumentsWidget(this,
|
||||||
unstagedFileNames, stagedFileNames);
|
workingDirectory,
|
||||||
|
unstagedFileNames,
|
||||||
editor = createVcsEditor(editorId, title,
|
stagedFileNames);
|
||||||
workingDirectory, CodecSource, "originalFileName", workingDirectory, argWidget);
|
vcsEditor = createVcsEditor(Git::Constants::GIT_DIFF_EDITOR_ID,
|
||||||
connect(editor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)), argWidget, SLOT(executeCommand()));
|
title,
|
||||||
|
workingDirectory,
|
||||||
|
CodecSource,
|
||||||
|
propertyName,
|
||||||
|
workingDirectory,
|
||||||
|
argWidget);
|
||||||
|
newEditor = vcsEditor->editor();
|
||||||
|
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
||||||
|
argWidget, SLOT(executeCommand()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GitCommitDiffArgumentsWidget *argWidget = qobject_cast<GitCommitDiffArgumentsWidget *>(editor->configurationWidget());
|
GitCommitDiffArgumentsWidget *argWidget = qobject_cast<GitCommitDiffArgumentsWidget *>(
|
||||||
|
vcsEditor->configurationWidget());
|
||||||
argWidget->setFileNames(unstagedFileNames, stagedFileNames);
|
argWidget->setFileNames(unstagedFileNames, stagedFileNames);
|
||||||
QStringList userDiffArgs = argWidget->arguments();
|
QStringList userDiffArgs = argWidget->arguments();
|
||||||
editor->setDiffBaseDirectory(workingDirectory);
|
vcsEditor->setDiffBaseDirectory(workingDirectory);
|
||||||
|
|
||||||
// Create a batch of 2 commands to be run after each other in case
|
// Create a batch of 2 commands to be run after each other in case
|
||||||
// we have a mixture of staged/unstaged files as is the case
|
// we have a mixture of staged/unstaged files as is the case
|
||||||
// when using the submit dialog.
|
// when using the submit dialog.
|
||||||
VcsBase::Command *command = createCommand(workingDirectory, editor);
|
VcsBase::Command *command = createCommand(workingDirectory, vcsEditor);
|
||||||
// Directory diff?
|
// Directory diff?
|
||||||
|
|
||||||
QStringList cmdArgs;
|
QStringList cmdArgs;
|
||||||
cmdArgs << QLatin1String("diff") << QLatin1String(noColorOption);
|
cmdArgs << QLatin1String("diff")
|
||||||
|
<< QLatin1String(noColorOption);
|
||||||
|
|
||||||
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
QStringList arguments(cmdArgs);
|
QStringList arguments(cmdArgs);
|
||||||
@@ -1004,101 +1117,175 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
// Files diff.
|
// Files diff.
|
||||||
if (!unstagedFileNames.empty()) {
|
if (!unstagedFileNames.empty()) {
|
||||||
QStringList arguments(cmdArgs);
|
QStringList arguments(cmdArgs);
|
||||||
arguments << userDiffArgs;
|
arguments << userDiffArgs
|
||||||
arguments << QLatin1String("--") << unstagedFileNames;
|
<< QLatin1String("--")
|
||||||
|
<< unstagedFileNames;
|
||||||
outputWindow()->appendCommand(workingDirectory, binary, arguments);
|
outputWindow()->appendCommand(workingDirectory, binary, arguments);
|
||||||
command->addJob(arguments, timeout);
|
command->addJob(arguments, timeout);
|
||||||
}
|
}
|
||||||
if (!stagedFileNames.empty()) {
|
if (!stagedFileNames.empty()) {
|
||||||
QStringList arguments(cmdArgs);
|
QStringList arguments(cmdArgs);
|
||||||
arguments << userDiffArgs;
|
arguments << userDiffArgs
|
||||||
arguments << QLatin1String("--cached") << QLatin1String("--") << stagedFileNames;
|
<< QLatin1String("--cached")
|
||||||
|
<< QLatin1String("--")
|
||||||
|
<< stagedFileNames;
|
||||||
outputWindow()->appendCommand(workingDirectory, binary, arguments);
|
outputWindow()->appendCommand(workingDirectory, binary, arguments);
|
||||||
command->addJob(arguments, timeout);
|
command->addJob(arguments, timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command->execute();
|
command->execute();
|
||||||
}
|
}
|
||||||
|
if (newEditor) {
|
||||||
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this,
|
||||||
|
showSideBySideEditor ? SimpleTextDiffEditor : SideBySideDiffEditor);
|
||||||
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
|
// local repository diff
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffRepository);
|
||||||
|
} else if (!stagedFileNames.empty()) {
|
||||||
|
// diff of selected files only with --cached option, used in commit editor
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffFileList);
|
||||||
|
switcher->setFileList(stagedFileNames, unstagedFileNames);
|
||||||
|
} else {
|
||||||
|
// current project diff
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffProjectList);
|
||||||
|
switcher->setProjectList(unstagedFileNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::diff(const QString &workingDirectory,
|
void GitClient::diff(const QString &workingDirectory,
|
||||||
const QString &fileName)
|
const QString &fileName,
|
||||||
|
DiffEditorType editorType)
|
||||||
{
|
{
|
||||||
const QString title = tr("Git Diff \"%1\"").arg(fileName);
|
const QString title = tr("Git Diff \"%1\"").arg(fileName);
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
const bool showSideBySideEditor = (editorType == DefaultDiffEditor
|
||||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
&& settings()->boolValue(GitSettings::useDiffEditorKey))
|
||||||
DiffEditor::DiffEditor *editor = findExistingOrOpenNewDiffEditor(
|
|| editorType == SideBySideDiffEditor;
|
||||||
"originalFileName",
|
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
||||||
sourceFile,
|
Core::IEditor *newEditor = 0;
|
||||||
title,
|
if (showSideBySideEditor) {
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
const char *propertyName = "sideBySideOriginalFileName";
|
||||||
|
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, sourceFile);
|
||||||
if (!fileName.isEmpty()) {
|
if (!diffEditor) {
|
||||||
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
newEditor = diffEditor = createDiffEditor(propertyName,
|
||||||
GitDiffHandler *handler = new GitDiffHandler(editor, gitBinaryPath(), workingDirectory, processEnvironment(), timeout);
|
sourceFile,
|
||||||
handler->diffFile(fileName);
|
title,
|
||||||
|
DiffEditor::Constants::DIFF_EDITOR_ID);
|
||||||
}
|
}
|
||||||
|
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
||||||
|
gitBinaryPath(),
|
||||||
|
workingDirectory,
|
||||||
|
processEnvironment(),
|
||||||
|
settings()->intValue(GitSettings::timeoutKey));
|
||||||
|
handler->diffFile(fileName);
|
||||||
} else {
|
} else {
|
||||||
const Core::Id editorId = Git::Constants::GIT_DIFF_EDITOR_ID;
|
const char *propertyName = "originalFileName";
|
||||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, fileName);
|
VcsBase::VcsBaseEditorWidget *vcsEditor = findExistingVCSEditor(propertyName, sourceFile);
|
||||||
|
if (!vcsEditor) {
|
||||||
VcsBase::VcsBaseEditorWidget *editor = findExistingVCSEditor("originalFileName", sourceFile);
|
|
||||||
if (!editor) {
|
|
||||||
GitFileDiffArgumentsWidget *argWidget =
|
GitFileDiffArgumentsWidget *argWidget =
|
||||||
new GitFileDiffArgumentsWidget(this, workingDirectory, fileName);
|
new GitFileDiffArgumentsWidget(this, workingDirectory, fileName);
|
||||||
|
|
||||||
editor = createVcsEditor(editorId, title, sourceFile, CodecSource, "originalFileName", sourceFile, argWidget);
|
vcsEditor = createVcsEditor(Git::Constants::GIT_DIFF_EDITOR_ID,
|
||||||
connect(editor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)), argWidget, SLOT(executeCommand()));
|
title,
|
||||||
|
sourceFile,
|
||||||
|
CodecSource,
|
||||||
|
propertyName,
|
||||||
|
sourceFile,
|
||||||
|
argWidget);
|
||||||
|
newEditor = vcsEditor->editor();
|
||||||
|
connect(vcsEditor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)),
|
||||||
|
argWidget, SLOT(executeCommand()));
|
||||||
}
|
}
|
||||||
editor->setDiffBaseDirectory(workingDirectory);
|
vcsEditor->setDiffBaseDirectory(workingDirectory);
|
||||||
|
|
||||||
GitFileDiffArgumentsWidget *argWidget = qobject_cast<GitFileDiffArgumentsWidget *>(editor->configurationWidget());
|
GitFileDiffArgumentsWidget *argWidget = qobject_cast<GitFileDiffArgumentsWidget *>(
|
||||||
|
vcsEditor->configurationWidget());
|
||||||
QStringList userDiffArgs = argWidget->arguments();
|
QStringList userDiffArgs = argWidget->arguments();
|
||||||
|
|
||||||
QStringList cmdArgs;
|
QStringList cmdArgs;
|
||||||
cmdArgs << QLatin1String("diff") << QLatin1String(noColorOption)
|
cmdArgs << QLatin1String("diff")
|
||||||
|
<< QLatin1String(noColorOption)
|
||||||
<< userDiffArgs;
|
<< userDiffArgs;
|
||||||
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
cmdArgs << QLatin1String("--") << fileName;
|
cmdArgs << QLatin1String("--") << fileName;
|
||||||
executeGit(workingDirectory, cmdArgs, editor);
|
executeGit(workingDirectory, cmdArgs, vcsEditor);
|
||||||
|
}
|
||||||
|
if (newEditor) {
|
||||||
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this,
|
||||||
|
showSideBySideEditor ? SimpleTextDiffEditor : SideBySideDiffEditor);
|
||||||
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffFile);
|
||||||
|
switcher->setFileName(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::diffBranch(const QString &workingDirectory,
|
void GitClient::diffBranch(const QString &workingDirectory,
|
||||||
const QStringList &diffArgs,
|
const QStringList &diffArgs,
|
||||||
const QString &branchName)
|
const QString &branchName,
|
||||||
|
DiffEditorType editorType)
|
||||||
{
|
{
|
||||||
const QString title = tr("Git Diff Branch \"%1\"").arg(branchName);
|
const QString title = tr("Git Diff Branch \"%1\"").arg(branchName);
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
const bool showSideBySideEditor = (editorType == DefaultDiffEditor
|
||||||
DiffEditor::DiffEditor *editor = findExistingOrOpenNewDiffEditor(
|
&& settings()->boolValue(GitSettings::useDiffEditorKey))
|
||||||
"BranchName",
|
|| editorType == SideBySideDiffEditor;
|
||||||
branchName,
|
Core::IEditor *newEditor = 0;
|
||||||
title,
|
if (showSideBySideEditor) {
|
||||||
DiffEditor::Constants::DIFF_EDITOR_ID);
|
const char *propertyName = "sideBySideBranchName";
|
||||||
|
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, branchName);
|
||||||
|
if (!diffEditor) {
|
||||||
|
newEditor = diffEditor = createDiffEditor(propertyName,
|
||||||
|
branchName,
|
||||||
|
title,
|
||||||
|
DiffEditor::Constants::DIFF_EDITOR_ID);
|
||||||
|
}
|
||||||
|
|
||||||
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
||||||
GitDiffHandler *handler = new GitDiffHandler(editor, gitBinaryPath(), workingDirectory, processEnvironment(), timeout);
|
gitBinaryPath(),
|
||||||
|
workingDirectory,
|
||||||
|
processEnvironment(),
|
||||||
|
settings()->intValue(GitSettings::timeoutKey));
|
||||||
handler->diffBranch(branchName);
|
handler->diffBranch(branchName);
|
||||||
} else {
|
} else {
|
||||||
const Core::Id editorId = Git::Constants::GIT_DIFF_EDITOR_ID;
|
const char *propertyName = "BranchName";
|
||||||
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, QStringList());
|
const QString sourceFile = VcsBase::VcsBaseEditorWidget::getSource(workingDirectory, QStringList());
|
||||||
|
|
||||||
VcsBase::VcsBaseEditorWidget *editor = findExistingVCSEditor("BranchName", branchName);
|
VcsBase::VcsBaseEditorWidget *vcsEditor = findExistingVCSEditor(propertyName, branchName);
|
||||||
if (!editor)
|
if (!vcsEditor) {
|
||||||
editor = createVcsEditor(editorId, title, sourceFile, CodecSource, "BranchName", branchName,
|
vcsEditor = createVcsEditor(Git::Constants::GIT_DIFF_EDITOR_ID,
|
||||||
new GitBranchDiffArgumentsWidget(this, workingDirectory,
|
title,
|
||||||
diffArgs, branchName));
|
sourceFile,
|
||||||
editor->setDiffBaseDirectory(workingDirectory);
|
CodecSource,
|
||||||
|
propertyName,
|
||||||
|
branchName,
|
||||||
|
new GitBranchDiffArgumentsWidget(this,
|
||||||
|
workingDirectory,
|
||||||
|
diffArgs,
|
||||||
|
branchName));
|
||||||
|
newEditor = vcsEditor->editor();
|
||||||
|
}
|
||||||
|
vcsEditor->setDiffBaseDirectory(workingDirectory);
|
||||||
|
|
||||||
GitBranchDiffArgumentsWidget *argWidget = qobject_cast<GitBranchDiffArgumentsWidget *>(editor->configurationWidget());
|
GitBranchDiffArgumentsWidget *argWidget = qobject_cast<GitBranchDiffArgumentsWidget *>(
|
||||||
|
vcsEditor->configurationWidget());
|
||||||
QStringList userDiffArgs = argWidget->arguments();
|
QStringList userDiffArgs = argWidget->arguments();
|
||||||
|
|
||||||
QStringList cmdArgs;
|
QStringList cmdArgs;
|
||||||
cmdArgs << QLatin1String("diff") << QLatin1String(noColorOption)
|
cmdArgs << QLatin1String("diff")
|
||||||
<< userDiffArgs << branchName;
|
<< QLatin1String(noColorOption)
|
||||||
|
<< userDiffArgs
|
||||||
|
<< branchName;
|
||||||
|
|
||||||
executeGit(workingDirectory, cmdArgs, editor);
|
executeGit(workingDirectory, cmdArgs, vcsEditor);
|
||||||
|
}
|
||||||
|
if (newEditor) {
|
||||||
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this,
|
||||||
|
showSideBySideEditor ? SimpleTextDiffEditor : SideBySideDiffEditor);
|
||||||
|
switcher->setWorkingDirectory(workingDirectory);
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffBranch);
|
||||||
|
switcher->setBaseArguments(diffArgs);
|
||||||
|
switcher->setBranchName(branchName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1194,7 +1381,8 @@ static inline QString msgCannotShow(const QString &sha)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::show(const QString &source, const QString &id,
|
void GitClient::show(const QString &source, const QString &id,
|
||||||
const QStringList &args, const QString &name)
|
const QStringList &args, const QString &name,
|
||||||
|
DiffEditorType editorType)
|
||||||
{
|
{
|
||||||
if (!canShow(id)) {
|
if (!canShow(id)) {
|
||||||
outputWindow()->appendError(msgCannotShow(id));
|
outputWindow()->appendError(msgCannotShow(id));
|
||||||
@@ -1203,36 +1391,66 @@ void GitClient::show(const QString &source, const QString &id,
|
|||||||
|
|
||||||
const QString title = tr("Git Show \"%1\"").arg(name.isEmpty() ? id : name);
|
const QString title = tr("Git Show \"%1\"").arg(name.isEmpty() ? id : name);
|
||||||
const QFileInfo sourceFi(source);
|
const QFileInfo sourceFi(source);
|
||||||
const QString workDir = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
|
const QString workingDirectory = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
|
||||||
if (settings()->boolValue(GitSettings::useDiffEditorKey)) {
|
const bool showSideBySideEditor = (editorType == DefaultDiffEditor
|
||||||
DiffEditor::DiffEditor *editor = findExistingOrOpenNewDiffEditor(
|
&& settings()->boolValue(GitSettings::useDiffEditorKey))
|
||||||
"show",
|
|| editorType == SideBySideDiffEditor;
|
||||||
id,
|
Core::IEditor *newEditor = 0;
|
||||||
title,
|
if (showSideBySideEditor) {
|
||||||
DiffEditor::Constants::DIFF_SHOW_EDITOR_ID);
|
const char *propertyName = "sideBySideShow";
|
||||||
|
DiffEditor::DiffEditor *diffEditor = findExistingDiffEditor(propertyName, id);
|
||||||
|
if (!diffEditor) {
|
||||||
|
newEditor = diffEditor = createDiffEditor(propertyName,
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
DiffEditor::Constants::DIFF_SHOW_EDITOR_ID);
|
||||||
|
}
|
||||||
|
|
||||||
int timeout = settings()->intValue(GitSettings::timeoutKey);
|
GitDiffHandler *handler = new GitDiffHandler(diffEditor,
|
||||||
GitDiffHandler *handler = new GitDiffHandler(editor, gitBinaryPath(), workDir,
|
gitBinaryPath(),
|
||||||
processEnvironment(), timeout);
|
workingDirectory,
|
||||||
|
processEnvironment(),
|
||||||
|
settings()->intValue(GitSettings::timeoutKey));
|
||||||
handler->show(id);
|
handler->show(id);
|
||||||
} else {
|
} else {
|
||||||
|
const char *propertyName = "show";
|
||||||
const Core::Id editorId = Git::Constants::GIT_DIFF_EDITOR_ID;
|
const Core::Id editorId = Git::Constants::GIT_DIFF_EDITOR_ID;
|
||||||
VcsBase::VcsBaseEditorWidget *editor = findExistingVCSEditor("show", id);
|
VcsBase::VcsBaseEditorWidget *vcsEditor = findExistingVCSEditor(propertyName, id);
|
||||||
if (!editor)
|
if (!vcsEditor) {
|
||||||
editor = createVcsEditor(editorId, title, source, CodecSource, "show", id,
|
vcsEditor = createVcsEditor(editorId,
|
||||||
new GitShowArgumentsWidget(this, source, args, id));
|
title,
|
||||||
|
source,
|
||||||
|
CodecSource,
|
||||||
|
propertyName,
|
||||||
|
id,
|
||||||
|
new GitShowArgumentsWidget(this,
|
||||||
|
source,
|
||||||
|
args,
|
||||||
|
id));
|
||||||
|
newEditor = vcsEditor->editor();
|
||||||
|
}
|
||||||
|
|
||||||
GitShowArgumentsWidget *argWidget = qobject_cast<GitShowArgumentsWidget *>(editor->configurationWidget());
|
GitShowArgumentsWidget *argWidget = qobject_cast<GitShowArgumentsWidget *>(
|
||||||
|
vcsEditor->configurationWidget());
|
||||||
QStringList userArgs = argWidget->arguments();
|
QStringList userArgs = argWidget->arguments();
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("show") << QLatin1String(noColorOption);
|
arguments << QLatin1String("show")
|
||||||
arguments << QLatin1String(decorateOption);
|
<< QLatin1String(noColorOption)
|
||||||
arguments.append(userArgs);
|
<< QLatin1String(decorateOption)
|
||||||
arguments << id;
|
<< userArgs
|
||||||
|
<< id;
|
||||||
|
|
||||||
editor->setDiffBaseDirectory(workDir);
|
vcsEditor->setDiffBaseDirectory(workingDirectory);
|
||||||
executeGit(workDir, arguments, editor);
|
executeGit(workingDirectory, arguments, vcsEditor);
|
||||||
|
}
|
||||||
|
if (newEditor) {
|
||||||
|
GitDiffSwitcher *switcher = new GitDiffSwitcher(newEditor, this,
|
||||||
|
showSideBySideEditor ? SimpleTextDiffEditor : SideBySideDiffEditor);
|
||||||
|
switcher->setDiffType(GitDiffSwitcher::DiffShow);
|
||||||
|
switcher->setFileName(source);
|
||||||
|
switcher->setBaseArguments(args);
|
||||||
|
switcher->setId(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ public:
|
|||||||
StashFlag m_flags;
|
StashFlag m_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum DiffEditorType {
|
||||||
|
DefaultDiffEditor, // value taken from settings
|
||||||
|
SideBySideDiffEditor,
|
||||||
|
SimpleTextDiffEditor
|
||||||
|
};
|
||||||
|
|
||||||
static const char *stashNamePrefix;
|
static const char *stashNamePrefix;
|
||||||
|
|
||||||
explicit GitClient(GitSettings *settings);
|
explicit GitClient(GitSettings *settings);
|
||||||
@@ -137,12 +143,17 @@ public:
|
|||||||
QString findRepositoryForDirectory(const QString &dir);
|
QString findRepositoryForDirectory(const QString &dir);
|
||||||
QString findGitDirForRepository(const QString &repositoryDir) const;
|
QString findGitDirForRepository(const QString &repositoryDir) const;
|
||||||
|
|
||||||
void diff(const QString &workingDirectory, const QString &fileName);
|
void diff(const QString &workingDirectory,
|
||||||
void diff(const QString &workingDirectory, const QStringList &unstagedFileNames,
|
const QString &fileName,
|
||||||
const QStringList &stagedFileNames = QStringList());
|
DiffEditorType editorType = DefaultDiffEditor);
|
||||||
|
void diff(const QString &workingDirectory,
|
||||||
|
const QStringList &unstagedFileNames,
|
||||||
|
const QStringList &stagedFileNames = QStringList(),
|
||||||
|
DiffEditorType editorType = DefaultDiffEditor);
|
||||||
void diffBranch(const QString &workingDirectory,
|
void diffBranch(const QString &workingDirectory,
|
||||||
const QStringList &diffArgs,
|
const QStringList &diffArgs,
|
||||||
const QString &branchName);
|
const QString &branchName,
|
||||||
|
DiffEditorType editorType = DefaultDiffEditor);
|
||||||
void merge(const QString &workingDirectory, const QStringList &unmergedFileNames = QStringList());
|
void merge(const QString &workingDirectory, const QStringList &unmergedFileNames = QStringList());
|
||||||
|
|
||||||
void status(const QString &workingDirectory);
|
void status(const QString &workingDirectory);
|
||||||
@@ -326,8 +337,11 @@ public:
|
|||||||
static QString msgNoCommits(bool includeRemote);
|
static QString msgNoCommits(bool includeRemote);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void show(const QString &source, const QString &id,
|
void show(const QString &source,
|
||||||
const QStringList &args = QStringList(), const QString &name = QString());
|
const QString &id,
|
||||||
|
const QStringList &args = QStringList(),
|
||||||
|
const QString &name = QString(),
|
||||||
|
DiffEditorType editorType = DefaultDiffEditor);
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -338,11 +352,9 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QTextCodec *getSourceCodec(const QString &file) const;
|
QTextCodec *getSourceCodec(const QString &file) const;
|
||||||
VcsBase::VcsBaseEditorWidget *findExistingVCSEditor(const char *registerDynamicProperty,
|
VcsBase::VcsBaseEditorWidget *findExistingVCSEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue) const;
|
const QString &dynamicPropertyValue) const;
|
||||||
DiffEditor::DiffEditor *findExistingOrOpenNewDiffEditor(const char *registerDynamicProperty,
|
DiffEditor::DiffEditor *findExistingDiffEditor(const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue,
|
const QString &dynamicPropertyValue) const;
|
||||||
const QString &titlePattern,
|
|
||||||
const Core::Id editorId) const;
|
|
||||||
|
|
||||||
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
enum CodecType { CodecSource, CodecLogOutput, CodecNone };
|
||||||
VcsBase::VcsBaseEditorWidget *createVcsEditor(const Core::Id &kind,
|
VcsBase::VcsBaseEditorWidget *createVcsEditor(const Core::Id &kind,
|
||||||
@@ -352,6 +364,10 @@ private:
|
|||||||
const char *registerDynamicProperty,
|
const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue,
|
const QString &dynamicPropertyValue,
|
||||||
QWidget *configWidget) const;
|
QWidget *configWidget) const;
|
||||||
|
DiffEditor::DiffEditor *createDiffEditor(const char *registerDynamicProperty,
|
||||||
|
const QString &dynamicPropertyValue,
|
||||||
|
const QString &titlePattern,
|
||||||
|
const Core::Id editorId) const;
|
||||||
|
|
||||||
VcsBase::Command *createCommand(const QString &workingDirectory,
|
VcsBase::Command *createCommand(const QString &workingDirectory,
|
||||||
VcsBase::VcsBaseEditorWidget* editor = 0,
|
VcsBase::VcsBaseEditorWidget* editor = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user