2013-05-07 14:02:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-05-07 14:02:08 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
#include "diffeditor.h"
|
2013-05-07 14:02:08 +02:00
|
|
|
#include "diffeditorconstants.h"
|
2014-01-30 14:27:50 +01:00
|
|
|
#include "diffeditordocument.h"
|
2014-02-24 11:10:17 +01:00
|
|
|
#include "diffeditorguicontroller.h"
|
2014-01-30 14:27:50 +01:00
|
|
|
#include "sidebysidediffeditorwidget.h"
|
2014-02-13 16:43:28 +01:00
|
|
|
#include "unifieddiffeditorwidget.h"
|
2013-05-07 14:02:08 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-06-03 12:32:07 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2014-01-30 17:04:54 +01:00
|
|
|
#include <coreplugin/minisplitter.h>
|
|
|
|
|
|
|
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/displaysettings.h>
|
2013-06-03 12:32:07 +02:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
#include <QStackedWidget>
|
2013-05-07 14:02:08 +02:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QLabel>
|
2013-05-21 13:51:26 +02:00
|
|
|
#include <QHBoxLayout>
|
2013-05-23 13:36:27 +02:00
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QFileInfo>
|
2014-06-30 15:04:36 +02:00
|
|
|
#include <QDir>
|
2014-02-13 16:43:28 +01:00
|
|
|
#include <QTextCodec>
|
2014-06-24 10:53:03 +03:00
|
|
|
#include <QTextBlock>
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
static const char settingsGroupC[] = "DiffEditor";
|
|
|
|
|
static const char diffEditorTypeKeyC[] = "DiffEditorType";
|
|
|
|
|
static const char sideBySideDiffEditorValueC[] = "SideBySide";
|
|
|
|
|
static const char unifiedDiffEditorValueC[] = "Unified";
|
|
|
|
|
|
|
|
|
|
static const char legacySettingsGroupC[] = "Git";
|
|
|
|
|
static const char useDiffEditorKeyC[] = "UseDiffEditor";
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class DescriptionEditorWidget : public BaseTextEditorWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
DescriptionEditorWidget(QWidget *parent = 0);
|
|
|
|
|
virtual QSize sizeHint() const;
|
|
|
|
|
|
2014-06-24 10:53:03 +03:00
|
|
|
signals:
|
|
|
|
|
void expandBranchesRequested();
|
|
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
public slots:
|
|
|
|
|
void setDisplaySettings(const DisplaySettings &ds);
|
|
|
|
|
|
|
|
|
|
protected:
|
2014-06-24 10:53:03 +03:00
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e);
|
|
|
|
|
|
|
|
|
|
bool findContentsUnderCursor(const QTextCursor &cursor);
|
|
|
|
|
void highlightCurrentContents();
|
|
|
|
|
void handleCurrentContents();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QTextCursor m_currentCursor;
|
2014-01-30 17:04:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
|
2014-08-18 17:49:04 +02:00
|
|
|
: BaseTextEditorWidget(parent)
|
2014-01-30 17:04:54 +01:00
|
|
|
{
|
2014-08-28 18:46:39 +02:00
|
|
|
setupFallBackEditor("DiffEditor.DescriptionEditor");
|
|
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
DisplaySettings settings = displaySettings();
|
|
|
|
|
settings.m_textWrapping = false;
|
|
|
|
|
settings.m_displayLineNumbers = false;
|
|
|
|
|
settings.m_highlightCurrentLine = false;
|
|
|
|
|
settings.m_displayFoldingMarkers = false;
|
|
|
|
|
settings.m_markTextChanges = false;
|
|
|
|
|
settings.m_highlightBlocks = false;
|
|
|
|
|
BaseTextEditorWidget::setDisplaySettings(settings);
|
|
|
|
|
|
|
|
|
|
setCodeFoldingSupported(true);
|
|
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
|
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize DescriptionEditorWidget::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
QSize size = BaseTextEditorWidget::sizeHint();
|
|
|
|
|
size.setHeight(size.height() / 5);
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds)
|
|
|
|
|
{
|
|
|
|
|
DisplaySettings settings = displaySettings();
|
|
|
|
|
settings.m_visualizeWhitespace = ds.m_visualizeWhitespace;
|
|
|
|
|
BaseTextEditorWidget::setDisplaySettings(settings);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 10:53:03 +03:00
|
|
|
void DescriptionEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->buttons()) {
|
|
|
|
|
TextEditor::BaseTextEditorWidget::mouseMoveEvent(e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::CursorShape cursorShape;
|
|
|
|
|
|
|
|
|
|
const QTextCursor cursor = cursorForPosition(e->pos());
|
|
|
|
|
if (findContentsUnderCursor(cursor)) {
|
|
|
|
|
highlightCurrentContents();
|
|
|
|
|
cursorShape = Qt::PointingHandCursor;
|
|
|
|
|
} else {
|
|
|
|
|
setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>());
|
|
|
|
|
cursorShape = Qt::IBeamCursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditor::BaseTextEditorWidget::mouseMoveEvent(e);
|
|
|
|
|
viewport()->setCursor(cursorShape);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DescriptionEditorWidget::mouseReleaseEvent(QMouseEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->button() == Qt::LeftButton && !(e->modifiers() & Qt::ShiftModifier)) {
|
|
|
|
|
const QTextCursor cursor = cursorForPosition(e->pos());
|
|
|
|
|
if (findContentsUnderCursor(cursor)) {
|
|
|
|
|
handleCurrentContents();
|
|
|
|
|
e->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditor::BaseTextEditorWidget::mouseReleaseEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor)
|
|
|
|
|
{
|
|
|
|
|
m_currentCursor = cursor;
|
|
|
|
|
return cursor.block().text() == QLatin1String(Constants::EXPAND_BRANCHES);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DescriptionEditorWidget::highlightCurrentContents()
|
|
|
|
|
{
|
|
|
|
|
QTextEdit::ExtraSelection sel;
|
|
|
|
|
sel.cursor = m_currentCursor;
|
|
|
|
|
sel.cursor.select(QTextCursor::LineUnderCursor);
|
|
|
|
|
sel.format.setFontUnderline(true);
|
|
|
|
|
setExtraSelections(BaseTextEditorWidget::OtherSelection,
|
|
|
|
|
QList<QTextEdit::ExtraSelection>() << sel);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DescriptionEditorWidget::handleCurrentContents()
|
|
|
|
|
{
|
|
|
|
|
m_currentCursor.select(QTextCursor::LineUnderCursor);
|
|
|
|
|
m_currentCursor.removeSelectedText();
|
|
|
|
|
m_currentCursor.insertText(QLatin1String("Branches: Expanding..."));
|
|
|
|
|
emit expandBranchesRequested();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
///////////////////////////////// DiffEditor //////////////////////////////////
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-08-21 21:12:04 +02:00
|
|
|
DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|
|
|
|
: m_document(doc)
|
2014-01-31 09:01:49 +01:00
|
|
|
, m_descriptionWidget(0)
|
2014-02-13 16:43:28 +01:00
|
|
|
, m_stackedWidget(0)
|
|
|
|
|
, m_sideBySideEditor(0)
|
|
|
|
|
, m_unifiedEditor(0)
|
|
|
|
|
, m_currentEditor(0)
|
2014-02-24 11:10:17 +01:00
|
|
|
, m_controller(0)
|
|
|
|
|
, m_guiController(0)
|
2014-01-31 09:01:49 +01:00
|
|
|
, m_toolBar(0)
|
2013-12-16 16:19:40 +01:00
|
|
|
, m_entriesComboBox(0)
|
2014-01-30 17:04:54 +01:00
|
|
|
, m_toggleDescriptionAction(0)
|
2014-07-04 13:55:51 +02:00
|
|
|
, m_reloadAction(0)
|
2014-02-13 16:43:28 +01:00
|
|
|
, m_diffEditorSwitcher(0)
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-01-30 17:04:54 +01:00
|
|
|
QSplitter *splitter = new Core::MiniSplitter(Qt::Vertical);
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
m_descriptionWidget = new Internal::DescriptionEditorWidget(splitter);
|
|
|
|
|
m_descriptionWidget->setReadOnly(true);
|
|
|
|
|
splitter->addWidget(m_descriptionWidget);
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
m_stackedWidget = new QStackedWidget(splitter);
|
|
|
|
|
splitter->addWidget(m_stackedWidget);
|
|
|
|
|
|
|
|
|
|
m_sideBySideEditor = new SideBySideDiffEditorWidget(m_stackedWidget);
|
|
|
|
|
m_stackedWidget->addWidget(m_sideBySideEditor);
|
|
|
|
|
|
|
|
|
|
m_unifiedEditor = new UnifiedDiffEditorWidget(m_stackedWidget);
|
|
|
|
|
m_stackedWidget->addWidget(m_unifiedEditor);
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
setWidget(splitter);
|
|
|
|
|
|
2014-06-24 10:53:03 +03:00
|
|
|
connect(m_descriptionWidget, SIGNAL(expandBranchesRequested()),
|
|
|
|
|
m_document->controller(), SLOT(expandBranchesRequested()));
|
2014-08-28 17:00:12 +02:00
|
|
|
connect(TextEditorSettings::instance(), &TextEditorSettings::displaySettingsChanged,
|
|
|
|
|
m_descriptionWidget, &BaseTextEditorWidget::setDisplaySettings);
|
|
|
|
|
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
|
|
|
|
m_descriptionWidget->textDocument(), &BaseTextDocument::setFontSettings);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
m_descriptionWidget->setDisplaySettings(
|
|
|
|
|
TextEditorSettings::displaySettings());
|
|
|
|
|
m_descriptionWidget->setCodeStyle(
|
|
|
|
|
TextEditorSettings::codeStyle());
|
2014-08-01 23:31:56 +02:00
|
|
|
m_descriptionWidget->textDocument()->setFontSettings(
|
2014-02-13 16:43:28 +01:00
|
|
|
TextEditorSettings::fontSettings());
|
2014-01-30 17:04:54 +01:00
|
|
|
|
2014-02-24 11:10:17 +01:00
|
|
|
m_controller = m_document->controller();
|
|
|
|
|
m_guiController = new DiffEditorGuiController(m_controller, this);
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-02-24 11:10:17 +01:00
|
|
|
connect(m_controller, SIGNAL(cleared(QString)),
|
2014-02-11 13:00:35 +01:00
|
|
|
this, SLOT(slotCleared(QString)));
|
2014-02-13 16:43:28 +01:00
|
|
|
connect(m_controller, SIGNAL(diffFilesChanged(QList<FileData>,QString)),
|
|
|
|
|
this, SLOT(slotDiffFilesChanged(QList<FileData>,QString)));
|
2014-02-24 11:10:17 +01:00
|
|
|
connect(m_controller, SIGNAL(descriptionChanged(QString)),
|
2014-01-31 09:01:49 +01:00
|
|
|
this, SLOT(slotDescriptionChanged(QString)));
|
2014-02-24 11:10:17 +01:00
|
|
|
connect(m_controller, SIGNAL(descriptionEnablementChanged(bool)),
|
2014-01-31 09:01:49 +01:00
|
|
|
this, SLOT(slotDescriptionVisibilityChanged()));
|
2014-02-24 11:10:17 +01:00
|
|
|
connect(m_guiController, SIGNAL(descriptionVisibilityChanged(bool)),
|
2014-01-31 09:01:49 +01:00
|
|
|
this, SLOT(slotDescriptionVisibilityChanged()));
|
2014-02-24 11:10:17 +01:00
|
|
|
connect(m_guiController, SIGNAL(currentDiffFileIndexChanged(int)),
|
|
|
|
|
this, SLOT(activateEntry(int)));
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-02-24 11:10:17 +01:00
|
|
|
slotDescriptionChanged(m_controller->description());
|
2014-01-31 09:01:49 +01:00
|
|
|
slotDescriptionVisibilityChanged();
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
showDiffEditor(readCurrentDiffEditorSetting());
|
|
|
|
|
|
|
|
|
|
toolBar();
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
DiffEditor::~DiffEditor()
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-01-31 09:01:49 +01:00
|
|
|
delete m_toolBar;
|
2013-05-07 14:02:08 +02:00
|
|
|
if (m_widget)
|
|
|
|
|
delete m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
Core::IEditor *DiffEditor::duplicate()
|
|
|
|
|
{
|
2014-08-21 21:12:04 +02:00
|
|
|
return new DiffEditor(m_document);
|
2014-01-31 09:01:49 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
bool DiffEditor::open(QString *errorString,
|
|
|
|
|
const QString &fileName,
|
|
|
|
|
const QString &realFileName)
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(realFileName)
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
if (!m_controller)
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-06-30 15:04:36 +02:00
|
|
|
QString patch;
|
|
|
|
|
if (m_document->read(fileName, &patch, errorString) != Utils::TextFileFormat::ReadSuccess)
|
2014-02-13 16:43:28 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
QList<FileData> fileDataList
|
|
|
|
|
= DiffUtils::readPatch(patch,
|
|
|
|
|
m_controller->isIgnoreWhitespace(),
|
|
|
|
|
&ok);
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*errorString = tr("Could not parse patch file \"%1\". "
|
2014-09-09 13:04:43 +02:00
|
|
|
"The content is not of unified diff format.")
|
2014-02-13 16:43:28 +01:00
|
|
|
.arg(fileName);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 15:04:36 +02:00
|
|
|
const QFileInfo fi(fileName);
|
|
|
|
|
m_document->setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
|
|
|
|
|
m_controller->setDiffFiles(fileDataList, fi.absolutePath());
|
2013-05-07 14:02:08 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
Core::IDocument *DiffEditor::document()
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-01-31 09:01:49 +01:00
|
|
|
return m_document.data();
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QToolBar *createToolBar(const QWidget *someWidget)
|
|
|
|
|
{
|
|
|
|
|
// Create
|
|
|
|
|
QToolBar *toolBar = new QToolBar;
|
2013-08-29 13:08:34 +02:00
|
|
|
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
2013-05-07 14:02:08 +02:00
|
|
|
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
|
|
|
|
toolBar->setIconSize(QSize(size, size));
|
|
|
|
|
|
|
|
|
|
return toolBar;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
QWidget *DiffEditor::toolBar()
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
2014-01-31 09:01:49 +01:00
|
|
|
if (m_toolBar)
|
|
|
|
|
return m_toolBar;
|
2013-05-07 14:02:08 +02:00
|
|
|
|
|
|
|
|
// Create
|
2014-02-13 16:43:28 +01:00
|
|
|
m_toolBar = createToolBar(m_sideBySideEditor);
|
2013-05-21 13:51:26 +02:00
|
|
|
|
2013-05-23 13:36:27 +02:00
|
|
|
m_entriesComboBox = new QComboBox;
|
|
|
|
|
m_entriesComboBox->setMinimumContentsLength(20);
|
|
|
|
|
// Make the combo box prefer to expand
|
|
|
|
|
QSizePolicy policy = m_entriesComboBox->sizePolicy();
|
|
|
|
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
|
|
|
|
m_entriesComboBox->setSizePolicy(policy);
|
|
|
|
|
connect(m_entriesComboBox, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(entryActivated(int)));
|
2014-01-31 09:01:49 +01:00
|
|
|
m_toolBar->addWidget(m_entriesComboBox);
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
QToolButton *whitespaceButton = new QToolButton(m_toolBar);
|
2013-05-15 16:26:27 +02:00
|
|
|
whitespaceButton->setText(tr("Ignore Whitespace"));
|
2013-05-07 14:02:08 +02:00
|
|
|
whitespaceButton->setCheckable(true);
|
2014-02-13 16:43:28 +01:00
|
|
|
whitespaceButton->setChecked(m_controller->isIgnoreWhitespace());
|
2014-01-31 09:01:49 +01:00
|
|
|
m_toolBar->addWidget(whitespaceButton);
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
QLabel *contextLabel = new QLabel(m_toolBar);
|
2013-05-30 12:01:07 +02:00
|
|
|
contextLabel->setText(tr("Context Lines:"));
|
2013-06-04 10:53:03 +02:00
|
|
|
contextLabel->setContentsMargins(6, 0, 6, 0);
|
2014-01-31 09:01:49 +01:00
|
|
|
m_toolBar->addWidget(contextLabel);
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
QSpinBox *contextSpinBox = new QSpinBox(m_toolBar);
|
2014-02-13 16:43:28 +01:00
|
|
|
contextSpinBox->setRange(1, 100);
|
|
|
|
|
contextSpinBox->setValue(m_controller->contextLinesNumber());
|
2013-05-30 12:01:07 +02:00
|
|
|
contextSpinBox->setFrame(false);
|
2014-02-13 16:43:28 +01:00
|
|
|
contextSpinBox->setSizePolicy(QSizePolicy::Minimum,
|
|
|
|
|
QSizePolicy::Expanding); // Mac Qt5
|
2014-01-31 09:01:49 +01:00
|
|
|
m_toolBar->addWidget(contextSpinBox);
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
QToolButton *toggleDescription = new QToolButton(m_toolBar);
|
2014-02-13 16:43:28 +01:00
|
|
|
toggleDescription->setIcon(
|
|
|
|
|
QIcon(QLatin1String(Constants::ICON_TOP_BAR)));
|
2014-01-30 17:04:54 +01:00
|
|
|
toggleDescription->setCheckable(true);
|
2014-02-13 16:43:28 +01:00
|
|
|
toggleDescription->setChecked(m_guiController->isDescriptionVisible());
|
2014-01-31 09:01:49 +01:00
|
|
|
m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
|
2014-01-30 17:04:54 +01:00
|
|
|
slotDescriptionVisibilityChanged();
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
QToolButton *reloadButton = new QToolButton(m_toolBar);
|
2014-06-12 17:54:46 +02:00
|
|
|
reloadButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RELOAD_GRAY)));
|
2014-02-13 16:43:28 +01:00
|
|
|
reloadButton->setToolTip(tr("Reload Editor"));
|
2014-07-04 13:55:51 +02:00
|
|
|
m_reloadAction = m_toolBar->addWidget(reloadButton);
|
|
|
|
|
slotReloaderChanged(m_controller->reloader());
|
|
|
|
|
|
|
|
|
|
QToolButton *toggleSync = new QToolButton(m_toolBar);
|
|
|
|
|
toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
|
|
|
|
toggleSync->setCheckable(true);
|
|
|
|
|
toggleSync->setChecked(m_guiController->horizontalScrollBarSynchronization());
|
|
|
|
|
toggleSync->setToolTip(tr("Synchronize Horizontal Scroll Bars"));
|
|
|
|
|
m_toolBar->addWidget(toggleSync);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
m_diffEditorSwitcher = new QToolButton(m_toolBar);
|
|
|
|
|
m_toolBar->addWidget(m_diffEditorSwitcher);
|
|
|
|
|
updateDiffEditorSwitcher();
|
|
|
|
|
|
2014-02-11 13:00:35 +01:00
|
|
|
connect(whitespaceButton, SIGNAL(clicked(bool)),
|
2014-02-13 16:43:28 +01:00
|
|
|
m_controller, SLOT(setIgnoreWhitespace(bool)));
|
|
|
|
|
connect(m_controller, SIGNAL(ignoreWhitespaceChanged(bool)),
|
|
|
|
|
whitespaceButton, SLOT(setChecked(bool)));
|
2014-02-11 13:00:35 +01:00
|
|
|
connect(contextSpinBox, SIGNAL(valueChanged(int)),
|
2014-02-13 16:43:28 +01:00
|
|
|
m_controller, SLOT(setContextLinesNumber(int)));
|
|
|
|
|
connect(m_controller, SIGNAL(contextLinesNumberChanged(int)),
|
|
|
|
|
contextSpinBox, SLOT(setValue(int)));
|
2014-02-11 13:00:35 +01:00
|
|
|
connect(toggleSync, SIGNAL(clicked(bool)),
|
2014-02-24 11:10:17 +01:00
|
|
|
m_guiController, SLOT(setHorizontalScrollBarSynchronization(bool)));
|
2014-02-11 13:00:35 +01:00
|
|
|
connect(toggleDescription, SIGNAL(clicked(bool)),
|
2014-02-24 11:10:17 +01:00
|
|
|
m_guiController, SLOT(setDescriptionVisible(bool)));
|
2014-02-13 16:43:28 +01:00
|
|
|
connect(m_diffEditorSwitcher, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(slotDiffEditorSwitched()));
|
|
|
|
|
connect(reloadButton, SIGNAL(clicked()),
|
|
|
|
|
m_controller, SLOT(requestReload()));
|
2014-07-04 13:55:51 +02:00
|
|
|
connect(m_controller, SIGNAL(reloaderChanged(DiffEditorReloader*)),
|
|
|
|
|
this, SLOT(slotReloaderChanged(DiffEditorReloader*)));
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
return m_toolBar;
|
2013-05-07 14:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
DiffEditorController *DiffEditor::controller() const
|
2014-02-11 13:00:35 +01:00
|
|
|
{
|
2014-02-24 11:10:17 +01:00
|
|
|
return m_controller;
|
2014-02-11 13:00:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::updateEntryToolTip()
|
|
|
|
|
{
|
|
|
|
|
const QString &toolTip = m_entriesComboBox->itemData(
|
|
|
|
|
m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString();
|
|
|
|
|
m_entriesComboBox->setToolTip(toolTip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::entryActivated(int index)
|
2013-05-23 13:36:27 +02:00
|
|
|
{
|
2014-02-11 13:00:35 +01:00
|
|
|
updateEntryToolTip();
|
2014-02-24 11:10:17 +01:00
|
|
|
m_guiController->setCurrentDiffFileIndex(index);
|
2014-02-11 13:00:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::slotCleared(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(message)
|
|
|
|
|
|
|
|
|
|
m_entriesComboBox->clear();
|
|
|
|
|
updateEntryToolTip();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
void DiffEditor::slotDiffFilesChanged(const QList<FileData> &diffFileList,
|
|
|
|
|
const QString &workingDirectory)
|
2014-02-11 13:00:35 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(workingDirectory)
|
|
|
|
|
|
2013-05-23 13:36:27 +02:00
|
|
|
m_entriesComboBox->clear();
|
|
|
|
|
const int count = diffFileList.count();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-13 16:43:28 +01:00
|
|
|
const DiffFileInfo leftEntry = diffFileList.at(i).leftFileInfo;
|
|
|
|
|
const DiffFileInfo rightEntry = diffFileList.at(i).rightFileInfo;
|
2013-05-23 13:36:27 +02:00
|
|
|
const QString leftShortFileName = QFileInfo(leftEntry.fileName).fileName();
|
|
|
|
|
const QString rightShortFileName = QFileInfo(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")
|
2014-02-13 16:43:28 +01:00
|
|
|
.arg(leftEntry.typeInfo,
|
|
|
|
|
rightEntry.typeInfo,
|
|
|
|
|
leftEntry.fileName);
|
2013-05-23 13:36:27 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (leftShortFileName == rightShortFileName) {
|
|
|
|
|
itemText = leftShortFileName;
|
|
|
|
|
} else {
|
|
|
|
|
itemText = tr("%1 vs. %2")
|
2014-02-13 16:43:28 +01:00
|
|
|
.arg(leftShortFileName,
|
|
|
|
|
rightShortFileName);
|
2013-05-23 13:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (leftEntry.typeInfo.isEmpty() && rightEntry.typeInfo.isEmpty()) {
|
|
|
|
|
itemToolTip = tr("%1 vs. %2")
|
2014-02-13 16:43:28 +01:00
|
|
|
.arg(leftEntry.fileName,
|
|
|
|
|
rightEntry.fileName);
|
2013-05-23 13:36:27 +02:00
|
|
|
} else {
|
|
|
|
|
itemToolTip = tr("[%1] %2 vs. [%3] %4")
|
2014-02-13 16:43:28 +01:00
|
|
|
.arg(leftEntry.typeInfo,
|
|
|
|
|
leftEntry.fileName,
|
|
|
|
|
rightEntry.typeInfo,
|
|
|
|
|
rightEntry.fileName);
|
2013-05-23 13:36:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_entriesComboBox->addItem(itemText);
|
2014-02-13 16:43:28 +01:00
|
|
|
m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1,
|
|
|
|
|
itemToolTip, Qt::ToolTipRole);
|
2013-05-23 13:36:27 +02:00
|
|
|
}
|
|
|
|
|
updateEntryToolTip();
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 12:15:22 +02:00
|
|
|
void DiffEditor::activateEntry(int index)
|
2013-05-23 13:36:27 +02:00
|
|
|
{
|
|
|
|
|
m_entriesComboBox->blockSignals(true);
|
|
|
|
|
m_entriesComboBox->setCurrentIndex(index);
|
|
|
|
|
m_entriesComboBox->blockSignals(false);
|
|
|
|
|
updateEntryToolTip();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 17:04:54 +01:00
|
|
|
void DiffEditor::slotDescriptionChanged(const QString &description)
|
|
|
|
|
{
|
|
|
|
|
m_descriptionWidget->setPlainText(description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::slotDescriptionVisibilityChanged()
|
|
|
|
|
{
|
2014-02-24 11:10:17 +01:00
|
|
|
const bool enabled = m_controller->isDescriptionEnabled();
|
|
|
|
|
const bool visible = m_guiController->isDescriptionVisible();
|
2014-01-30 17:04:54 +01:00
|
|
|
|
|
|
|
|
m_descriptionWidget->setVisible(visible && enabled);
|
|
|
|
|
|
|
|
|
|
if (!m_toggleDescriptionAction)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
QWidget *toggle = m_toolBar->widgetForAction(m_toggleDescriptionAction);
|
2014-01-30 17:04:54 +01:00
|
|
|
if (visible)
|
|
|
|
|
toggle->setToolTip(tr("Hide Change Description"));
|
|
|
|
|
else
|
|
|
|
|
toggle->setToolTip(tr("Show Change Description"));
|
|
|
|
|
|
|
|
|
|
m_toggleDescriptionAction->setVisible(enabled);
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-04 13:55:51 +02:00
|
|
|
void DiffEditor::slotReloaderChanged(DiffEditorReloader *reloader)
|
|
|
|
|
{
|
|
|
|
|
m_reloadAction->setVisible(reloader);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
void DiffEditor::slotDiffEditorSwitched()
|
|
|
|
|
{
|
|
|
|
|
QWidget *oldEditor = m_currentEditor;
|
|
|
|
|
QWidget *newEditor = 0;
|
|
|
|
|
if (oldEditor == m_sideBySideEditor)
|
|
|
|
|
newEditor = m_unifiedEditor;
|
|
|
|
|
else if (oldEditor == m_unifiedEditor)
|
|
|
|
|
newEditor = m_sideBySideEditor;
|
|
|
|
|
else
|
|
|
|
|
newEditor = readCurrentDiffEditorSetting();
|
|
|
|
|
|
|
|
|
|
showDiffEditor(newEditor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::updateDiffEditorSwitcher()
|
|
|
|
|
{
|
|
|
|
|
if (!m_diffEditorSwitcher)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QIcon actionIcon;
|
|
|
|
|
QString actionToolTip;
|
|
|
|
|
if (m_currentEditor == m_unifiedEditor) {
|
|
|
|
|
actionIcon = QIcon(QLatin1String(Constants::ICON_SIDE_BY_SIDE_DIFF));
|
|
|
|
|
actionToolTip = tr("Switch to Side By Side Diff Editor");
|
|
|
|
|
} else if (m_currentEditor == m_sideBySideEditor) {
|
|
|
|
|
actionIcon = QIcon(QLatin1String(Constants::ICON_UNIFIED_DIFF));
|
|
|
|
|
actionToolTip = tr("Switch to Unified Diff Editor");
|
|
|
|
|
}
|
2014-01-30 17:04:54 +01:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
m_diffEditorSwitcher->setIcon(actionIcon);
|
|
|
|
|
m_diffEditorSwitcher->setToolTip(actionToolTip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::showDiffEditor(QWidget *newEditor)
|
|
|
|
|
{
|
|
|
|
|
if (m_currentEditor == newEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_currentEditor == m_sideBySideEditor)
|
|
|
|
|
m_sideBySideEditor->setDiffEditorGuiController(0);
|
|
|
|
|
else if (m_currentEditor == m_unifiedEditor)
|
|
|
|
|
m_unifiedEditor->setDiffEditorGuiController(0);
|
|
|
|
|
|
|
|
|
|
m_currentEditor = newEditor;
|
|
|
|
|
|
|
|
|
|
if (m_currentEditor == m_unifiedEditor)
|
|
|
|
|
m_unifiedEditor->setDiffEditorGuiController(m_guiController);
|
|
|
|
|
else if (m_currentEditor == m_sideBySideEditor)
|
|
|
|
|
m_sideBySideEditor->setDiffEditorGuiController(m_guiController);
|
|
|
|
|
|
|
|
|
|
m_stackedWidget->setCurrentWidget(m_currentEditor);
|
|
|
|
|
|
|
|
|
|
writeCurrentDiffEditorSetting(m_currentEditor);
|
|
|
|
|
updateDiffEditorSwitcher();
|
2014-08-13 13:28:37 +02:00
|
|
|
widget()->setFocusProxy(m_currentEditor);
|
2014-02-13 16:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DiffEditor::readLegacyCurrentDiffEditorSetting()
|
|
|
|
|
{
|
|
|
|
|
QSettings *s = Core::ICore::settings();
|
|
|
|
|
|
|
|
|
|
s->beginGroup(QLatin1String(legacySettingsGroupC));
|
|
|
|
|
const bool legacyExists = s->contains(QLatin1String(useDiffEditorKeyC));
|
|
|
|
|
const bool legacyEditor = s->value(
|
|
|
|
|
QLatin1String(useDiffEditorKeyC), true).toBool();
|
|
|
|
|
if (legacyExists)
|
|
|
|
|
s->remove(QLatin1String(useDiffEditorKeyC));
|
|
|
|
|
s->endGroup();
|
|
|
|
|
|
|
|
|
|
QWidget *currentEditor = m_sideBySideEditor;
|
|
|
|
|
if (!legacyEditor)
|
|
|
|
|
currentEditor = m_unifiedEditor;
|
|
|
|
|
|
|
|
|
|
if (legacyExists && currentEditor == m_unifiedEditor)
|
|
|
|
|
writeCurrentDiffEditorSetting(currentEditor);
|
|
|
|
|
|
|
|
|
|
return currentEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DiffEditor::readCurrentDiffEditorSetting()
|
|
|
|
|
{
|
|
|
|
|
// replace it with m_sideBySideEditor when dropping legacy stuff
|
|
|
|
|
QWidget *defaultEditor = readLegacyCurrentDiffEditorSetting();
|
|
|
|
|
|
|
|
|
|
QSettings *s = Core::ICore::settings();
|
|
|
|
|
s->beginGroup(QLatin1String(settingsGroupC));
|
|
|
|
|
const QString editorString = s->value(
|
|
|
|
|
QLatin1String(diffEditorTypeKeyC)).toString();
|
|
|
|
|
s->endGroup();
|
|
|
|
|
if (editorString == QLatin1String(unifiedDiffEditorValueC))
|
|
|
|
|
return m_unifiedEditor;
|
|
|
|
|
|
|
|
|
|
if (editorString == QLatin1String(sideBySideDiffEditorValueC))
|
|
|
|
|
return m_sideBySideEditor;
|
|
|
|
|
|
|
|
|
|
return defaultEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DiffEditor::writeCurrentDiffEditorSetting(QWidget *currentEditor)
|
|
|
|
|
{
|
|
|
|
|
const QString editorString = currentEditor == m_unifiedEditor
|
|
|
|
|
? QLatin1String(unifiedDiffEditorValueC)
|
|
|
|
|
: QLatin1String(sideBySideDiffEditorValueC);
|
|
|
|
|
QSettings *s = Core::ICore::settings();
|
|
|
|
|
s->beginGroup(QLatin1String(settingsGroupC));
|
|
|
|
|
s->setValue(QLatin1String(diffEditorTypeKeyC), editorString);
|
|
|
|
|
s->endGroup();
|
2014-01-30 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
} // namespace DiffEditor
|
2014-01-30 17:04:54 +01:00
|
|
|
|
|
|
|
|
#include "diffeditor.moc"
|