Skip to content

Commit

Permalink
v0.4.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
dail8859 committed Jan 8, 2022
2 parents 97f50b3 + 216859e commit 50d713e
Show file tree
Hide file tree
Showing 22 changed files with 868 additions and 313 deletions.
15 changes: 10 additions & 5 deletions installer/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,13 @@ Section "Notepad Next"
SectionIn RO
SetOutPath $INSTDIR

File /r ..\build\package\*
File /r /x libcrypto-1_1-x64.dll /x libssl-1_1-x64.dll ..\build\package\*

SetRegView 64

# Register the application (e.g. cmd> start notepadnext)
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\App Paths\NotepadNext.exe" "" "$INSTDIR\NotepadNext.exe"

# Enable the auto updater
# TODO: later make this a selectable section by the user
WriteRegDWORD SHCTX "Software\NotepadNext\NotepadNext\" "AutoUpdate" 1

# Register 'Open With' menu suggestion. No real good documentation for this. https://stackoverflow.com/a/62783311
WriteRegStr SHCTX "Software\Classes\NotepadNext\shell" "" "open"
WriteRegStr SHCTX "Software\Classes\NotepadNext\shell\open\command" "" "$\"$INSTDIR\NotepadNext.exe$\" $\"%1$\""
Expand Down Expand Up @@ -147,6 +143,15 @@ Section /o "Context Menu"
WriteRegStr SHCTX "Software\Classes\*\shell\NotepadNext\command" "" "$\"$INSTDIR\NotepadNext.exe$\" $\"%1$\""
SectionEnd

Section /o "Auto Updater"
SetRegView 64
SetOutPath $INSTDIR

File ..\build\package\libcrypto-1_1-x64.dll ..\build\package\libssl-1_1-x64.dll

WriteRegDWORD SHCTX "Software\NotepadNext\NotepadNext\" "AutoUpdate" 1
SectionEnd


Section "Uninstall"
SetRegView 64
Expand Down
2 changes: 1 addition & 1 deletion src/NotepadNext.pro
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ win32 {

zip.target = zip
zip.depends = package
zip.commands = 7z a -tzip $$quote(NotepadNext-v$${APP_VERSION}.zip) $$shell_path(./package/*)
zip.commands = 7z a -tzip $$quote(NotepadNext-v$${APP_VERSION}.zip) $$shell_path(./package/*) -x!libssl-1_1-x64.dll -x!libcrypto-1_1-x64.dll

installer.target = installer
installer.depends = package
Expand Down
61 changes: 22 additions & 39 deletions src/NotepadNext/EditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "EditorManager.h"
#include "ScintillaNext.h"
#include "Scintilla.h"
#include "ScintillaTypes.h"

// Editor decorators
#include "BraceMatch.h"
Expand All @@ -31,15 +30,17 @@
#include "BetterMultiSelection.h"
#include "AutoIndentation.h"


const int MARK_BOOKMARK = 24;
const int MARK_HIDELINESBEGIN = 23;
const int MARK_HIDELINESEND = 22;
const int MARK_HIDELINESUNDERLINE = 21;


EditorManager::EditorManager(QObject *parent) : QObject(parent)
{
connect(this, &EditorManager::editorCreated, [=](ScintillaNext *editor) {
connect(editor, &ScintillaNext::closed, [=]() {
connect(this, &EditorManager::editorCreated, this, [=](ScintillaNext *editor) {
connect(editor, &ScintillaNext::closed, this, [=]() {
emit editorClosed(editor);
});
});
Expand All @@ -48,8 +49,8 @@ EditorManager::EditorManager(QObject *parent) : QObject(parent)
ScintillaNext *EditorManager::createEmptyEditor(const QString &name)
{
ScintillaNext *editor = new ScintillaNext(name);
QPointer<ScintillaNext> pointer = QPointer<ScintillaNext>(editor);
editors.append(pointer);

manageEditor(editor);

setupEditor(editor);

Expand All @@ -61,8 +62,8 @@ ScintillaNext *EditorManager::createEmptyEditor(const QString &name)
ScintillaNext *EditorManager::createEditorFromFile(const QString &filePath)
{
ScintillaNext *editor = ScintillaNext::fromFile(filePath);
QPointer<ScintillaNext> pointer = QPointer<ScintillaNext>(editor);
editors.append(pointer);

manageEditor(editor);

setupEditor(editor);

Expand All @@ -74,8 +75,8 @@ ScintillaNext *EditorManager::createEditorFromFile(const QString &filePath)
ScintillaNext *EditorManager::cloneEditor(ScintillaNext *editor)
{
ScintillaNext *clonedEditor = new ScintillaNext("Clone");
QPointer<ScintillaNext> pointer = QPointer<ScintillaNext>(clonedEditor);
editors.append(pointer);

manageEditor(editor);

setupEditor(clonedEditor);

Expand All @@ -100,13 +101,24 @@ ScintillaNext *EditorManager::getEditorByFilePath(const QString &filePath)
return Q_NULLPTR;
}

void EditorManager::manageEditor(ScintillaNext *editor)
{
editors.append(QPointer<ScintillaNext>(editor));
}

void EditorManager::setupEditor(ScintillaNext *editor)
{
qInfo(Q_FUNC_INFO);

editor->clearCmdKey(SCK_INSERT);

setFoldMarkers(editor, "box");
editor->setFoldMarkers(QStringLiteral("box"));
for (int i = SC_MARKNUM_FOLDEREND; i <= SC_MARKNUM_FOLDEROPEN; ++i) {
editor->markerSetFore(i, 0xF3F3F3);
editor->markerSetBack(i, 0x808080);
editor->markerSetBackSelected(i, 0x0000FF);
}

editor->setIdleStyling(SC_IDLESTYLING_TOVISIBLE);
editor->setEndAtLastLine(false);

Expand Down Expand Up @@ -229,35 +241,6 @@ void EditorManager::setupEditor(ScintillaNext *editor)
ai->setEnabled(true);
}

// TODO: Move this into the editor eventually?
void EditorManager::setFoldMarkers(ScintillaNext *editor, const QString &type)
{
QMap<QString, QList<int>> map{
{"simple", {SC_MARK_MINUS, SC_MARK_PLUS, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY}},
{"arrow", {SC_MARK_ARROWDOWN, SC_MARK_ARROW, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY}},
{"circle", {SC_MARK_CIRCLEMINUS, SC_MARK_CIRCLEPLUS, SC_MARK_VLINE, SC_MARK_LCORNERCURVE, SC_MARK_CIRCLEPLUSCONNECTED, SC_MARK_CIRCLEMINUSCONNECTED, SC_MARK_TCORNERCURVE }},
{"box", {SC_MARK_BOXMINUS, SC_MARK_BOXPLUS, SC_MARK_VLINE, SC_MARK_LCORNER, SC_MARK_BOXPLUSCONNECTED, SC_MARK_BOXMINUSCONNECTED, SC_MARK_TCORNER }},
};

if (!map.contains(type))
return;

const auto types = map[type];
editor->markerDefine(SC_MARKNUM_FOLDEROPEN, types[0]);
editor->markerDefine(SC_MARKNUM_FOLDER, types[1]);
editor->markerDefine(SC_MARKNUM_FOLDERSUB, types[2]);
editor->markerDefine(SC_MARKNUM_FOLDERTAIL, types[3]);
editor->markerDefine(SC_MARKNUM_FOLDEREND, types[4]);
editor->markerDefine(SC_MARKNUM_FOLDEROPENMID, types[5]);
editor->markerDefine(SC_MARKNUM_FOLDERMIDTAIL, types[6]);

for (int i = SC_MARKNUM_FOLDEREND; i <= SC_MARKNUM_FOLDEROPEN; ++i) {
editor->markerSetFore(i, 0xF3F3F3);
editor->markerSetBack(i, 0x808080);
editor->markerSetBackSelected(i, 0x0000FF);
}
}

void EditorManager::purgeOldEditorPointers()
{
QMutableListIterator<QPointer<ScintillaNext>> it(editors);
Expand Down
2 changes: 1 addition & 1 deletion src/NotepadNext/EditorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class EditorManager : public QObject
void editorClosed(ScintillaNext *editor);

private:
void manageEditor(ScintillaNext *editor);
void setupEditor(ScintillaNext *editor);
void setFoldMarkers(ScintillaNext *editor, const QString &type);
void purgeOldEditorPointers();

QList<QPointer<ScintillaNext>> editors;
Expand Down
5 changes: 5 additions & 0 deletions src/NotepadNext/NotepadNext.pro
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ SOURCES += \
decorators/BetterMultiSelection.cpp \
decorators/EditorConfigAppDecorator.cpp \
decorators/SurroundSelection.cpp \
dialogs/EditorInspectorDock.cpp \
dialogs/FindReplaceDialog.cpp \
dialogs/LanguageInspectorDock.cpp \
dialogs/LuaConsoleDock.cpp \
Expand All @@ -98,6 +99,7 @@ SOURCES += \
decorators/HighlightedScrollBar.cpp \
decorators/LineNumbers.cpp \
decorators/SmartHighlighter.cpp \
widgets/EditorInfoStatusBar.cpp \
widgets/StatusLabel.cpp

HEADERS += \
Expand Down Expand Up @@ -130,6 +132,7 @@ HEADERS += \
decorators/BetterMultiSelection.h \
decorators/EditorConfigAppDecorator.h \
decorators/SurroundSelection.h \
dialogs/EditorInspectorDock.h \
dialogs/FindReplaceDialog.h \
dialogs/LanguageInspectorDock.h \
dialogs/LuaConsoleDock.h \
Expand All @@ -142,10 +145,12 @@ HEADERS += \
decorators/HighlightedScrollBar.h \
decorators/LineNumbers.h \
decorators/SmartHighlighter.h \
widgets/EditorInfoStatusBar.h \
widgets/StatusLabel.h

FORMS += \
QuickFindWidget.ui \
dialogs/EditorInspectorDock.ui \
dialogs/LanguageInspectorDock.ui \
dialogs/MainWindow.ui \
dialogs/FindReplaceDialog.ui \
Expand Down
96 changes: 92 additions & 4 deletions src/NotepadNext/NotepadNextApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include "EditorConfigAppDecorator.h"

#include "ILexer.h"
#include "Lexilla.h"
#include "SciLexer.h"

#include <QCommandLineParser>
#include <QSettings>

Expand Down Expand Up @@ -156,15 +160,21 @@ bool NotepadNextApplication::initGui()
}
});

applyArguments(SingleApplication::arguments());
// Keep Lua's editor reference up to date
connect(windows.first(), &MainWindow::editorActivated, this, [](ScintillaNext *editor) {
LuaExtension::Instance().setEditor(editor);
});

// Everything should be ready at this point
applyArguments(SingleApplication::arguments());

// If the window does not have any editors (meaning the applyArguments() did not
// have any files to open) then create a new empty file
if (windows.first()->getDockedEditor()->count() == 0) {
if (windows.first()->editorCount() == 0) {
windows.first()->newFile();
}

// Everything should be ready at this point

windows.first()->show();
windows.first()->bringWindowToForeground();

Expand All @@ -188,7 +198,85 @@ QString NotepadNextApplication::getFileDialogFilter() const
return table.concat(filter, ";;")
)=");

return filter;
return filter;
}

QStringList NotepadNextApplication::getLanguages() const
{
return getLuaState()->executeAndReturn<QStringList>(
R"(
local names = {}
for k in pairs(languages) do table.insert(names, k) end
table.sort(names, function (a, b) return string.lower(a) < string.lower(b) end)
return names
)");
}

void NotepadNextApplication::setEditorLanguage(ScintillaNext *editor, const QString &languageName) const
{
LuaExtension::Instance().setEditor(editor);

getLuaState()->execute(QString("languageName = \"%1\"").arg(QString(languageName)).toLatin1().constData());
const QString lexer = getLuaState()->executeAndReturn<QString>("return languages[languageName].lexer");

editor->languageName = languageName;
auto lexerInstance = CreateLexer(lexer.toLatin1().constData());
editor->setILexer((sptr_t) lexerInstance);

getLuaState()->execute(R"(
local L = languages[languageName]
editor.UseTabs = (L.tabSettings or "tabs") == "tabs"
editor.TabWidth = L.tabSize or 4
if L.styles then
for name, style in pairs(L.styles) do
editor.StyleFore[style.id] = style.fgColor
editor.StyleBack[style.id] = style.bgColor
if style.fontStyle then
if style.fontStyle & 1 == 1 then
editor.StyleBold[style.id] = true
end
if style.fontStyle & 2 == 2 then
editor.StyleItalic[style.id] = true
end
if style.fontStyle & 4 == 4 then
editor.StyleUnderline[style.id] = true
end
end
end
end
if L.keywords then
for id, kw in pairs(L.keywords) do
editor.KeyWords[id] = kw
end
end
if L.properties then
for p,v in pairs(L.properties) do
editor.Property[p] = v
end
end
editor.Property["fold"] = "1"
editor.Property["fold.compact"] = "0"
-- The document needs redone, but don't force it to do the whole thing
-- since SC_IDLESTYLING_TOVISIBLE is used
editor:Colourise(0, 1);
)");
}

QString NotepadNextApplication::detectLanguageFromExtension(const QString &extension) const
{
return getLuaState()->executeAndReturn<QString>(QString(R"(
local ext = "%1"
for name, L in pairs(languages) do
for _, v in ipairs(L.extensions) do
if v == ext then
return name
end
end
end
return "null"
)").arg(extension).toLatin1().constData());
}

void NotepadNextApplication::applyArguments(const QStringList &args)
Expand Down
5 changes: 5 additions & 0 deletions src/NotepadNext/NotepadNextApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MainWindow;
class LuaState;
class EditorManager;
class RecentFilesListManager;
class ScintillaNext;

class NotepadNextApplication : public SingleApplication
{
Expand All @@ -48,6 +49,10 @@ class NotepadNextApplication : public SingleApplication
QString getFileDialogFilter() const;
Settings *getSettings() const { return settings; }

QStringList getLanguages() const;
void setEditorLanguage(ScintillaNext *editor, const QString &languageName) const;
QString detectLanguageFromExtension(const QString &extension) const;

private:
EditorManager *editorManager;
RecentFilesListManager *recentFilesListManager;
Expand Down
Loading

0 comments on commit 50d713e

Please sign in to comment.