Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@57: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@560: Copyright (c) 2012 Chris Cannam Chris@560: Copyright (c) 2012 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ jtkorhonen@0: Chris@96: #include "hgtabwidget.h" jtkorhonen@0: #include "common.h" Chris@88: #include "filestatuswidget.h" Chris@116: #include "historywidget.h" Chris@44: Chris@50: #include Chris@50: #include Chris@50: #include Chris@50: Chris@44: #include jtkorhonen@0: Chris@96: HgTabWidget::HgTabWidget(QWidget *parent, Chris@95: QString workFolderPath) : Chris@505: QTabWidget(parent), Chris@505: m_haveMerge(false) jtkorhonen@0: { Chris@326: // Work tab Chris@116: m_fileStatusWidget = new FileStatusWidget; Chris@116: m_fileStatusWidget->setLocalPath(workFolderPath); Chris@326: Chris@116: connect(m_fileStatusWidget, SIGNAL(selectionChanged()), Chris@95: this, SIGNAL(selectionChanged())); Chris@326: Chris@484: connect(m_fileStatusWidget, SIGNAL(showAllChanged()), Chris@484: this, SIGNAL(showAllChanged())); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(annotateFiles(QStringList)), Chris@326: this, SIGNAL(annotateFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(diffFiles(QStringList)), Chris@326: this, SIGNAL(diffFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(commitFiles(QStringList)), Chris@326: this, SIGNAL(commitFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(revertFiles(QStringList)), Chris@326: this, SIGNAL(revertFiles(QStringList))); Chris@326: Chris@361: connect(m_fileStatusWidget, SIGNAL(renameFiles(QStringList)), Chris@361: this, SIGNAL(renameFiles(QStringList))); Chris@361: Chris@361: connect(m_fileStatusWidget, SIGNAL(copyFiles(QStringList)), Chris@361: this, SIGNAL(copyFiles(QStringList))); Chris@361: Chris@326: connect(m_fileStatusWidget, SIGNAL(addFiles(QStringList)), Chris@326: this, SIGNAL(addFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(removeFiles(QStringList)), Chris@326: this, SIGNAL(removeFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(redoFileMerges(QStringList)), Chris@326: this, SIGNAL(redoFileMerges(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(markFilesResolved(QStringList)), Chris@326: this, SIGNAL(markFilesResolved(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(ignoreFiles(QStringList)), Chris@326: this, SIGNAL(ignoreFiles(QStringList))); Chris@326: Chris@326: connect(m_fileStatusWidget, SIGNAL(unIgnoreFiles(QStringList)), Chris@326: this, SIGNAL(unIgnoreFiles(QStringList))); Chris@326: sam@624: connect(m_fileStatusWidget, SIGNAL(showIn(QStringList)), sam@624: this, SIGNAL(showIn(QStringList))); sam@624: Chris@116: addTab(m_fileStatusWidget, tr("My work")); Chris@88: Chris@326: // History graph tab Chris@116: m_historyWidget = new HistoryWidget; Chris@116: addTab(m_historyWidget, tr("History")); Chris@141: Chris@141: connect(m_historyWidget, SIGNAL(commit()), Chris@141: this, SIGNAL(commit())); Chris@141: Chris@141: connect(m_historyWidget, SIGNAL(revert()), Chris@141: this, SIGNAL(revert())); Chris@141: Chris@168: connect(m_historyWidget, SIGNAL(showSummary()), Chris@168: this, SIGNAL(showSummary())); Chris@168: Chris@311: connect(m_historyWidget, SIGNAL(newBranch()), Chris@311: this, SIGNAL(newBranch())); Chris@311: Chris@311: connect(m_historyWidget, SIGNAL(noBranch()), Chris@311: this, SIGNAL(noBranch())); Chris@311: Chris@141: connect(m_historyWidget, SIGNAL(diffWorkingFolder()), Chris@141: this, SIGNAL(diffWorkingFolder())); Chris@141: Chris@153: connect(m_historyWidget, SIGNAL(showWork()), Chris@153: this, SLOT(showWorkTab())); Chris@153: Chris@141: connect(m_historyWidget, SIGNAL(updateTo(QString)), Chris@141: this, SIGNAL(updateTo(QString))); Chris@141: Chris@141: connect(m_historyWidget, SIGNAL(diffToCurrent(QString)), Chris@141: this, SIGNAL(diffToCurrent(QString))); Chris@141: Chris@148: connect(m_historyWidget, SIGNAL(diffToParent(QString, QString)), Chris@148: this, SIGNAL(diffToParent(QString, QString))); Chris@141: Chris@289: connect(m_historyWidget, SIGNAL(showSummary(Changeset *)), Chris@289: this, SIGNAL(showSummary(Changeset *))); Chris@288: Chris@141: connect(m_historyWidget, SIGNAL(mergeFrom(QString)), Chris@141: this, SIGNAL(mergeFrom(QString))); Chris@141: Chris@278: connect(m_historyWidget, SIGNAL(newBranch(QString)), Chris@278: this, SIGNAL(newBranch(QString))); Chris@278: Chris@514: connect(m_historyWidget, SIGNAL(closeBranch(QString)), Chris@514: this, SIGNAL(closeBranch(QString))); Chris@514: Chris@141: connect(m_historyWidget, SIGNAL(tag(QString)), Chris@141: this, SIGNAL(tag(QString))); jtkorhonen@32: } jtkorhonen@32: Chris@96: void HgTabWidget::clearSelections() Chris@94: { Chris@116: m_fileStatusWidget->clearSelections(); Chris@94: } Chris@94: Chris@153: void HgTabWidget::setCurrent(QStringList ids, QString branch) Chris@128: { Chris@505: m_historyWidget->setCurrent(ids, branch, haveChangesToCommit()); Chris@129: } Chris@129: Chris@506: void HgTabWidget::setClosedHeadIds(QSet closed) Chris@506: { Chris@506: m_historyWidget->setClosedHeadIds(closed); Chris@506: } Chris@506: Chris@608: void HgTabWidget::clearAll() Chris@608: { Chris@608: m_fileStatusWidget->clearWidgets(); Chris@608: m_historyWidget->clear(); Chris@608: } Chris@608: Chris@230: void HgTabWidget::updateFileStates() Chris@230: { Chris@230: m_fileStatusWidget->updateWidgets(); Chris@230: } Chris@230: Chris@154: void HgTabWidget::updateHistory() Chris@154: { Chris@154: m_historyWidget->update(); Chris@154: } Chris@154: Chris@555: void HgTabWidget::setSearchText(QString text) Chris@555: { Chris@555: m_fileStatusWidget->setSearchText(text); Chris@555: m_historyWidget->setSearchText(text); Chris@555: } Chris@555: Chris@163: bool HgTabWidget::canDiff() const Chris@163: { Chris@237: return canRevert(); Chris@163: } Chris@163: Chris@96: bool HgTabWidget::canCommit() const Chris@90: { Chris@505: if (!haveChangesToCommit()) return false; Chris@505: if (!getAllUnresolvedFiles().empty()) return false; Chris@326: return true; Chris@90: } jtkorhonen@0: Chris@109: bool HgTabWidget::canRevert() const Chris@109: { Chris@237: // Not the same as canCommit() -- we can revert (and diff) Chris@237: // unresolved files, but we can't commit them Chris@505: if (!haveChangesToCommit() && Chris@505: getAllUnresolvedFiles().empty()) return false; Chris@326: return true; Chris@109: } Chris@109: Chris@96: bool HgTabWidget::canAdd() const Chris@95: { Chris@327: // Permit this only when work tab is visible Chris@327: if (currentIndex() != 0) return false; Chris@327: Chris@505: QStringList addable = getSelectedAddableFiles(); Chris@204: if (addable.empty()) return false; Chris@204: Chris@505: QStringList removable = getSelectedRemovableFiles(); Chris@204: if (!removable.empty()) return false; Chris@204: Chris@326: return true; Chris@95: } Chris@95: Chris@96: bool HgTabWidget::canRemove() const Chris@95: { Chris@327: // Permit this only when work tab is visible Chris@327: if (currentIndex() != 0) return false; Chris@327: Chris@505: if (getSelectedRemovableFiles().empty()) return false; Chris@505: if (!getSelectedAddableFiles().empty()) return false; Chris@95: return true; Chris@95: } Chris@95: Chris@163: bool HgTabWidget::canResolve() const Chris@95: { Chris@505: return !getAllUnresolvedFiles().empty(); Chris@95: } Chris@95: Chris@425: bool HgTabWidget::canIgnore() const Chris@425: { Chris@425: return canAdd(); Chris@425: } Chris@425: Chris@172: bool HgTabWidget::haveChangesToCommit() const Chris@172: { Chris@505: return m_haveMerge || m_fileStatusWidget->haveChangesToCommit(); Chris@172: } Chris@172: Chris@109: QStringList HgTabWidget::getAllCommittableFiles() const Chris@109: { Chris@116: return m_fileStatusWidget->getAllCommittableFiles(); Chris@109: } Chris@109: Chris@109: QStringList HgTabWidget::getAllRevertableFiles() const Chris@109: { Chris@116: return m_fileStatusWidget->getAllRevertableFiles(); Chris@109: } Chris@109: Chris@96: QStringList HgTabWidget::getSelectedAddableFiles() const Chris@95: { Chris@116: return m_fileStatusWidget->getSelectedAddableFiles(); Chris@95: } Chris@95: Chris@96: QStringList HgTabWidget::getSelectedRemovableFiles() const Chris@95: { Chris@116: return m_fileStatusWidget->getSelectedRemovableFiles(); Chris@95: } Chris@95: Chris@163: QStringList HgTabWidget::getAllUnresolvedFiles() const Chris@163: { Chris@163: return m_fileStatusWidget->getAllUnresolvedFiles(); Chris@163: } Chris@163: Chris@96: void HgTabWidget::updateWorkFolderFileList(QString fileList) jtkorhonen@0: { Chris@116: m_fileStates.parseStates(fileList); Chris@116: m_fileStatusWidget->setFileStates(m_fileStates); jtkorhonen@0: } jtkorhonen@0: Chris@505: void HgTabWidget::setHaveMerge(bool haveMerge) Chris@505: { Chris@505: if (m_haveMerge != haveMerge) { Chris@505: m_haveMerge = haveMerge; Chris@505: m_historyWidget->setShowUncommitted(haveChangesToCommit()); Chris@505: updateHistory(); Chris@505: } Chris@505: } Chris@505: Chris@120: void HgTabWidget::setNewLog(QString hgLogList) jtkorhonen@0: { Chris@120: m_historyWidget->parseNewLog(hgLogList); Chris@134: if (m_historyWidget->haveNewItems()) { Chris@153: showHistoryTab(); Chris@134: } Chris@120: } Chris@120: Chris@120: void HgTabWidget::addIncrementalLog(QString hgLogList) Chris@120: { Chris@120: m_historyWidget->parseIncrementalLog(hgLogList); Chris@134: if (m_historyWidget->haveNewItems()) { Chris@153: showHistoryTab(); Chris@134: } jtkorhonen@0: } jtkorhonen@0: Chris@287: void HgTabWidget::setLocalPath(QString workFolderPath) jtkorhonen@0: { Chris@116: m_fileStatusWidget->setLocalPath(workFolderPath); Chris@106: } Chris@153: Chris@153: void HgTabWidget::showWorkTab() Chris@153: { Chris@153: setCurrentWidget(m_fileStatusWidget); Chris@153: } Chris@153: Chris@153: void HgTabWidget::showHistoryTab() Chris@153: { Chris@153: setCurrentWidget(m_historyWidget); Chris@153: } Chris@153: Chris@484: bool HgTabWidget::shouldShowAll() const Chris@484: { Chris@484: return m_fileStatusWidget->shouldShowAll(); Chris@484: } Chris@484: