diff options
Diffstat (limited to 'lsmainwindow.cpp')
-rw-r--r-- | lsmainwindow.cpp | 186 |
1 files changed, 119 insertions, 67 deletions
diff --git a/lsmainwindow.cpp b/lsmainwindow.cpp index 735d7a3..66c51b3 100644 --- a/lsmainwindow.cpp +++ b/lsmainwindow.cpp @@ -20,24 +20,25 @@ #include <QMenuBar> #include <QFileDialog> #include <QInputDialog> +#include <QMessageBox> #include "lyt/archivepackage.h" LSMainWindow::LSMainWindow(QWidget *parent) : QMainWindow(parent) { - m_package = 0; - m_dirty = false; - m_isSaved = false; + m_package = 0; + m_dirty = false; + m_isSaved = false; createActions(); m_view = new QTreeView(this); setCentralWidget(m_view); - newArchive(); + newArchive(); } LSMainWindow::~LSMainWindow() { - if (m_package) - delete m_package; + if (m_package) + delete m_package; } @@ -71,6 +72,9 @@ void LSMainWindow::createActions() { connect(m_addTextureAction, SIGNAL(triggered()), m_addActionMapper, SLOT(map())); connect(m_addActionMapper, SIGNAL(mapped(int)), SLOT(handleAddSomething(int))); + connect(m_renameAction, SIGNAL(triggered()), SLOT(handleRenameItem())); + connect(m_removeAction, SIGNAL(triggered()), SLOT(handleRemoveItem())); + QMenuBar *bar = menuBar(); QMenu *m; @@ -130,94 +134,142 @@ void LSMainWindow::handleAddSomething(int whatToAdd) { } +void LSMainWindow::handleRemoveItem() { + QString what = selectedItem(); + LYTPackageBase::ItemType whatType = selectedItemType(); + + if (!what.isEmpty()) { + QString confirmText = QString("Are you sure you want to delete '%1'? You'll lose it forever...!").arg(what); + + int confirm = QMessageBox::question(this, + "Confirm Removal", + confirmText, + QMessageBox::Yes, + QMessageBox::No); + + if (confirm == QMessageBox::Yes) { + m_package->remove(whatType, what); + } + } +} + + +void LSMainWindow::handleRenameItem() { + QString what = selectedItem(); + LYTPackageBase::ItemType whatType = selectedItemType(); + + if (!what.isEmpty()) { + QString newName = QInputDialog::getText(this, + "Rename Item", + QString("Enter a new name:"), + QLineEdit::NoEcho, + what); + + if (!newName.isEmpty()) { + m_package->rename(whatType, what, newName); + } + } +} + + +QString LSMainWindow::selectedItem() const { + QModelIndex idx = m_view->currentIndex(); + return m_model->itemNameForIndex(idx); +} + +LYTPackageBase::ItemType LSMainWindow::selectedItemType() const { + QModelIndex idx = m_view->currentIndex(); + return m_model->itemTypeForIndex(idx); +} + bool LSMainWindow::ensureSaved() { - // TODO - return false; + // TODO + return false; } void LSMainWindow::updateTitleBar() { - QString title; - if (m_isSaved) - title = m_package->description(); - else - title = "[Unsaved]"; - - if (m_dirty) - title.append('*'); - title.append(" - LayoutStudio"); - - setWindowTitle(title); - setWindowModified(m_dirty); + QString title; + if (m_isSaved) + title = m_package->description(); + else + title = "[Unsaved]"; + + if (m_dirty) + title.append('*'); + title.append(" - LayoutStudio"); + + setWindowTitle(title); + setWindowModified(m_dirty); } void LSMainWindow::newArchive() { - if (ensureSaved()) - return; + if (ensureSaved()) + return; - LYTArchivePackage *pkg = new LYTArchivePackage; - setCurrentPackage(pkg); + LYTArchivePackage *pkg = new LYTArchivePackage; + setCurrentPackage(pkg); - m_dirty = false; - m_isSaved = false; - updateTitleBar(); + m_dirty = false; + m_isSaved = false; + updateTitleBar(); } void LSMainWindow::openArchive() { - if (ensureSaved()) - return; + if (ensureSaved()) + return; - QString path = QFileDialog::getOpenFileName(this, - "Open a Layout Archive", - QString(), - "Wii Archives (*.arc)" - ); + QString path = QFileDialog::getOpenFileName(this, + "Open a Layout Archive", + QString(), + "Wii Archives (*.arc)" + ); - if (path.isEmpty()) - return; + if (path.isEmpty()) + return; - LYTArchivePackage *pkg = new LYTArchivePackage(path); - setCurrentPackage(pkg); + LYTArchivePackage *pkg = new LYTArchivePackage(path); + setCurrentPackage(pkg); - m_dirty = false; - m_isSaved = false; - updateTitleBar(); + m_dirty = false; + m_isSaved = false; + updateTitleBar(); } void LSMainWindow::save() { - // TODO: check that m_package is an arc - if (m_isSaved) { - m_dirty = false; - m_package->savePackage(); - updateTitleBar(); - } else { - saveArchiveAs(); - } + // TODO: check that m_package is an arc + if (m_isSaved) { + m_dirty = false; + m_package->savePackage(); + updateTitleBar(); + } else { + saveArchiveAs(); + } } void LSMainWindow::saveArchiveAs() { - // TODO: check that m_package is an arc - QString newPath = QFileDialog::getSaveFileName(this, - "Save Layout Archive", - QString(), - "Wii Archives (*.arc)" - ); - - if (newPath.isEmpty()) - return; - - LYTArchivePackage *pkg = (LYTArchivePackage*)m_package; - pkg->setFilename(newPath); - pkg->savePackage(); - - m_dirty = false; - m_isSaved = true; - updateTitleBar(); + // TODO: check that m_package is an arc + QString newPath = QFileDialog::getSaveFileName(this, + "Save Layout Archive", + QString(), + "Wii Archives (*.arc)" + ); + + if (newPath.isEmpty()) + return; + + LYTArchivePackage *pkg = (LYTArchivePackage*)m_package; + pkg->setFilename(newPath); + pkg->savePackage(); + + m_dirty = false; + m_isSaved = true; + updateTitleBar(); } void LSMainWindow::setCurrentPackage(LYTPackageBase *pkg) { - m_package = pkg; + m_package = pkg; QItemSelectionModel *oldSel = m_view->selectionModel(); QAbstractItemModel *model = m_view->model(); |