[vlmc-devel] MainWindow: Add Recent Projects action

Yikai Lu git at videolan.org
Mon Aug 22 04:19:24 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sun Aug 21 21:08:55 2016 -0500| [0079c8927a4fbfb29af7f5f3836df6cf34c6863f] | committer: Yikai Lu

MainWindow: Add Recent Projects action

> https://code.videolan.org/videolan/vlmc/commit/0079c8927a4fbfb29af7f5f3836df6cf34c6863f
---

 src/Gui/MainWindow.cpp   | 24 ++++++++++++++++++++++++
 src/Gui/MainWindow.h     |  1 +
 src/Gui/ui/MainWindow.ui |  6 ++++++
 3 files changed, 31 insertions(+)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index aa7b5d0..e5807e7 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -90,6 +90,7 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
     checkFolders();
     loadGlobalProxySettings();
     createProjectPreferences();
+    updateRecentProjects();
 
 #ifdef WITH_CRASHBUTTON
     setupCrashTester();
@@ -105,6 +106,8 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
              this, SLOT( onProjectSaved() ) );
     connect( Core::instance()->project(), &Project::cleanStateChanged,
              this, &MainWindow::cleanStateChanged );
+    connect( Core::instance()->recentProjects(), &RecentProjects::updated,
+             this, &MainWindow::updateRecentProjects );
 
     //Connecting Library stuff:
     const ClipRenderer* clipRenderer = qobject_cast<const ClipRenderer*>( m_clipPreview->getAbstractRenderer() );
@@ -821,6 +824,27 @@ MainWindow::closeEvent( QCloseEvent* e )
 }
 
 void
+MainWindow::updateRecentProjects()
+{
+    auto menu = new QMenu;
+    for ( const auto& var : Core::instance()->recentProjects()->toVariant().toList() )
+    {
+        const auto& m = var.toMap();
+        auto name = m["name"].toString();
+        auto file = m["file"].toString();
+        auto action = menu->addAction( QString( "%1 - %2" )
+                                       .arg( name )
+                                       .arg( file )
+                                       );
+        connect( action, &QAction::triggered, this, [this, file]()
+        {
+            Core::instance()->loadProject( file );
+        } );
+    }
+    m_ui.actionRecent_Projects->setMenu( menu );
+}
+
+void
 MainWindow::projectNameChanged( const QString& projectName )
 {
     QString title = tr( "%1 VideoLAN Movie Creator [*]" ).arg( projectName );
diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h
index 98b731a..40f51e0 100644
--- a/src/Gui/MainWindow.h
+++ b/src/Gui/MainWindow.h
@@ -157,6 +157,7 @@ private slots:
     void                    on_actionCrash_triggered();
     void                    on_actionImport_triggered();
     void                    toolButtonClicked( QAction *action );
+    void                    updateRecentProjects();
     void                    projectNameChanged(const QString& projectName);
     void                    cleanStateChanged( bool isClean );
     void                    canUndoChanged( bool canUndo );
diff --git a/src/Gui/ui/MainWindow.ui b/src/Gui/ui/MainWindow.ui
index 5cd4233..c76bc4a 100644
--- a/src/Gui/ui/MainWindow.ui
+++ b/src/Gui/ui/MainWindow.ui
@@ -65,6 +65,7 @@
     <addaction name="separator"/>
     <addaction name="actionSave"/>
     <addaction name="actionSave_As"/>
+    <addaction name="actionRecent_Projects"/>
     <addaction name="separator"/>
     <addaction name="actionImport"/>
     <addaction name="menu_Export"/>
@@ -396,6 +397,11 @@
     <bool>false</bool>
    </property>
   </action>
+  <action name="actionRecent_Projects">
+   <property name="text">
+    <string>&Recent Projects</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../../../resources.qrc"/>



More information about the Vlmc-devel mailing list