Add open project menu item to Nostalgia Studio
This commit is contained in:
parent
c971969a73
commit
3901493274
@ -8,7 +8,6 @@
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
#include <project.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
@ -16,25 +15,55 @@ namespace studio {
|
||||
|
||||
using namespace ox::fs;
|
||||
|
||||
QString Project::ROM_FILE = "/ROM.oxfs";
|
||||
|
||||
Project::Project(QString path) {
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
Project::~Project() {
|
||||
if (m_fs) {
|
||||
delete m_fs;
|
||||
m_fs = nullptr;
|
||||
}
|
||||
if (m_romBuff) {
|
||||
delete m_romBuff;
|
||||
m_romBuff = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::create() {
|
||||
QDir().mkpath(m_path);
|
||||
|
||||
m_romBuff = new QByteArray(1024, 0);
|
||||
FileSystem32::format(m_romBuff->data(), m_romBuff->size(), true);
|
||||
auto fs = ox::fs::createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
|
||||
fs->mkdir("/Tilesets");
|
||||
m_fs->mkdir("/Tilesets");
|
||||
|
||||
QFile file(m_path + "/ROM.oxfs");
|
||||
QFile file(m_path + ROM_FILE);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(*m_romBuff);
|
||||
file.close();
|
||||
}
|
||||
|
||||
delete fs;
|
||||
int Project::open() {
|
||||
QFile file(m_path + ROM_FILE);
|
||||
m_romBuff = new QByteArray(file.size(), 0);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (file.read(m_romBuff->data(), file.size()) > 0) {
|
||||
m_fs = createFileSystem(m_romBuff->data(), m_romBuff->size());
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Project::save() {
|
||||
QFile file(m_path + ROM_FILE);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(*m_romBuff);
|
||||
file.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/fs/filesystem.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
@ -15,13 +17,22 @@ class Project: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static QString ROM_FILE;
|
||||
|
||||
QString m_path = "";
|
||||
QByteArray *m_romBuff = nullptr;
|
||||
ox::fs::FileSystem *m_fs = nullptr;
|
||||
|
||||
public:
|
||||
Project(QString path);
|
||||
|
||||
~Project();
|
||||
|
||||
void create();
|
||||
|
||||
int open();
|
||||
|
||||
void save();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@ -63,6 +64,16 @@ void MainWindow::setupMenu() {
|
||||
QKeySequence::Quit,
|
||||
QApplication::quit
|
||||
);
|
||||
|
||||
|
||||
addAction(
|
||||
fileMenu,
|
||||
tr("Open &Project"),
|
||||
tr(""),
|
||||
QKeySequence::Open,
|
||||
this,
|
||||
SLOT(openProject())
|
||||
);
|
||||
}
|
||||
|
||||
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
||||
@ -87,6 +98,13 @@ void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::openProject() {
|
||||
auto p = QFileDialog::getExistingDirectory(this, tr("Select Project Directory..."), QDir::homePath());
|
||||
auto project = new Project(p);
|
||||
project->open();
|
||||
m_project = project;
|
||||
}
|
||||
|
||||
void MainWindow::showNewWizard() {
|
||||
const QString PROJECT_NAME = "projectName";
|
||||
const QString PROJECT_PATH = "projectPath";
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
#include <QModelIndex>
|
||||
#include <QMainWindow>
|
||||
#include <QPoint>
|
||||
@ -16,6 +15,10 @@
|
||||
#include <QVector>
|
||||
#include <functional>
|
||||
|
||||
#include <ox/std/types.hpp>
|
||||
|
||||
#include "lib/project.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
@ -38,7 +41,7 @@ class MainWindow: public QMainWindow {
|
||||
static const QString AppTitle;
|
||||
|
||||
private:
|
||||
QString m_projectPath;
|
||||
Project *m_project = nullptr;
|
||||
QVector<std::function<void()>> m_cleanupTasks;
|
||||
|
||||
public:
|
||||
@ -63,6 +66,8 @@ class MainWindow: public QMainWindow {
|
||||
int writeSettings(QString path);
|
||||
|
||||
private slots:
|
||||
void openProject();
|
||||
|
||||
void showNewWizard();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user