diff src/mainwindow.cpp @ 541:0a16db274f2c fswatcher

Update the filesystem watcher with work directory / file state. Still doesn't track "clean" files properly unless "show all files" is enabled
author Chris Cannam
date Tue, 14 Feb 2012 16:17:23 +0000
parents fc2df97920e8
children 7829da6abe97
line wrap: on
line diff
--- a/src/mainwindow.cpp	Mon Feb 13 17:29:06 2012 +0000
+++ b/src/mainwindow.cpp	Tue Feb 14 16:17:23 2012 +0000
@@ -68,7 +68,7 @@
     m_fsWatcher = new FsWatcher();
     m_fsWatcherToken = m_fsWatcher->getNewToken();
     m_commandSequenceInProgress = false;
-    connect(m_fsWatcher, SIGNAL(changed()), this, SLOT(fsWatcherChanged()));
+    connect(m_fsWatcher, SIGNAL(changed()), this, SLOT(checkFilesystem()));
 
     m_commitsSincePush = 0;
     m_shouldHgStat = true;
@@ -122,6 +122,7 @@
     setUnifiedTitleAndToolBarOnMac(true);
     connectActions();
     clearState();
+    updateFsWatcher();
     enableDisableActions();
 
     if (m_firstStart) {
@@ -261,6 +262,10 @@
 
     m_lastStatOutput = "";
 
+    // We're about to do a stat, so we can silently bring ourselves
+    // up-to-date on any file changes to this point
+    (void)m_fsWatcher->getChangedPaths(m_fsWatcherToken);
+
     m_runner->requestAction(HgAction(ACT_STAT, m_workFolderPath, params));
 }
 
@@ -1424,6 +1429,7 @@
             if (result) {
                 enableDisableActions();
                 clearState();
+                updateFsWatcher();
                 hgQueryPaths();
                 done = true;
             }
@@ -1509,6 +1515,7 @@
     if (openLocal(local)) {
         enableDisableActions();
         clearState();
+        updateFsWatcher();
         hgQueryPaths();
     }
 }
@@ -1815,16 +1822,22 @@
     }
 }
 
+void MainWindow::updateFsWatcher()
+{
+    m_fsWatcher->setWorkDirPath(m_workFolderPath);
+    m_fsWatcher->setTrackedFilePaths(m_hgTabs->getFileStates().trackedFiles());
+}
+
 void MainWindow::checkFilesystem()
 {
     DEBUG << "MainWindow::checkFilesystem" << endl;
-    hgRefresh();
-}
-
-void MainWindow::fsWatcherChanged()
-{
-    DEBUG << "MainWindow::fsWatcherChanged" << endl;
-
+    if (!m_commandSequenceInProgress) {
+        if (!m_fsWatcher->getChangedPaths(m_fsWatcherToken).empty()) {
+            hgRefresh();
+            return;
+        }
+    }
+    updateFsWatcher();
 }
 
 QString MainWindow::format1(QString head)
@@ -2507,6 +2520,7 @@
         enableDisableActions();
         m_hgTabs->updateHistory();
         updateRecentMenu();
+        checkFilesystem();
     }
 }