Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/NotepadNext/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStrin
CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral(""))
CREATE_SETTING(Editor, URLHighlighting, urlHighlighting, bool, true)
CREATE_SETTING(Editor, ShowLineNumbers, showLineNumbers, bool, true)
CREATE_SETTING(Editor, IndentSize, indentSize, int, 4)
CREATE_SETTING(Editor, TabChar, tabChar, bool, true)
CREATE_SETTING(Editor, TabCharSpaces, tabCharSpaces, bool, false)
3 changes: 3 additions & 0 deletions src/NotepadNext/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ class ApplicationSettings : public QSettings
DEFINE_SETTING(DefaultEOLMode, defaultEOLMode, QString)
DEFINE_SETTING(URLHighlighting, urlHighlighting, bool)
DEFINE_SETTING(ShowLineNumbers, showLineNumbers, bool)
DEFINE_SETTING(IndentSize, indentSize, int);
DEFINE_SETTING(TabChar, tabChar, bool);
DEFINE_SETTING(TabCharSpaces, tabCharSpaces, bool);
};
17 changes: 16 additions & 1 deletion src/NotepadNext/EditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ EditorManager::EditorManager(ApplicationSettings *settings, QObject *parent)
}
}
});

connect(settings, &ApplicationSettings::indentSizeChanged, this, [=](int indentSize){
for (auto &editor : getEditors()) {
editor->setTabWidth(indentSize);
editor->setIndent(indentSize);
}
});

connect(settings, &ApplicationSettings::tabCharChanged, this, [=](bool useTabs){
for (auto &editor : getEditors()) {
editor->setUseTabs(useTabs);
}
});
}

ScintillaNext *EditorManager::createEditor(const QString &name)
Expand Down Expand Up @@ -216,7 +229,9 @@ void EditorManager::setupEditor(ScintillaNext *editor)
editor->setScrollWidth(1);

editor->setTabDrawMode(SCTD_STRIKEOUT);
editor->setTabWidth(4);
editor->setTabWidth(settings->indentSize());
editor->setIndent(settings->indentSize());
editor->setUseTabs(settings->tabChar());
editor->setBackSpaceUnIndents(true);

editor->setCaretLineVisible(true);
Expand Down
18 changes: 18 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par

MapSettingToCheckBox(ui->checkBoxHighlightURLs, &ApplicationSettings::urlHighlighting, &ApplicationSettings::setURLHighlighting, &ApplicationSettings::urlHighlightingChanged);
MapSettingToCheckBox(ui->checkBoxShowLineNumbers, &ApplicationSettings::showLineNumbers, &ApplicationSettings::setShowLineNumbers, &ApplicationSettings::showLineNumbersChanged);

ui->sbpIndentSize->setValue(settings->indentSize());
connect(ui->sbpIndentSize, QOverload<int>::of(&QSpinBox::valueChanged), settings, &ApplicationSettings::setIndentSize);
connect(settings, &::ApplicationSettings::fontSizeChanged, ui->sbpIndentSize, &QSpinBox::setValue);

MapSettingToRadioButton(ui->rbTabChar, &ApplicationSettings::tabChar, &ApplicationSettings::setTabChar, &ApplicationSettings::tabCharChanged);
MapSettingToRadioButton(ui->rbSpaceChar, &ApplicationSettings::tabCharSpaces, &ApplicationSettings::setTabCharSpaces, &ApplicationSettings::tabCharSpacesChanged);
}

PreferencesDialog::~PreferencesDialog()
Expand Down Expand Up @@ -134,6 +141,17 @@ void PreferencesDialog::MapSettingToGroupBox(QGroupBox *groupBox, Func1 getter,
connect(groupBox, &QGroupBox::toggled, settings, setter);
}

template<typename Func1, typename Func2, typename Func3>
void PreferencesDialog::MapSettingToRadioButton(QRadioButton *radioButton, Func1 getter, Func2 setter, Func3 notifier) const
{
// Get the value and set the radiobutton state
radioButton->setChecked(std::bind(getter, settings)());

// Set up two way connection
connect(settings, notifier, radioButton, &QRadioButton::setChecked);
connect(radioButton, &QRadioButton::toggled, settings, setter);
}

void PreferencesDialog::populateTranslationComboBox()
{
NotepadNextApplication *app = qobject_cast<NotepadNextApplication *>(qApp);
Expand Down
4 changes: 4 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QDialog>
#include <QCheckBox>
#include <QGroupBox>
#include <QRadioButton>

namespace Ui {
class PreferencesDialog;
Expand Down Expand Up @@ -52,6 +53,9 @@ class PreferencesDialog : public QDialog
template <typename Func1, typename Func2, typename Func3>
void MapSettingToGroupBox(QGroupBox *groupBox, Func1 getter, Func2 setter, Func3 notifier) const;

template <typename Func1, typename Func2, typename Func3>
void MapSettingToRadioButton(QRadioButton *radioButton, Func1 getter, Func2 setter, Func3 notifier) const;

void populateTranslationComboBox();
};

Expand Down
71 changes: 68 additions & 3 deletions src/NotepadNext/dialogs/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>783</width>
<height>545</height>
<y>-281</y>
<width>762</width>
<height>816</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
Expand Down Expand Up @@ -194,6 +194,9 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</item>
<item>
<widget class="QCheckBox" name="checkBoxHighlightURLs">
<property name="text">
Expand All @@ -208,6 +211,68 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Indentation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Indent size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbpIndentSize">
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Indent using:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbTabChar">
<property name="text">
<string>Tab character</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbSpaceChar">
<property name="text">
<string>Space character(s)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
Loading