Skip to content

Commit

Permalink
edit menu
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Nov 2, 2024
1 parent 9d6108e commit 5c244b7
Show file tree
Hide file tree
Showing 26 changed files with 850 additions and 1,095 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Change Log

## 0.0.40
## 0.0.41

- Implemented:
- Blank Operations -> Trim Trailing Space
- Blank Operations -> Trim Leading Space
- Blank Operations -> Trim Leading and Trailing Space
- Blank Operations -> EOL to Space
- Blank Operations -> Tab to Space
- Indentation -> Default Settings
- Indentation -> Custom


0.0.40

- Implemented:
- Delete
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ set(PROJECT_SOURCES
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
Expand All @@ -61,12 +61,19 @@ set(PROJECT_SOURCES
src/mainwindow/session.h
src/mainwindow/textoperations.cpp
src/mainwindow/textoperations.h
src/indentation/indentationdialog.ui
src/indentation/indentationdialog.cpp
src/indentation/indentationdialog.h
src/indentation/indentationmanager.cpp
src/indentation/indentationmanager.h
)

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

# Link Qt6 libraries
Expand Down
18 changes: 9 additions & 9 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-30T06:37:11. -->
<!-- Written by QtCreator 14.0.2, 2024-11-01T22:26:52. -->
<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_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}</value>
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-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_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}</value>
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A simple light text editor.
Notepadqq was my choice editor. Unfortunately it doesn't maintain anymore. I tried to help but there was old PRs and plenty of unanswered issues. The project was a mix of C++/Qt/Javascript/HTML,CSS,Python...
It is a while I didn't code in C++ and my knowledge of Qt is a little. All that said this is a **toy** project, at least for a while. The -- (minus minus) indicates that this is a minimalistic project. I will design GUI just like Notepadqq so there is no new GUI learning. For now I just release for Linux which has Qt6 installed (dynamic compile).
It is a while I didn't code in C++ and my knowledge of Qt is a little. All that said this is a **toy** project, at least for a while. The -- (minus minus) indicates that this is a minimalistic project. I will design GUI just like Notepadqq so there is no new GUI learning. For now I just release for Linux which has Qt6 installed (dynamic compile) and C++ 20.
Any contribution is welcome.

In a world without walls and fences, who needs **windows** and **gates**?
Expand Down
5 changes: 5 additions & 0 deletions src/codeeditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "codeeditor.h"
#include <QPainter>
#include <QTextBlock>
#include "mainwindow/helpers.h"

CodeEditor::CodeEditor(QWidget *parent)
: QPlainTextEdit(parent), lineNumberArea(new LineNumberArea(this)) {
Expand Down Expand Up @@ -148,3 +149,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) {
++blockNumber;
}
}

void CodeEditor::applyIndentation(bool useTabs, int indentationWidth) {
// TODO: Implement indentation
}
1 change: 1 addition & 0 deletions src/codeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CodeEditor : public QPlainTextEdit {
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void highlightCurrentLine();
void applyIndentation(bool useTabs, int indentationWidth);

protected:
void resizeEvent(QResizeEvent *event) override;
Expand Down
2 changes: 1 addition & 1 deletion src/fileloaderworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <QFile>

FileLoaderWorker::FileLoaderWorker(const QString &filePath, Document *doc, QObject *parent)
: QObject(parent), m_filePath(filePath), m_file(filePath), document(doc) {
: QObject(parent), m_file(filePath), m_filePath(filePath), document(doc) {
qDebug() << "FileLoaderWorker initialized for file:" << filePath;
qDebug() << "FileLoaderWorker thread at initialization:" << QThread::currentThread();
}
Expand Down
6 changes: 3 additions & 3 deletions src/fileloaderworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public slots:
void startLoading();

private:
qint64 m_fileSize;
Document *document;
QString m_filePath;
QFile m_file;
QString m_filePath;
Document *document;
qint64 m_fileSize;
};
89 changes: 89 additions & 0 deletions src/indentation/indentationdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <QSettings>
#include "indentationdialog.h"
#include "ui_indentationdialog.h"
#include "../settings.h"
#include "../document.h"
#include "../codeeditor.h"
#include "../mainwindow/helpers.h"

IndentationDialog::IndentationDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::IndentationDialog)
{
ui->setupUi(this);

loadSettings();

connect(ui->tabs, &QRadioButton::clicked, this, &IndentationDialog::onIndentationSelected);
connect(ui->spaces, &QRadioButton::clicked, this, &IndentationDialog::onIndentationSelected);

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &IndentationDialog::onOkClicked);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &IndentationDialog::reject);
}

IndentationDialog::~IndentationDialog()
{
delete ui;
}

bool IndentationDialog::isTabsSelected() const {
return ui->tabs->isChecked();
}

int IndentationDialog::getIndentationValue() const {
return ui->number->value();
}

void IndentationDialog::onIndentationSelected() {
// Your logic when the indentation is selected
qDebug() << "Indentation option selected.";
}

void IndentationDialog::loadSettings() {
QSettings settings("Remisa", "Notepad--");
settings.beginGroup("IndentationSettings");
QString value = settings.value("indentationOption", "Tabs").toString(); // Default to tabs if no value found
int indentationSize = settings.value("indentationSize", 1).toInt(); // Default to 1 if no value found
settings.endGroup();

ui->tabs->setChecked(value == "Tabs");
ui->spaces->setChecked(value == "Spaces");
ui->number->setValue(indentationSize);
}

void IndentationDialog::saveSettings() {
QSettings settings("Remisa", "Notepad--"); // Adjust organization and application name
settings.beginGroup("IndentationSettings");
settings.setValue("indentationOption", ui->tabs->isChecked() ? "Tabs" : "Spaces");
settings.setValue("indentationSize", ui->number->value());
settings.endGroup();
}

void IndentationDialog::onOkClicked() {
saveSettings(); // Save settings when OK is clicked
accept();
}

void IndentationDialog::setTabsChecked(bool checked) {
ui->tabs->setChecked(checked);
}

bool IndentationDialog::isTabsChecked() const {
return ui->tabs->isChecked();
}

void IndentationDialog::on_buttonBox_accepted()
{
bool useTabs = ui->tabs->isChecked();
int indentationWidth = ui->number->value();

auto* settings = Settings::instance();
settings->setValue("IndentationSettings/indentationOption", useTabs ? "Tabs" : "Spaces");
settings->setValue("IndentationSettings/indentationSize", indentationWidth);

Document* doc = qobject_cast<Document*>(parent());
if (doc && doc->editor()) {
doc->editor()->applyIndentation(useTabs, indentationWidth);
}
Helpers::notImplemented(this);
}

33 changes: 33 additions & 0 deletions src/indentation/indentationdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <QDialog>

namespace Ui {
class IndentationDialog;
}

class IndentationDialog : public QDialog
{
Q_OBJECT

public:
explicit IndentationDialog(QWidget *parent = nullptr);
~IndentationDialog();

bool isTabsSelected() const;
int getIndentationValue() const;
void setTabsChecked(bool checked);
bool isTabsChecked() const;

private slots:
void onIndentationSelected();

void on_buttonBox_accepted();

private:
Ui::IndentationDialog *ui;
void loadSettings();
void saveSettings();
void onOkClicked();
};

123 changes: 123 additions & 0 deletions src/indentation/indentationdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IndentationDialog</class>
<widget class="QDialog" name="IndentationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>364</width>
<height>119</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>4</x>
<y>70</y>
<width>341</width>
<height>41</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
<widget class="QSpinBox" name="number">
<property name="geometry">
<rect>
<x>184</x>
<y>40</y>
<width>161</width>
<height>26</height>
</rect>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
<widget class="QRadioButton" name="spaces">
<property name="geometry">
<rect>
<x>98</x>
<y>11</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Spaces</string>
</property>
</widget>
<widget class="QRadioButton" name="tabs">
<property name="geometry">
<rect>
<x>30</x>
<y>9</y>
<width>51</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Tabs</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>32</x>
<y>43</y>
<width>121</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;Indentation Width:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>IndentationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>IndentationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit 5c244b7

Please sign in to comment.