]> Creatis software - clitk.git/commitdiff
When an image is opened it is now added to the recently opened files menu
authorMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 13:51:54 +0000 (15:51 +0200)
committerMaxime <mpech@russule.clb.loc>
Fri, 6 May 2011 13:51:54 +0000 (15:51 +0200)
vv/vvMainWindow.cxx
vv/vvMainWindow.h

index 3a11afe6f176917ae6dc5d566b262268958eea2e..df3b67570cae733ca809e938c417f46be75b2e2e 100644 (file)
@@ -308,17 +308,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 
   //Recently opened files
   std::list<std::string> recent_files = GetRecentlyOpenedImages();
+  recentlyOpenedFilesMenu=NULL;
   if ( !recent_files.empty() ) {
-    QMenu * rmenu = new QMenu("Recently opened files...");
-    rmenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png")));
-    menuFile->insertMenu(actionOpen_Image_With_Time,rmenu);
-    menuFile->insertSeparator(actionOpen_Image_With_Time);
-    for (std::list<std::string>::iterator i = recent_files.begin(); i!=recent_files.end(); i++) {
-      QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")),
-                                   (*i).c_str(),this);
-      rmenu->addAction(current);
-      connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage()));
-    }
+    createRecentlyOpenedFilesMenu();
+    updateRecentlyOpenedFilesMenu(recent_files);
   }
 
   // Adding all new tools (insertion in the menu)
@@ -351,6 +344,35 @@ void vvMainWindow::UpdateMemoryUsage()
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvMainWindow::createRecentlyOpenedFilesMenu()
+{
+    recentlyOpenedFilesMenu = new QMenu("Recently opened files...");
+    recentlyOpenedFilesMenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png")));
+    menuFile->insertMenu(actionOpen_Image_With_Time,recentlyOpenedFilesMenu);
+    menuFile->insertSeparator(actionOpen_Image_With_Time);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+
+void vvMainWindow::updateRecentlyOpenedFilesMenu(const std::list<std::string> &recent_files)
+{
+  if(recentlyOpenedFilesMenu==NULL){
+    createRecentlyOpenedFilesMenu();
+  }else{
+    recentlyOpenedFilesMenu->clear();
+  }
+  for (std::list<std::string>::const_iterator i = recent_files.begin(); i!=recent_files.end(); i++) {
+    QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")), i->c_str(),this);
+    recentlyOpenedFilesMenu->addAction(current);
+    connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage()));
+  }
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvMainWindow::ComputeMidPosition()
 {
@@ -796,6 +818,7 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
   if (files.size() == 1) {
     QFileInfo finfo=tr(files[0].c_str());
     AddToRecentlyOpenedImages(finfo.absoluteFilePath().toStdString());
+    updateRecentlyOpenedFilesMenu(GetRecentlyOpenedImages());
   }
   //init the progress events
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
index d95e7fa166e0468f68e12ee24b8f910e205293fb..e01bcec1d55763f0786a7e622408e69522f2abc7 100644 (file)
@@ -152,7 +152,12 @@ public slots:
   }
   void UpdateRenderWindows();
   void UpdateMemoryUsage();
-
+  
+protected:
+  
+  void createRecentlyOpenedFilesMenu();
+  void updateRecentlyOpenedFilesMenu(const std::list<std::string> &files);
+  
 private:
 
   //variables
@@ -184,6 +189,7 @@ private:
   int GetImageDuplicateFilenameNumber(std::string filename);
 
   QMenu contextMenu;
+  QMenu* recentlyOpenedFilesMenu;
   //QMenu *AddSubImageMenu;
   std::vector<QAction*> contextActions;
   std::vector<QSlider*> horizontalSliders;