2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "CommitsCursor.h"
20 #include "CommitsMatcher.h"
24 CommitsCursor::CommitsCursor(SelectionType selectionType
)
29 m_done(! m_head
.isValid()),
31 m_selectionType(selectionType
)
33 if (selectionType
== SelectRange
)
34 m_firstInBranch
= m_head
.firstCommitInBranch();
37 CommitsCursor::~CommitsCursor()
42 int CommitsCursor::forward(Scope scope
, bool skipAnswered
)
45 Q_UNUSED(skipAnswered
);
46 // go to a parent commit
47 int newIndex
= m_currentIndex
;
48 if (m_current
.previousCommitsCount() > 0) {
49 Commit parent
= m_current
.previous()[0];
51 if (! parent
.isValid())
52 return m_currentIndex
;
54 CommitsMatcher::ExpectedAction action
= CommitsMatcher::ShowPatch
;
56 action
= m_matcher
->match(parent
);
57 if (action
== CommitsMatcher::ShowPatch
) {
59 m_currentIndex
= newIndex
;
62 if (action
== CommitsMatcher::Exit
) {
64 return m_currentIndex
;
66 if (parent
.previousCommitsCount() == 0) {// no more commits;
68 return m_currentIndex
;
70 parent
= parent
.previous()[0];
73 return m_currentIndex
;
76 int CommitsCursor::back(Scope scope
)
79 Commit c
= m_current
.next();
80 int newIndex
= m_currentIndex
;
83 return m_currentIndex
;
85 CommitsMatcher::ExpectedAction action
= CommitsMatcher::ShowPatch
;
87 action
= m_matcher
->match(c
);
88 if (action
== CommitsMatcher::ShowPatch
) {
90 if (m_current
== m_firstInBranch
)
92 m_currentIndex
= newIndex
;
93 return m_currentIndex
;
95 if (action
== CommitsMatcher::Exit
) {
97 return m_currentIndex
;
103 void CommitsCursor::setResponse(bool response
, Scope scope
)
106 m_current
.setAcceptance(response
? Vng::Accepted
: Vng::Rejected
);
107 if ((m_selectionType
== SelectRange
&& !response
)
108 || (m_selectionType
== SelectOnePatch
&& response
)) // exit when user says 'no'
110 m_oldestIndex
= qMax(m_oldestIndex
, m_currentIndex
);
113 int CommitsCursor::count()
115 return -1; // TODO we _can_ count.. Its just not quite useful in most cases.
118 void CommitsCursor::forceCount()
120 // TODO sure you want to do that??
123 QString
CommitsCursor::currentText() const
125 return QString("\n") +
126 m_current
.commitTime().toString() + QString(" ") + m_current
.author() + QString("\n ") +
127 m_current
.logMessage();
130 QString
CommitsCursor::helpMessage() const
133 "How to use unrecord...\n"
134 "y: unrecord this patch\n"
135 "n: don't unrecord it\n\n"
136 // "v: view this patch in full with pager\n"
137 // "x: view a summary of this patch\n"
138 "d: unrecord selected patches\n"
139 "q: cancel unrecord\n\n"
140 "j: skip to next patch\n"
141 "k: back up to previous patch\n"
142 "c: calculate number of patches\n"
143 "h or ?: show this help\n");
146 bool CommitsCursor::isValid() const
148 return !m_done
&& m_current
.previousCommitsCount() > 0;
151 QString
CommitsCursor::allowedOptions() const
153 QString allowed
= "ynq";
154 if (m_selectionType
== SelectRange
)
156 // if (m_total == -1)
161 Commit
CommitsCursor::head()
166 void CommitsCursor::setUseMatcher(bool use
)
175 m_matcher
= new CommitsMatcher();