forked from qt-creator/qt-creator
DiffEditor: Introduce a base class for the different views
... of the diff. Currently that is side-by-side and unified, just as before. Change-Id: I62a5462344c4b4ae652899f9d5b2936aa5a692b8 Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
This commit is contained in:
@@ -32,8 +32,7 @@
|
|||||||
#include "diffeditorconstants.h"
|
#include "diffeditorconstants.h"
|
||||||
#include "diffeditordocument.h"
|
#include "diffeditordocument.h"
|
||||||
#include "diffeditorguicontroller.h"
|
#include "diffeditorguicontroller.h"
|
||||||
#include "sidebysidediffeditorwidget.h"
|
#include "diffview.h"
|
||||||
#include "unifieddiffeditorwidget.h"
|
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -44,6 +43,7 @@
|
|||||||
#include <texteditor/displaysettings.h>
|
#include <texteditor/displaysettings.h>
|
||||||
#include <texteditor/marginsettings.h>
|
#include <texteditor/marginsettings.h>
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -61,8 +61,6 @@
|
|||||||
|
|
||||||
static const char settingsGroupC[] = "DiffEditor";
|
static const char settingsGroupC[] = "DiffEditor";
|
||||||
static const char diffEditorTypeKeyC[] = "DiffEditorType";
|
static const char diffEditorTypeKeyC[] = "DiffEditorType";
|
||||||
static const char sideBySideDiffEditorValueC[] = "SideBySide";
|
|
||||||
static const char unifiedDiffEditorValueC[] = "Unified";
|
|
||||||
|
|
||||||
static const char legacySettingsGroupC[] = "Git";
|
static const char legacySettingsGroupC[] = "Git";
|
||||||
static const char useDiffEditorKeyC[] = "UseDiffEditor";
|
static const char useDiffEditorKeyC[] = "UseDiffEditor";
|
||||||
@@ -204,9 +202,7 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|||||||
: m_document(doc)
|
: m_document(doc)
|
||||||
, m_descriptionWidget(0)
|
, m_descriptionWidget(0)
|
||||||
, m_stackedWidget(0)
|
, m_stackedWidget(0)
|
||||||
, m_sideBySideEditor(0)
|
, m_currentViewIndex(0)
|
||||||
, m_unifiedEditor(0)
|
|
||||||
, m_currentEditor(0)
|
|
||||||
, m_guiController(0)
|
, m_guiController(0)
|
||||||
, m_toolBar(0)
|
, m_toolBar(0)
|
||||||
, m_entriesComboBox(0)
|
, m_entriesComboBox(0)
|
||||||
@@ -225,15 +221,11 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|||||||
m_stackedWidget = new QStackedWidget(splitter);
|
m_stackedWidget = new QStackedWidget(splitter);
|
||||||
splitter->addWidget(m_stackedWidget);
|
splitter->addWidget(m_stackedWidget);
|
||||||
|
|
||||||
m_sideBySideEditor = new SideBySideDiffEditorWidget(m_stackedWidget);
|
addView(new SideBySideView);
|
||||||
m_stackedWidget->addWidget(m_sideBySideEditor);
|
addView(new UnifiedView);
|
||||||
|
|
||||||
m_unifiedEditor = new UnifiedDiffEditorWidget(m_stackedWidget);
|
|
||||||
m_stackedWidget->addWidget(m_unifiedEditor);
|
|
||||||
|
|
||||||
setWidget(splitter);
|
setWidget(splitter);
|
||||||
|
|
||||||
|
|
||||||
DiffEditorController *control = controller();
|
DiffEditorController *control = controller();
|
||||||
m_guiController = new DiffEditorGuiController(control, this);
|
m_guiController = new DiffEditorGuiController(control, this);
|
||||||
|
|
||||||
@@ -254,7 +246,7 @@ DiffEditor::DiffEditor(const QSharedPointer<DiffEditorDocument> &doc)
|
|||||||
slotDescriptionChanged(control->description());
|
slotDescriptionChanged(control->description());
|
||||||
slotDescriptionVisibilityChanged();
|
slotDescriptionVisibilityChanged();
|
||||||
|
|
||||||
showDiffEditor(readCurrentDiffEditorSetting());
|
showDiffView(readCurrentDiffEditorSetting());
|
||||||
|
|
||||||
toolBar();
|
toolBar();
|
||||||
}
|
}
|
||||||
@@ -283,12 +275,12 @@ Core::IDocument *DiffEditor::document()
|
|||||||
return m_document.data();
|
return m_document.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QToolBar *createToolBar(const QWidget *someWidget)
|
static QToolBar *createToolBar(IDiffView *someView)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
QToolBar *toolBar = new QToolBar;
|
QToolBar *toolBar = new QToolBar;
|
||||||
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||||
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
const int size = someView->widget()->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
toolBar->setIconSize(QSize(size, size));
|
toolBar->setIconSize(QSize(size, size));
|
||||||
|
|
||||||
return toolBar;
|
return toolBar;
|
||||||
@@ -296,13 +288,15 @@ static QToolBar *createToolBar(const QWidget *someWidget)
|
|||||||
|
|
||||||
QWidget *DiffEditor::toolBar()
|
QWidget *DiffEditor::toolBar()
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(!m_views.isEmpty(), return 0);
|
||||||
|
|
||||||
if (m_toolBar)
|
if (m_toolBar)
|
||||||
return m_toolBar;
|
return m_toolBar;
|
||||||
|
|
||||||
DiffEditorController *control = controller();
|
DiffEditorController *control = controller();
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
m_toolBar = createToolBar(m_sideBySideEditor);
|
m_toolBar = createToolBar(m_views.at(0));
|
||||||
|
|
||||||
m_entriesComboBox = new QComboBox;
|
m_entriesComboBox = new QComboBox;
|
||||||
m_entriesComboBox->setMinimumContentsLength(20);
|
m_entriesComboBox->setMinimumContentsLength(20);
|
||||||
@@ -334,8 +328,7 @@ QWidget *DiffEditor::toolBar()
|
|||||||
m_contextSpinBoxAction = m_toolBar->addWidget(contextSpinBox);
|
m_contextSpinBoxAction = m_toolBar->addWidget(contextSpinBox);
|
||||||
|
|
||||||
QToolButton *toggleDescription = new QToolButton(m_toolBar);
|
QToolButton *toggleDescription = new QToolButton(m_toolBar);
|
||||||
toggleDescription->setIcon(
|
toggleDescription->setIcon(QIcon(QLatin1String(Constants::ICON_TOP_BAR)));
|
||||||
QIcon(QLatin1String(Constants::ICON_TOP_BAR)));
|
|
||||||
toggleDescription->setCheckable(true);
|
toggleDescription->setCheckable(true);
|
||||||
toggleDescription->setChecked(m_guiController->isDescriptionVisible());
|
toggleDescription->setChecked(m_guiController->isDescriptionVisible());
|
||||||
m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
|
m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription);
|
||||||
@@ -371,7 +364,7 @@ QWidget *DiffEditor::toolBar()
|
|||||||
connect(toggleDescription, &QAbstractButton::clicked,
|
connect(toggleDescription, &QAbstractButton::clicked,
|
||||||
m_guiController, &DiffEditorGuiController::setDescriptionVisible);
|
m_guiController, &DiffEditorGuiController::setDescriptionVisible);
|
||||||
connect(m_diffEditorSwitcher, &QAbstractButton::clicked,
|
connect(m_diffEditorSwitcher, &QAbstractButton::clicked,
|
||||||
this, &DiffEditor::slotDiffEditorSwitched);
|
this, [this]() { showDiffView(nextView()); });
|
||||||
connect(reloadButton, &QAbstractButton::clicked,
|
connect(reloadButton, &QAbstractButton::clicked,
|
||||||
control, &DiffEditorController::requestReload);
|
control, &DiffEditorController::requestReload);
|
||||||
connect(control, &DiffEditorController::reloaderChanged,
|
connect(control, &DiffEditorController::reloaderChanged,
|
||||||
@@ -505,65 +498,67 @@ void DiffEditor::slotReloaderChanged()
|
|||||||
m_reloadAction->setVisible(reloader);
|
m_reloadAction->setVisible(reloader);
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
void DiffEditor::updateDiffEditorSwitcher()
|
||||||
{
|
{
|
||||||
if (!m_diffEditorSwitcher)
|
if (!m_diffEditorSwitcher)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QIcon actionIcon;
|
m_diffEditorSwitcher->setIcon(currentView()->icon());
|
||||||
QString actionToolTip;
|
m_diffEditorSwitcher->setToolTip(currentView()->toolTip());
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_diffEditorSwitcher->setIcon(actionIcon);
|
|
||||||
m_diffEditorSwitcher->setToolTip(actionToolTip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::showDiffEditor(QWidget *newEditor)
|
void DiffEditor::addView(IDiffView *view)
|
||||||
{
|
{
|
||||||
if (m_currentEditor == newEditor)
|
QTC_ASSERT(!m_views.contains(view), return);
|
||||||
|
m_views.append(view);
|
||||||
|
m_stackedWidget->addWidget(view->widget());
|
||||||
|
}
|
||||||
|
|
||||||
|
IDiffView *DiffEditor::currentView() const
|
||||||
|
{
|
||||||
|
return m_views.at(m_currentViewIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::setCurrentView(IDiffView *view)
|
||||||
|
{
|
||||||
|
const int pos = Utils::indexOf(m_views, [view](IDiffView *v) { return v == view; });
|
||||||
|
QTC_ASSERT(pos >= 0 && pos < m_views.count(), return);
|
||||||
|
m_currentViewIndex = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDiffView *DiffEditor::nextView()
|
||||||
|
{
|
||||||
|
++m_currentViewIndex;
|
||||||
|
if (m_currentViewIndex >= m_views.count())
|
||||||
|
m_currentViewIndex = 0;
|
||||||
|
|
||||||
|
return currentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiffEditor::showDiffView(IDiffView *newView)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(newView, return);
|
||||||
|
|
||||||
|
if (currentView() == newView)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_currentEditor == m_sideBySideEditor)
|
currentView()->setDiffEditorGuiController(0);
|
||||||
m_sideBySideEditor->setDiffEditorGuiController(0);
|
setCurrentView(newView);
|
||||||
else if (m_currentEditor == m_unifiedEditor)
|
currentView()->setDiffEditorGuiController(m_guiController);
|
||||||
m_unifiedEditor->setDiffEditorGuiController(0);
|
|
||||||
|
|
||||||
m_currentEditor = newEditor;
|
m_stackedWidget->setCurrentWidget(currentView()->widget());
|
||||||
|
|
||||||
if (m_currentEditor == m_unifiedEditor)
|
writeCurrentDiffEditorSetting(currentView());
|
||||||
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();
|
updateDiffEditorSwitcher();
|
||||||
widget()->setFocusProxy(m_currentEditor);
|
widget()->setFocusProxy(currentView()->widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *DiffEditor::readLegacyCurrentDiffEditorSetting()
|
// TODO: Remove in 3.6:
|
||||||
|
IDiffView *DiffEditor::readLegacyCurrentDiffEditorSetting()
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(!m_views.isEmpty(), return 0);
|
||||||
|
QTC_ASSERT(m_views.count() == 2, return m_views.at(0));
|
||||||
|
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
|
|
||||||
s->beginGroup(QLatin1String(legacySettingsGroupC));
|
s->beginGroup(QLatin1String(legacySettingsGroupC));
|
||||||
@@ -574,43 +569,35 @@ QWidget *DiffEditor::readLegacyCurrentDiffEditorSetting()
|
|||||||
s->remove(QLatin1String(useDiffEditorKeyC));
|
s->remove(QLatin1String(useDiffEditorKeyC));
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
QWidget *currentEditor = m_sideBySideEditor;
|
IDiffView *currentEditor = m_views.at(0);
|
||||||
if (!legacyEditor)
|
if (!legacyEditor)
|
||||||
currentEditor = m_unifiedEditor;
|
currentEditor = m_views.at(1);
|
||||||
|
|
||||||
if (legacyExists && currentEditor == m_unifiedEditor)
|
if (legacyExists)
|
||||||
writeCurrentDiffEditorSetting(currentEditor);
|
writeCurrentDiffEditorSetting(currentEditor);
|
||||||
|
|
||||||
return currentEditor;
|
return currentEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *DiffEditor::readCurrentDiffEditorSetting()
|
IDiffView *DiffEditor::readCurrentDiffEditorSetting()
|
||||||
{
|
{
|
||||||
// replace it with m_sideBySideEditor when dropping legacy stuff
|
// replace it with m_sideBySideEditor when dropping legacy stuff
|
||||||
QWidget *defaultEditor = readLegacyCurrentDiffEditorSetting();
|
IDiffView *view = readLegacyCurrentDiffEditorSetting();
|
||||||
|
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
s->beginGroup(QLatin1String(settingsGroupC));
|
s->beginGroup(QLatin1String(settingsGroupC));
|
||||||
const QString editorString = s->value(
|
const Core::Id id = Core::Id::fromSetting(s->value(QLatin1String(diffEditorTypeKeyC)));
|
||||||
QLatin1String(diffEditorTypeKeyC)).toString();
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
if (editorString == QLatin1String(unifiedDiffEditorValueC))
|
|
||||||
return m_unifiedEditor;
|
|
||||||
|
|
||||||
if (editorString == QLatin1String(sideBySideDiffEditorValueC))
|
return Utils::findOr(m_views, view, [id](IDiffView *v) { return v->id() == id; });
|
||||||
return m_sideBySideEditor;
|
|
||||||
|
|
||||||
return defaultEditor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffEditor::writeCurrentDiffEditorSetting(QWidget *currentEditor)
|
void DiffEditor::writeCurrentDiffEditorSetting(IDiffView *currentEditor)
|
||||||
{
|
{
|
||||||
const QString editorString = currentEditor == m_unifiedEditor
|
QTC_ASSERT(currentEditor, return);
|
||||||
? QLatin1String(unifiedDiffEditorValueC)
|
|
||||||
: QLatin1String(sideBySideDiffEditorValueC);
|
|
||||||
QSettings *s = Core::ICore::settings();
|
QSettings *s = Core::ICore::settings();
|
||||||
s->beginGroup(QLatin1String(settingsGroupC));
|
s->beginGroup(QLatin1String(settingsGroupC));
|
||||||
s->setValue(QLatin1String(diffEditorTypeKeyC), editorString);
|
s->setValue(QLatin1String(diffEditorTypeKeyC), currentEditor->id().toSetting());
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,8 +51,7 @@ namespace Internal {
|
|||||||
class DescriptionEditorWidget;
|
class DescriptionEditorWidget;
|
||||||
class DiffEditorDocument;
|
class DiffEditorDocument;
|
||||||
class DiffEditorGuiController;
|
class DiffEditorGuiController;
|
||||||
class UnifiedDiffEditorWidget;
|
class IDiffView;
|
||||||
class SideBySideDiffEditorWidget;
|
|
||||||
|
|
||||||
class DiffEditor : public Core::IEditor
|
class DiffEditor : public Core::IEditor
|
||||||
{
|
{
|
||||||
@@ -85,22 +84,24 @@ private slots:
|
|||||||
void slotDescriptionChanged(const QString &description);
|
void slotDescriptionChanged(const QString &description);
|
||||||
void slotDescriptionVisibilityChanged();
|
void slotDescriptionVisibilityChanged();
|
||||||
void slotReloaderChanged();
|
void slotReloaderChanged();
|
||||||
void slotDiffEditorSwitched();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateEntryToolTip();
|
void updateEntryToolTip();
|
||||||
void showDiffEditor(QWidget *newEditor);
|
void showDiffView(IDiffView *newEditor);
|
||||||
void updateDiffEditorSwitcher();
|
void updateDiffEditorSwitcher();
|
||||||
QWidget *readLegacyCurrentDiffEditorSetting();
|
void addView(IDiffView *view);
|
||||||
QWidget *readCurrentDiffEditorSetting();
|
IDiffView *currentView() const;
|
||||||
void writeCurrentDiffEditorSetting(QWidget *currentEditor);
|
void setCurrentView(IDiffView *view);
|
||||||
|
IDiffView *nextView();
|
||||||
|
IDiffView *readLegacyCurrentDiffEditorSetting();
|
||||||
|
IDiffView *readCurrentDiffEditorSetting();
|
||||||
|
void writeCurrentDiffEditorSetting(IDiffView *currentEditor);
|
||||||
|
|
||||||
QSharedPointer<DiffEditorDocument> m_document;
|
QSharedPointer<DiffEditorDocument> m_document;
|
||||||
DescriptionEditorWidget *m_descriptionWidget;
|
DescriptionEditorWidget *m_descriptionWidget;
|
||||||
QStackedWidget *m_stackedWidget;
|
QStackedWidget *m_stackedWidget;
|
||||||
SideBySideDiffEditorWidget *m_sideBySideEditor;
|
QVector<IDiffView *> m_views;
|
||||||
UnifiedDiffEditorWidget *m_unifiedEditor;
|
int m_currentViewIndex;
|
||||||
QWidget *m_currentEditor;
|
|
||||||
DiffEditorGuiController *m_guiController;
|
DiffEditorGuiController *m_guiController;
|
||||||
QToolBar *m_toolBar;
|
QToolBar *m_toolBar;
|
||||||
QComboBox *m_entriesComboBox;
|
QComboBox *m_entriesComboBox;
|
||||||
|
@@ -13,6 +13,7 @@ HEADERS += diffeditor_global.h \
|
|||||||
diffeditorreloader.h \
|
diffeditorreloader.h \
|
||||||
differ.h \
|
differ.h \
|
||||||
diffutils.h \
|
diffutils.h \
|
||||||
|
diffview.h \
|
||||||
selectabletexteditorwidget.h \
|
selectabletexteditorwidget.h \
|
||||||
sidebysidediffeditorwidget.h \
|
sidebysidediffeditorwidget.h \
|
||||||
unifieddiffeditorwidget.h
|
unifieddiffeditorwidget.h
|
||||||
@@ -27,6 +28,7 @@ SOURCES += diffeditor.cpp \
|
|||||||
diffeditorreloader.cpp \
|
diffeditorreloader.cpp \
|
||||||
differ.cpp \
|
differ.cpp \
|
||||||
diffutils.cpp \
|
diffutils.cpp \
|
||||||
|
diffview.cpp \
|
||||||
selectabletexteditorwidget.cpp \
|
selectabletexteditorwidget.cpp \
|
||||||
sidebysidediffeditorwidget.cpp \
|
sidebysidediffeditorwidget.cpp \
|
||||||
unifieddiffeditorwidget.cpp
|
unifieddiffeditorwidget.cpp
|
||||||
|
@@ -34,6 +34,8 @@ QtcPlugin {
|
|||||||
"differ.h",
|
"differ.h",
|
||||||
"diffutils.cpp",
|
"diffutils.cpp",
|
||||||
"diffutils.h",
|
"diffutils.h",
|
||||||
|
"diffview.cpp",
|
||||||
|
"diffview.h",
|
||||||
"selectabletexteditorwidget.cpp",
|
"selectabletexteditorwidget.cpp",
|
||||||
"selectabletexteditorwidget.h",
|
"selectabletexteditorwidget.h",
|
||||||
"sidebysidediffeditorwidget.cpp",
|
"sidebysidediffeditorwidget.cpp",
|
||||||
|
@@ -41,8 +41,6 @@ const char DIFF_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("DiffEditor", "Diff Ed
|
|||||||
const char DIFF_EDITOR_MIMETYPE[] = "text/x-patch";
|
const char DIFF_EDITOR_MIMETYPE[] = "text/x-patch";
|
||||||
const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options";
|
const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options";
|
||||||
|
|
||||||
const char ICON_SIDE_BY_SIDE_DIFF[] = ":/diffeditor/images/sidebysidediff.png";
|
|
||||||
const char ICON_UNIFIED_DIFF[] = ":/diffeditor/images/unifieddiff.png";
|
|
||||||
const char ICON_TOP_BAR[] = ":/diffeditor/images/topbar.png";
|
const char ICON_TOP_BAR[] = ":/diffeditor/images/topbar.png";
|
||||||
|
|
||||||
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
const char EXPAND_BRANCHES[] = "Branches: <Expand>";
|
||||||
|
113
src/plugins/diffeditor/diffview.cpp
Normal file
113
src/plugins/diffeditor/diffview.cpp
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** 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://www.qt.io/licensing. For further information
|
||||||
|
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "diffview.h"
|
||||||
|
|
||||||
|
#include "unifieddiffeditorwidget.h"
|
||||||
|
#include "sidebysidediffeditorwidget.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
QIcon IDiffView::icon() const
|
||||||
|
{
|
||||||
|
return m_icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString IDiffView::toolTip() const
|
||||||
|
{
|
||||||
|
return m_toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Id IDiffView::id() const
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDiffView::setIcon(const QIcon &icon)
|
||||||
|
{
|
||||||
|
m_icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDiffView::setToolTip(const QString &toolTip)
|
||||||
|
{
|
||||||
|
m_toolTip = toolTip;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IDiffView::setId(const Core::Id &id)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnifiedView::UnifiedView() : m_widget(0)
|
||||||
|
{
|
||||||
|
setId(UNIFIED_VIEW_ID);
|
||||||
|
setIcon(QIcon(QLatin1String(":/diffeditor/images/unifieddiff.png")));
|
||||||
|
setToolTip(QCoreApplication::translate("DiffEditor::UnifiedView", "Switch to Unified Diff Editor"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *UnifiedView::widget()
|
||||||
|
{
|
||||||
|
if (!m_widget)
|
||||||
|
m_widget = new UnifiedDiffEditorWidget;
|
||||||
|
return m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnifiedView::setDiffEditorGuiController(DiffEditorGuiController *controller)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_widget, return);
|
||||||
|
m_widget->setDiffEditorGuiController(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
SideBySideView::SideBySideView() : m_widget(0)
|
||||||
|
{
|
||||||
|
setId(SIDE_BY_SIDE_VIEW_ID);
|
||||||
|
setIcon(QIcon(QLatin1String(":/diffeditor/images/sidebysidediff.png")));
|
||||||
|
setToolTip(QCoreApplication::translate("DiffEditor::SideBySideView",
|
||||||
|
"Switch to Side By Side Diff Editor"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *SideBySideView::widget()
|
||||||
|
{
|
||||||
|
if (!m_widget)
|
||||||
|
m_widget = new SideBySideDiffEditorWidget;
|
||||||
|
return m_widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SideBySideView::setDiffEditorGuiController(DiffEditorGuiController *controller)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_widget, return);
|
||||||
|
m_widget->setDiffEditorGuiController(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace DiffEditor
|
99
src/plugins/diffeditor/diffview.h
Normal file
99
src/plugins/diffeditor/diffview.h
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** 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://www.qt.io/licensing. For further information
|
||||||
|
** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DIFFVIEW_H
|
||||||
|
#define DIFFVIEW_H
|
||||||
|
|
||||||
|
#include <coreplugin/id.h>
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QString>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace DiffEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class DiffEditorGuiController;
|
||||||
|
class SideBySideDiffEditorWidget;
|
||||||
|
class UnifiedDiffEditorWidget;
|
||||||
|
|
||||||
|
const char SIDE_BY_SIDE_VIEW_ID[] = "SideBySide";
|
||||||
|
const char UNIFIED_VIEW_ID[] = "Unified";
|
||||||
|
|
||||||
|
class IDiffView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IDiffView() { }
|
||||||
|
virtual ~IDiffView() { }
|
||||||
|
|
||||||
|
QIcon icon() const;
|
||||||
|
QString toolTip() const;
|
||||||
|
|
||||||
|
Core::Id id() const;
|
||||||
|
virtual QWidget *widget() = 0;
|
||||||
|
virtual void setDiffEditorGuiController(DiffEditorGuiController *controller) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setIcon(const QIcon &icon);
|
||||||
|
void setToolTip(const QString &toolTip);
|
||||||
|
void setId(const Core::Id &id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QIcon m_icon;
|
||||||
|
QString m_toolTip;
|
||||||
|
Core::Id m_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnifiedView : public IDiffView {
|
||||||
|
public:
|
||||||
|
UnifiedView();
|
||||||
|
|
||||||
|
QWidget *widget();
|
||||||
|
void setDiffEditorGuiController(DiffEditorGuiController *controller);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UnifiedDiffEditorWidget *m_widget;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SideBySideView : public IDiffView {
|
||||||
|
public:
|
||||||
|
SideBySideView();
|
||||||
|
|
||||||
|
QWidget *widget();
|
||||||
|
void setDiffEditorGuiController(DiffEditorGuiController *controller);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SideBySideDiffEditorWidget *m_widget;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace DiffEditor
|
||||||
|
|
||||||
|
#endif // DIFFVIEW_H
|
Reference in New Issue
Block a user