Mercurial > hg > tony
comparison src/MainWindow.cpp @ 257:949c9446ebb5
Add save session options, etc
author | Chris Cannam |
---|---|
date | Wed, 02 Apr 2014 10:50:48 +0100 |
parents | 72622fcdd12c |
children | 2042fec57e0b |
comparison
equal
deleted
inserted
replaced
256:69c22ec29698 | 257:949c9446ebb5 |
---|---|
430 | 430 |
431 icon = il.load("fileopen"); | 431 icon = il.load("fileopen"); |
432 icon.addPixmap(il.loadPixmap("fileopen-22")); | 432 icon.addPixmap(il.loadPixmap("fileopen-22")); |
433 action = new QAction(icon, tr("&Open..."), this); | 433 action = new QAction(icon, tr("&Open..."), this); |
434 action->setShortcut(tr("Ctrl+O")); | 434 action->setShortcut(tr("Ctrl+O")); |
435 action->setStatusTip(tr("Open a file")); | 435 action->setStatusTip(tr("Open a session or audio file")); |
436 connect(action, SIGNAL(triggered()), this, SLOT(openFile())); | 436 connect(action, SIGNAL(triggered()), this, SLOT(openFile())); |
437 m_keyReference->registerShortcut(action); | 437 m_keyReference->registerShortcut(action); |
438 menu->addAction(action); | 438 menu->addAction(action); |
439 toolbar->addAction(action); | 439 toolbar->addAction(action); |
440 | 440 |
450 setupRecentFilesMenu(); | 450 setupRecentFilesMenu(); |
451 connect(&m_recentFiles, SIGNAL(recentChanged()), | 451 connect(&m_recentFiles, SIGNAL(recentChanged()), |
452 this, SLOT(setupRecentFilesMenu())); | 452 this, SLOT(setupRecentFilesMenu())); |
453 | 453 |
454 menu->addSeparator(); | 454 menu->addSeparator(); |
455 | |
456 icon = il.load("filesave"); | |
457 icon.addPixmap(il.loadPixmap("filesave-22")); | |
458 action = new QAction(icon, tr("&Save Session"), this); | |
459 action->setShortcut(tr("Ctrl+S")); | |
460 action->setStatusTip(tr("Save the current session into a %1 session file").arg(QApplication::applicationName())); | |
461 connect(action, SIGNAL(triggered()), this, SLOT(saveSession())); | |
462 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool))); | |
463 m_keyReference->registerShortcut(action); | |
464 menu->addAction(action); | |
465 toolbar->addAction(action); | |
466 | |
467 icon = il.load("filesaveas"); | |
468 icon.addPixmap(il.loadPixmap("filesaveas-22")); | |
469 action = new QAction(icon, tr("Save Session &As..."), this); | |
470 action->setShortcut(tr("Ctrl+Shift+S")); | |
471 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName())); | |
472 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs())); | |
473 menu->addAction(action); | |
474 toolbar->addAction(action); | |
475 | |
476 menu->addSeparator(); | |
477 | |
455 action = new QAction(tr("I&mport Pitch Track Data..."), this); | 478 action = new QAction(tr("I&mport Pitch Track Data..."), this); |
456 action->setStatusTip(tr("Import pitch-track data from a CSV, RDF, or layer XML file")); | 479 action->setStatusTip(tr("Import pitch-track data from a CSV, RDF, or layer XML file")); |
457 connect(action, SIGNAL(triggered()), this, SLOT(importPitchLayer())); | 480 connect(action, SIGNAL(triggered()), this, SLOT(importPitchLayer())); |
458 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool))); | 481 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool))); |
459 menu->addAction(action); | 482 menu->addAction(action); |
1556 { | 1579 { |
1557 // cerr << "MainWindow::closeEvent" << endl; | 1580 // cerr << "MainWindow::closeEvent" << endl; |
1558 | 1581 |
1559 if (m_openingAudioFile) { | 1582 if (m_openingAudioFile) { |
1560 // cerr << "Busy - ignoring close event" << endl; | 1583 // cerr << "Busy - ignoring close event" << endl; |
1561 e->ignore(); | 1584 e->ignore(); |
1562 return; | 1585 return; |
1563 } | 1586 } |
1564 | 1587 |
1565 if (!m_abandoning && !checkSaveModified()) { | 1588 if (!m_abandoning && !checkSaveModified()) { |
1566 // cerr << "Ignoring close event" << endl; | 1589 // cerr << "Ignoring close event" << endl; |
1567 e->ignore(); | 1590 e->ignore(); |
1568 return; | 1591 return; |
1569 } | 1592 } |
1570 | 1593 |
1571 QSettings settings; | 1594 QSettings settings; |
1572 settings.beginGroup("MainWindow"); | 1595 settings.beginGroup("MainWindow"); |
1573 settings.setValue("size", size()); | 1596 settings.setValue("size", size()); |
1632 // cancel. | 1655 // cancel. |
1633 | 1656 |
1634 if (!m_documentModified) return true; | 1657 if (!m_documentModified) return true; |
1635 | 1658 |
1636 int button = | 1659 int button = |
1637 QMessageBox::warning(this, | 1660 QMessageBox::warning(this, |
1638 tr("Session modified"), | 1661 tr("Session modified"), |
1639 tr("The current session has been modified.\nDo you want to save it?"), | 1662 tr("The current session has been modified.\nDo you want to save it?"), |
1640 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 1663 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
1641 QMessageBox::Yes); | 1664 QMessageBox::Yes); |
1642 | 1665 |
1643 if (button == QMessageBox::Yes) { | 1666 if (button == QMessageBox::Yes) { |
1644 saveSession(); | 1667 saveSession(); |
1645 if (m_documentModified) { // save failed -- don't proceed! | 1668 if (m_documentModified) { // save failed -- don't proceed! |
1646 return false; | 1669 return false; |
1647 } else { | 1670 } else { |
1648 return true; // saved, so it's safe to continue now | 1671 return true; // saved, so it's safe to continue now |
1649 } | 1672 } |
1650 } else if (button == QMessageBox::No) { | 1673 } else if (button == QMessageBox::No) { |
1651 m_documentModified = false; // so we know to abandon it | 1674 m_documentModified = false; // so we know to abandon it |
1652 return true; | 1675 return true; |
1653 } | 1676 } |
1654 | 1677 |
1655 // else cancel | 1678 // else cancel |
1656 return false; | 1679 return false; |
1657 } | 1680 } |
1658 | 1681 |
1659 void | 1682 void |
1660 MainWindow::saveSession() | 1683 MainWindow::saveSession() |
1661 { | 1684 { |
1662 if (m_sessionFile != "") { | 1685 if (m_sessionFile != "") { |
1663 if (!saveSessionFile(m_sessionFile)) { | 1686 if (!saveSessionFile(m_sessionFile)) { |
1664 QMessageBox::critical(this, tr("Failed to save file"), | 1687 QMessageBox::critical |
1665 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile)); | 1688 (this, tr("Failed to save file"), |
1689 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile)); | |
1690 } else { | |
1691 CommandHistory::getInstance()->documentSaved(); | |
1692 documentRestored(); | |
1693 } | |
1666 } else { | 1694 } else { |
1667 CommandHistory::getInstance()->documentSaved(); | 1695 saveSessionAs(); |
1668 documentRestored(); | |
1669 } | |
1670 } else { | |
1671 saveSessionAs(); | |
1672 } | 1696 } |
1673 } | 1697 } |
1674 | 1698 |
1675 void | 1699 void |
1676 MainWindow::saveSessionAs() | 1700 MainWindow::saveSessionAs() |