Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
11 changes: 10 additions & 1 deletion src/NotepadNext/EditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<URLFinder *>(QString(), Qt::FindDirectChildrenOnly);
if (urlFinder) {
urlFinder->setEnabled(b);
}
}
});
}

ScintillaNext *EditorManager::createEditor(const QString &name)
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 18 additions & 4 deletions src/NotepadNext/decorators/URLFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/NotepadNext/decorators/URLFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class URLFinder : public EditorDecorator

private slots:
void findURLs();
void clearURLs();

public slots:
void notify(const Scintilla::NotificationData *pscn) override;
Expand Down
2 changes: 2 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 11 additions & 4 deletions src/NotepadNext/dialogs/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxHighlightURLs">
<property name="text">
<string>Highlight URLs</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -255,8 +262,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>641</x>
<y>439</y>
<x>792</x>
<y>553</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand All @@ -271,8 +278,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>709</x>
<y>439</y>
<x>792</x>
<y>553</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand Down