Tracker: Find Panel - fix handling of duplicate mimetype descriptions.

Currently, Haiku has two mimetypes for MIDI files, which causes the
logic for clearing the currently marked item to sometimes fail. Instead,
when two mimetypes have the same description, the subtype is added to
the label in parentheses as is done in the FileTypes preflet.
This commit is contained in:
Jessica Hamilton 2013-05-04 09:11:04 +12:00
parent 0459d905e8
commit 9b438e176a

View File

@ -1783,6 +1783,16 @@ FindPanel::SetCurrentMimeType(const char* label)
} }
static
void AddSubtype(BString& text, const BMimeType& type)
{
text.Append(" (");
text.Append(strchr(type.Type(), '/') + 1);
// omit the slash
text.Append(")");
}
bool bool
FindPanel::AddOneMimeTypeToMenu(const ShortMimeInfo* info, void* castToMenu) FindPanel::AddOneMimeTypeToMenu(const ShortMimeInfo* info, void* castToMenu)
{ {
@ -1799,8 +1809,24 @@ FindPanel::AddOneMimeTypeToMenu(const ShortMimeInfo* info, void* castToMenu)
BMessage* msg = new BMessage(kMIMETypeItem); BMessage* msg = new BMessage(kMIMETypeItem);
msg->AddString("mimetype", info->InternalName()); msg->AddString("mimetype", info->InternalName());
superItem->Submenu()->AddItem(new IconMenuItem( // check to ensure previous item's name differs
info->ShortDescription(), msg, info->InternalName(), BMenu* menu = superItem->Submenu();
BMenuItem* previous = menu->ItemAt(menu->CountItems() - 1);
BString text = info->ShortDescription();
if (previous != NULL && strcasecmp(previous->Label(),
info->ShortDescription()) == 0) {
AddSubtype(text, type);
// update the previous item as well
BMimeType type(previous->Message()->GetString("mimetype",
NULL));
BString label = ShortMimeInfo(type).ShortDescription();
AddSubtype(label, type);
previous->SetLabel(label);
}
menu->AddItem(new IconMenuItem(
text, msg, info->InternalName(),
B_MINI_ICON)); B_MINI_ICON));
} }