Highlighter für Kommentare hinzugefügt.
13
BareCode.desktop
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Version=1.0
|
||||||
|
Type=Application
|
||||||
|
Name=BareCode
|
||||||
|
GenericName=Code Editor
|
||||||
|
Comment=Modularer Code-Editor für HTML, PHP, CSS und mehr
|
||||||
|
Exec=BareCode %F
|
||||||
|
Icon=barecode
|
||||||
|
Terminal=false
|
||||||
|
Categories=Development;TextEditor;
|
||||||
|
MimeType=text/plain;text/html;text/css;text/x-php;text/x-csrc;text/x-chdr;text/x-c++src;text/x-c++hdr;
|
||||||
|
Keywords=editor;code;html;php;css;c++;
|
||||||
|
StartupWMClass=BareCode
|
||||||
1
BareCode.rc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
IDI_ICON1 ICON "resources/BareCode.ico"
|
||||||
@@ -43,10 +43,18 @@ add_subdirectory(src)
|
|||||||
qt_add_resources(BARECODE_RESOURCES resources/resources.qrc)
|
qt_add_resources(BARECODE_RESOURCES resources/resources.qrc)
|
||||||
|
|
||||||
# Main executable
|
# Main executable
|
||||||
qt_add_executable(BareCode
|
if(WIN32)
|
||||||
main.cpp
|
qt_add_executable(BareCode
|
||||||
${BARECODE_RESOURCES}
|
main.cpp
|
||||||
)
|
BareCode.rc
|
||||||
|
${BARECODE_RESOURCES}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
qt_add_executable(BareCode
|
||||||
|
main.cpp
|
||||||
|
${BARECODE_RESOURCES}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(BareCode PRIVATE
|
target_link_libraries(BareCode PRIVATE
|
||||||
BareCode_Core
|
BareCode_Core
|
||||||
@@ -67,3 +75,18 @@ include(GNUInstallDirs)
|
|||||||
install(TARGETS BareCode
|
install(TARGETS BareCode
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
# Icons in den Standard-Hicolor-Theme-Pfad installieren
|
||||||
|
foreach(SIZE 16 32 48 64 128 256 512)
|
||||||
|
install(FILES resources/icon_${SIZE}.png
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps
|
||||||
|
RENAME barecode.png
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# .desktop Datei
|
||||||
|
install(FILES BareCode.desktop
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|||||||
12
main.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QIcon>
|
||||||
#include "core/MainWindow.h"
|
#include "core/MainWindow.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -9,6 +10,17 @@ int main(int argc, char *argv[])
|
|||||||
app.setApplicationVersion("1.0.0");
|
app.setApplicationVersion("1.0.0");
|
||||||
app.setOrganizationName("BareCode");
|
app.setOrganizationName("BareCode");
|
||||||
|
|
||||||
|
// Icon in allen verfügbaren Größen setzen
|
||||||
|
QIcon appIcon;
|
||||||
|
appIcon.addFile(":/icon_16.png", QSize(16, 16));
|
||||||
|
appIcon.addFile(":/icon_32.png", QSize(32, 32));
|
||||||
|
appIcon.addFile(":/icon_48.png", QSize(48, 48));
|
||||||
|
appIcon.addFile(":/icon_64.png", QSize(64, 64));
|
||||||
|
appIcon.addFile(":/icon_128.png", QSize(128, 128));
|
||||||
|
appIcon.addFile(":/icon_256.png", QSize(256, 256));
|
||||||
|
appIcon.addFile(":/icon_512.png", QSize(512, 512));
|
||||||
|
app.setWindowIcon(appIcon);
|
||||||
|
|
||||||
MainWindow window;
|
MainWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
|
|||||||
BIN
resources/BareCode.ico
Normal file
|
After Width: | Height: | Size: 707 B |
BIN
resources/icon_128.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
resources/icon_16.png
Normal file
|
After Width: | Height: | Size: 685 B |
BIN
resources/icon_256.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
resources/icon_32.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
resources/icon_48.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
resources/icon_512.png
Normal file
|
After Width: | Height: | Size: 269 KiB |
BIN
resources/icon_64.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
@@ -1,5 +1,11 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<!-- Icons and other assets can be added here -->
|
<file>icon_512.png</file>
|
||||||
|
<file>icon_256.png</file>
|
||||||
|
<file>icon_128.png</file>
|
||||||
|
<file>icon_64.png</file>
|
||||||
|
<file>icon_48.png</file>
|
||||||
|
<file>icon_32.png</file>
|
||||||
|
<file>icon_16.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -373,6 +373,62 @@ void PhpHighlighter::highlightPhpRange(const QString &text, int start, int lengt
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /* */ Block-Kommentare innerhalb des PHP-Bereichs mehrzeilig behandeln.
|
||||||
|
// Block-Zustand 3 = wir sind mitten in einem /* ... */ PHP-Kommentar.
|
||||||
|
static const QRegularExpression blockOpen(R"(/\*)");
|
||||||
|
static const QRegularExpression blockClose(R"(\*/)");
|
||||||
|
|
||||||
|
int searchFrom = 0;
|
||||||
|
|
||||||
|
// Waren wir bereits in einem Block-Kommentar?
|
||||||
|
if (previousBlockState() == 3)
|
||||||
|
{
|
||||||
|
QRegularExpressionMatch closeMatch = blockClose.match(phpText, 0);
|
||||||
|
if (closeMatch.hasMatch())
|
||||||
|
{
|
||||||
|
const int end = static_cast<int>(closeMatch.capturedStart())
|
||||||
|
+ static_cast<int>(closeMatch.capturedLength());
|
||||||
|
setFormat(start, end, m_phpCommentFormat);
|
||||||
|
searchFrom = end;
|
||||||
|
// Block-Kommentar geschlossen — Zustand wird weiter unten gesetzt
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Gesamter Bereich ist noch Kommentar
|
||||||
|
setFormat(start, length, m_phpCommentFormat);
|
||||||
|
setCurrentBlockState(3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neue /* ... */ Kommentare innerhalb dieses PHP-Bereichs suchen
|
||||||
|
while (searchFrom < phpText.length())
|
||||||
|
{
|
||||||
|
QRegularExpressionMatch openMatch = blockOpen.match(phpText, searchFrom);
|
||||||
|
if (!openMatch.hasMatch())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int openPos = static_cast<int>(openMatch.capturedStart());
|
||||||
|
QRegularExpressionMatch closeMatch = blockClose.match(phpText, openPos + 2);
|
||||||
|
|
||||||
|
if (closeMatch.hasMatch())
|
||||||
|
{
|
||||||
|
const int closeEnd = static_cast<int>(closeMatch.capturedStart())
|
||||||
|
+ static_cast<int>(closeMatch.capturedLength());
|
||||||
|
setFormat(start + openPos, closeEnd - openPos, m_phpCommentFormat);
|
||||||
|
searchFrom = closeEnd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Kein schließendes */ gefunden — geht über Zeilenende
|
||||||
|
setFormat(start + openPos, length - openPos, m_phpCommentFormat);
|
||||||
|
setCurrentBlockState(3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhpHighlighter::highlightBlock(const QString &text)
|
void PhpHighlighter::highlightBlock(const QString &text)
|
||||||
@@ -380,8 +436,10 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
|||||||
// Zuerst HTML-Basis-Regeln auf den gesamten Text anwenden
|
// Zuerst HTML-Basis-Regeln auf den gesamten Text anwenden
|
||||||
SyntaxHighlighter::highlightBlock(text);
|
SyntaxHighlighter::highlightBlock(text);
|
||||||
|
|
||||||
// Dann PHP-Blöcke <?php ... ?> und <?= ... ?> finden und überschreiben
|
// Block-Zustände:
|
||||||
// Block-Zustände: 0 = HTML, 2 = innerhalb PHP-Block
|
// 0 = HTML-Modus
|
||||||
|
// 2 = innerhalb PHP-Block (kein /* */ Kommentar)
|
||||||
|
// 3 = innerhalb PHP /* */ Block-Kommentar
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
|
|
||||||
static const QRegularExpression phpOpen(R"(<\?(?:php|=)?\s?)",
|
static const QRegularExpression phpOpen(R"(<\?(?:php|=)?\s?)",
|
||||||
@@ -390,9 +448,9 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
if (previousBlockState() == 2)
|
if (previousBlockState() == 2 || previousBlockState() == 3)
|
||||||
{
|
{
|
||||||
// Wir befinden uns bereits in einem PHP-Block
|
// Wir befinden uns bereits in einem PHP-Block (ggf. in einem Kommentar)
|
||||||
QRegularExpressionMatch closeMatch = phpClose.match(text, 0);
|
QRegularExpressionMatch closeMatch = phpClose.match(text, 0);
|
||||||
if (closeMatch.hasMatch())
|
if (closeMatch.hasMatch())
|
||||||
{
|
{
|
||||||
@@ -408,7 +466,12 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
highlightPhpRange(text, 0, text.length());
|
highlightPhpRange(text, 0, text.length());
|
||||||
setCurrentBlockState(2);
|
// highlightPhpRange setzt den Zustand auf 3 falls nötig,
|
||||||
|
// sonst behalten wir 2 (offener PHP-Block ohne Kommentar)
|
||||||
|
if (currentBlockState() != 3)
|
||||||
|
{
|
||||||
|
setCurrentBlockState(2);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,7 +487,6 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
|||||||
const int openStart = static_cast<int>(openMatch.capturedStart());
|
const int openStart = static_cast<int>(openMatch.capturedStart());
|
||||||
const int openEnd = openStart + static_cast<int>(openMatch.capturedLength());
|
const int openEnd = openStart + static_cast<int>(openMatch.capturedLength());
|
||||||
|
|
||||||
// <?php-Tag selbst einfärben
|
|
||||||
setFormat(openStart, static_cast<int>(openMatch.capturedLength()), m_phpTagFormat);
|
setFormat(openStart, static_cast<int>(openMatch.capturedLength()), m_phpTagFormat);
|
||||||
|
|
||||||
QRegularExpressionMatch closeMatch = phpClose.match(text, openEnd);
|
QRegularExpressionMatch closeMatch = phpClose.match(text, openEnd);
|
||||||
@@ -441,9 +503,11 @@ void PhpHighlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// PHP-Block geht über Zeilenende hinaus
|
|
||||||
highlightPhpRange(text, openEnd, text.length() - openEnd);
|
highlightPhpRange(text, openEnd, text.length() - openEnd);
|
||||||
setCurrentBlockState(2);
|
if (currentBlockState() != 3)
|
||||||
|
{
|
||||||
|
setCurrentBlockState(2);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||