# # # patch "src/view/InventoryView.cpp" # from [441ff9c1a21693b33b00efe2894d0f50425f6b3c] # to [0207a6e08fed77d118b60410c1e432ee5ba458ad] # # patch "src/view/InventoryView.h" # from [fd0d9c5eb87a628057d22b2a41426dcbbe84ca03] # to [8f7dc8077f7692611c1fc99c4db0a11f70d62823] # ============================================================ --- src/view/InventoryView.cpp 441ff9c1a21693b33b00efe2894d0f50425f6b3c +++ src/view/InventoryView.cpp 0207a6e08fed77d118b60410c1e432ee5ba458ad @@ -20,24 +20,17 @@ #include "InventoryView.h" #include "Settings.h" -#include "Platform.h" #include "InventoryItem.h" -#include "Monotone.h" -#include "FileDiff.h" -#include "FileHistory.h" -#include "RevisionDiff.h" #include "vocab.h" -#include "Guitone.h" #include #include #include -#include #include #include -InventoryView::InventoryView(QWidget* parent) -: TreeView(parent), invViewDelegate(parent) +InventoryView::InventoryView(QWidget * parent) + : TreeView(parent), invViewDelegate(parent) { setItemDelegate(&invViewDelegate); setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -45,16 +38,16 @@ InventoryView::InventoryView(QWidget* pa setDropIndicatorShown(true); setSortingEnabled(true); sortByColumn(0, Qt::AscendingOrder); - + header()->setClickable(true); - + createAndConnectContextActions(); - + connect( this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemClicked(const QModelIndex &)) ); - + connect( this, SIGNAL(contextMenuRequested(const QModelIndexList &, const QPoint &)), this, SLOT(slotContextMenuRequested(const QModelIndexList &, const QPoint &)) @@ -65,16 +58,16 @@ void InventoryView::setType(Type t) { // ensure that a model is already set, otherwise the app crashes I(model()); - + type = t; - + if (type == FileList) { disconnect( this, SIGNAL(clicked(const QModelIndex &)), this, SLOT(itemClicked(const QModelIndex &)) ); - + setRootIsDecorated(false); setItemsExpandable(false); } @@ -91,74 +84,74 @@ void InventoryView::createAndConnectCont void InventoryView::createAndConnectContextActions() { - actChdir = new QAction(tr("Go into"), this); + actChdir = new QAction(tr("Go into"), this); actChdir->setStatusTip(tr("Go into the directory")); connect(actChdir, SIGNAL(triggered()), this, SLOT(slotChdir())); - actOpen = new QAction(tr("Open"), this); - actOpen->setStatusTip(tr("Open in default program")); + actOpen = new QAction(tr("Open"), this); + actOpen->setStatusTip(tr("Open in default program")); connect(actOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); - actAdd = new QAction(tr("Add"), this); - actAdd->setStatusTip(tr("Add to workspace")); + actAdd = new QAction(tr("Add"), this); + actAdd->setStatusTip(tr("Add to workspace")); connect(actAdd, SIGNAL(triggered()), this, SLOT(slotAdd())); - actRemove = new QAction(tr("Remove"), this); - actRemove->setStatusTip(tr("Remove from workspace")); + actRemove = new QAction(tr("Remove"), this); + actRemove->setStatusTip(tr("Remove from workspace")); connect(actRemove, SIGNAL(triggered()), this, SLOT(slotRemove())); - actCommit = new QAction(tr("Commit"), this); + actCommit = new QAction(tr("Commit"), this); actCommit->setStatusTip(tr("Commit")); connect(actCommit, SIGNAL(triggered()), this, SLOT(slotCommit())); - actIgnore = new QAction(tr("Ignore"), this); + actIgnore = new QAction(tr("Ignore"), this); actIgnore->setStatusTip(tr("Ignore file")); connect(actIgnore, SIGNAL(triggered()), this, SLOT(slotIgnore())); - - actUnignore = new QAction(tr("Unignore"), this); + + actUnignore = new QAction(tr("Unignore"), this); actUnignore->setStatusTip(tr("Unignore file")); connect(actUnignore, SIGNAL(triggered()), this, SLOT(slotUnignore())); - - actRevert = new QAction(tr("Revert"), this); + + actRevert = new QAction(tr("Revert"), this); actRevert->setStatusTip(tr("Revert uncommitted changes")); connect(actRevert, SIGNAL(triggered()), this, SLOT(slotRevert())); - - actFileDiff = new QAction(tr("Diff"), this); + + actFileDiff = new QAction(tr("Diff"), this); actFileDiff->setStatusTip(tr("Diff against base revision")); connect(actFileDiff, SIGNAL(triggered()), this, SLOT(slotFileDiff())); - - actFileHistory = new QAction(tr("History"), this); + + actFileHistory = new QAction(tr("History"), this); actFileHistory->setStatusTip(tr("Display the history of this file")); connect(actFileHistory, SIGNAL(triggered()), this, SLOT(slotFileHistory())); - - actRevisionDiff = new QAction(tr("Diff all"), this); + + actRevisionDiff = new QAction(tr("Diff all"), this); actRevisionDiff->setStatusTip(tr("Show all differences")); connect(actRevisionDiff, SIGNAL(triggered()), this, SLOT(slotRevisionDiff())); - - actRename = new QAction(tr("Rename"), this); + + actRename = new QAction(tr("Rename"), this); actRename->setStatusTip(tr("Rename file")); connect(actRename, SIGNAL(triggered()), this, SLOT(slotRename())); - + actAddMultiple = new QAction(tr("Add %1 items"), this); actAddMultiple->setStatusTip(tr("Add multiple items")); connect(actAddMultiple, SIGNAL(triggered()), this, SLOT(slotAdd())); - + actRemoveMultiple = new QAction(tr("Remove %1 items"), this); actRemoveMultiple->setStatusTip(tr("Remove multiple items")); connect(actRemoveMultiple, SIGNAL(triggered()), this, SLOT(slotRemove())); - + actCommitMultiple = new QAction(tr("Commit %1 items"), this); actCommitMultiple->setStatusTip(tr("Commit multiple items")); connect(actCommitMultiple, SIGNAL(triggered()), this, SLOT(slotCommit())); - + actIgnoreMultiple = new QAction(tr("Ignore %1 items"), this); actIgnoreMultiple->setStatusTip(tr("Ignore multiple items")); connect(actIgnoreMultiple, SIGNAL(triggered()), this, SLOT(slotIgnore())); - + actUnignoreMultiple = new QAction(tr("Unignore %1 items"), this); actUnignoreMultiple->setStatusTip(tr("Unignore multiple items")); connect(actUnignoreMultiple, SIGNAL(triggered()), this, SLOT(slotUnignore())); - + actRevertMultiple = new QAction(tr("Revert %1 items"), this); actRevertMultiple->setStatusTip(tr("Revert multiple items")); connect(actRevertMultiple, SIGNAL(triggered()), this, SLOT(slotRevert())); @@ -173,10 +166,10 @@ InventoryView::~InventoryView() delete actCommit; delete actIgnore; delete actUnignore; - delete actRevert; + delete actRevert; delete actFileDiff; delete actFileHistory; - delete actRevisionDiff; + delete actRevisionDiff; delete actRename; delete actAddMultiple; delete actRemoveMultiple; @@ -189,6 +182,7 @@ void InventoryView::setModel(QAbstractIt // ensure that we only accept sortfilterproxymodels void InventoryView::setModel(QAbstractItemModel * model) { + Q_UNUSED(model); I(false); } @@ -202,7 +196,7 @@ void InventoryView::setModel(QSortFilter this, SLOT(delegateModelReset()) ); } - + TreeView::setModel(newModel); connect( @@ -226,7 +220,7 @@ void InventoryView::modelReset() C("Index invalid, aborting..."); return; } - + if (type == FileList) { setRootIndex(index); @@ -242,66 +236,65 @@ void InventoryView::slotContextMenuReque void InventoryView::slotContextMenuRequested(const QModelIndexList & indexList, const QPoint & pos) { D(QString("Selected indexes: %1").arg(indexList.size())); - + QMenu menu(this); - + if (indexList.size() == 1) { QModelIndex sourceIndex = static_cast(indexList[0].model())->mapToSource(indexList[0]); - - InventoryItem* item = static_cast(sourceIndex.internalPointer()); - - + + InventoryItem* item = static_cast(sourceIndex.internalPointer()); + if (item->isDirectory()) { menu.addAction(actChdir); } - + menu.addAction(actOpen); - + if (item->hasStatus(InventoryItem::Unknown)) { menu.addAction(actAdd); menu.addAction(actIgnore); } - + if (item->hasStatus(InventoryItem::Ignored)) { menu.addAction(actUnignore); } - + if (item->hasChangedRecursive()) { menu.addAction(actCommit); menu.addAction(actRevisionDiff); } - - if (item->hasNotStatus(InventoryItem::Ignored) && + + if (item->hasNotStatus(InventoryItem::Ignored) && item->hasNotStatus(InventoryItem::Unknown) && !item->isRootDirectory() && !item->isCdUp()) { menu.addAction(actRemove); menu.addAction(actRename); - + // as long as it is not unchanged, it can be converted if (item->hasNotStatus(InventoryItem::Unchanged)) { menu.addAction(actRevert); - + if (item->hasNotStatus(InventoryItem::Added) && !item->isDirectory()) { menu.addAction(actFileDiff); - } + } } - + if (item->hasNotStatus(InventoryItem::Added) && !item->isDirectory()) { menu.addAction(actFileHistory); } } - + // // determine the default action // @@ -309,7 +302,7 @@ void InventoryView::slotContextMenuReque activeFont.setBold(true); QFont normalFont; normalFont.setBold(false); - + if (item->isDirectory()) { actOpen->setFont(normalFont); @@ -317,7 +310,7 @@ void InventoryView::slotContextMenuReque } else { - if (item->hasStatus(InventoryItem::Patched) && + if (item->hasStatus(InventoryItem::Patched) && item->hasNotStatus(InventoryItem::Added)) { actFileDiff->setFont(activeFont); @@ -329,45 +322,45 @@ void InventoryView::slotContextMenuReque actOpen->setFont(activeFont); } } - + menu.exec(pos); } else { InventoryItem * item; QModelIndex sourceIndex; - + QStringList actions; - actions << "add" << "drop" << "commit" + actions << "add" << "drop" << "commit" << "ignore" << "unignore" << "revert"; - - QMap actionMapping; + + QMap actionMapping; actionMapping.insert("add", actAddMultiple); actionMapping.insert("drop", actRemoveMultiple); actionMapping.insert("commit", actCommitMultiple); actionMapping.insert("revert", actRevertMultiple); actionMapping.insert("ignore", actIgnoreMultiple); actionMapping.insert("unignore", actUnignoreMultiple); - + QMap actionCounter; - + foreach(QString action, actions) { actionCounter.insert(action, 0); } - + foreach(QModelIndex index, indexList) { - sourceIndex = - static_cast(index.model()) + sourceIndex = + static_cast(index.model()) ->mapToSource(index); - item = static_cast(sourceIndex.internalPointer()); - + item = static_cast(sourceIndex.internalPointer()); + if (!item->isTracked()) { actionCounter["add"]++; - + if (item->hasStatus(InventoryItem::Unknown)) { actionCounter["ignore"]++; @@ -378,20 +371,20 @@ void InventoryView::slotContextMenuReque } continue; } - + if (item->hasChangedRecursive()) { actionCounter["commit"]++; actionCounter["revert"]++; } - + actionCounter["drop"]++; } - + QMapIterator i(actionCounter); int totalItems = indexList.size(); bool commonActions = false; - + while (i.hasNext()) { i.next(); @@ -401,7 +394,7 @@ void InventoryView::slotContextMenuReque act->setText(act->text().arg(totalItems)); menu.addAction(act); } - + if (!commonActions) { QAction * act = new QAction( @@ -409,7 +402,7 @@ void InventoryView::slotContextMenuReque ); menu.addAction(act); } - + menu.exec(pos); return; } @@ -417,24 +410,24 @@ void InventoryView::slotChdir() void InventoryView::slotChdir() { - QItemSelectionModel *selectionModel = this->selectionModel(); + QItemSelectionModel * selectionModel = this->selectionModel(); QList list(selectionModel->selectedIndexes()); I(list.size() > 0); - + emit directoryChanged(list[0]); changeDirectory(list[0]); } void InventoryView::changeDirectory(const QModelIndex & proxyIndex) { - QModelIndex source = static_cast(model())->mapToSource(proxyIndex); - InventoryItem *item = static_cast(source.internalPointer()); - + QModelIndex source = static_cast(model())->mapToSource(proxyIndex); + InventoryItem * item = static_cast(source.internalPointer()); + if (type == FileList) { // retranslate the proxy index to an index of the current model - QModelIndex proxyFileIndex = - static_cast(model())->mapFromSource(source); + QModelIndex proxyFileIndex = + static_cast(model())->mapFromSource(source); if (item->isCdUp()) { @@ -445,14 +438,14 @@ void InventoryView::changeDirectory(cons setRootIndex(proxyFileIndex); return; } - + // retranslate the proxy index to an index of the current model - QModelIndex proxyFolderIndex = - static_cast(model())->mapFromSource(source); - + QModelIndex proxyFolderIndex = + static_cast(model())->mapFromSource(source); + // expand the selection if needed expand(proxyFolderIndex); - + // select the item selectionModel()->setCurrentIndex( proxyFolderIndex, @@ -464,32 +457,10 @@ void InventoryView::slotOpen() { QModelIndex index(getSingleSelection()); if (!index.isValid()) return; - - InventoryItem * item = static_cast(index.internalPointer()); - - QFileInfo file(MTN(this)->getNormalizedWorkspacePath() + "/" + item->getPath()); - if (!file.exists()) - { - - QMessageBox::critical( - this, - tr("Error"), - tr("The file you're trying to open does not exist."), - QMessageBox::Ok, 0, 0 - ); - return; - } - - if (!Platform::openFile(this, file.absoluteFilePath())) - { - QMessageBox::critical( - this, - tr("Error"), - tr("Unable to open files on your platform - please contact the " - "author about this problem."), - QMessageBox::Ok, 0, 0 - ); - } + + InventoryItem * item = static_cast(index.internalPointer()); + + emit openFile(item->getPath()); } void InventoryView::slotAdd() @@ -518,7 +489,7 @@ void InventoryView::slotRename() } // -// TODO: there is no mtn API for the next two commands available +// TODO: there is no mtn API for the next two commands available // right now so we need to manually edit the WD/.mtn-ignore file // Q: If this file is under version control, should a change // be committed in the background? @@ -537,106 +508,97 @@ void InventoryView::slotFileDiff() { QModelIndex index(getSingleSelection()); if (!index.isValid()) return; - - InventoryItem * item = static_cast(index.internalPointer()); - - if (item->isDirectory() || !item->hasStatus(InventoryItem::Patched)) + + InventoryItem * item = static_cast(index.internalPointer()); + + if (item->isDirectory() || !item->hasStatus(InventoryItem::Patched)) { D("File is a directory or not patched/unknown."); return; } - - FileDiff dlg(this, item->getPath()); - dlg.exec(); - clearSelection(); + emit diffFile(item->getPath()); } void InventoryView::slotFileHistory() { QModelIndex index(getSingleSelection()); if (!index.isValid()) return; - - InventoryItem * item = static_cast(index.internalPointer()); - + + InventoryItem * item = static_cast(index.internalPointer()); + QString path = item->getPath(); + // determine the original path, if needed - if (item->hasStatus(InventoryItem::RenamedFrom)) + if (item->hasStatus(InventoryItem::RenamedFrom)) { InventoryItem * newItem = item->getRenamedTo(); - I(newItem); + I(newItem != 0); path = newItem->getPath(); } if (item->hasStatus(InventoryItem::RenamedTo)) { InventoryItem * oldItem = item->getRenamedFrom(); - I(oldItem); + I(oldItem != 0); path = oldItem->getPath(); } - - FileHistory dlg(this, path); - dlg.exec(); - clearSelection(); + emit fileHistory(path); } void InventoryView::slotRevisionDiff() { QModelIndex index(getSingleSelection()); if (!index.isValid()) return; - - InventoryItem * item = static_cast(index.internalPointer()); - - RevisionDiff dlg(this); - dlg.init(item->getPath(), QString(), QString()); - dlg.exec(); - clearSelection(); + InventoryItem * item = static_cast(index.internalPointer()); + + emit diffRevision(item->getPath(), QString(), QString()); } QModelIndex InventoryView::getSingleSelection(bool mapToSource /* = true */) { QItemSelectionModel * selectionModel = this->selectionModel(); QList list(selectionModel->selectedIndexes()); - + if (list.size() == 0) { D("No item selected."); return QModelIndex(); } - + if (list.size() > 1) { D("Multiple items selected, only returning the first."); } - + if (!mapToSource) return list[0]; - - return static_cast(list[0].model())->mapToSource(list[0]); + + return static_cast(list[0].model())->mapToSource(list[0]); } void InventoryView::itemClicked(const QModelIndex & index) { if (!index.isValid()) return; - QModelIndex sourceIndex = - static_cast(index.model())->mapToSource(index); - - InventoryItem * item = static_cast(sourceIndex.internalPointer()); - + QModelIndex sourceIndex = + static_cast(index.model())->mapToSource(index); + + InventoryItem * item = static_cast(sourceIndex.internalPointer()); + if (item->isDirectory()) { emit directoryChanged(index); changeDirectory(index); return; } - + if (item->hasStatus(InventoryItem::Patched) && item->hasNotStatus(InventoryItem::Added)) { slotFileDiff(); return; } - + // default action on double click slotOpen(); return; ============================================================ --- src/view/InventoryView.h fd0d9c5eb87a628057d22b2a41426dcbbe84ca03 +++ src/view/InventoryView.h 8f7dc8077f7692611c1fc99c4db0a11f70d62823 @@ -35,15 +35,19 @@ public: public: enum Type { FolderTree, FileList }; - + InventoryView(QWidget*); ~InventoryView(); void setModel(QSortFilterProxyModel *); void setType(Type); - + signals: void directoryChanged(const QModelIndex &); + void openFile(const QString &); + void diffRevision(const QString &, const QString &, const QString &); + void diffFile(const QString &); + void fileHistory(const QString &); private: void setModel(QAbstractItemModel *); @@ -63,26 +67,26 @@ private: QAction * actFileDiff; QAction * actFileHistory; QAction * actRevisionDiff; - + QAction * actAddMultiple; QAction * actRemoveMultiple; QAction * actCommitMultiple; QAction * actIgnoreMultiple; QAction * actUnignoreMultiple; QAction * actRevertMultiple; - + Type type; - + InventoryViewDelegate invViewDelegate; - + private slots: void delegateModelReset(); void modelReset(); - + void changeDirectory(const QModelIndex &); void itemClicked(const QModelIndex & index); void slotContextMenuRequested(const QModelIndexList &, const QPoint &); - + void slotChdir(); void slotOpen(); void slotAdd();