Skip to content

Commit

Permalink
Refactoring & File menu completed
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Oct 28, 2024
1 parent cb34b4b commit 042b8a6
Show file tree
Hide file tree
Showing 22 changed files with 2,292 additions and 872 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ jobs:
}
}
# Install Qt
# Install Qt with simplified arguments
Write-Host "Installing Qt..."
Start-Process -FilePath $qtInstallerPath -ArgumentList `
'--accept-messages', '--confirm-command', '--no-interaction', `
'--platform minimal', '--select-components qt.qt6.653.win64_msvc2019_64', `
'--install-root C:\Qt' -NoNewWindow -Wait
'--accept-messages', '--confirm-command', '--platform minimal' `
-NoNewWindow -Wait
# Verify installation
if (!(Test-Path "C:\Qt\6.5.3\msvc2019_64")) {
# Verify installation path exists
if (!(Test-Path "C:\Qt")) {
throw "Qt installation failed!"
}
Expand Down
62 changes: 45 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project(Notepad-- VERSION 0.1 LANGUAGES CXX)

# Enable automatic handling of Qt6 features
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
Expand All @@ -10,51 +11,72 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find Qt6 libraries
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Concurrent)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets PrintSupport)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
# Enable strict compiler warnings (optional)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Translation file path in 'translations' folder
# Find Qt6 packages in a single call
find_package(Qt6 REQUIRED COMPONENTS
Core
Gui
Widgets
Concurrent
PrintSupport
LinguistTools
)

# Translation files (optional)
set(TS_FILES translations/Notepad--_en_GB.ts)

# Project sources, organized under 'src' and 'src/languages' folders
# Define project sources
set(PROJECT_SOURCES
src/main.cpp
src/mainwindow.ui
src/mainwindow.cpp
src/mainwindow.h
src/mainwindow.ui
src/document.cpp
src/document.h
src/codeeditor.cpp
src/codeeditor.h
src/fileloaderworker.cpp
src/fileloaderworker.h
src/languages/languagemanager.cpp
src/languages/languagemanager.h
src/languages/cppsyntaxhighlighter.cpp
src/languages/cppsyntaxhighlighter.h
src/languages/pythonsyntaxhighlighter.cpp
src/languages/pythonsyntaxhighlighter.h
src/languages/languagemanager.cpp
src/languages/languagemanager.h
src/mainwindow/fileoperations.cpp
src/mainwindow/fileoperations.h
src/mainwindow/recentfiles.cpp
src/mainwindow/recentfiles.h
src/mainwindow/settings.cpp
src/mainwindow/settings.h
src/mainwindow/helpers.cpp
src/mainwindow/helpers.h
src/mainwindow/formatting.cpp
src/mainwindow/formatting.h
src/mainwindow/session.cpp
src/mainwindow/session.h
)

# Add executable for Qt6
# Add Qt6 executable
qt_add_executable(Notepad--
MANUAL_FINALIZATION
${PROJECT_SOURCES}
src/fileloaderworker.h src/fileloaderworker.cpp

)

# Link necessary Qt6 libraries
# Link Qt6 libraries
target_link_libraries(Notepad--
PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Concurrent Qt6::PrintSupport
)

# Set target properties for macOS/iOS
# Set properties for macOS/iOS and Windows
set_target_properties(Notepad-- PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)

Expand All @@ -66,5 +88,11 @@ install(TARGETS Notepad--
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# Finalize executable for Qt6
# Optional: Add translation files to target (if available)
qt_add_translation(QM_FILES ${TS_FILES})
if(QM_FILES)
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/translations)
endif()

# Finalize the Qt6 executable setup
qt_finalize_executable(Notepad--)
34 changes: 17 additions & 17 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.2, 2024-10-22T11:30:32. -->
<!-- Written by QtCreator 14.0.2, 2024-10-28T06:02:02. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -94,22 +94,22 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 6.7.2 (System)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 6.7.2 (System)</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{5fcd4be8-31fb-480b-a925-a47ce5b3bbaf}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="CMake.Build.Type">Debug</value>
<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">-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_GENERATOR:STRING=Ninja</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">-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}</value>
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_GENERATOR:STRING=Ninja</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 Expand Up @@ -243,7 +243,7 @@
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/data/Code/Qt/Notepad--/build/Desktop-Release</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/data/Code/Qt/Notepad--/build/Desktop-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
Expand Down
13 changes: 10 additions & 3 deletions src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "languages/languagemanager.h"

Document::Document(const QString &filePath, QWidget *parent)
: QWidget(parent), m_filePath(filePath), m_isModified(false), m_totalBytesRead(0), m_workerThread(new QThread(this)) {
: QWidget(parent), m_totalBytesRead(0), m_workerThread(new QThread(this)), m_filePath(filePath), m_isModified(false) {

qDebug() << "Document created for file: " << filePath;
// Initialize the code editor and layout
Expand Down Expand Up @@ -125,10 +125,12 @@ void Document::onLoadingStarted() {
}

void Document::onSavingStarted() {
qDebug() << "Saving started for document:" << m_filePath;
m_isSaving = true;
m_statusLabel->setText("Saving File...");
m_statusLabel->setVisible(true);
m_progressBar->setVisible(true);
m_progressBar->setValue(0);
m_progressBar->setVisible(true);
}

void Document::onLoadingProgress(int progress) {
Expand All @@ -148,6 +150,8 @@ void Document::onSavingProgress(int progress) {
m_progressBar->setValue(progress);

if (progress == 100) {
qDebug() << "File saving complete.";
onSavingFinished();
emit hideProgressBar();
}
}
Expand Down Expand Up @@ -176,8 +180,10 @@ void Document::onLoadingFinished() {
}

void Document::onSavingFinished() {
qDebug() << "Saving finished for document:" << m_filePath;
m_isSaving = false;
m_statusLabel->setText("");
m_statusLabel->clear();
m_statusLabel->setVisible(false);
m_progressBar->setVisible(false);
}

Expand Down Expand Up @@ -259,6 +265,7 @@ void Document::saveFile() {
m_progressBar->setValue(0);
m_progressBar->setVisible(true);
m_statusLabel->setText("Saving File...");
m_statusLabel->setVisible(true);

// Start the save operation in the worker thread
m_isSaving = true;
Expand Down
1 change: 1 addition & 0 deletions src/fileloaderworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "document.h"

class Document;
class MainWindow;

class FileLoaderWorker : public QObject {
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);

qRegisterMetaType<QStringList>("QStringList");

MainWindow w;
w.show();

Expand Down
Loading

0 comments on commit 042b8a6

Please sign in to comment.