ResourceEditor can now list directories and open text files.
This commit is contained in:
parent
722a001462
commit
39da8a0609
@ -28,6 +28,7 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -45,6 +46,8 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(std::make_unique<Ui::MainWindow>())
|
, ui(std::make_unique<Ui::MainWindow>())
|
||||||
, filesystem_model(std::make_unique<QFileSystemModel>())
|
, filesystem_model(std::make_unique<QFileSystemModel>())
|
||||||
|
, current_directory(QDir::homePath())
|
||||||
|
|
||||||
{
|
{
|
||||||
this->ui->setupUi(this);
|
this->ui->setupUi(this);
|
||||||
|
|
||||||
@ -52,9 +55,9 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
this->ui->actionOpen,
|
this->ui->actionOpen,
|
||||||
&QAction::triggered,
|
&QAction::triggered,
|
||||||
this,
|
this,
|
||||||
&MainWindow::onclick_open_directory
|
&MainWindow::onclick_menuaction_open_directory
|
||||||
);
|
);
|
||||||
this->read_directory("/Users/sdavid");
|
this->read_directory(current_directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {}
|
MainWindow::~MainWindow() {}
|
||||||
@ -72,7 +75,18 @@ void MainWindow::showEvent(QShowEvent* event)
|
|||||||
|
|
||||||
this->move(center_point);
|
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 current_directory = QDir::current().dirName();
|
||||||
auto user_selection = QFileDialog::getExistingDirectory(
|
auto user_selection = QFileDialog::getExistingDirectory(
|
||||||
@ -101,32 +115,39 @@ void MainWindow::read_directory(const QString& directory)
|
|||||||
this->ui->fsTreeView,
|
this->ui->fsTreeView,
|
||||||
&QTreeView::doubleClicked,
|
&QTreeView::doubleClicked,
|
||||||
this,
|
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 path = filesystem_model->filePath(index);
|
||||||
auto found_document_iter = open_documents.find(path);
|
|
||||||
QMdiSubWindow* subwindow = nullptr;
|
|
||||||
|
|
||||||
QFileInfo path_info(path);
|
QFileInfo path_info(path);
|
||||||
if (path_info.isDir()) {
|
if (path_info.isDir()) {
|
||||||
this->read_directory(path);
|
this->read_directory(path);
|
||||||
return;
|
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(
|
this->statusBar()->showMessage(
|
||||||
tr("Document was already loaded"), 1000
|
tr("Document was already loaded"), 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
subwindow = found_document_iter->second;
|
|
||||||
} else {
|
} else {
|
||||||
this->statusBar()->showMessage(tr("Opened New Document"), 1000);
|
this->statusBar()->showMessage(tr("Opened New Document"), 1000);
|
||||||
auto text_widget = new QPlainTextEdit(this->ui->mdiArea);
|
auto text_widget = new QPlainTextEdit(this->ui->mdiArea);
|
||||||
subwindow = this->ui->mdiArea->addSubWindow(text_widget);
|
|
||||||
|
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
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());
|
text_widget->setPlainText(file_text.readAll());
|
||||||
file.close();
|
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();
|
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<QMdiSubWindow*> kSubWindows =
|
|
||||||
ui->mdiArea->subWindowList(); for (auto* window : kSubWindows) { auto*
|
|
||||||
editor_widget = qobject_cast<EntityEditor*>(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
|
// clang-format off
|
||||||
|
@ -9,43 +9,47 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include "ui_MainWindow.h"
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QStringListModel>
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "ui_MainWindow.h"
|
|
||||||
|
|
||||||
class QMdiSubWindow;
|
class QMdiSubWindow;
|
||||||
class QFileSystemModel;
|
class QFileSystemModel;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class QMdiSubWindow;
|
class QMdiSubWindow;
|
||||||
|
|
||||||
namespace ResourceEditor {
|
namespace ResourceEditor {
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
// NOLINTNEXTLINE
|
// NOLINTNEXTLINE
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
template<typename TData>
|
||||||
|
using Ptr = std::unique_ptr<TData>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget* parent = nullptr);
|
MainWindow(QWidget* parent = nullptr);
|
||||||
~MainWindow() override;
|
~MainWindow() override;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onclick_open_directory();
|
void onclick_menuaction_open_directory();
|
||||||
|
void onclick_menuaction_new_file();
|
||||||
|
|
||||||
|
void onclick_fstree_file(const QModelIndex& index);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent*) override;
|
void showEvent(QShowEvent*) override;
|
||||||
void read_directory(const QString& directory);
|
|
||||||
void on_file_click(const QModelIndex& index);
|
|
||||||
|
|
||||||
std::unique_ptr<Ui::MainWindow> ui;
|
void read_directory(const QString& directory = "");
|
||||||
std::unique_ptr<QFileSystemModel> filesystem_model;
|
|
||||||
|
|
||||||
std::map<QString, QMdiSubWindow*> open_documents;
|
QString current_directory;
|
||||||
|
Ptr<Ui::MainWindow> ui;
|
||||||
|
Ptr<QFileSystemModel> filesystem_model;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
Apps/Editors/README.md
Normal file
24
Apps/Editors/README.md
Normal file
@ -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.*
|
||||||
|
|
@ -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.
|
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
|
## License
|
||||||
This project is licensed under the MPL 2.0 License.
|
This project is licensed under the MPL 2.0 License.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user