From 8c93b6bfee54a06aa116e63751dad919162c5d10 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Aug 2015 15:46:10 +0200 Subject: [PATCH] Fixes #2272 and other problems with the templates Removes the non-intuitive saving of the default template in MainWindow::createNewProject. Other fixed problems: * User entries were not shown in the menu of the tool button that creates new projects from templates. Now they are shown as well. Other changes: * Adds a new option "New from template" in the file menu. It shows the same menu as the tool button. --- include/ConfigManager.h | 5 +++++ src/gui/MainWindow.cpp | 44 +++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/ConfigManager.h b/include/ConfigManager.h index 0cc2f5922..3ad94e185 100644 --- a/include/ConfigManager.h +++ b/include/ConfigManager.h @@ -120,6 +120,11 @@ public: return dataDir() + PROJECTS_PATH; } + QString factoryTemplatesDir() const + { + return factoryProjectsDir() + TEMPLATE_PATH; + } + QString factoryPresetsDir() const { return dataDir() + PRESETS_PATH; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e9c3dd850..5f8f57d89 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -244,6 +244,13 @@ void MainWindow::finalize() this, SLOT( createNewProject() ), QKeySequence::New ); + m_templatesMenu = new QMenu( tr("New from template"), this ); + connect( m_templatesMenu, SIGNAL( aboutToShow() ), SLOT( fillTemplatesMenu() ) ); + connect( m_templatesMenu, SIGNAL( triggered( QAction * ) ), + SLOT( createNewProjectFromTemplate( QAction * ) ) ); + + project_menu->addMenu(m_templatesMenu); + project_menu->addAction( embed::getIconPixmap( "project_open" ), tr( "&Open..." ), this, SLOT( openProject() ), @@ -269,6 +276,7 @@ void MainWindow::finalize() tr( "Save as New &Version" ), this, SLOT( saveProjectAsNewVersion() ), Qt::CTRL + Qt::ALT + Qt::Key_S ); + project_menu->addSeparator(); project_menu->addAction( embed::getIconPixmap( "project_import" ), tr( "Import..." ), @@ -382,12 +390,6 @@ void MainWindow::finalize() tr( "Create new project from template" ), this, SLOT( emptySlot() ), m_toolBar ); - - m_templatesMenu = new QMenu( project_new_from_template ); - connect( m_templatesMenu, SIGNAL( aboutToShow() ), - this, SLOT( fillTemplatesMenu() ) ); - connect( m_templatesMenu, SIGNAL( triggered( QAction * ) ), - this, SLOT( createNewProjectFromTemplate( QAction * ) ) ); project_new_from_template->setMenu( m_templatesMenu ); project_new_from_template->setPopupMode( ToolButton::InstantPopup ); @@ -771,14 +773,6 @@ void MainWindow::createNewProject() { Engine::getSong()->createNewProject(); } - QString default_template = ConfigManager::inst()->userTemplateDir() - + "default.mpt"; - - //if we dont have a user default template, make one - if( !QFile::exists( default_template ) ) - { - Engine::getSong()->saveProjectFile( default_template ); - } } @@ -786,14 +780,16 @@ void MainWindow::createNewProject() void MainWindow::createNewProjectFromTemplate( QAction * _idx ) { - if( m_templatesMenu != NULL && mayChangeProject(true) ) + if( m_templatesMenu && mayChangeProject(true) ) { - QString dir_base = m_templatesMenu->actions().indexOf( _idx ) - >= m_custom_templates_count ? - ConfigManager::inst()->factoryProjectsDir() : - ConfigManager::inst()->userProjectsDir(); + int indexOfTemplate = m_templatesMenu->actions().indexOf( _idx ); + bool isFactoryTemplate = indexOfTemplate >= m_custom_templates_count; + QString dir_base = isFactoryTemplate ? + ConfigManager::inst()->factoryTemplatesDir() : + ConfigManager::inst()->userTemplateDir(); + Engine::getSong()->createNewProjectFromTemplate( - dir_base + "templates/" + _idx->text() + ".mpt" ); + dir_base + _idx->text() + ".mpt" ); } } @@ -811,11 +807,11 @@ void MainWindow::openProject() if( ofd.exec () == QDialog::Accepted && !ofd.selectedFiles().isEmpty() ) { - Engine::getSong()->stop(); + Song *song = Engine::getSong(); + song->stop(); setCursor( Qt::WaitCursor ); - Engine::getSong()->loadProject( - ofd.selectedFiles()[0] ); + song->loadProject( ofd.selectedFiles()[0] ); setCursor( Qt::ArrowCursor ); } } @@ -1344,7 +1340,7 @@ void MainWindow::fillTemplatesMenu() { m_templatesMenu->clear(); - QDir user_d( ConfigManager::inst()->userProjectsDir() + "templates" ); + QDir user_d( ConfigManager::inst()->userTemplateDir() ); QStringList templates = user_d.entryList( QStringList( "*.mpt" ), QDir::Files | QDir::Readable );