Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #9

Merged
merged 2 commits into from
Oct 7, 2024
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
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-04T22:04:12. -->
<!-- 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_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
-DCMAKE_BUILD_TYPE:STRING=Debug
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-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_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
-DCMAKE_BUILD_TYPE:STRING=Release
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-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
23 changes: 23 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);

QMenu *menuLanguage = ui->menu_Language;
QMenu *menuZ = new QMenu("z", this);
QAction *actionZ80 = new QAction("Z80", this);
menuZ->addAction(actionZ80);
menuLanguage->addMenu(menuZ);
connect(actionZ80, &QAction::triggered, this, &MainWindow::onActionZ80Triggered);

QActionGroup *group = new QActionGroup(this);
group->setExclusive(true); // Ensure only one action is checked at a time

Expand Down Expand Up @@ -305,3 +312,19 @@ void MainWindow::on_action_Word_wrap_triggered()
// TODO: Word Wrap
}

void MainWindow::onActionZ80Triggered()
{
qDebug() << "Z80 action triggered!";
}

void MainWindow::on_actionAbout_Qt_triggered()
{
QApplication::aboutQt();
}


void MainWindow::on_action_About_Notepad_triggered()
{
// TODO: About Remisa Yousefvand
}

5 changes: 5 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private slots:
void on_actionC_lose_all_triggered();
void on_actionC_3_triggered();
void on_actionPython_triggered();
void onActionZ80Triggered();

void on_actionSav_e_all_triggered();

Expand All @@ -57,6 +58,10 @@ private slots:

void on_action_Word_wrap_triggered();

void on_actionAbout_Qt_triggered();

void on_action_About_Notepad_triggered();

private:
Ui::MainWindow *ui;
void initialize();
Expand Down
22 changes: 20 additions & 2 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@
<addaction name="actionInterpret_as_UTF_16BE_UCS_2_Big_Endian"/>
<addaction name="actionInterpret_As"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="action_Reload_file_interpreted_as"/>
<addaction name="actionConvert_to_UTF_8"/>
<addaction name="actionConvert_to_UTF_8_without_BOM"/>
Expand Down Expand Up @@ -519,6 +518,7 @@
<string>Settin&amp;gs</string>
</property>
<addaction name="action_Prefrences"/>
<addaction name="separator"/>
<addaction name="action_Show_menu_bar"/>
<addaction name="actionS_how_Toolbar"/>
</widget>
Expand Down Expand Up @@ -834,6 +834,9 @@
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset theme="media-playlist-repeat"/>
</property>
<property name="text">
<string>&amp;Word wrap</string>
</property>
Expand Down Expand Up @@ -900,7 +903,7 @@
</action>
<action name="actionConvert_to_UTF_8">
<property name="text">
<string>Convert to UTF-8</string>
<string>&amp;Convert to UTF-8</string>
</property>
</action>
<action name="actionConvert_to_UTF_8_without_BOM">
Expand Down Expand Up @@ -929,11 +932,23 @@
</property>
</action>
<action name="action_Show_menu_bar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Show Menubar</string>
</property>
</action>
<action name="actionS_how_Toolbar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>S&amp;how Toolbar</string>
</property>
Expand All @@ -949,6 +964,9 @@
</property>
</action>
<action name="action_Open_a_new_window">
<property name="icon">
<iconset theme="window-new"/>
</property>
<property name="text">
<string>&amp;Open a new window</string>
</property>
Expand Down
Loading