~saiko/mcrestool unlisted

ecacd7fc8bb73fd9e1aa1f94dda86c27c91ac798 — 2xsaiko a month ago 20bca64
Auto update list when adding resource
3 files changed, 35 insertions(+), 10 deletions(-)

M src/ui/mainwindow.cpp
M src/workspace/fstreemodel.cpp
M src/workspace/fstreemodel.h
M src/ui/mainwindow.cpp => src/ui/mainwindow.cpp +16 -3
@@ 30,14 30,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
    connect(ui->res_tree_view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(show_restree_context_menu(QPoint)));
    connect(ui->res_tree_view, SIGNAL(activated(const QModelIndex &)), this, SLOT(restree_open(const QModelIndex &)));

    // ui->res_tree_view->setModel(new ResourceTree(this));
    ui->res_tree_view->setModel(new FsTreeModel(this->ws, this));
}

void MainWindow::center() {
    QRect qRect = frameGeometry();
    const QScreen* screen = QGuiApplication::screenAt(QApplication::desktop()->cursor().pos());
    const QPoint& center = screen->geometry().center();
    QPoint center = screen->geometry().center();
    qRect.moveCenter(center);
    this->move(qRect.topLeft());
}


@@ 84,14 83,28 @@ void MainWindow::show_game_objects(bool shown) {

void MainWindow::add_res_file() {
    QStringList sources = QFileDialog::getOpenFileNames(this, tr("Add Resource Pack/Mod"), QString(), "Minecraft Content(*.zip *.jar);;All Files(*.*)");
    for (auto source: sources) {

    auto* model = qobject_cast<FsTreeModel*>(ui->res_tree_view->model());
    int count = model->rowCount(QModelIndex());
    model->beginInsertRows1(QModelIndex(), count, count + sources.size() - 1);

    for (const auto& source: sources) {
        this->ws->add_file(source);
    }

    model->endInsertRows1();
}

void MainWindow::add_res_dir() {
    QString source = QFileDialog::getExistingDirectory(this, tr("Add Resource Folder"));

    auto* model = qobject_cast<FsTreeModel*>(ui->res_tree_view->model());
    int count = model->rowCount(QModelIndex());
    model->beginInsertRows1(QModelIndex(), count, count);

    this->ws->add_dir(source);

    model->endInsertRows1();
}

void MainWindow::sub_window_focus_change(QMdiSubWindow* window) {

M src/workspace/fstreemodel.cpp => src/workspace/fstreemodel.cpp +8 -0
@@ 90,3 90,11 @@ int FsTreeModel::columnCount(const QModelIndex& parent) const {
    return 1;
}

void FsTreeModel::beginInsertRows1(const QModelIndex& parent, int first, int last) {
    QAbstractItemModel::beginInsertRows(parent, first, last);
}

void FsTreeModel::endInsertRows1() {
    QAbstractItemModel::endInsertRows();
}


M src/workspace/fstreemodel.h => src/workspace/fstreemodel.h +11 -7
@@ 12,19 12,23 @@ class FsTreeModel : public QAbstractItemModel {
public:
    explicit FsTreeModel(Workspace* ws, QObject* parent = nullptr);

    QModelIndex index(int row, int column, const QModelIndex& parent) const override;
    [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex& parent) const override;

    QModelIndex parent(const QModelIndex& child) const override;
    [[nodiscard]] QModelIndex parent(const QModelIndex& child) const override;

    QVariant data(const QModelIndex& index, int role) const override;
    [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;

    Qt::ItemFlags flags(const QModelIndex& index) const override;
    [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index) const override;

    QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
    [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

    int rowCount(const QModelIndex& parent) const override;
    [[nodiscard]] int rowCount(const QModelIndex& parent) const override;

    int columnCount(const QModelIndex& parent) const override;
    [[nodiscard]] int columnCount(const QModelIndex& parent) const override;

    void beginInsertRows1(const QModelIndex &parent, int first, int last);

    void endInsertRows1();

public slots: