# HG changeset patch # User Chris Cannam # Date 1290530149 0 # Node ID b43355c2473a5b827701e2ca17eb49b32c8fb217 # Parent 622da79c0f4f53fe86156b1b295916d063d3de63 * Add filesystem watcher; initial work on enable/disable logic for actions in new scheme diff -r 622da79c0f4f -r b43355c2473a filestatuswidget.h --- a/filestatuswidget.h Tue Nov 23 14:49:13 2010 +0000 +++ b/filestatuswidget.h Tue Nov 23 16:35:49 2010 +0000 @@ -41,6 +41,12 @@ StatParser statParser() const { return m_statParser; } void setStatParser(StatParser sp); + bool haveChangesToCommit() const { + return !m_statParser.added.empty() || + !m_statParser.removed.empty() || + !m_statParser.modified.empty(); + } + private: QString m_localPath; QLabel *m_localPathLabel; diff -r 622da79c0f4f -r b43355c2473a hgexpwidget.cpp --- a/hgexpwidget.cpp Tue Nov 23 14:49:13 2010 +0000 +++ b/hgexpwidget.cpp Tue Nov 23 16:35:49 2010 +0000 @@ -200,7 +200,10 @@ } } - +bool HgExpWidget::canCommit() const +{ + return fileStatusWidget->haveChangesToCommit(); +} QString HgExpWidget::getStatFlags() { diff -r 622da79c0f4f -r b43355c2473a hgexpwidget.h --- a/hgexpwidget.h Tue Nov 23 14:49:13 2010 +0000 +++ b/hgexpwidget.h Tue Nov 23 16:35:49 2010 +0000 @@ -55,6 +55,10 @@ QString getStatFlags(void); unsigned char getFileTypesBits(); + //!!! StatParser really should be renamed to express "status state" rather than activity + StatParser getStatParser() { return statParser; } + + bool canCommit() const; QListWidget *workFolderFileList; QListWidget *localRepoHeadsList; diff -r 622da79c0f4f -r b43355c2473a mainwindow.cpp --- a/mainwindow.cpp Tue Nov 23 14:49:13 2010 +0000 +++ b/mainwindow.cpp Tue Nov 23 16:35:49 2010 +0000 @@ -28,6 +28,7 @@ #include #include #include +#include #include "mainwindow.h" #include "settingsdialog.h" @@ -42,6 +43,8 @@ { QString wndTitle; + fsWatcher = 0; + createActions(); createMenus(); createToolBars(); @@ -91,6 +94,7 @@ void MainWindow::closeEvent(QCloseEvent *) { writeSettings(); + delete fsWatcher; } @@ -175,6 +179,7 @@ void MainWindow::hgLog() { +//!!! This needs to be incremental, except when we pull or set new repo if (runningAction == ACT_NONE) { QStringList params; @@ -306,8 +311,16 @@ } } -int MainWindow::getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle) +bool MainWindow::getCommentOrTag(QString& commentOrTag, + QString question, + QString dlgTitle) { + bool ok = false; + QString text = QInputDialog::getText(this, dlgTitle, question, QLineEdit::Normal, commentOrTag, &ok); + commentOrTag = text; + return ok; + + /*!!! int ret; QDialog dlg(this); @@ -339,6 +352,7 @@ ret = dlg.exec(); commentOrTag = commentOrTagEdit -> text(); return ret; + */ } void MainWindow::hgCommit() @@ -348,7 +362,7 @@ QStringList params; QString comment; - if (QDialog::Accepted == getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)"))) + if (getCommentOrTag(comment, tr("Comment:"), tr("Save (commit)"))) { if (!comment.isEmpty()) { @@ -401,7 +415,7 @@ QStringList params; QString tag; - if (QDialog::Accepted == getCommentOrTag(tag, tr("Tag:"), tr("Tag"))) + if (getCommentOrTag(tag, tr("Tag:"), tr("Tag"))) { if (!tag.isEmpty()) { @@ -1219,6 +1233,48 @@ } +void MainWindow::updateFileSystemWatcher() +{ + //!!! this needs to be incremental when something changes + + delete fsWatcher; + fsWatcher = new QFileSystemWatcher(); + std::deque pending; + pending.push_back(workFolderPath); + while (!pending.empty()) { + QString path = pending.front(); + pending.pop_front(); + fsWatcher->addPath(path); + DEBUG << "Added to file system watcher: " << path << endl; + QDir d(path); + if (d.exists()) { + d.setFilter(QDir::Files | QDir::Dirs | + QDir::NoDotAndDotDot | QDir::Readable); + foreach (QString entry, d.entryList()) { + if (entry == ".hg") continue; + QString entryPath = d.absoluteFilePath(entry); + pending.push_back(entryPath); + } + } + } + connect(fsWatcher, SIGNAL(directoryChanged(QString)), + this, SLOT(fsDirectoryChanged(QString))); + connect(fsWatcher, SIGNAL(fileChanged(QString)), + this, SLOT(fsFileChanged(QString))); +} + +void MainWindow::fsDirectoryChanged(QString) +{ + //!!! should just queue one of these! + hgStat(); +} + +void MainWindow::fsFileChanged(QString) +{ + //!!! should just queue one of these! + hgStat(); +} + void MainWindow::commandFailed() { DEBUG << "MainWindow::commandFailed" << endl; @@ -1267,6 +1323,7 @@ case ACT_STAT: hgExp -> updateWorkFolderFileList(runner -> getOutput()); + updateFileSystemWatcher(); break; case ACT_INCOMING: @@ -1403,10 +1460,8 @@ } } } - else - { - enableDisableActions(); - } + + enableDisableActions(); } void MainWindow::connectActions() @@ -1456,36 +1511,32 @@ void MainWindow::enableDisableActions() { + DEBUG << "MainWindow::enableDisableActions" << endl; + QDir localRepoDir; QDir workFolderDir; bool workFolderExist; bool localRepoExist; remoteRepoActionsEnabled = true; - if (remoteRepoPath.isEmpty()) - { + if (remoteRepoPath.isEmpty()) { remoteRepoActionsEnabled = false; } localRepoActionsEnabled = true; - if (workFolderPath.isEmpty()) - { + if (workFolderPath.isEmpty()) { localRepoActionsEnabled = false; workFolderExist = false; } - if (!workFolderDir.exists(workFolderPath)) - { + if (!workFolderDir.exists(workFolderPath)) { localRepoActionsEnabled = false; workFolderExist = false; - } - else - { + } else { workFolderExist = true; } - if (!localRepoDir.exists(workFolderPath + getHgDirName())) - { + if (!localRepoDir.exists(workFolderPath + "/" + getHgDirName())) { localRepoActionsEnabled = false; localRepoExist = false; } @@ -1520,6 +1571,14 @@ hgExp -> enableDisableOtherTabs(tabPage); + DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl; + DEBUG << "canCommit = " << hgExp->canCommit() << endl; + + //!!! new stuff: + hgCommitAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit()); + hgRevertAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit()); + +/*!!! int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked; countModifications(hgExp -> workFolderFileList, @@ -1623,6 +1682,7 @@ hgUpdateToRevAct -> setEnabled(false); } } + */ } void MainWindow::createActions() diff -r 622da79c0f4f -r b43355c2473a mainwindow.h --- a/mainwindow.h Tue Nov 23 14:49:13 2010 +0000 +++ b/mainwindow.h Tue Nov 23 16:35:49 2010 +0000 @@ -24,6 +24,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QAction; @@ -116,6 +117,9 @@ void hgServe(); void hgIgnore(); + void fsDirectoryChanged(QString); + void fsFileChanged(QString); + private: void hgHeads(); void hgParents(); @@ -127,7 +131,7 @@ void createStatusBar(); void readSettings(); void splitChangeSets(QStringList *list, QString hgLogOutput); - int getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle); + bool getCommentOrTag(QString& commentOrTag, QString question, QString dlgTitle); void presentLongStdoutToUser(QString stdo); void countModifications(QListWidget *workList, int& added, int& modified, int& removed, int& notTracked, int& selected, @@ -158,6 +162,8 @@ bool askToOpenParentRepo(QString, QString); bool askToOpenInsteadOfInit(QString); + void updateFileSystemWatcher(); + bool firstStart; //Actions enabled flags @@ -210,6 +216,8 @@ HGACTIONS runningAction; HgRunner *runner; + QFileSystemWatcher *fsWatcher; + int tabPage; unsigned char initialFileTypesBits; bool justMerged;