Skip to content

Commit 5744f21

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

6 files changed

Lines changed: 102 additions & 1 deletion

File tree

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ void PreferencesDialog::MapSettingToGroupBox(QGroupBox *groupBox, Func1 getter,
177177
connect(groupBox, &QGroupBox::toggled, settings, setter);
178178
}
179179

180+
template<typename Func1, typename Func2, typename Func3>
181+
void PreferencesDialog::MapSettingToRadioButton(QRadioButton *radioButton, Func1 getter, Func2 setter, Func3 notifier) const
182+
{
183+
// Get the value and set the radiobutton state
184+
radioButton->setChecked(std::bind(getter, settings)());
185+
186+
// Set up two way connection
187+
connect(settings, notifier, radioButton, &QRadioButton::setChecked);
188+
connect(radioButton, &QRadioButton::toggled, settings, setter);
189+
}
190+
180191
void PreferencesDialog::populateTranslationComboBox()
181192
{
182193
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)