comparison 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
comparison
equal deleted inserted replaced
358:ea6f76c0aa76 359:550650bbb959
27 #include <QApplication> 27 #include <QApplication>
28 #include <QToolBar> 28 #include <QToolBar>
29 #include <QToolButton> 29 #include <QToolButton>
30 #include <QSettings> 30 #include <QSettings>
31 #include <QInputDialog> 31 #include <QInputDialog>
32 #include <QWidgetAction>
32 #include <QRegExp> 33 #include <QRegExp>
33 #include <QShortcut> 34 #include <QShortcut>
34 #include <QUrl> 35 #include <QUrl>
35 #include <QTimer> 36 #include <QTimer>
36 37
127 cs->addDefaultName(""); 128 cs->addDefaultName("");
128 cs->addDefaultName("default"); 129 cs->addDefaultName("default");
129 cs->addDefaultName(getUserInfo()); 130 cs->addDefaultName(getUserInfo());
130 131
131 hgTest(); 132 hgTest();
133 updateRecentMenu();
132 } 134 }
133 135
134 136
135 void MainWindow::closeEvent(QCloseEvent *) 137 void MainWindow::closeEvent(QCloseEvent *)
136 { 138 {
1076 tr("Open a local folder, by creating a Mercurial repository in it."), 1078 tr("Open a local folder, by creating a Mercurial repository in it."),
1077 MultiChoiceDialog::DirectoryArg); 1079 MultiChoiceDialog::DirectoryArg);
1078 1080
1079 QSettings settings; 1081 QSettings settings;
1080 settings.beginGroup("General"); 1082 settings.beginGroup("General");
1081 QString lastChoice = settings.value("lastopentype", "local").toString(); 1083 QString lastChoice = settings.value("lastopentype", "remote").toString();
1082 if (lastChoice != "local" && 1084 if (lastChoice != "local" &&
1083 lastChoice != "remote" && 1085 lastChoice != "remote" &&
1084 lastChoice != "init") { 1086 lastChoice != "init") {
1085 lastChoice = "local"; 1087 lastChoice = "remote";
1086 } 1088 }
1087 1089
1088 d->setCurrentChoice(lastChoice); 1090 d->setCurrentChoice(lastChoice);
1089 1091
1090 if (d->exec() == QDialog::Accepted) { 1092 if (d->exec() == QDialog::Accepted) {
1117 done = true; 1119 done = true;
1118 } 1120 }
1119 1121
1120 delete d; 1122 delete d;
1121 } 1123 }
1124 }
1125
1126 void MainWindow::recentMenuActivated()
1127 {
1128 QAction *a = qobject_cast<QAction *>(sender());
1129 if (!a) return;
1130 QString local = a->text();
1131 open(local);
1122 } 1132 }
1123 1133
1124 void MainWindow::changeRemoteRepo() 1134 void MainWindow::changeRemoteRepo()
1125 { 1135 {
1126 // This will involve rewriting the local .hgrc 1136 // This will involve rewriting the local .hgrc
1309 1319
1310 bool MainWindow::askToInitExisting(QString arg) 1320 bool MainWindow::askToInitExisting(QString arg)
1311 { 1321 {
1312 return (QMessageBox::question 1322 return (QMessageBox::question
1313 (this, tr("Folder has no repository"), 1323 (this, tr("Folder has no repository"),
1314 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>") 1324 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>")
1315 .arg(xmlEncode(arg)), 1325 .arg(xmlEncode(arg)),
1316 QMessageBox::Ok | QMessageBox::Cancel, 1326 QMessageBox::Ok | QMessageBox::Cancel,
1317 QMessageBox::Ok) 1327 QMessageBox::Ok)
1318 == QMessageBox::Ok); 1328 == QMessageBox::Ok);
1319 } 1329 }
2215 2225
2216 if (noMore) { 2226 if (noMore) {
2217 m_stateUnknown = false; 2227 m_stateUnknown = false;
2218 enableDisableActions(); 2228 enableDisableActions();
2219 m_hgTabs->updateHistory(); 2229 m_hgTabs->updateHistory();
2230 updateRecentMenu();
2220 } 2231 }
2221 } 2232 }
2222 2233
2223 void MainWindow::connectActions() 2234 void MainWindow::connectActions()
2224 { 2235 {
2503 } else { 2514 } else {
2504 m_workStatus->setState(tr("At the head of %1").arg(branchText)); 2515 m_workStatus->setState(tr("At the head of %1").arg(branchText));
2505 } 2516 }
2506 } 2517 }
2507 2518
2519
2520 void MainWindow::updateRecentMenu()
2521 {
2522 m_recentMenu->clear();
2523 RecentFiles rf("Recent-local");
2524 QStringList recent = rf.getRecent();
2525 if (recent.empty()) {
2526 QLabel *label = new QLabel(tr("No recent local repositories"));
2527 QWidgetAction *wa = new QWidgetAction(m_recentMenu);
2528 wa->setDefaultWidget(label);
2529 return;
2530 }
2531 foreach (QString r, recent) {
2532 QAction *a = m_recentMenu->addAction(r);
2533 connect(a, SIGNAL(activated()), this, SLOT(recentMenuActivated()));
2534 }
2535 }
2536
2508 void MainWindow::createActions() 2537 void MainWindow::createActions()
2509 { 2538 {
2510 //File actions 2539 //File actions
2511 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this); 2540 m_openAct = new QAction(QIcon(":/images/fileopen.png"), tr("Open..."), this);
2512 m_openAct -> setStatusTip(tr("Open an existing repository or working folder")); 2541 m_openAct -> setStatusTip(tr("Open an existing repository or working folder"));
2582 void MainWindow::createMenus() 2611 void MainWindow::createMenus()
2583 { 2612 {
2584 m_fileMenu = menuBar()->addMenu(tr("File")); 2613 m_fileMenu = menuBar()->addMenu(tr("File"));
2585 2614
2586 m_fileMenu -> addAction(m_openAct); 2615 m_fileMenu -> addAction(m_openAct);
2616 m_recentMenu = m_fileMenu->addMenu(tr("Open Recent"));
2587 m_fileMenu -> addAction(m_changeRemoteRepoAct); 2617 m_fileMenu -> addAction(m_changeRemoteRepoAct);
2588 m_fileMenu -> addSeparator(); 2618 m_fileMenu -> addSeparator();
2589 2619
2590 m_advancedMenu = m_fileMenu->addMenu(tr("Advanced")); 2620 m_advancedMenu = m_fileMenu->addMenu(tr("Advanced"));
2591 2621