From 594a2a0350e46ca90468822627cd5dd17130522a Mon Sep 17 00:00:00 2001 From: dail8859 Date: Thu, 19 Jun 2025 22:52:22 -0400 Subject: [PATCH] Allow toggling visibility of line numbers Closes #772 --- src/NotepadNext/ApplicationSettings.cpp | 1 + src/NotepadNext/ApplicationSettings.h | 1 + src/NotepadNext/EditorManager.cpp | 17 +++++++++++++---- src/NotepadNext/dialogs/PreferencesDialog.cpp | 1 + src/NotepadNext/dialogs/PreferencesDialog.ui | 11 +++++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/NotepadNext/ApplicationSettings.cpp b/src/NotepadNext/ApplicationSettings.cpp index 623761b73..f655b6a16 100644 --- a/src/NotepadNext/ApplicationSettings.cpp +++ b/src/NotepadNext/ApplicationSettings.cpp @@ -67,3 +67,4 @@ CREATE_SETTING(Editor, FontSize, fontSize, int, []() { return qApp->font().point CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStringLiteral("")); CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral("")) CREATE_SETTING(Editor, URLHighlighting, urlHighlighting, bool, true) +CREATE_SETTING(Editor, ShowLineNumbers, showLineNumbers, bool, true) diff --git a/src/NotepadNext/ApplicationSettings.h b/src/NotepadNext/ApplicationSettings.h index add2b3f07..666aed92b 100644 --- a/src/NotepadNext/ApplicationSettings.h +++ b/src/NotepadNext/ApplicationSettings.h @@ -109,4 +109,5 @@ class ApplicationSettings : public QSettings DEFINE_SETTING(AdditionalWordChars, additionalWordChars, QString); DEFINE_SETTING(DefaultEOLMode, defaultEOLMode, QString) DEFINE_SETTING(URLHighlighting, urlHighlighting, bool) + DEFINE_SETTING(ShowLineNumbers, showLineNumbers, bool) }; diff --git a/src/NotepadNext/EditorManager.cpp b/src/NotepadNext/EditorManager.cpp index 17dad0925..e60f2911f 100644 --- a/src/NotepadNext/EditorManager.cpp +++ b/src/NotepadNext/EditorManager.cpp @@ -113,9 +113,18 @@ EditorManager::EditorManager(ApplicationSettings *settings, QObject *parent) connect(settings, &ApplicationSettings::urlHighlightingChanged, this, [=](bool b){ for (auto &editor : getEditors()) { - URLFinder *urlFinder = editor->findChild(QString(), Qt::FindDirectChildrenOnly); - if (urlFinder) { - urlFinder->setEnabled(b); + URLFinder *decorator = editor->findChild(QString(), Qt::FindDirectChildrenOnly); + if (decorator) { + decorator->setEnabled(b); + } + } + }); + + connect(settings, &ApplicationSettings::showLineNumbersChanged, this, [=](bool b){ + for (auto &editor : getEditors()) { + LineNumbers *decorator = editor->findChild(QString(), Qt::FindDirectChildrenOnly); + if (decorator) { + decorator->setEnabled(b); } } }); @@ -302,7 +311,7 @@ void EditorManager::setupEditor(ScintillaNext *editor) b->setEnabled(true); LineNumbers *l = new LineNumbers(editor); - l->setEnabled(true); + l->setEnabled(settings->showLineNumbers()); SurroundSelection *ss = new SurroundSelection(editor); ss->setEnabled(true); diff --git a/src/NotepadNext/dialogs/PreferencesDialog.cpp b/src/NotepadNext/dialogs/PreferencesDialog.cpp index e00bbad68..7fdcbc887 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.cpp +++ b/src/NotepadNext/dialogs/PreferencesDialog.cpp @@ -98,6 +98,7 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par }); MapSettingToCheckBox(ui->checkBoxHighlightURLs, &ApplicationSettings::urlHighlighting, &ApplicationSettings::setURLHighlighting, &ApplicationSettings::urlHighlightingChanged); + MapSettingToCheckBox(ui->checkBoxShowLineNumbers, &ApplicationSettings::showLineNumbers, &ApplicationSettings::setShowLineNumbers, &ApplicationSettings::showLineNumbersChanged); } PreferencesDialog::~PreferencesDialog() diff --git a/src/NotepadNext/dialogs/PreferencesDialog.ui b/src/NotepadNext/dialogs/PreferencesDialog.ui index b9660d8ea..f78aa9e3e 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.ui +++ b/src/NotepadNext/dialogs/PreferencesDialog.ui @@ -7,7 +7,7 @@ 0 0 803 - 564 + 597 @@ -25,7 +25,7 @@ 0 0 783 - 512 + 545 @@ -201,6 +201,13 @@ + + + + Show Line Numbers + + +