diff options
author | - <nemo@alice.(none)> | 2013-04-30 19:57:25 +0200 |
---|---|---|
committer | - <nemo@alice.(none)> | 2013-04-30 19:57:25 +0200 |
commit | f715a24e9c704a03ad8bd99111c3e397fdd58e98 (patch) | |
tree | ad942e86b64d33c3ee48382643bf975c943060c8 /plugingui | |
parent | 24e92963007cb9747a75f41f985af41387dae783 (diff) |
Sorting fails when it handles only two items. Fixed that by sorting a different way when only two items.
Diffstat (limited to 'plugingui')
-rw-r--r-- | plugingui/listboxbasic.cc | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index 3d903a4..03fd0c4 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -92,16 +92,25 @@ void GUI::ListBoxBasic::addItems(std::vector<GUI::ListBoxBasic::Item> &is) } // sort - for(int x = 0; x < (int)items.size() - 1; x++) { - for(int y = 0; y < (int)items.size() - 1; y++) { - if(items[x].name < items[y].name) { - - if(x == selected) setSelection(y); - else if(selected == y) setSelection(x); - - GUI::ListBoxBasic::Item tmp = items[x]; - items[x] = items[y]; - items[y] = tmp; + if(items.size() == 2) { + DEBUG(list, "Sorting special case with two items\n"); + if(items[0].name > items[1].name) { + GUI::ListBoxBasic::Item tmp = items[0]; + items[0] = items[1]; + items[1] = tmp; + } + } + else { + for(int x = 0; x < (int)items.size() - 1; x++) { + for(int y = 0; y < (int)items.size() - 1; y++) { + if(items[x].name < items[y].name) { + if(x == selected) setSelection(y); + else if(selected == y) setSelection(x); + + GUI::ListBoxBasic::Item tmp = items[x]; + items[x] = items[y]; + items[y] = tmp; + } } } } |