changeset 360:f34848e8094b

Merge from branch "feature_91"
author Chris Cannam
date Thu, 17 Mar 2011 16:36:02 +0000
parents ea6f76c0aa76 (current diff) 550650bbb959 (diff)
children 73fb5ef55744
files
diffstat 2 files changed, 37 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mainwindow.cpp	Thu Mar 17 13:52:57 2011 +0000
+++ b/mainwindow.cpp	Thu Mar 17 16:36:02 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();
 
--- a/mainwindow.h	Thu Mar 17 13:52:57 2011 +0000
+++ b/mainwindow.h	Thu Mar 17 16:36:02 2011 +0000
@@ -58,6 +58,7 @@
     void about();
     void settings();
     void open();
+    void recentMenuActivated();
     void changeRemoteRepo();
     void startupDialog();
     void clearSelections();
@@ -115,6 +116,8 @@
     void hgQueryParents();
     void hgLog();
     void hgLogIncremental(QStringList prune);
+
+    void updateRecentMenu();
     void createActions();
     void connectActions();
     void connectTabsSignals();
@@ -215,6 +218,7 @@
 
     // Menus
     QMenu *m_fileMenu;
+    QMenu *m_recentMenu;
     QMenu *m_advancedMenu;
     QMenu *m_helpMenu;