From 8c93b6bfee54a06aa116e63751dad919162c5d10 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Aug 2015 15:46:10 +0200 Subject: [PATCH 1/3] 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 ); From bc1a416cd145259ed14402a4d551383c20876cff Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 16 Aug 2015 16:18:38 +0200 Subject: [PATCH 2/3] Added an option to save a project as the default template A new option to save a project as the default template is now available in the file menu. If the default template already exists the user is asked whether he wants to overwrite it. --- include/MainWindow.h | 1 + src/gui/MainWindow.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/MainWindow.h b/include/MainWindow.h index 68c6dc24e..f3b93740f 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -113,6 +113,7 @@ public slots: bool saveProject(); bool saveProjectAs(); bool saveProjectAsNewVersion(); + void saveProjectAsDefaultTemplate(); void showSettingsDialog(); void aboutLMMS(); void help(); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 5f8f57d89..218c41f3f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -277,6 +277,9 @@ void MainWindow::finalize() this, SLOT( saveProjectAsNewVersion() ), Qt::CTRL + Qt::ALT + Qt::Key_S ); + project_menu->addAction( tr( "Save as default template" ), + this, SLOT( saveProjectAsDefaultTemplate() ) ); + project_menu->addSeparator(); project_menu->addAction( embed::getIconPixmap( "project_import" ), tr( "Import..." ), @@ -933,6 +936,29 @@ bool MainWindow::saveProjectAsNewVersion() +void MainWindow::saveProjectAsDefaultTemplate() +{ + QString defaultTemplate = ConfigManager::inst()->userTemplateDir() + "default.mpt"; + + QFileInfo fileInfo(defaultTemplate); + if (fileInfo.exists()) + { + if (QMessageBox::warning(this, + tr("Overwrite default template?"), + tr("This will overwrite your current default template."), + QMessageBox::Ok, + QMessageBox::Cancel) != QMessageBox::Ok) + { + return; + } + } + + Engine::getSong()->saveProjectFile( defaultTemplate ); +} + + + + void MainWindow::showSettingsDialog() { SetupDialog sd; From abbd7c48cfb3651eeb3ea69a111eee56463001b0 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Wed, 26 Aug 2015 18:59:31 +0200 Subject: [PATCH 3/3] Switch local variable to camel case --- src/gui/MainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 218c41f3f..389dcd75e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -787,12 +787,12 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx ) { int indexOfTemplate = m_templatesMenu->actions().indexOf( _idx ); bool isFactoryTemplate = indexOfTemplate >= m_custom_templates_count; - QString dir_base = isFactoryTemplate ? + QString dirBase = isFactoryTemplate ? ConfigManager::inst()->factoryTemplatesDir() : ConfigManager::inst()->userTemplateDir(); Engine::getSong()->createNewProjectFromTemplate( - dir_base + _idx->text() + ".mpt" ); + dirBase + _idx->text() + ".mpt" ); } }