Skip to content

Commit 4316b8f

Browse files
committed
Implementation of Tab spaces and indentation size.
from dail8859#844 rebased
1 parent 9d1f746 commit 4316b8f

File tree

6 files changed

+111
-4
lines changed

6 files changed

+111
-4
lines changed

src/NotepadNext/ApplicationSettings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStrin
7171
CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral(""))
7272
CREATE_SETTING(Editor, URLHighlighting, urlHighlighting, bool, true)
7373
CREATE_SETTING(Editor, ShowLineNumbers, showLineNumbers, bool, true)
74+
CREATE_SETTING(Editor, IndentSize, indentSize, int, 4)
75+
CREATE_SETTING(Editor, TabChar, tabChar, bool, true)
76+
CREATE_SETTING(Editor, TabCharSpaces, tabCharSpaces, bool, false)

src/NotepadNext/ApplicationSettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,7 @@ class ApplicationSettings : public QSettings
119119
DEFINE_SETTING(DefaultEOLMode, defaultEOLMode, QString)
120120
DEFINE_SETTING(URLHighlighting, urlHighlighting, bool)
121121
DEFINE_SETTING(ShowLineNumbers, showLineNumbers, bool)
122+
DEFINE_SETTING(IndentSize, indentSize, int);
123+
DEFINE_SETTING(TabChar, tabChar, bool);
124+
DEFINE_SETTING(TabCharSpaces, tabCharSpaces, bool);
122125
};

src/NotepadNext/EditorManager.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ EditorManager::EditorManager(ApplicationSettings *settings, QObject *parent)
128128
}
129129
}
130130
});
131+
132+
connect(settings, &ApplicationSettings::indentSizeChanged, this, [=](int indentSize){
133+
for (auto &editor : getEditors()) {
134+
editor->setTabWidth(indentSize);
135+
editor->setIndent(indentSize);
136+
}
137+
});
138+
139+
connect(settings, &ApplicationSettings::tabCharChanged, this, [=](bool useTabs){
140+
for (auto &editor : getEditors()) {
141+
editor->setUseTabs(useTabs);
142+
}
143+
});
131144
}
132145

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

218231
editor->setTabDrawMode(SCTD_STRIKEOUT);
219-
editor->setTabWidth(4);
232+
editor->setTabWidth(settings->indentSize());
233+
editor->setIndent(settings->indentSize());
234+
editor->setUseTabs(settings->tabChar());
220235
editor->setBackSpaceUnIndents(true);
221236

222237
editor->setCaretLineVisible(true);

src/NotepadNext/dialogs/PreferencesDialog.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par
102102
MapSettingToCheckBox(ui->checkBoxHighlightURLs, &ApplicationSettings::urlHighlighting, &ApplicationSettings::setURLHighlighting, &ApplicationSettings::urlHighlightingChanged);
103103
MapSettingToCheckBox(ui->checkBoxShowLineNumbers, &ApplicationSettings::showLineNumbers, &ApplicationSettings::setShowLineNumbers, &ApplicationSettings::showLineNumbersChanged);
104104

105+
ui->sbpIndentSize->setValue(settings->indentSize());
106+
connect(ui->sbpIndentSize, QOverload<int>::of(&QSpinBox::valueChanged), settings, &ApplicationSettings::setIndentSize);
107+
connect(settings, &::ApplicationSettings::fontSizeChanged, ui->sbpIndentSize, &QSpinBox::setValue);
108+
109+
MapSettingToRadioButton(ui->rbTabChar, &ApplicationSettings::tabChar, &ApplicationSettings::setTabChar, &ApplicationSettings::tabCharChanged);
110+
MapSettingToRadioButton(ui->rbSpaceChar, &ApplicationSettings::tabCharSpaces, &ApplicationSettings::setTabCharSpaces, &ApplicationSettings::tabCharSpacesChanged);
105111

106112
QButtonGroup *buttonGroup = new QButtonGroup(this);
107113
buttonGroup->addButton(ui->radioFollowCurrentDirectory, ApplicationSettings::FollowCurrentDocument);
@@ -177,6 +183,17 @@ void PreferencesDialog::MapSettingToGroupBox(QGroupBox *groupBox, Func1 getter,
177183
connect(groupBox, &QGroupBox::toggled, settings, setter);
178184
}
179185

186+
template<typename Func1, typename Func2, typename Func3>
187+
void PreferencesDialog::MapSettingToRadioButton(QRadioButton *radioButton, Func1 getter, Func2 setter, Func3 notifier) const
188+
{
189+
// Get the value and set the radiobutton state
190+
radioButton->setChecked(std::bind(getter, settings)());
191+
192+
// Set up two way connection
193+
connect(settings, notifier, radioButton, &QRadioButton::setChecked);
194+
connect(radioButton, &QRadioButton::toggled, settings, setter);
195+
}
196+
180197
void PreferencesDialog::populateTranslationComboBox()
181198
{
182199
NotepadNextApplication *app = qobject_cast<NotepadNextApplication *>(qApp);

src/NotepadNext/dialogs/PreferencesDialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QDialog>
2626
#include <QCheckBox>
2727
#include <QGroupBox>
28+
#include <QRadioButton>
2829

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

56+
template <typename Func1, typename Func2, typename Func3>
57+
void MapSettingToRadioButton(QRadioButton *radioButton, Func1 getter, Func2 setter, Func3 notifier) const;
58+
5559
void populateTranslationComboBox();
5660
};
5761

src/NotepadNext/dialogs/PreferencesDialog.ui

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
<property name="geometry">
2424
<rect>
2525
<x>0</x>
26-
<y>-99</y>
27-
<width>769</width>
28-
<height>644</height>
26+
<y>-281</y>
27+
<width>762</width>
28+
<height>816</height>
2929
</rect>
3030
</property>
3131
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -194,6 +194,9 @@
194194
</item>
195195
</layout>
196196
</item>
197+
<item>
198+
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
199+
</item>
197200
<item>
198201
<widget class="QCheckBox" name="checkBoxHighlightURLs">
199202
<property name="text">
@@ -252,6 +255,68 @@
252255
</layout>
253256
</widget>
254257
</item>
258+
<item>
259+
<widget class="QGroupBox" name="groupBox_2">
260+
<property name="title">
261+
<string>Indentation</string>
262+
</property>
263+
<layout class="QVBoxLayout" name="verticalLayout_5">
264+
<item>
265+
<widget class="QWidget" name="widget" native="true">
266+
<layout class="QFormLayout" name="formLayout_4">
267+
<item row="0" column="0">
268+
<widget class="QLabel" name="label_5">
269+
<property name="text">
270+
<string>Indent size:</string>
271+
</property>
272+
</widget>
273+
</item>
274+
<item row="0" column="1">
275+
<widget class="QSpinBox" name="sbpIndentSize">
276+
<property name="maximumSize">
277+
<size>
278+
<width>40</width>
279+
<height>16777215</height>
280+
</size>
281+
</property>
282+
<property name="alignment">
283+
<set>Qt::AlignCenter</set>
284+
</property>
285+
<property name="minimum">
286+
<number>1</number>
287+
</property>
288+
<property name="value">
289+
<number>4</number>
290+
</property>
291+
</widget>
292+
</item>
293+
</layout>
294+
</widget>
295+
</item>
296+
<item>
297+
<widget class="QLabel" name="label_6">
298+
<property name="text">
299+
<string>Indent using:</string>
300+
</property>
301+
</widget>
302+
</item>
303+
<item>
304+
<widget class="QRadioButton" name="rbTabChar">
305+
<property name="text">
306+
<string>Tab character</string>
307+
</property>
308+
</widget>
309+
</item>
310+
<item>
311+
<widget class="QRadioButton" name="rbSpaceChar">
312+
<property name="text">
313+
<string>Space character(s)</string>
314+
</property>
315+
</widget>
316+
</item>
317+
</layout>
318+
</widget>
319+
</item>
255320
<item>
256321
<spacer name="verticalSpacer">
257322
<property name="orientation">

0 commit comments

Comments
 (0)