diff --git a/src/met/core-editor.cpp b/src/met/core-editor.cpp new file mode 100644 index 0000000..74108f3 --- /dev/null +++ b/src/met/core-editor.cpp @@ -0,0 +1,75 @@ +#include "core-editor.h" + +EchidnaCoreEditor::EchidnaCoreEditor(QWidget *parent) : QPlainTextEdit(parent) { + LineNumberArea *lineNumber = new LineNumberArea(this); + + QObject::connect(this, &EchidnaCoreEditor::cursorPositionChanged, &EchidnaCoreEditor::highlightCurrentLine); + QObject::connect(this, &EchidnaCoreEditor::updateRequest, &EchidnaCoreEditor::updateLineNumberArea); + QObject::connect(this, &EchidnaCoreEditor::blockCountChanged, &EchidnaCoreEditor::updateLineNumberAreaWidth); + + this->highlightCurrentLine(); + this->updateLineNumberAreaWidth(0); +} + +EchidnaCoreEditor::~EchidnaCoreEditor(){ + +} + +int EchidnaCoreEditor::lineNumberAreaWidth(){ + +} + + +void EchidnaCoreEditor::lineNumberAreaPaintEvent(QPaintEvent *event){ + +} + +void EchidnaCoreEditor::resizeEvent(QResizeEvent *e){ + + QPlainTextEdit::resizeEvent(e); + + QRect contentsRect = this->contentsRect(); + + +} + + /** + * + * This function implements the functionaly that highlight the current line your cursor is currently on. + * + * TODO: Implement support for multi-line editing. + * + */ +void EchidnaCoreEditor::highlightCurrentLine(){ + + if(this->isReadOnly()){ + return; + } else { + QList selections; + + QTextEdit::ExtraSelection selection; + + selection.format.setProperty(QTextFormat::FullWidthSelection, true); + + QBrush selectionFormatBrush = selection.format.foreground(); + + + } + +} + + + +/* + +the method `set_menubar` exists for reference `&components::echidna_editor::imp::EchidnaEditor`, but its trait bounds were not satisfied + +method cannot be called on `&components::echidna_editor::imp::EchidnaEditor` due to unsatisfied trait bounds + +note: the following trait bounds were not satisfied: + `components::echidna_editor::imp::EchidnaEditor: glib::IsA` + which is required by `components::echidna_editor::imp::EchidnaEditor: gtk4::prelude::GtkApplicationExt` + `&components::echidna_editor::imp::EchidnaEditor: glib::IsA` + which is required by `&components::echidna_editor::imp::EchidnaEditor: gtk4::prelude::GtkApplicationExt` + +*/ diff --git a/src/met/core-editor.h b/src/met/core-editor.h new file mode 100644 index 0000000..f27dab1 --- /dev/null +++ b/src/met/core-editor.h @@ -0,0 +1,58 @@ + +/* + + Echidna Core Text Editor. This is the Monaco replacement for Echidna. + + A lot of the code are ~~stolen~~ inspired from [Qt's Code Editor example](https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html), with added features to replicate the Visual Studio Code experience. + +*/ + +#include + +class LineNumberArea : public QWidget +{ + +public: + LineNumberArea(EchidnaCoreEditor *editor) : QWidget(editor), coreEditor(editor) + { + } + + QSize sizeHint() const override + { + return QSize(coreEditor->lineNumberAreaWidth(), 0); + } + +protected: + void paintEvent(QPaintEvent *event) override + { + coreEditor->lineNumberAreaPaintEvent(event); + } + + EchidnaCoreEditor *coreEditor; +}; + +class EchidnaCoreEditor : public QPlainTextEdit +{ + Q_OBJECT + +public: + EchidnaCoreEditor(QWidget *parent = nullptr); + ~EchidnaCoreEditor(); + + void lineNumberAreaPaintEvent(QPaintEvent *event); + int lineNumberAreaWidth(); +protected: + void resizeEvent(QResizeEvent *event) override; + +private slots: + void highlightCurrentLine(); + void updateLineNumberAreaWidth(int newBlockCount); + void updateLineNumberArea(const QRect &rect, int dy); + + + LineNumberArea *lineNumber; +}; + + + + diff --git a/src/met/editor.cpp b/src/met/editor.cpp new file mode 100644 index 0000000..bacc01c --- /dev/null +++ b/src/met/editor.cpp @@ -0,0 +1,64 @@ +#include "editor.h" +#include +#include +#include +#include + +EchidnaEditor::EchidnaEditor(QWidget *parent) : QMainWindow(parent), + ui(new Ui::EchidnaEditor) +{ + + ui->setupUi(this); + this->setCentralWidget(ui->centralWidget); + + QObject::connect(this, &EchidnaEditor::newFileOpened, &EchidnaEditor::handleNewFileOpened); +} + +EchidnaEditor::~EchidnaEditor() +{ + delete ui; +}; + +void EchidnaEditor::actionOpenFolder() +{ + QString dir = QFileDialog::getExistingDirectory(this, + "Add a Folder to Workspace", + QDir::homePath(), + QFileDialog::ShowDirsOnly); + + + std::vector::iterator foundExistingOpenedFolders = std::find_if(this->folders->begin(), this->folders->end(), + [&](QFileSystemModel *iterator) + { + return iterator->rootPath() == dir; + }); + if (this->folders->end() != foundExistingOpenedFolders) + { + } + else + { + QFileSystemModel *model = new QFileSystemModel; + model->setRootPath(dir); + + } + + +} + +void EchidnaEditor::actionOpenFile(){ + QStringList files = QFileDialog::getOpenFileNames(this, + "Open Files", + QDir::homePath() + ); + + for(int i = 0; i < files.size(); ++i){ + emit this->newFileOpened(files.at(i)); + } +} +void EchidnaEditor::handleNewFileOpened(QString filename){ + + QFile file(filename); + + + +} \ No newline at end of file diff --git a/src/met/editor.h b/src/met/editor.h new file mode 100644 index 0000000..7aecf04 --- /dev/null +++ b/src/met/editor.h @@ -0,0 +1,39 @@ +#include +#include +#include +namespace Ui +{ + class EchidnaEditor; +} + +class EchidnaEditor : public QMainWindow +{ + Q_OBJECT + +public: + explicit EchidnaEditor(QWidget *parent = nullptr); + ~EchidnaEditor(); + +private slots: + + void actionOpenFolder(); + void actionAddFolderToWorkspace(QString folder); + void actionOpenFile(); + void handleNewFileOpened(QString file); + +signals: + + void newFileOpened(QString file); + void newFolderOpened(); +private: + Ui::EchidnaEditor *ui; + std::vector *folders; + std::vector *files; +}; + + + + + + + diff --git a/src/met/main.cpp b/src/met/main.cpp new file mode 100644 index 0000000..cbaed37 --- /dev/null +++ b/src/met/main.cpp @@ -0,0 +1,14 @@ +#include +#include "editor.h" + +int main(int argc, char *argv[]){ + + QApplication EchidnaEditorApp(argc, argv); + + EchidnaEditor Editor; + + Editor.show(); + + EchidnaEditorApp.exec(); + +} \ No newline at end of file