diff --git a/src/NotepadNext/ApplicationSettings.cpp b/src/NotepadNext/ApplicationSettings.cpp index 8914b3892..623761b73 100644 --- a/src/NotepadNext/ApplicationSettings.cpp +++ b/src/NotepadNext/ApplicationSettings.cpp @@ -66,3 +66,4 @@ CREATE_SETTING(Editor, FontName, fontName, QString, QStringLiteral("Courier New" CREATE_SETTING(Editor, FontSize, fontSize, int, []() { return qApp->font().pointSize() + 2; }) CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStringLiteral("")); CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral("")) +CREATE_SETTING(Editor, URLHighlighting, urlHighlighting, bool, true) diff --git a/src/NotepadNext/ApplicationSettings.h b/src/NotepadNext/ApplicationSettings.h index 50d2533b5..add2b3f07 100644 --- a/src/NotepadNext/ApplicationSettings.h +++ b/src/NotepadNext/ApplicationSettings.h @@ -108,4 +108,5 @@ class ApplicationSettings : public QSettings DEFINE_SETTING(FontSize, fontSize, int); DEFINE_SETTING(AdditionalWordChars, additionalWordChars, QString); DEFINE_SETTING(DefaultEOLMode, defaultEOLMode, QString) + DEFINE_SETTING(URLHighlighting, urlHighlighting, bool) }; diff --git a/src/NotepadNext/EditorManager.cpp b/src/NotepadNext/EditorManager.cpp index bfae40348..17dad0925 100644 --- a/src/NotepadNext/EditorManager.cpp +++ b/src/NotepadNext/EditorManager.cpp @@ -110,6 +110,15 @@ 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); + } + } + }); } ScintillaNext *EditorManager::createEditor(const QString &name) @@ -308,7 +317,7 @@ void EditorManager::setupEditor(ScintillaNext *editor) ac->setEnabled(true); URLFinder *uf = new URLFinder(editor); - uf->setEnabled(true); + uf->setEnabled(settings->urlHighlighting()); BookMarkDecorator *bm = new BookMarkDecorator(editor); bm->setEnabled(true); diff --git a/src/NotepadNext/decorators/URLFinder.cpp b/src/NotepadNext/decorators/URLFinder.cpp index 56e9e4c8a..66a124d53 100644 --- a/src/NotepadNext/decorators/URLFinder.cpp +++ b/src/NotepadNext/decorators/URLFinder.cpp @@ -42,14 +42,22 @@ URLFinder::URLFinder(ScintillaNext *editor) : timer->setInterval(200); timer->setSingleShot(true); connect(timer, &QTimer::timeout, this, &URLFinder::findURLs); + + connect(this, &EditorDecorator::stateChanged, this, [=](bool b) { + if (b) { + connect(editor, &ScintillaNext::resized, timer, qOverload<>(&QTimer::start)); + findURLs(); + } + else { + disconnect(editor, &ScintillaNext::resized, timer, qOverload<>(&QTimer::start)); + clearURLs(); + } + }); } void URLFinder::findURLs() { - //qInfo(Q_FUNC_INFO); - - editor->setIndicatorCurrent(indicator); - editor->indicatorClearRange(0, editor->length()); + clearURLs(); int currentLine = editor->docLineFromVisible(editor->firstVisibleLine()); int linesLeftToProcess = editor->linesOnScreen(); @@ -103,6 +111,12 @@ void URLFinder::findURLs() } } +void URLFinder::clearURLs() +{ + editor->setIndicatorCurrent(indicator); + editor->indicatorClearRange(0, editor->length()); +} + void URLFinder::notify(const Scintilla::NotificationData *pscn) { // TODO: handle editor folding/unfolding diff --git a/src/NotepadNext/decorators/URLFinder.h b/src/NotepadNext/decorators/URLFinder.h index e628e7b76..e5b4ae4b7 100644 --- a/src/NotepadNext/decorators/URLFinder.h +++ b/src/NotepadNext/decorators/URLFinder.h @@ -33,6 +33,7 @@ class URLFinder : public EditorDecorator private slots: void findURLs(); + void clearURLs(); public slots: void notify(const Scintilla::NotificationData *pscn) override; diff --git a/src/NotepadNext/dialogs/PreferencesDialog.cpp b/src/NotepadNext/dialogs/PreferencesDialog.cpp index 4df72f4df..e00bbad68 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.cpp +++ b/src/NotepadNext/dialogs/PreferencesDialog.cpp @@ -96,6 +96,8 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par int index = ui->comboBoxLineEndings->findData(defaultEOLMode); ui->comboBoxLineEndings->setCurrentIndex(index == -1 ? 0 : index); }); + + MapSettingToCheckBox(ui->checkBoxHighlightURLs, &ApplicationSettings::urlHighlighting, &ApplicationSettings::setURLHighlighting, &ApplicationSettings::urlHighlightingChanged); } PreferencesDialog::~PreferencesDialog() diff --git a/src/NotepadNext/dialogs/PreferencesDialog.ui b/src/NotepadNext/dialogs/PreferencesDialog.ui index e9f76f1ce..b9660d8ea 100644 --- a/src/NotepadNext/dialogs/PreferencesDialog.ui +++ b/src/NotepadNext/dialogs/PreferencesDialog.ui @@ -194,6 +194,13 @@ + + + + Highlight URLs + + + @@ -255,8 +262,8 @@ accept() - 641 - 439 + 792 + 553 157 @@ -271,8 +278,8 @@ reject() - 709 - 439 + 792 + 553 286