diff --git a/Apps/Editors/MainWindow.cpp b/Apps/Editors/MainWindow.cpp index 68c0419..6260d23 100644 --- a/Apps/Editors/MainWindow.cpp +++ b/Apps/Editors/MainWindow.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) , ui(std::make_unique()) , filesystem_model(std::make_unique()) + , current_directory(QDir::homePath()) + { this->ui->setupUi(this); @@ -52,9 +55,9 @@ MainWindow::MainWindow(QWidget* parent) this->ui->actionOpen, &QAction::triggered, this, - &MainWindow::onclick_open_directory + &MainWindow::onclick_menuaction_open_directory ); - this->read_directory("/Users/sdavid"); + this->read_directory(current_directory); } MainWindow::~MainWindow() {} @@ -72,7 +75,18 @@ void MainWindow::showEvent(QShowEvent* event) this->move(center_point); } -void MainWindow::onclick_open_directory() +void MainWindow::onclick_menuaction_open_directory() +{ + auto current_directory = QDir::current().dirName(); + auto user_selection = QFileDialog::getExistingDirectory( + this, + QWidget::tr("Open Directory"), + current_directory, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks + ); + this->read_directory(user_selection); +}; +void MainWindow::onclick_menuaction_new_file() { auto current_directory = QDir::current().dirName(); auto user_selection = QFileDialog::getExistingDirectory( @@ -101,32 +115,39 @@ void MainWindow::read_directory(const QString& directory) this->ui->fsTreeView, &QTreeView::doubleClicked, this, - &MainWindow::on_file_click + &MainWindow::onclick_fstree_file ); + current_directory = directory; } -void MainWindow::on_file_click(const QModelIndex& index) +void MainWindow::onclick_fstree_file(const QModelIndex& index) { auto path = filesystem_model->filePath(index); - auto found_document_iter = open_documents.find(path); - QMdiSubWindow* subwindow = nullptr; - QFileInfo path_info(path); if (path_info.isDir()) { this->read_directory(path); return; } - if (found_document_iter != open_documents.end()) { + auto subwindow_list = this->ui->mdiArea->subWindowList(); + QMdiSubWindow* subwindow = nullptr; + + auto result = std::find_if( + subwindow_list.begin(), + subwindow_list.end(), + [&path](QWidget* widget_ptr) { + return (widget_ptr->objectName() == path); + } + ); + + if (result != subwindow_list.end()) { + subwindow = *result; this->statusBar()->showMessage( tr("Document was already loaded"), 1000 ); - - subwindow = found_document_iter->second; } else { this->statusBar()->showMessage(tr("Opened New Document"), 1000); auto text_widget = new QPlainTextEdit(this->ui->mdiArea); - subwindow = this->ui->mdiArea->addSubWindow(text_widget); QFile file(path); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -134,64 +155,14 @@ void MainWindow::on_file_click(const QModelIndex& index) text_widget->setPlainText(file_text.readAll()); file.close(); } - this->open_documents[path] = subwindow; + + subwindow = this->ui->mdiArea->addSubWindow(text_widget); + subwindow->setObjectName(path); + subwindow->setWindowTitle(path_info.fileName()); } - ////this->ui->mdiArea->setActiveSubWindow(subwindow); subwindow->show(); } - -/* -void MainWindow::load_file(const QString& file_path) -{ - QMdiSubWindow* document_to_open = -find_document_window(file_path); - - if (document_to_open) { - statusBar()->showMessage( - tr("Document was already loaded"), 1000 - ); - } else { - document_to_open = create_document_window(file_path); - - if (document_to_open) { - statusBar()->showMessage(tr("File loaded"), -1000); } else { throw IOCore::Exception("The file could not be loaded!"); - } - } - - ui->mdiArea->setActiveSubWindow(document_to_open); - document_to_open->show(); -} - -auto MainWindow::find_document_window(const QString& file_path) -> -QMdiSubWindow* -{ - QString absolute_path = QFileInfo(file_path).canonicalFilePath(); - - const QList kSubWindows = -ui->mdiArea->subWindowList(); for (auto* window : kSubWindows) { auto* -editor_widget = qobject_cast(window->widget()); - - if (editor_widget) { - if (editor_widget->GetFileName() == -absolute_path) { return window; - } - } - } - return nullptr; -} - -auto MainWindow::create_document_window(const QString& file_path) - -> QMdiSubWindow* -{ - auto editor = new EntityEditor(ui->mdiArea, file_path); - auto sub_window = ui->mdiArea->addSubWindow(editor); - - sub_window->setWindowTitle(file_path); - return sub_window; -} -*/ } // clang-format off diff --git a/Apps/Editors/MainWindow.hpp b/Apps/Editors/MainWindow.hpp index 3071a39..ede1920 100644 --- a/Apps/Editors/MainWindow.hpp +++ b/Apps/Editors/MainWindow.hpp @@ -9,43 +9,47 @@ #pragma once -#include -#include +#include "ui_MainWindow.h" #include -#include +#include +#include +#include #include #include -#include "ui_MainWindow.h" - class QMdiSubWindow; class QFileSystemModel; class QModelIndex; class QMdiSubWindow; namespace ResourceEditor { - class MainWindow : public QMainWindow { // NOLINTNEXTLINE Q_OBJECT + + template + using Ptr = std::unique_ptr; + public: MainWindow(QWidget* parent = nullptr); ~MainWindow() override; protected slots: - void onclick_open_directory(); + void onclick_menuaction_open_directory(); + void onclick_menuaction_new_file(); + + void onclick_fstree_file(const QModelIndex& index); protected: void showEvent(QShowEvent*) override; - void read_directory(const QString& directory); - void on_file_click(const QModelIndex& index); - std::unique_ptr ui; - std::unique_ptr filesystem_model; + void read_directory(const QString& directory = ""); - std::map open_documents; + QString current_directory; + Ptr ui; + Ptr filesystem_model; }; } diff --git a/Apps/Editors/README.md b/Apps/Editors/README.md new file mode 100644 index 0000000..b7c11be --- /dev/null +++ b/Apps/Editors/README.md @@ -0,0 +1,24 @@ +# Editors +This folder contains the source code for various editors used in the development of elemental. Each program here is designed to facilitate the creation and modification of different resources used by elemental-based games. + +## Current Status + +**Important**: Please note that all the editors within this folder are a work in progress. The functionality and interfaces of these editors may change as development progresses. + +## ResourceEditor + +As of now, there is only the one binary target, `ResourceEditor`. +The goal is to create smaller sub-editor that share a common framework such that they can be used within the overarching ResourceEditor. + +### Features of ResourceEditor + +- Open and edit various types of game resources. +- User-friendly interface. +- Extensible framework for future types of files. + +### Screenshot + +Coming soon. + +*Screenshot of the ResourceEditor in action.* + diff --git a/README.md b/README.md index c5d6d2d..a47aeb1 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,13 @@ A game and custom-built game engine designed for creating simple, top-down strat ``` This will execute the Catch2 test suite. +## Contributing +I am not against recieving contributions and help, but I retain the right to determine the general direction of this project. +That being said, feel free to fork this project and use it as a base for your own - just make sure to comply with the Mozilla Public License. +([See here](https://www.tldrlegal.com/license/mozilla-public-license-2-0-mpl-2)) + +Official rules for contribution might be outlined in a CONTRIBUTING.md at some point in the future, as needed. + ## License This project is licensed under the MPL 2.0 License.