# HG changeset patch # User Chris Cannam # Date 1305032339 -3600 # Node ID 72a2b4210e509ef6ae1a378469cd17b5060d93d1 # Parent eaab4c65c7bcc10f19b0027211280c42b8a3576a Add filesystem watcher to recreate template menu when templates change; start implementing save-session-as-template diff -r eaab4c65c7bc -r 72a2b4210e50 main/MainWindow.cpp --- a/main/MainWindow.cpp Mon May 09 16:57:29 2011 +0100 +++ b/main/MainWindow.cpp Tue May 10 13:58:59 2011 +0100 @@ -114,6 +114,7 @@ #include #include #include +#include #include #include @@ -139,6 +140,7 @@ m_sliceMenu(0), m_recentFilesMenu(0), m_recentTransformsMenu(0), + m_templatesMenu(0), m_rightButtonMenu(0), m_rightButtonLayerMenu(0), m_rightButtonTransformsMenu(0), @@ -160,7 +162,8 @@ m_preferencesDialog(0), m_layerTreeDialog(0), m_activityLog(new ActivityLog()), - m_keyReference(new KeyReference()) + m_keyReference(new KeyReference()), + m_templateWatcher(0) { Profiler profiler("MainWindow::MainWindow"); @@ -1697,6 +1700,13 @@ connect(action, SIGNAL(triggered()), this, SLOT(manageSavedTemplates())); action->setEnabled(havePersonal); m_templatesMenu->addAction(action); + + if (!m_templateWatcher) { + m_templateWatcher = new QFileSystemWatcher(this); + m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates")); + connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)), + this, SLOT(setupTemplatesMenu())); + } } void @@ -2859,9 +2869,13 @@ tr("Please enter a name for the saved template:")); if (name == "") return; - //!!! sanitise! - - + //!!! sanitise name! + + //!!! check/confirm if target exists! + + ResourceFinder rf; + QString dir = rf.getResourceSaveDir("templates"); + saveSessionTemplate(QString("%1/%2.svt").arg(dir).arg(name)); } void diff -r eaab4c65c7bc -r 72a2b4210e50 main/MainWindow.h --- a/main/MainWindow.h Mon May 09 16:57:29 2011 +0100 +++ b/main/MainWindow.h Tue May 10 13:58:59 2011 +0100 @@ -58,6 +58,7 @@ class KeyReference; class Labeller; class ActivityLog; +class QFileSystemWatcher; class MainWindow : public MainWindowBase { @@ -227,6 +228,8 @@ ActivityLog *m_activityLog; KeyReference *m_keyReference; + QFileSystemWatcher *m_templateWatcher; + struct LayerConfiguration { LayerConfiguration(LayerFactory::LayerType _layer = LayerFactory::TimeRuler,