Ticket #9736: 0001-Tracker-Find-Panel-fix-handling-of-duplicate-mimetyp.patch

File 0001-Tracker-Find-Panel-fix-handling-of-duplicate-mimetyp.patch, 2.1 KB (added by jessicah, 11 years ago)
  • src/kits/tracker/FindPanel.cpp

    From c1284ddf07ec00770f74419b55c284d7b44dd30e Mon Sep 17 00:00:00 2001
    From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
    Date: Sat, 4 May 2013 09:11:04 +1200
    Subject: [PATCH] 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.
    ---
     src/kits/tracker/FindPanel.cpp | 30 ++++++++++++++++++++++++++++--
     1 file changed, 28 insertions(+), 2 deletions(-)
    
    diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp
    index f42c7dd..709308f 100644
    a b FindPanel::SetCurrentMimeType(const char* label)  
    17231723    }
    17241724
    17251725    return found ? B_OK : B_ENTRY_NOT_FOUND;
     1726}
     1727
     1728
     1729static
     1730void AddSubtype(BString& text, const BMimeType& type)
     1731{
     1732    text.Append(" (");
     1733    text.Append(strchr(type.Type(), '/') + 1);
     1734        // omit the slash
     1735    text.Append(")");
    17261736}
    17271737
    17281738
    FindPanel::AddOneMimeTypeToMenu(const ShortMimeInfo* info, void* castToMenu)  
    17421752        BMessage* msg = new BMessage(kMIMETypeItem);
    17431753        msg->AddString("mimetype", info->InternalName());
    17441754
    1745         superItem->Submenu()->AddItem(new IconMenuItem(
    1746             info->ShortDescription(), msg, info->InternalName(),
     1755        // check to ensure previous item's name differs
     1756        BMenu* menu = superItem->Submenu();
     1757        BMenuItem* previous = menu->ItemAt(menu->CountItems() - 1);
     1758        BString text = info->ShortDescription();
     1759        if (previous != NULL && strcasecmp(previous->Label(),
     1760                info->ShortDescription()) == 0) {
     1761            AddSubtype(text, type);
     1762
     1763            // update the previous item as well
     1764            BMimeType type(previous->Message()->GetString("mimetype",
     1765                NULL));
     1766            BString label = ShortMimeInfo(type).ShortDescription();
     1767            AddSubtype(label, type);
     1768            previous->SetLabel(label);
     1769        }
     1770
     1771        menu->AddItem(new IconMenuItem(
     1772            text, msg, info->InternalName(),
    17471773            B_MINI_ICON));
    17481774    }
    17491775