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 ;)
This commit is contained in:
@@ -77,6 +77,9 @@ public:
|
|||||||
BTranslatorRoster* roster = NULL);
|
BTranslatorRoster* roster = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int CompareTranslationFormatByName(const void* format1,
|
||||||
|
const void* format2);
|
||||||
|
|
||||||
static color_space sBitmapSpace;
|
static color_space sBitmapSpace;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <CharacterSetRoster.h>
|
#include <CharacterSetRoster.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <List.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
@@ -834,6 +835,7 @@ BTranslationUtils::GetDefaultSettings(const char *kTranslatorName,
|
|||||||
return pMessage;
|
return pMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// AddTranslationItems
|
// AddTranslationItems
|
||||||
//
|
//
|
||||||
@@ -908,24 +910,45 @@ BTranslationUtils::AddTranslationItems(BMenu *intoMenu, uint32 fromType,
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Get supported output formats
|
||||||
|
BList formatList;
|
||||||
err = roster->GetOutputFormats(ids[tix], &formats, &numFormats);
|
err = roster->GetOutputFormats(ids[tix], &formats, &numFormats);
|
||||||
if (err == B_OK) {
|
if (err == B_OK) {
|
||||||
for (int oix = 0; oix < numFormats; oix++) {
|
for (int oix = 0; oix < numFormats; oix++) {
|
||||||
if (formats[oix].type != fromType) {
|
if (formats[oix].type != fromType) {
|
||||||
BMessage *itemmsg;
|
formatList.AddItem(const_cast<translation_format*>(
|
||||||
if (kModel)
|
&formats[oix]));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
delete[] ids;
|
||||||
return B_OK;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user