diff mainwindow.cpp @ 359:550650bbb959 feature_91

Add "Open Recent". Fixes #91
author Chris Cannam
date Thu, 17 Mar 2011 16:35:38 +0000
parents ea6f76c0aa76
children 73fb5ef55744
line wrap: on
line diff
--- a/mainwindow.cpp	Thu Mar 17 13:52:57 2011 +0000
+++ b/mainwindow.cpp	Thu Mar 17 16:35:38 2011 +0000
@@ -29,6 +29,7 @@
 #include <QToolButton>
 #include <QSettings>
 #include <QInputDialog>
+#include <QWidgetAction>
 #include <QRegExp>
 #include <QShortcut>
 #include <QUrl>
@@ -129,6 +130,7 @@
     cs->addDefaultName(getUserInfo());
 
     hgTest();
+    updateRecentMenu();
 }
 
 
@@ -1078,11 +1080,11 @@
 
         QSettings settings;
         settings.beginGroup("General");
-        QString lastChoice = settings.value("lastopentype", "local").toString();
+        QString lastChoice = settings.value("lastopentype", "remote").toString();
         if (lastChoice != "local" &&
             lastChoice != "remote" &&
             lastChoice != "init") {
-            lastChoice = "local";
+            lastChoice = "remote";
         }
 
         d->setCurrentChoice(lastChoice);
@@ -1121,6 +1123,14 @@
     }
 }
 
+void MainWindow::recentMenuActivated()
+{
+    QAction *a = qobject_cast<QAction *>(sender());
+    if (!a) return;
+    QString local = a->text();
+    open(local);
+}
+
 void MainWindow::changeRemoteRepo()
 {
     // This will involve rewriting the local .hgrc
@@ -1311,7 +1321,7 @@
 {
     return (QMessageBox::question
             (this, tr("Folder has no repository"),
-             tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder does not contain a Mercurial repository.<br><br>Would you like to initialise a repository here?</qt>")
+             tr("<qt><b>Initialise a repository here?</b><br><br>You asked to open \"%1\".<br>This folder is not a Mercurial working copy.<br><br>Would you like to initialise a repository here?</qt>")
              .arg(xmlEncode(arg)),
              QMessageBox::Ok | QMessageBox::Cancel,
              QMessageBox::Ok)
@@ -2217,6 +2227,7 @@
         m_stateUnknown = false;
         enableDisableActions();
         m_hgTabs->updateHistory();
+        updateRecentMenu();
     }
 }
 
@@ -2505,6 +2516,24 @@
     }
 }
 
+
+void MainWindow::updateRecentMenu()
+{
+    m_recentMenu->clear();
+    RecentFiles rf("Recent-local");
+    QStringList recent = rf.getRecent();
+    if (recent.empty()) {
+        QLabel *label = new QLabel(tr("No recent local repositories"));
+        QWidgetAction *wa = new QWidgetAction(m_recentMenu);
+        wa->setDefaultWidget(label);
+        return;
+    }
+    foreach (QString r, recent) {
+        QAction *a = m_recentMenu->addAction(r);
+        connect(a, SIGNAL(activated()), this, SLOT(recentMenuActivated()));
+    }
+}
+
 void MainWindow::createActions()
 {
     //File actions
@@ -2584,6 +2613,7 @@
     m_fileMenu = menuBar()->addMenu(tr("File"));
 
     m_fileMenu -> addAction(m_openAct);
+    m_recentMenu = m_fileMenu->addMenu(tr("Open Recent"));
     m_fileMenu -> addAction(m_changeRemoteRepoAct);
     m_fileMenu -> addSeparator();