Skip to content

Commit

Permalink
apply highlighting fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Oct 7, 2024
1 parent 5a602a1 commit 927f0e3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev ninja-build qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
echo "CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt5" >> $GITHUB_ENV
sudo apt-get update
sudo apt-get install -y ninja-build qt6-base-dev qt6-base-dev-tools qt6-qmake
echo "CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6" >> $GITHUB_ENV
# Install dependencies for macOS
- name: Install dependencies (macOS)
Expand All @@ -49,7 +49,12 @@ jobs:
# Set up MSVC on Windows
- name: Set up MSVC (Windows)
if: matrix.os == 'windows-latest'
uses: microsoft/setup-msbuild@v1 # Corrected action
uses: microsoft/setup-msbuild@v1 # Ensure MSVC is set up
- name: Set up VC Environment (Windows)
if: matrix.os == 'windows-latest'
uses: microsoft/setup-vc@v1
with:
arch: x64

# Set reusable strings
- name: Set reusable strings
Expand Down
26 changes: 13 additions & 13 deletions CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 14.0.1, 2024-10-06T22:30:56. -->
<!-- Written by QtCreator 14.0.1, 2024-10-07T04:55:20. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -102,14 +102,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_GENERATOR:STRING=Ninja</value>
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Debug</value>
Expand Down Expand Up @@ -160,14 +160,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_GENERATOR:STRING=Ninja</value>
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
Expand Down
44 changes: 18 additions & 26 deletions src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,17 @@ Document::Document(const QString &filePath, QWidget *parent)
m_fileLoaderWorker = new FileLoaderWorker(m_filePath, this);
m_fileLoaderWorker->moveToThread(m_workerThread);

// Connect worker signals
connect(m_fileLoaderWorker, &FileLoaderWorker::loadingStarted, this, &Document::onLoadingStarted);
connect(m_fileLoaderWorker, &FileLoaderWorker::errorOccurred, this, &Document::onLoadingError);
connect(m_fileLoaderWorker, &FileLoaderWorker::contentLoaded, this, &Document::onContentLoaded, Qt::UniqueConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::fileSizeDetermined, this, &Document::onFileSizeDetermined);

connect(m_fileLoaderWorker, &FileLoaderWorker::savingStarted, this, &Document::onSavingStarted);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingProgress, this, &Document::onSavingProgress);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished);
connect(this, &Document::savingProgress, m_progressBar, &QProgressBar::setValue);

connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, &Document::onLoadingProgress, Qt::UniqueConnection);
/*
connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, [this](int progress) {
QMetaObject::invokeMethod(m_progressBar, "setValue", Qt::QueuedConnection, Q_ARG(int, progress));
});
*/

connect(m_fileLoaderWorker, &FileLoaderWorker::loadingFinished, this, &Document::onLoadingFinished);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished);
connect(m_fileLoaderWorker, &FileLoaderWorker::loadingStarted, this, &Document::onLoadingStarted, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::errorOccurred, this, &Document::onLoadingError, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::contentLoaded, this, &Document::onContentLoaded, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::fileSizeDetermined, this, &Document::onFileSizeDetermined, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingStarted, this, &Document::onSavingStarted, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingProgress, this, &Document::onSavingProgress, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::loadingProgress, this, &Document::onLoadingProgress, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::loadingFinished, this, &Document::onLoadingFinished, Qt::QueuedConnection);
connect(this, &Document::savingProgress, m_progressBar, &QProgressBar::setValue, Qt::QueuedConnection);
connect(m_fileLoaderWorker, &FileLoaderWorker::savingFinished, this, &Document::onSavingFinished, Qt::QueuedConnection);

// Start worker thread
m_workerThread->start();
Expand Down Expand Up @@ -183,7 +174,9 @@ QString Document::filePath() const {

void Document::openFile(const QString &filePath) {
m_filePath = filePath;
qDebug() << "Opening file:" << m_filePath;
qDebug() << "Opening file: " << m_filePath;
m_fileExtension = QFileInfo(filePath).suffix();
qDebug() << "file extension is: " << m_filePath;

qDebug() << "About to emit uiReady signal from openFile...";
// Emit the signal to start loading the file in the worker thread
Expand Down Expand Up @@ -304,15 +297,14 @@ void Document::goToLineNumberInText(QWidget* parent) {
void Document::applySyntaxHighlighter(const QString &language) {
qDebug() << "Applying syntax highlighter for language:" << language;

if (syntaxHighlighter) {
delete syntaxHighlighter;
syntaxHighlighter = nullptr;
}
// Automatically replaces and deletes the old syntax highlighter if it exists
syntaxHighlighter = nullptr;

// Assuming LanguageManager handles creating syntax highlighters for specific languages
syntaxHighlighter = LanguageManager::createHighlighterForExtension(language, editor->document());
syntaxHighlighter = std::unique_ptr<QSyntaxHighlighter>(LanguageManager::createHighlighterForExtension(language, editor->document()));

if (syntaxHighlighter) {
qDebug() << "Rehighlighting document...";
syntaxHighlighter->rehighlight();
qDebug() << "Syntax highlighter applied for language:" << language;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private slots:
QString m_fileExtension;
QFile m_file;
CodeEditor *editor;
QSyntaxHighlighter *syntaxHighlighter;
std::unique_ptr<QSyntaxHighlighter> syntaxHighlighter;
qint64 m_fileSize;
QMap<qint64, QString> m_changedSegments;
QString m_currentText;
Expand Down
19 changes: 13 additions & 6 deletions src/languages/languagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
#include "pythonsyntaxhighlighter.h"

QSyntaxHighlighter* LanguageManager::createHighlighterForExtension(const QString &identifier, QTextDocument *document) {
if (identifier == "C++" || identifier == "cpp" || identifier == "cxx" || identifier == "h" || identifier == "hpp") {
return new CppSyntaxHighlighter(document);
} else if (identifier == "Python" || identifier == "py") {
return new PythonSyntaxHighlighter(document);
qDebug() << "Creating highlighter for language:" << identifier << "with document:" << document;
if (document == nullptr) {
qDebug() << "Error: document is nullptr";
return nullptr;
}

// Add more language mappings here as needed
// Create highlighter based on language identifier
if (identifier == "C++") {
auto* highlighter = new CppSyntaxHighlighter(document);
qDebug() << "Created C++ syntax highlighter at:" << highlighter;
return highlighter;
}

return nullptr; // Return nullptr if no matching highlighter is found
// Return nullptr if no matching highlighter is found
qDebug() << "Error: No matching highlighter found for language:" << identifier;
return nullptr;
}

QString LanguageManager::getLanguageFromExtension(const QString &extension) {
Expand Down

0 comments on commit 927f0e3

Please sign in to comment.