Skip to content

Operation context menu #29

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

Merged
merged 35 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
94f9c09
Feature: Added File/Folder deletion in context menu
chrisdedman Mar 31, 2025
8a5b00e
Added context menu headers
chrisdedman Mar 31, 2025
e12fe53
UnitTest: Added unit test for deletion file
chrisdedman Mar 31, 2025
d5fb7bd
Doc: Fixed typo in the documentation
chrisdedman Mar 31, 2025
165cab7
[Refactor] Separated logic for deleting file and folder
chrisdedman Apr 1, 2025
42fbef0
[Add] Added auto indentation when keyboard enter key is pressed + del…
chrisdedman Apr 1, 2025
b213da7
[Refactor] Move context menu action logic from Tree to FileManager
chrisdedman Apr 1, 2025
82c9728
[Refactor] Move context menu logic to FileManager + [Add] Added call …
chrisdedman Apr 1, 2025
75ae46b
[Feature] Added renaming file/folder logic + moved deletion file/fold…
chrisdedman Apr 1, 2025
7187bb7
[Test] Added unit test for renaming path
chrisdedman Apr 1, 2025
0d62803
[Make] Updated CodeAstra versioning
chrisdedman Apr 1, 2025
4d2ee4b
[Add] Added function header for new folder + duplcated path
chrisdedman Apr 4, 2025
d400d93
[Feature] Added duplicate a file + check if a path if valid
chrisdedman Apr 4, 2025
4477f41
[Feature] Added duplicate file action to the context
chrisdedman Apr 4, 2025
afd6918
[UnitTests] Added init unit tests for new folder and duplicate path
chrisdedman Apr 4, 2025
4b67933
[Make] added flag for build
chrisdedman Apr 4, 2025
de45f5e
[Refactor] refactor makefile for uninstall software
chrisdedman Apr 4, 2025
8fa167f
[Feature] Added safe guard to files/folders deletion from permanent t…
chrisdedman Apr 4, 2025
d6282d2
[UnitTests] Added duplicate path test + refactor temporary file creat…
chrisdedman Apr 4, 2025
afe903a
[Update] Added structure for operation result
chrisdedman Apr 7, 2025
2cfaa38
[Feature] Implemented newFile + newFolder with a refactor of some oth…
chrisdedman Apr 7, 2025
4a37ab5
[Feature] Added newFile and newFolder context action
chrisdedman Apr 7, 2025
3b2ce12
[UnitTests] Added unit tests for newFile and newFolder actions
chrisdedman Apr 7, 2025
88294dd
[fix] wrapped result.message to QString
chrisdedman Apr 7, 2025
b09ed0a
[Feature] renamed test tree to test file manager
chrisdedman Apr 17, 2025
67b80d8
[refactor] Improve test file manager code readability and structure
chrisdedman Apr 17, 2025
c7391d6
[refactor] Change file manager methods to return OperationResult inst…
chrisdedman Apr 17, 2025
e977e10
[refactor] Added isSuccessful method to Tree class for improved opera…
chrisdedman Apr 17, 2025
5e652e0
[refactor] Simplify file operation handling in Tree class by centrali…
chrisdedman Apr 17, 2025
157e204
[refactor] Clean up Makefile structure and improve build process clarity
chrisdedman Apr 17, 2025
a7d22b4
[refactor] Streamline CMakeLists.txt by consolidating project setup a…
chrisdedman Apr 17, 2025
ae0883b
[Refactor] Create CMakeLists.txt for project configuration and build …
chrisdedman Apr 17, 2025
fe46d87
[Refactor] refactor CMakeLists.txt for test executables and library l…
chrisdedman Apr 17, 2025
614f331
[Refactor] Improve test cases in TestFileManager by utilizing QTempor…
chrisdedman Apr 17, 2025
46d2d41
[Refactor] Removed whitespace
chrisdedman Apr 17, 2025
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
142 changes: 18 additions & 124 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,141 +1,35 @@
cmake_minimum_required(VERSION 3.16)

# Project name
set(TARGET_NAME CodeAstraApp)
set(EXECUTABLE_NAME CodeAstra)
project(CodeAstra VERSION 0.1.0 DESCRIPTION "Code Editor written in modern C++ using Qt6")

set(QT_MAJOR_VERSION 6)

project(${TARGET_NAME} VERSION 0.0.1 DESCRIPTION "Code Editor written in C++ using Qt6")

# Enable automatic MOC (Meta-Object Compiler) handling for Qt
set(CMAKE_AUTOMOC ON)

# Set the CXX standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set default build output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
# Use cmake/ for custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Detect operating system
if(WIN32)
set(OS_NAME "Windows")
elseif(APPLE)
set(OS_NAME "macOS")
else()
set(OS_NAME "Linux")
endif()
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

message(STATUS "Building for ${OS_NAME}")
# Enable Qt tools
set(CMAKE_AUTOMOC ON)

# Locate Qt installation
if(DEFINED ENV{Qt${QT_MAJOR_VERSION}_HOME})
set(Qt_DIR "$ENV{Qt${QT_MAJOR_VERSION}_HOME}")
message(STATUS "Using Qt from: ${Qt_DIR}")
else()
if(WIN32)
set(Qt_DIR "C:/Qt/${QT_MAJOR_VERSION}/msvc2022_64/lib/cmake/Qt${QT_MAJOR_VERSION}")
elseif(APPLE)
set(Qt_DIR "/usr/local/opt/qt/lib/cmake/Qt${QT_MAJOR_VERSION}")
else()
set(Qt_DIR "/usr/lib/cmake/Qt${QT_MAJOR_VERSION}")
endif()
message(STATUS "Using default Qt path: ${Qt_DIR}")
endif()
# Define target names
set(TARGET_NAME CodeAstra)
set(EXECUTABLE_NAME ${TARGET_NAME}App)

# Set Qt path for find_package
set(CMAKE_PREFIX_PATH ${Qt_DIR})
# Set Qt version
set(QT_MAJOR_VERSION 6)

# Find Qt components
# Find Qt
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Widgets Test)

# Locate yaml-cpp
if(APPLE)
set(yaml-cpp_DIR "/opt/homebrew/Cellar/yaml-cpp/0.8.0/lib/cmake/yaml-cpp")
endif()
# yaml-cpp
find_package(yaml-cpp REQUIRED CONFIG)

# Copy YAML files to the build directory (non-macOS case)
set(YAML_SOURCE_DIR ${CMAKE_SOURCE_DIR}/config)
set(YAML_DEST_DIR ${CMAKE_BINARY_DIR}/config)
file(MAKE_DIRECTORY ${YAML_DEST_DIR})
file(GLOB YAML_FILES "${YAML_SOURCE_DIR}/*.yaml")

foreach(YAML_FILE ${YAML_FILES})
file(COPY ${YAML_FILE} DESTINATION ${YAML_DEST_DIR})
endforeach()

# Create the CodeAstra library
add_library(${TARGET_NAME}
src/MainWindow.cpp
src/CodeEditor.cpp
src/Tree.cpp
src/FileManager.cpp
src/Syntax.cpp
src/SyntaxManager.cpp
include/MainWindow.h
include/CodeEditor.h
include/Tree.h
include/LineNumberArea.h
include/FileManager.h
include/SyntaxManager.h
include/Syntax.h
)

# Link YAML-CPP to the CodeAstra library
target_link_libraries(${TARGET_NAME} PRIVATE yaml-cpp)

# Create the executable for the application
add_executable(${EXECUTABLE_NAME} src/main.cpp)

# Ensure YAML config files are copied into macOS app bundle
# if(APPLE)
# add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${YAML_SOURCE_DIR}" "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
# COMMENT "Copying YAML config files into macOS app bundle..."
# )
# endif()

# Link the main executable with the CodeAstra library and Qt libraries
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${TARGET_NAME} Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets)

# Add the tests subdirectory
# Add subdirectories
add_subdirectory(src)
add_subdirectory(tests)

# Qt resource files
qt_add_resources(APP_RESOURCES resources.qrc)
target_sources(${EXECUTABLE_NAME} PRIVATE ${APP_RESOURCES})

# Compiler flags per OS
if(MSVC)
target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /WX)
elseif(APPLE)
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
# set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
else()
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()

# Include directories
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${Qt${QT_MAJOR_VERSION}_INCLUDE_DIRS})
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)

# Set output names properly for Debug and Release
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEBUG_OUTPUT_NAME "${EXECUTABLE_NAME}d"
RELEASE_OUTPUT_NAME ${EXECUTABLE_NAME}
)

# Link necessary Qt libraries to CodeAstra library
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets)

# Ensure correct linking of yaml-cpp (macOS)
if(APPLE)
target_include_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/include)
target_link_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/lib)
endif()
29 changes: 13 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
PROJECT = CodeAstra
BUILD_DIR = $(PWD)/build
EXECUTABLE = $(PROJECT)

# Set CMake options
CMAKE_OPTIONS = ..

# Default target: Run CMake and install the project
all: build install
.PHONY: all build clean install build_tests test

all: install

# Run CMake to build the project
build:
@echo "Building $(PROJECT) with CMake..."
@echo "Building $(PROJECT)..."
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && cmake $(CMAKE_OPTIONS)

# Clean the build directory
clean:
@echo "Cleaning the build directory..."
@rm -rf $(BUILD_DIR)

# Uninstalling the software
uninstall: clean
@echo "Uninstalling $(PROJECT)..."
@rm -rf $(EXECUTABLE).app $(EXECUTABLE)d.app

# Install the project
install: build
@echo "Installing $(PROJECT)..."
@cd $(BUILD_DIR) && make
@echo "$(PROJECT) installed."
@cmake --build $(BUILD_DIR)
@echo "Installation complete."

build_tests: build
@cd $(BUILD_DIR)/tests/ && make
@echo "Building tests..."
@$(MAKE) -C $(BUILD_DIR)/tests

test: build_tests
@echo "Running tests..."
@for test in ./build/tests/test_*; do \
if [ -f $$test ]; then \
echo "Running $$test..."; \
$$test; \
fi; \
done

run:
@echo "Running $(PROJECT)..."
@./build/bin/$(PROJECT)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Please, check the [wiki](https://github.com/sandbox-science/CodeAstra/wiki) for
- [ ] Create a new file ~ in progress
- [x] File tree navigation
- [ ] Syntax highlighting ~ in progress
- Supported Languagues:
- Supported Languages:
- [x] Markdown (**foundation**)
- [x] YAML (**foundation**)
- [ ] C/C++ (**in progress**)
Expand All @@ -63,4 +63,4 @@ Please, check the [wiki](https://github.com/sandbox-science/CodeAstra/wiki) for
- [ ] Plugin system

## To-Do
Find tasks to-do on our open [issues](https://github.com/sandbox-science/CodeAstra/issues)
Find tasks to do on our open [issues](https://github.com/sandbox-science/CodeAstra/issues)
1 change: 1 addition & 0 deletions include/CodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CodeEditor : public QPlainTextEdit
Mode mode = NORMAL;
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void autoIndentation();

signals:
void statusMessageChanged(const QString &message);
Expand Down
19 changes: 17 additions & 2 deletions include/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
#include <QObject>
#include <memory>
#include <QSyntaxHighlighter>
#include <QFileInfo>

class CodeEditor;
class MainWindow;

struct OperationResult
{
bool success;
std::string message;
};

/**
* @class FileManager
* @brief Manages file operations such as creating, saving, and opening files.
Expand All @@ -25,9 +32,11 @@ class FileManager : public QObject
static FileManager &getInstance(CodeEditor *editor = nullptr, MainWindow *mainWindow = nullptr)
{
static FileManager instance(editor, mainWindow);
if (editor && mainWindow) {
instance.initialize(editor, mainWindow);
}
return instance;
}

FileManager(const FileManager &) = delete;
FileManager &operator=(const FileManager &) = delete;

Expand All @@ -37,6 +46,12 @@ class FileManager : public QObject
void setCurrentFileName(const QString fileName);
void initialize(CodeEditor *editor, MainWindow *mainWindow);

static OperationResult renamePath(const QFileInfo &pathInfo, const QString &newName);
static OperationResult newFile(const QFileInfo &pathInfo, QString newFilePath);
static OperationResult newFolder(const QFileInfo &pathInfo, QString newFolderPath);
static OperationResult duplicatePath(const QFileInfo &pathInfo);
static OperationResult deletePath(const QFileInfo &pathInfo);

public slots:
void newFile();
void saveFile();
Expand All @@ -54,4 +69,4 @@ public slots:
MainWindow *m_mainWindow;
QSyntaxHighlighter *m_currentHighlighter = nullptr;
QString m_currentFileName;
};
};
8 changes: 7 additions & 1 deletion include/Tree.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#pragma once

#include "FileManager.h"

#include <QSplitter>
#include <QObject>
#include <memory>
#include <QFileInfo>

// Forward declarations
class QTreeView;
class QFileSystemModel;
class QFileIconProvider;
class FileManager;

/**
* @class Tree
Expand All @@ -30,8 +32,12 @@ class Tree : public QObject
void setupTree();
void openFile(const QModelIndex &index);

QFileSystemModel* getModel() const;

private:
void showContextMenu(const QPoint &pos);
QFileInfo getPathInfo();
void isSuccessful(OperationResult result);

std::unique_ptr<QFileIconProvider> m_iconProvider;
std::unique_ptr<QFileSystemModel> m_model;
Expand Down
58 changes: 58 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
set(TARGET_NAME CodeAstraApp)
set(EXECUTABLE_NAME CodeAstra)

# Source files
set(SOURCES
MainWindow.cpp
CodeEditor.cpp
Tree.cpp
FileManager.cpp
Syntax.cpp
SyntaxManager.cpp
)

# Headers
set(HEADERS
${CMAKE_SOURCE_DIR}/include/MainWindow.h
${CMAKE_SOURCE_DIR}/include/CodeEditor.h
${CMAKE_SOURCE_DIR}/include/Tree.h
${CMAKE_SOURCE_DIR}/include/FileManager.h
${CMAKE_SOURCE_DIR}/include/Syntax.h
${CMAKE_SOURCE_DIR}/include/SyntaxManager.h
${CMAKE_SOURCE_DIR}/include/LineNumberArea.h
)

# Find yaml-cpp using CMake's package config
find_package(yaml-cpp REQUIRED)

# Library
add_library(${TARGET_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)

# Link against the proper target
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets yaml-cpp::yaml-cpp)
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Executable
add_executable(${EXECUTABLE_NAME} ${CMAKE_SOURCE_DIR}/src/main.cpp)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${TARGET_NAME} Qt6::Core Qt6::Widgets)
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)

# Resources
qt_add_resources(APP_RESOURCES ${CMAKE_SOURCE_DIR}/resources.qrc)
target_sources(${EXECUTABLE_NAME} PRIVATE ${APP_RESOURCES})

# OS-specific flags
if(MSVC)
target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /WX /analyze /sdl /guard:cf)
elseif(APPLE OR UNIX)
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion -Wsign-conversion -fsanitize=address,undefined -fstack-protector)
target_link_options(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined)
endif()

# Copy config files
file(GLOB YAML_FILES "${CMAKE_SOURCE_DIR}/config/*.yaml")
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/config)
foreach(YAML_FILE ${YAML_FILES})
configure_file(${YAML_FILE} ${CMAKE_BINARY_DIR}/config/ COPYONLY)
endforeach()
Loading
Loading