Fix OxFSTreeView to properly list added files

This commit is contained in:
Gary Talent 2017-08-19 12:31:53 -05:00
parent d8a3cd5dfb
commit 7a6174953d
9 changed files with 95 additions and 30 deletions

View File

@ -17,8 +17,7 @@ const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName";
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
const QString ImportTilesheetWizardPage::BPP = "bpp";
ImportTilesheetWizardPage::ImportTilesheetWizardPage(studio::PluginArgs args) {
m_project = args.project;
ImportTilesheetWizardPage::ImportTilesheetWizardPage(studio::PluginArgs args): m_project(args.project) {
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) {
auto importPath = field(IMPORT_PATH).toString();
if (QFile(importPath).exists()) {

View File

@ -18,7 +18,7 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage {
static const QString TILESHEET_NAME;
static const QString IMPORT_PATH;
static const QString BPP;
studio::Project *m_project = nullptr;
studio::Project *&m_project;
public:
ImportTilesheetWizardPage(studio::PluginArgs args);

View File

@ -16,40 +16,64 @@ namespace studio {
using namespace ox;
OxFSFile::OxFSFile(FileSystem *fs, QString path, OxFSFile *parentItem) {
m_fs = fs;
m_path = path;
m_parentItem = parentItem;
// find children
if (fs) {
QVector<DirectoryListing<QString>> ls;
if (fs->stat((const char*) m_path.toUtf8()).fileType == FileType_Directory) {
fs->ls(m_path.toUtf8(), &ls);
qSort(ls);
}
for (auto v : ls) {
auto ch = new OxFSFile(fs, m_path + "/" + v.name, this);
m_childItems.push_back(ch);
}
}
}
OxFSFile::~OxFSFile() {
qDeleteAll(m_childItems);
}
void OxFSFile::appendChild(OxFSFile*) {
void OxFSFile::appendChild(OxFSModel *model, QStringList pathItems, QString currentPath) {
if (pathItems.size()) {
auto target = pathItems[0];
currentPath += "/" + target;
OxFSFile *nextItem = nullptr;
int index = m_childItems.size();
for (int i = 0; i < m_childItems.size(); i++) {
if (m_childItems[i]->name() >= target) {
index = i;
break;
}
}
if (m_childItems.size() == index || m_childItems[index]->name() != target) {
auto idx = model->createIndex(row(), 0, this);
model->beginInsertRows(idx, index, index);
nextItem = new OxFSFile(nullptr, currentPath, this);
m_childItems.insert(index, nextItem);
model->endInsertRows();
}
nextItem = m_childItems[index];
nextItem->appendChild(model, pathItems.mid(1), currentPath);
}
}
OxFSFile *OxFSFile::child(int row) {
if (m_fs) {
QVector<DirectoryListing<QString>> ls;
m_fs->ls(m_path.toUtf8(), &ls);
auto ch = new OxFSFile(m_fs, m_path + "/" + ls[row].name, this);
m_childItems.push_back(ch);
return ch;
if (row < m_childItems.size()) {
return m_childItems[row];
} else {
return nullptr;
}
}
int OxFSFile::childCount() const {
if (m_fs) {
QVector<DirectoryListing<QString>> ls;
if (m_fs->stat((const char*) m_path.toUtf8()).fileType == FileType_Directory) {
m_fs->ls(m_path.toUtf8(), &ls);
}
return ls.size();
} else {
return 0;
}
return m_childItems.size();
}
int OxFSFile::columnCount() const {
@ -57,7 +81,7 @@ int OxFSFile::columnCount() const {
}
QVariant OxFSFile::data(int) const {
return m_path.mid(m_path.lastIndexOf('/') + 1);
return name();
}
int OxFSFile::row() const {
@ -72,6 +96,10 @@ OxFSFile *OxFSFile::parentItem() {
return m_parentItem;
}
QString OxFSFile::name() const {
return m_path.mid(m_path.lastIndexOf("/") + 1);
}
// OxFSModel
@ -82,6 +110,7 @@ OxFSModel::OxFSModel(FileSystem *fs, QObject *parent) {
OxFSModel::~OxFSModel() {
if (m_rootItem) {
delete m_rootItem;
m_rootItem = nullptr;
}
}
@ -167,6 +196,11 @@ int OxFSModel::columnCount(const QModelIndex &parent) const {
}
}
void OxFSModel::updateFile(QString path) {
auto pathItems = path.split("/").mid(1);
m_rootItem->appendChild(this, pathItems, "");
}
void OxFSModel::setupModelData(const QStringList &lines, OxFSFile *parent) {
}

View File

@ -19,7 +19,6 @@ namespace studio {
class OxFSFile {
private:
ox::FileSystem *m_fs = nullptr;
OxFSFile *m_parentItem = nullptr;
QString m_path;
QVector<OxFSFile*> m_childItems;
@ -29,7 +28,7 @@ class OxFSFile {
~OxFSFile();
void appendChild(OxFSFile *child);
void appendChild(class OxFSModel *model, QStringList pathItems, QString fullPath);
OxFSFile *child(int row);
@ -42,11 +41,15 @@ class OxFSFile {
int row() const;
OxFSFile *parentItem();
QString name() const;
};
class OxFSModel: public QAbstractItemModel {
Q_OBJECT
friend OxFSFile;
private:
OxFSFile *m_rootItem = nullptr;
@ -71,6 +74,9 @@ class OxFSModel: public QAbstractItemModel {
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
public slots:
void updateFile(QString path);
private:
void setupModelData(const QStringList &lines, OxFSFile *parent);
};

View File

@ -22,7 +22,7 @@ namespace nostalgia {
namespace studio {
struct PluginArgs {
Project *project = nullptr;
Project *&project;
};
struct WizardMaker {

View File

@ -79,11 +79,15 @@ FileSystem *Project::romFs() {
}
int Project::mkdir(QString path) {
return m_fs->mkdir(path.toUtf8().data());
auto err = m_fs->mkdir(path.toUtf8().data());
emit updated(path);
return err;
}
int Project::write(QString path, uint8_t *buff, size_t buffLen) {
return m_fs->write(path.toUtf8().data(), buff, buffLen);
auto err = m_fs->write(path.toUtf8().data(), buff, buffLen);
emit updated(path);
return err;
}
}

View File

@ -40,6 +40,9 @@ class Project: public QObject {
int mkdir(QString path);
int write(QString path, uint8_t *buff, size_t buffLen);
signals:
void updated(QString path);
};
}

View File

@ -7,8 +7,8 @@
*/
#include <QApplication>
#include <QDesktopWidget>
#include <QDebug>
#include <QDesktopWidget>
#include <QDialog>
#include <QFileDialog>
#include <QGridLayout>
@ -226,7 +226,9 @@ int MainWindow::openProject(QString projectPath) {
m_project = nullptr;
}
m_project = project;
m_projectExplorer->setModel(new OxFSModel(m_project->romFs()));
m_oxfsView = new OxFSModel(m_project->romFs());
m_projectExplorer->setModel(m_oxfsView);
connect(m_project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
m_importAction->setEnabled(true);
m_state.projectPath = projectPath;
}
@ -236,8 +238,13 @@ int MainWindow::openProject(QString projectPath) {
int MainWindow::closeProject() {
auto err = 0;
if (m_project) {
disconnect(m_project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
delete m_project;
m_project = nullptr;
delete m_oxfsView;
m_oxfsView = nullptr;
}
if (m_projectExplorer->model()) {
delete m_projectExplorer->model();
@ -322,8 +329,9 @@ void MainWindow::showImportWizard() {
auto ws = new WizardSelect();
wizard.addPage(ws);
PluginArgs args;
args.project = m_project;
PluginArgs args {
.project = m_project
};
for (auto p : m_plugins) {
for (auto w : p->importWizards(args)) {
ws->addOption(w.name, w.make);
@ -334,5 +342,12 @@ void MainWindow::showImportWizard() {
wizard.exec();
}
void MainWindow::refreshProjectExplorer(QString path) {
if (m_oxfsView) {
m_oxfsView->updateFile(path);
qInfo() << "asdf\n";
}
}
}
}

View File

@ -22,6 +22,7 @@
#include <ox/std/types.hpp>
#include "lib/oxfstreeview.hpp"
#include "lib/plugin.hpp"
#include "lib/project.hpp"
@ -88,6 +89,7 @@ class MainWindow: public QMainWindow {
QVector<QPointer<QDockWidget>> m_dockWidgets;
QTreeView *m_projectExplorer = nullptr;
QVector<Plugin*> m_plugins;
QPointer<OxFSModel> m_oxfsView = nullptr;
public:
MainWindow(QString profilePath);
@ -127,6 +129,8 @@ class MainWindow: public QMainWindow {
void showNewWizard();
void showImportWizard();
void refreshProjectExplorer(QString path);
};
}