Skip to content

Commit

Permalink
Let undo more complete
Browse files Browse the repository at this point in the history
After modifying, it can restore multiple phrases after restore
single phrase.
  • Loading branch information
kuoyliu committed May 19, 2017
1 parent 457f4c2 commit 98f60c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/model/UserphraseModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ void UserphraseModel::remove(QModelIndexList indexList)
auto last = indexList.first().row();

emit beginRemoveRows(indexList.first().parent(), first, last);

int remove_cnt = 0;
int remove_cnt = 0;
foreach(auto item, indexList) {
auto index = item.row();

Expand All @@ -115,7 +114,7 @@ void UserphraseModel::remove(QModelIndexList indexList)
}
// FIXME: Handle chewing_userphrase_remove fails.
}
maxundocnt = remove_cnt;
maxundocnt.push_back(remove_cnt);
emit endRemoveRows();

emit removePhraseCompleted(indexList.size());
Expand Down Expand Up @@ -234,14 +233,15 @@ const Userphrase *UserphraseModel::getUserphrase(const QModelIndex& idx)

void UserphraseModel::undo()
{
if (!removerecord_.empty() && maxundocnt>0) {
while(maxundocnt--){
auto last = removerecord_.end() - 1;
const QString phrase = last->display_;
add(last->phrase_, last->bopomofo_);
removerecord_.erase(last);
emit undoCompleted(phrase);
}
maxundocnt = 1;
int cnt = *(maxundocnt.end() -1);
if (!removerecord_.empty() && cnt>0) {
while (cnt--) {
auto last = removerecord_.end() -1;
const QString phrase = last->display_;
add(last->phrase_, last->bopomofo_);
removerecord_.erase(last);
emit undoCompleted(phrase);
}
maxundocnt.pop_back();
}
}
2 changes: 1 addition & 1 deletion src/model/UserphraseModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public slots:
std::unique_ptr<ChewingContext, void (*)(ChewingContext*)> ctx_;
UserphraseSet userphrase_;
std::vector<Userphrase> removerecord_;
std::vector<int> maxundocnt;
int addresult_;
int maxundocnt;
};

0 comments on commit 98f60c2

Please sign in to comment.