From c0ea325df9f61a1fb05c2f2f0cc5b402a882313a Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 19 Oct 2010 21:59:58 +0000 Subject: [PATCH] * fix sorting of languages in ReadOnlyBootPrompt git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39014 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../readonlybootprompt/BootPromptWindow.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/apps/readonlybootprompt/BootPromptWindow.cpp b/src/apps/readonlybootprompt/BootPromptWindow.cpp index ae2c05fae5..b43bb04141 100644 --- a/src/apps/readonlybootprompt/BootPromptWindow.cpp +++ b/src/apps/readonlybootprompt/BootPromptWindow.cpp @@ -63,6 +63,18 @@ private: }; +static int +compare_void_list_items(const void* _a, const void* _b) +{ + static BCollator collator; + + LanguageItem* a = *(LanguageItem**)_a; + LanguageItem* b = *(LanguageItem**)_b; + + return collator.Compare(a->Text(), b->Text()); +} + + BootPromptWindow::BootPromptWindow() : BWindow(BRect(0, 0, 450, 380), "", @@ -268,6 +280,7 @@ BootPromptWindow::_PopulateLanguages() // limited to catalogs written for this application, which is on purpose! const char* languageString; + LanguageItem* currentItem = NULL; for (int32 i = 0; installedCatalogs.FindString("langs", i, &languageString) == B_OK; i++) { BLanguage* language; @@ -291,16 +304,17 @@ BootPromptWindow::_PopulateLanguages() languageString); fLanguagesListView->AddItem(item); // Select this item if it is the first preferred language - if (strcmp(firstPreferredLanguage, languageString) == 0) { - fLanguagesListView->Select( - fLanguagesListView->CountItems() - 1); - } + if (strcmp(firstPreferredLanguage, languageString) == 0) + currentItem = item; delete language; } else printf("failed to get BLanguage for %s\n", languageString); } + fLanguagesListView->SortItems(compare_void_list_items); + if (currentItem != NULL) + fLanguagesListView->Select(fLanguagesListView->IndexOf(currentItem)); fLanguagesListView->ScrollToSelection(); // Re-enable sending the selection message.