# # # patch "notes/TODO" # from [6022e4c00c664e2dc943340f467a5f9ce72bd544] # to [78eeaafe1d2ff9732f1fea2e4344873c0b0c19a3] # # patch "src/model/GetFile.cpp" # from [1ae287f9505265565759d3b171f1fa14c6d11a6f] # to [3fffb3be172e0e28451322370f80dbf80408f132] # # patch "src/view/dialogs/FileDiff.cpp" # from [b5178b6755daa3f433adbc942034889cb266aebe] # to [6262b76d6938115b063ca83e7bca6082595f52c4] # # patch "src/view/dialogs/FileDiff.h" # from [ba57120aa6697586ec041e4dbb6175927cc49861] # to [14c54d84f6d8f41b74cb461a378d942ec0db690f] # ============================================================ --- notes/TODO 6022e4c00c664e2dc943340f467a5f9ce72bd544 +++ notes/TODO 78eeaafe1d2ff9732f1fea2e4344873c0b0c19a3 @@ -1,4 +1,4 @@ Current TODO, for "long-term" stuff see Current TODO, for "long-term" stuff see IDEAS. -* make previous / next group buttons work again in detailed diff dialog -* Mac OS X: close the app from the dock icon does not work \ No newline at end of file +* Mac OS X: closing the app from the dock icon does not work +* Mac OS X: sometimes foregrounding the application does not work - find out why! \ No newline at end of file ============================================================ --- src/model/GetFile.cpp 1ae287f9505265565759d3b171f1fa14c6d11a6f +++ src/model/GetFile.cpp 3fffb3be172e0e28451322370f80dbf80408f132 @@ -95,6 +95,7 @@ void GetFile::applyDiff(Diff * diff) { int addedLines = 0; + for (int i=0, s=diff->hunks.size(); ihunks.at(i); @@ -157,24 +158,34 @@ QModelIndex GetFile::getNextGroup(const QModelIndex GetFile::getNextGroup(const QModelIndex & base, bool recurse) { int startRow = 0; - DiffLine::State lastState = DiffLine::Unchanged; + bool startedInChange = false; if (base.isValid() && base.row() < fileContents.size()) { startRow = base.row(); - lastState = fileContents.at(startRow)->state; + ContentLine * line = fileContents.at(startRow); + startedInChange = line->state != DiffLine::Unchanged && + line->state != DiffLine::UnchangedMissingNewline; } for (int i=startRow, j=fileContents.size(); istate == DiffLine::Unchanged || - line->state == DiffLine::UnchangedMissingNewline || - (line->state == DiffLine::AddedMissingNewline && lastState == DiffLine::Added) || - (line->state == DiffLine::RemovedMissingNewline && lastState == DiffLine::Removed)) + bool inChange = line->state != DiffLine::Unchanged && + line->state != DiffLine::UnchangedMissingNewline; + + if (( startedInChange && inChange) || + (!startedInChange && !inChange)) + continue; + + if (startedInChange && !inChange) { - lastState = line->state; + // if we started in a change, we obviously want to go to the + // next change which should follow after at least one + // unchanged line + startedInChange = false; continue; } + return index(i, 0, QModelIndex()); } @@ -187,41 +198,50 @@ QModelIndex GetFile::getPrevGroup(const QModelIndex GetFile::getPrevGroup(const QModelIndex & base, bool recurse) { int startRow = fileContents.size() - 1; - DiffLine::State lastState = DiffLine::Unchanged; + bool startedInChange = false; if (base.isValid() && base.row() < fileContents.size()) { startRow = base.row(); - lastState = fileContents.at(startRow)->state; + ContentLine * line = fileContents.at(startRow); + startedInChange = line->state != DiffLine::Unchanged && + line->state != DiffLine::UnchangedMissingNewline; } - bool foundLast = false; + bool foundLastLine = false; for (int i=startRow; i>=0; i--) { ContentLine * line = fileContents.at(i); + bool inChange = line->state != DiffLine::Unchanged && + line->state != DiffLine::UnchangedMissingNewline; - // did we already found the last line of a group of similar lines? - if (!foundLast) - { - if (line->state == DiffLine::Unchanged || - line->state == DiffLine::UnchangedMissingNewline || - (line->state == DiffLine::Added && lastState == DiffLine::AddedMissingNewline) || - (line->state == DiffLine::Removed && lastState == DiffLine::RemovedMissingNewline)) - { - lastState = line->state; - continue; - } - foundLast = true; - } + if (( startedInChange && inChange) || + (!startedInChange && !inChange)) + continue; - if (foundLast) + if (startedInChange && !inChange) { - // if the marker just changed, the previous line was our - // first line - if (line->state != lastState) + // if we already found the last line, then this is the sign + // that we've just left the hunk we want to scroll to next, + // so we're returning the previously processed line as scrol + // target + if (foundLastLine) { return index(i + 1, 0, QModelIndex()); } + + // if we started in a change, we obviously want to go to the + // prev change which should be separated with at least one + // unchanged line + startedInChange = false; + continue; } + + // now we've seem to have found the last line of the previous + // hunk, we just need to find the first line and return that + // and we just use the same machinery for this ... we start in a + // change and go up until we're no longer in this change... + foundLastLine = true; + startedInChange = true; } // if we've already recursed, stop here ============================================================ --- src/view/dialogs/FileDiff.cpp b5178b6755daa3f433adbc942034889cb266aebe +++ src/view/dialogs/FileDiff.cpp 6262b76d6938115b063ca83e7bca6082595f52c4 @@ -22,8 +22,10 @@ #include #include +#include -FileDiff::FileDiff(QWidget * parent) : Dialog(parent) +FileDiff::FileDiff(QWidget * parent) + : Dialog(parent), fileModel(0), fileProxyModel(0), diffModel(0) { setupUi(this); Dialog::init(); @@ -34,7 +36,13 @@ FileDiff::FileDiff(QWidget * parent) : D diffView->header()->setResizeMode(1, QHeaderView::Interactive); diffView->header()->setResizeMode(2, QHeaderView::ResizeToContents); + QScrollBar * vertBar = diffView->verticalScrollBar(); connect( + vertBar, SIGNAL(valueChanged(int)), + this, SLOT(changeCurrentIndex(int)) + ); + + connect( firstRevision, SIGNAL(toggled(bool)), this, SLOT(versionToggled()) ); @@ -156,7 +164,12 @@ void FileDiff::forWorkspace(const Worksp diffModel->readWorkspaceDiff(ws, fileName, base, target); } -FileDiff::~FileDiff() {} +FileDiff::~FileDiff() +{ + if (fileModel) delete fileModel; + if (fileProxyModel) delete fileProxyModel; + if (diffModel) delete diffModel; +} void FileDiff::applyDiff() { @@ -252,3 +265,17 @@ void FileDiff::getNextGroup() scrollToGroup(true); } +void FileDiff::changeCurrentIndex(int pos) +{ + if (!fileProxyModel) return; + + QModelIndex newCurrent = fileProxyModel->mapToSource( + fileProxyModel->index(pos, 0, QModelIndex()) + ); + + if (newCurrent.isValid()) + { + currentIndex = newCurrent; + } +} + ============================================================ --- src/view/dialogs/FileDiff.h ba57120aa6697586ec041e4dbb6175927cc49861 +++ src/view/dialogs/FileDiff.h 14c54d84f6d8f41b74cb461a378d942ec0db690f @@ -41,6 +41,7 @@ private slots: void scrollToGroup(bool); void getPrevGroup(); void getNextGroup(); + void changeCurrentIndex(int); private: ContentDiff * diffModel;