Commit 41d027e6 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Add diff style to config dialog

parent 2165e21e
......@@ -20,7 +20,7 @@ struct LineHighlight {
bool added;
};
enum DiffStyle { SideBySide, Unified, Raw };
enum DiffStyle { SideBySide = 0, Unified, Raw };
class DiffEditor : public QPlainTextEdit
{
......
......@@ -3,7 +3,6 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "diffwidget.h"
#include "diffeditor.h"
#include "ktexteditor_utils.h"
#include "gitprocess.h"
......@@ -17,6 +16,8 @@
#include <QScrollBar>
#include <QSyntaxHighlighter>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/Format>
#include <KSyntaxHighlighting/Repository>
......@@ -61,6 +62,10 @@ DiffWidget::DiffWidget(QWidget *parent)
for (auto *e : {m_left, m_right}) {
connect(e, &DiffEditor::switchStyle, this, &DiffWidget::handleStyleChange);
}
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup cgGeneral = KConfigGroup(config, "General");
handleStyleChange(cgGeneral.readEntry("Diff Show Style", (int)SideBySide));
}
void DiffWidget::handleStyleChange(int newStyle)
......@@ -69,21 +74,21 @@ void DiffWidget::handleStyleChange(int newStyle)
return;
}
m_style = (DiffStyle)newStyle;
m_left->clearData();
m_right->clearData();
const auto diff = m_rawDiff;
clearData();
if (m_style == SideBySide) {
m_left->setVisible(true);
m_right->setVisible(true);
openDiff(m_rawDiff);
openDiff(diff);
} else if (m_style == Unified) {
m_left->setVisible(true);
m_right->setVisible(false);
openDiff(m_rawDiff);
openDiff(diff);
} else if (m_style == Raw) {
m_left->setVisible(true);
m_right->setVisible(false);
openDiff(m_rawDiff);
openDiff(diff);
} else {
qWarning() << "Unexpected diff style value: " << newStyle;
Q_UNREACHABLE();
......
......@@ -282,6 +282,21 @@ void KateConfigDialog::addBehaviorPage()
buttonGroup->setLayout(vbox);
/** DIFF **/
buttonGroup = new QGroupBox(i18n("Diff"), generalFrame);
vbox = new QVBoxLayout(buttonGroup);
hlayout = new QHBoxLayout;
vbox->addLayout(hlayout);
layout->addWidget(buttonGroup);
m_diffStyle = new QComboBox;
m_diffStyle->addItem(i18n("Side By Side"));
m_diffStyle->addItem(i18n("Unified"));
m_diffStyle->addItem(i18n("Raw"));
hlayout->addWidget(new QLabel(i18n("Diff Style:")));
hlayout->addWidget(m_diffStyle);
m_diffStyle->setCurrentIndex(cgGeneral.readEntry("Diff Show Style", 0));
connect(m_diffStyle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateConfigDialog::slotChanged);
layout->addStretch(1); // :-] works correct without autoadd
}
......@@ -518,6 +533,8 @@ void KateConfigDialog::slotApply()
cg.writeEntry("Allow Tab Scrolling", m_tabsScrollable->isChecked());
cg.writeEntry("Elide Tab Text", m_tabsElided->isChecked());
cg.writeEntry("Diff Show Style", m_diffStyle->currentIndex());
// patch document modified warn state
const QList<KTextEditor::Document *> &docs = KateApp::self()->documentManager()->documentList();
for (KTextEditor::Document *doc : docs) {
......
......@@ -102,6 +102,7 @@ private:
QCheckBox *m_tabMiddleClickCloseDocument;
QCheckBox *m_tabsScrollable = nullptr;
QCheckBox *m_tabsElided = nullptr;
QComboBox *m_diffStyle = nullptr;
Ui::SessionConfigWidget sessionConfigUi;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment