DataTranslations: sort by supertype before name
Fixes #9618 (which suggested using a tree view, but I think that's not useful, just proper sorting of the items seems fine to me) Change-Id: Ie1298eec048f9cb42528b8420a91e807e8f00eab Reviewed-on: https://review.haiku-os.org/c/haiku/+/3030 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
ebcb6f5f4f
commit
24f8ae4156
@@ -14,15 +14,22 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <String.h>
|
||||
#include <TranslatorRoster.h>
|
||||
|
||||
|
||||
static int
|
||||
compare_items(const void* a, const void* b)
|
||||
{
|
||||
const BStringItem* stringA = *(const BStringItem**)a;
|
||||
const BStringItem* stringB = *(const BStringItem**)b;
|
||||
const TranslatorItem* itemA = *(const TranslatorItem**)a;
|
||||
const TranslatorItem* itemB = *(const TranslatorItem**)b;
|
||||
|
||||
return strcmp(stringA->Text(), stringB->Text());
|
||||
// Compare by supertype, then by name
|
||||
int typeDiff = itemA->Supertype().Compare(itemB->Supertype());
|
||||
if (typeDiff != 0)
|
||||
return typeDiff;
|
||||
|
||||
return strcmp(itemA->Text(), itemB->Text());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +41,19 @@ TranslatorItem::TranslatorItem(translator_id id, const char* name)
|
||||
BStringItem(name),
|
||||
fID(id)
|
||||
{
|
||||
static BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||
|
||||
const translation_format* format;
|
||||
int32 count;
|
||||
roster->GetOutputFormats(id, &format, &count);
|
||||
|
||||
// Find a supertype to categorize the item in ("application" is too generic,
|
||||
// so exclude it unless it's the only one available)
|
||||
do {
|
||||
fSupertype = format->MIME;
|
||||
int32 slash = fSupertype.FindFirst('/');
|
||||
fSupertype.Truncate(slash);
|
||||
} while (fSupertype == "application" && --count != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
|
||||
#include <ListView.h>
|
||||
#include <String.h>
|
||||
#include <TranslationDefs.h>
|
||||
|
||||
|
||||
@@ -21,9 +22,11 @@ public:
|
||||
virtual ~TranslatorItem();
|
||||
|
||||
translator_id ID() const { return fID; }
|
||||
const BString& Supertype() const { return fSupertype; }
|
||||
|
||||
private:
|
||||
translator_id fID;
|
||||
BString fSupertype;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user