hrev44478 adds 1 changeset to branch 'master' old head: f022b1e7c08e2626af4fa61f76065d2dc6c08192 new head: adfe152ee269d1d6153827ca38a174f217d2634d ---------------------------------------------------------------------------- adfe152: Sort the translation formats in AddTranslationItems by name. This is used by ShowImage and CodyCam to create a list of image formats which a file can be saved as. Tracker sorts the image MIME types used in the Find window by name, so this makes these Save As menus match that (minus the icons which I think are superfluous.) Fixes #6782. If the use of BList is no longer recommended, I welcome better suggestions for sorting which will work in both GCC2 and GCC4. But this works ;) [ Ryan Leavengood <leavengood@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev44478 Commit: adfe152ee269d1d6153827ca38a174f217d2634d URL: http://cgit.haiku-os.org/haiku/commit/?id=adfe152 Author: Ryan Leavengood <leavengood@xxxxxxxxx> Date: Mon Aug 6 06:08:37 2012 UTC Ticket: https://dev.haiku-os.org/ticket/6782 ---------------------------------------------------------------------------- 2 files changed, 37 insertions(+), 11 deletions(-) headers/os/translation/TranslationUtils.h | 3 ++ src/kits/translation/TranslationUtils.cpp | 45 +++++++++++++++++++------ ---------------------------------------------------------------------------- diff --git a/headers/os/translation/TranslationUtils.h b/headers/os/translation/TranslationUtils.h index f1a2480..66c927a 100644 --- a/headers/os/translation/TranslationUtils.h +++ b/headers/os/translation/TranslationUtils.h @@ -77,6 +77,9 @@ public: BTranslatorRoster* roster = NULL); private: + static int CompareTranslationFormatByName(const void* format1, + const void* format2); + static color_space sBitmapSpace; }; diff --git a/src/kits/translation/TranslationUtils.cpp b/src/kits/translation/TranslationUtils.cpp index dd8118c..1d40796 100644 --- a/src/kits/translation/TranslationUtils.cpp +++ b/src/kits/translation/TranslationUtils.cpp @@ -17,6 +17,7 @@ #include <CharacterSetRoster.h> #include <Entry.h> #include <File.h> +#include <List.h> #include <MenuItem.h> #include <NodeInfo.h> #include <Path.h> @@ -834,6 +835,7 @@ BTranslationUtils::GetDefaultSettings(const char *kTranslatorName, return pMessage; } + // --------------------------------------------------------------- // AddTranslationItems // @@ -908,24 +910,45 @@ BTranslationUtils::AddTranslationItems(BMenu *intoMenu, uint32 fromType, if (!ok) continue; + // Get supported output formats + BList formatList; err = roster->GetOutputFormats(ids[tix], &formats, &numFormats); if (err == B_OK) { - for (int oix = 0; oix < numFormats; oix++) { - if (formats[oix].type != fromType) { - BMessage *itemmsg; - if (kModel) - itemmsg = new BMessage(*kModel); - else - itemmsg = new BMessage(B_TRANSLATION_MENU); - itemmsg->AddInt32(kTranslatorIdName, ids[tix]); - itemmsg->AddInt32(kTranslatorTypeName, formats[oix].type); - intoMenu->AddItem( - new BMenuItem(formats[oix].name, itemmsg)); + for (int oix = 0; oix < numFormats; oix++) { + if (formats[oix].type != fromType) { + formatList.AddItem(const_cast<translation_format*>( + &formats[oix])); } } } + + // Sort alphabetically by name + formatList.SortItems(&CompareTranslationFormatByName); + + // Now add the menu items + for (int i = 0; i < formatList.CountItems(); i++) { + translation_format* format = static_cast<translation_format*>( + formatList.ItemAt(i)); + + BMessage *itemmsg; + if (kModel) + itemmsg = new BMessage(*kModel); + else + itemmsg = new BMessage(B_TRANSLATION_MENU); + itemmsg->AddInt32(kTranslatorIdName, ids[tix]); + itemmsg->AddInt32(kTranslatorTypeName, format->type); + intoMenu->AddItem(new BMenuItem(format->name, itemmsg)); + } } delete[] ids; return B_OK; } + + +int +BTranslationUtils::CompareTranslationFormatByName(const void* format1, const void* format2) +{ + return strcasecmp(static_cast<const translation_format*>(format1)->name, + static_cast<const translation_format*>(format2)->name); +}