From 59f99d0b9968e0b1457deaaba8a63025260bfbfb Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 29 Aug 2018 22:19:53 -1000 Subject: [PATCH] Better unsaved project warning --- Editor/ADSREditor.cpp | 4 +- Editor/MainWindow.cpp | 48 ++++-- Editor/MainWindow.hpp | 1 + Editor/ProjectModel.cpp | 3 + Editor/SongGroupEditor.cpp | 1 + Editor/resources/lang_de.ts | 330 ++++++++++++++++++------------------ 6 files changed, 207 insertions(+), 180 deletions(-) diff --git a/Editor/ADSREditor.cpp b/Editor/ADSREditor.cpp index 1700f38..61c053e 100644 --- a/Editor/ADSREditor.cpp +++ b/Editor/ADSREditor.cpp @@ -185,10 +185,8 @@ void ADSRView::mousePressEvent(QMouseEvent* ev) PointDistance(ev->localPos(), points[2]) }; - QPointF testPos = ev->localPos(); - int minDist = 0; - if (dists[1] < dists[minDist]) + if (dists[1] < dists[minDist] + 8.0) /* pt1 overlaps pt0, so include radius in test */ minDist = 1; if (dists[2] < dists[minDist]) minDist = 2; diff --git a/Editor/MainWindow.cpp b/Editor/MainWindow.cpp index b3f99de..cfb0907 100644 --- a/Editor/MainWindow.cpp +++ b/Editor/MainWindow.cpp @@ -613,6 +613,8 @@ bool MainWindow::openEditor(ProjectModel::SampleNode* node, bool appendNav) bool MainWindow::openEditor(ProjectModel::INode* node, bool appendNav) { + if (m_uiDisabled) + return false; switch (node->type()) { case ProjectModel::INode::Type::SongGroup: @@ -750,13 +752,10 @@ void MainWindow::aboutToDeleteNode(ProjectModel::INode* node) closeEditor(); } -void MainWindow::closeEvent(QCloseEvent* ev) +bool MainWindow::askAboutSave() { if (!m_projectModel) - { - ev->accept(); - return; - } + return true; if (!m_undoStack->isClean()) { @@ -766,23 +765,24 @@ void MainWindow::closeEvent(QCloseEvent* ev) if (result == QMessageBox::Save) { saveAction(); - ev->accept(); - } - else if (result == QMessageBox::Discard) - { - ev->accept(); - } - else - { - ev->ignore(); + return true; } + return result == QMessageBox::Discard; } else { - ev->accept(); + return true; } } +void MainWindow::closeEvent(QCloseEvent* ev) +{ + if (askAboutSave()) + ev->accept(); + else + ev->ignore(); +} + void MainWindow::showEvent(QShowEvent* ev) { m_studioSetup->updateWindowPosition(); @@ -790,6 +790,9 @@ void MainWindow::showEvent(QShowEvent* ev) void MainWindow::newAction() { + if (!askAboutSave()) + return; + QString path = QFileDialog::getSaveFileName(this, tr("New Project")); if (path.isEmpty()) return; @@ -858,6 +861,9 @@ bool MainWindow::openProject(const QString& path) void MainWindow::openAction() { + if (!askAboutSave()) + return; + QString path = QFileDialog::getExistingDirectory(this, tr("Open Project")); if (path.isEmpty()) return; @@ -866,6 +872,9 @@ void MainWindow::openAction() void MainWindow::openRecentFileAction() { + if (!askAboutSave()) + return; + if (QAction *action = qobject_cast(sender())) if (!openProject(action->data().toString())) { @@ -898,6 +907,15 @@ void MainWindow::saveAction() void MainWindow::revertAction() { + if (m_projectModel && !m_undoStack->isClean()) + { + QDir dir(m_projectModel->path()); + int result = m_mainMessenger.question(tr("Unsaved Changes"), tr("Discard Changes in %1?").arg(dir.dirName()), + QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel); + if (result == QMessageBox::Cancel) + return; + } + QString path = m_projectModel->path(); closeEditor(); m_undoStack->clear(); diff --git a/Editor/MainWindow.hpp b/Editor/MainWindow.hpp index b333942..da048b3 100644 --- a/Editor/MainWindow.hpp +++ b/Editor/MainWindow.hpp @@ -188,6 +188,7 @@ public: void pushUndoCommand(EditorUndoCommand* cmd); void updateFocus(); void aboutToDeleteNode(ProjectModel::INode* node); + bool askAboutSave(); void closeEvent(QCloseEvent* ev); void showEvent(QShowEvent* ev); diff --git a/Editor/ProjectModel.cpp b/Editor/ProjectModel.cpp index 37fc6d3..cddf993 100644 --- a/Editor/ProjectModel.cpp +++ b/Editor/ProjectModel.cpp @@ -1275,6 +1275,7 @@ protected: m_data = g_MainWindow->projectModel()->_delNode(static_cast(m_node.get()), m_nameReg); setObsolete(true); g_MainWindow->m_undoStack->clear(); + g_MainWindow->m_undoStack->resetClean(); } public: explicit GroupNodeUndoCommand(const QString& text, std::unique_ptr&& data, @@ -2172,6 +2173,7 @@ void ProjectModel::del(const QModelIndex& index) NameUndoRegistry nameReg; g_MainWindow->projectModel()->_delNode(static_cast(n), nameReg); g_MainWindow->m_undoStack->clear(); + g_MainWindow->m_undoStack->resetClean(); break; } case INode::Type::SongGroup: @@ -2208,6 +2210,7 @@ void ProjectModel::del(const QModelIndex& index) gn->getAudioGroup()->deleteSample(static_cast(n)->id()); _delPoolNode(static_cast(n), gn, nameReg, gn->getAudioGroup()->getSdir().sampleEntries()); g_MainWindow->m_undoStack->clear(); + g_MainWindow->m_undoStack->resetClean(); break; } default: diff --git a/Editor/SongGroupEditor.cpp b/Editor/SongGroupEditor.cpp index f18f842..1dacd63 100644 --- a/Editor/SongGroupEditor.cpp +++ b/Editor/SongGroupEditor.cpp @@ -1261,6 +1261,7 @@ void PageTableView::setModel(QAbstractItemModel* model) PageTableView::PageTableView(QWidget* parent) : QTableView(parent) { + setObjectName("amusetable"); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::ExtendedSelection); setGridStyle(Qt::NoPen); diff --git a/Editor/resources/lang_de.ts b/Editor/resources/lang_de.ts index 6e71047..5149f51 100644 --- a/Editor/resources/lang_de.ts +++ b/Editor/resources/lang_de.ts @@ -4,94 +4,94 @@ ADSRControls - + Change Attack - + Change Decay - + Change Sustain - + Change Attack/Decay - + Change Decay/Sustain - + Change Release - + Change DLS - + Change Vel To Attack - + Change Key To Decay - + Attack - - - + + + sec - + Decay - + Sustain - + % - + Release - + DLS - + Vel To Attack - + Key To Decay @@ -427,13 +427,13 @@ MIDIPlayerWidget - + Stop - - + + Play @@ -477,13 +477,13 @@ - + The directory at '%1' must not be empty. - + Directory empty @@ -533,251 +533,257 @@ - + + Unsaved Changes - + Save Changes in %1? - + New Project - + The directory at '%1' does not exist. - + Bad Directory - + Opening - - - - - + + + + + Scanning Project - + Opening %1 - + Open Project - + + Discard Changes in %1? + + + + Reloading Samples - + Scanning %1 - + Import Project - + The file at '%1' could not be interpreted as a MusyX container. - + Unsupported MusyX Container - + Sample Import Mode - + Amuse can import samples as WAV files for ease of editing, import original compressed data for lossless repacking, or both. Exporting the project will prefer whichever version was modified most recently. - + Import Compressed - + Import WAVs - + Import Both - + Raw Import Mode - + Would you like to scan for all MusyX group files in this directory? - + Project Name - + What should this project be named? - - + + Importing - - + + Importing %1 - + Import Songs - + Exporting - + Exporting %1 - - + + Import C Headers - + <p>Importing names from C headers depends on up-to-date, consistent names relative to the sound group data.</p><p>Headers are imported on a per-subproject basis from a single directory. Headers must be named with the form <code>&lt;subproject&gt;.h</code>.</p><p>Group, Song and SFX definitions are matched according to the following forms:<pre>#define GRP&lt;name&gt; &lt;id&gt; #define SNG&lt;name&gt; &lt;id&gt; #define SFX&lt;name> &lt;id&gt;</pre></p><p><strong>This operation cannot be undone! Is is recommended to make a backup of the project directory before proceeding.</strong></p><p>Continue?</p> - + Export C Headers - + New Subproject - + What should this subproject be named? - + New SFX Group - + What should the new SFX group in %1 be named? - + New Song Group - + What should the new Song group in %1 be named? - + New ADSR - + What should the new ADSR in %1 be named? - + New Curve - + What should the new Curve in %1 be named? - + New Keymap - + What should the new Keymap in %1 be named? - + New Layers - + What should the new Layers in %1 be named? - + About Amuse - + Export Complete - + %1? @@ -1316,234 +1322,234 @@ - + Subproject Conflict - + The subproject %1 is already defined - - - + + + Add Subproject %1 - + Sound Group Conflict - - + + The group %1 is already defined - - - + + + Add Sound Group %1 - + Song Group Conflict - - - + + + Add Song Group %1 - + Sound Macro Conflict - + The macro %1 is already defined - - + + Add Sound Macro %1 - + ADSR Conflict - + The ADSR %1 is already defined - - - + + + Add ADSR %1 - + Curve Conflict - + The Curve %1 is already defined - - - + + + Add Curve %1 - + Keymap Conflict - + The Keymap %1 is already defined - - - + + + Add Keymap %1 - + Layers Conflict - + Layers %1 is already defined - - - + + + Add Layers %1 - - + + -copy - + Add SoundMacro %1 - + Cut SongGroup %1 - + Cut SFXGroup %1 - + Cut SoundMacro %1 - + Cut ADSR %1 - + Cut Curve %1 - + Cut Keymap %1 - + Cut Layers %1 - + Delete Subproject - + <p>The subproject %1 will be permanently deleted from the project. Sample files will be permanently removed from the file system.</p><p><strong>This action cannot be undone!</strong></p><p>Continue?</p> - + Delete Sample - + <p>The sample %1 will be permanently deleted from the file system. <p><strong>This action cannot be undone!</strong></p><p>Continue?</p> - + Delete SongGroup %1 - + Delete SFXGroup %1 - + Delete SoundMacro %1 - + Delete ADSR %1 - + Delete Curve %1 - + Delete Keymap %1 - + Delete Layers %1 @@ -1551,7 +1557,7 @@ QDialogButtonBox - + OK @@ -1559,12 +1565,12 @@ QMessageBox - + <h3>About Amuse</h3> - + <p>Amuse is an alternate editor and runtime library for MusyX sound groups.</p><p>MusyX originally served as a widely-deployed audio system for developing games on the Nintendo 64, GameCube, and GameBoy Advance.</p><p>Amuse is available under the MIT license.<br>Please see <a href="https://gitlab.axiodl.com/AxioDL/amuse/blob/master/LICENSE">https://gitlab.axiodl.com/AxioDL/amuse/blob/master/LICENSE</a> for futher information.</p><p>Copyright (C) 2015-2018 Antidote / Jackoalan.</p><p>MusyX is a trademark of Factor 5, LLC.</p><p>Nintendo 64, GameCube, and GameBoy Advance are trademarks of Nintendo Co., Ltd.</p> @@ -1797,12 +1803,12 @@ SetupTableView - + Delete Setup Entries - + Delete Setup Entry @@ -1810,37 +1816,37 @@ SongGroupEditor - + Add new page entry - + Remove selected page entries - + Normal Pages - + Add Page Entry - + Add Setup Entry - + Drum Pages - + MIDI Setups @@ -2014,52 +2020,52 @@ TreeDelegate - + Export GameCube Group - + Find Usages - + Cut - + Copy - + Paste - + Duplicate - + Delete - + Rename - + Exporting - + Exporting %1