- Added a new CreateMimeMenu() method that creates the menu with attributes
for a specific MIME type. - Attribute menus now display a hierarchy with type and supertype attributes. This looks a bit ugly but mostly because not all types and supertypes have icons and descriptions. Anyone up to do a MIME database cleanup? :) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27125 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3110,6 +3110,92 @@ BContainerWindow::AddMimeTypesToMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create a menu for a specific MIME type.
|
||||||
|
BMenu*
|
||||||
|
BContainerWindow::CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
||||||
|
BMenu* menu, int32 start, int32 count)
|
||||||
|
{
|
||||||
|
// Check if we already have an entry for this MIME type in the menu.
|
||||||
|
for (int32 subindex = start; subindex < count; subindex++) {
|
||||||
|
BMenuItem *item = menu->ItemAt(subindex);
|
||||||
|
if (!item)
|
||||||
|
continue;
|
||||||
|
BMessage *message = item->Message();
|
||||||
|
if (!message)
|
||||||
|
continue;
|
||||||
|
const char *str;
|
||||||
|
if (message->FindString("mimetype", &str) == B_OK
|
||||||
|
&& strcmp(mimeType.Type(), str) == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessage attrInfo;
|
||||||
|
char description[B_MIME_TYPE_LENGTH];
|
||||||
|
const char *nameToAdd = mimeType.Type();
|
||||||
|
|
||||||
|
if (!mimeType.IsInstalled())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// only add things to menu which have "user-visible" data
|
||||||
|
if (mimeType.GetAttrInfo(&attrInfo) != B_OK)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (mimeType.GetShortDescription(description) == B_OK
|
||||||
|
&& description[0])
|
||||||
|
nameToAdd = description;
|
||||||
|
|
||||||
|
// go through each field in meta mime and add it to a menu
|
||||||
|
BMenu *localMenu = NULL;
|
||||||
|
int32 index = -1;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
|
if (isSuperType) {
|
||||||
|
// If it is a supertype, we create the menu anyway as it may have
|
||||||
|
// submenus later on.
|
||||||
|
localMenu = new BMenu(nameToAdd);
|
||||||
|
BFont font;
|
||||||
|
menu->GetFont(&font);
|
||||||
|
localMenu->SetFont(&font);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (attrInfo.FindString("attr:public_name", ++index, &str) == B_OK) {
|
||||||
|
if (!attrInfo.FindBool("attr:viewable", index)) {
|
||||||
|
// don't add if attribute not viewable
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 type;
|
||||||
|
int32 align;
|
||||||
|
int32 width;
|
||||||
|
bool editable;
|
||||||
|
const char *attrName;
|
||||||
|
|
||||||
|
if (attrInfo.FindString("attr:name", index, &attrName) != B_OK
|
||||||
|
|| attrInfo.FindInt32("attr:type", index, &type) != B_OK
|
||||||
|
|| attrInfo.FindBool("attr:editable", index, &editable) != B_OK
|
||||||
|
|| attrInfo.FindInt32("attr:width", index, &width) != B_OK
|
||||||
|
|| attrInfo.FindInt32("attr:alignment", index, &align) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BString displayAs;
|
||||||
|
attrInfo.FindString("attr:display_as", index, &displayAs);
|
||||||
|
|
||||||
|
if (!localMenu) {
|
||||||
|
// do a lazy allocation of the menu
|
||||||
|
localMenu = new BMenu(nameToAdd);
|
||||||
|
BFont font;
|
||||||
|
menu->GetFont(&font);
|
||||||
|
localMenu->SetFont(&font);
|
||||||
|
}
|
||||||
|
localMenu->AddItem(NewAttributeMenuItem(str, attrName, type,
|
||||||
|
displayAs.String(), width, align, editable, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return localMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BContainerWindow::AddMimeTypesToMenu(BMenu *menu)
|
BContainerWindow::AddMimeTypesToMenu(BMenu *menu)
|
||||||
{
|
{
|
||||||
@@ -3152,83 +3238,33 @@ BContainerWindow::AddMimeTypesToMenu(BMenu *menu)
|
|||||||
int32 typeCount = PoseView()->CountMimeTypes();
|
int32 typeCount = PoseView()->CountMimeTypes();
|
||||||
|
|
||||||
for (int32 index = 0; index < typeCount; index++) {
|
for (int32 index = 0; index < typeCount; index++) {
|
||||||
bool shouldAdd = true;
|
BMimeType mimeType(PoseView()->MimeTypeAt(index));
|
||||||
const char *signature = PoseView()->MimeTypeAt(index);
|
BMimeType superType;
|
||||||
|
mimeType.GetSupertype(&superType);
|
||||||
|
|
||||||
for (int32 subindex = start; subindex < count; subindex++) {
|
BMenu* levelOneMenu = CreateMimeMenu(superType, true, menu, start, count);
|
||||||
BMenuItem *item = menu->ItemAt(subindex);
|
if (levelOneMenu) {
|
||||||
if (!item)
|
// We have a supertype menu.
|
||||||
continue;
|
BMenu* levelTwoMenu = CreateMimeMenu(mimeType, false, levelOneMenu, start,
|
||||||
BMessage *message = item->Message();
|
count);
|
||||||
if (!message)
|
if (levelTwoMenu) {
|
||||||
continue;
|
// And also a one for the main MIME type. Adde them to the menu
|
||||||
const char *str;
|
// hierarchy.
|
||||||
if (message->FindString("mimetype", &str) == B_OK
|
BMessage *message1 = new BMessage(kMIMETypeItem);
|
||||||
&& strcmp(signature, str) == 0) {
|
message1->AddString("mimetype", mimeType.Type());
|
||||||
shouldAdd = false;
|
levelOneMenu->AddItem(new IconMenuItem(levelTwoMenu, message1,
|
||||||
break;
|
mimeType.Type(), B_MINI_ICON));
|
||||||
}
|
|
||||||
}
|
BMessage *message2 = new BMessage(kMIMETypeItem);
|
||||||
|
message2->AddString("mimetype", superType.Type());
|
||||||
if (shouldAdd) {
|
menu->AddItem(new IconMenuItem(levelOneMenu, message2,
|
||||||
BMessage attrInfo;
|
superType.Type(), B_MINI_ICON));
|
||||||
char description[B_MIME_TYPE_LENGTH];
|
|
||||||
const char *nameToAdd = signature;
|
} else {
|
||||||
|
if (levelOneMenu->CountItems() == 0) {
|
||||||
BMimeType mimetype(signature);
|
// Our supertype menu is empty, so we remove it now.
|
||||||
|
delete levelOneMenu;
|
||||||
if (!mimetype.IsInstalled())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// only add things to menu which have "user-visible" data
|
|
||||||
if (mimetype.GetAttrInfo(&attrInfo) != B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (mimetype.GetShortDescription(description) == B_OK
|
|
||||||
&& description[0])
|
|
||||||
nameToAdd = description;
|
|
||||||
|
|
||||||
// go through each field in meta mime and add it to a menu
|
|
||||||
BMenu *localMenu = 0;
|
|
||||||
int32 index = -1;
|
|
||||||
const char *str;
|
|
||||||
|
|
||||||
while (attrInfo.FindString("attr:public_name", ++index, &str) == B_OK) {
|
|
||||||
if (!attrInfo.FindBool("attr:viewable", index)) {
|
|
||||||
// don't add if attribute not viewable
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 type;
|
|
||||||
int32 align;
|
|
||||||
int32 width;
|
|
||||||
bool editable;
|
|
||||||
const char *attrName;
|
|
||||||
|
|
||||||
if (attrInfo.FindString("attr:name", index, &attrName) != B_OK
|
|
||||||
|| attrInfo.FindInt32("attr:type", index, &type) != B_OK
|
|
||||||
|| attrInfo.FindBool("attr:editable", index, &editable) != B_OK
|
|
||||||
|| attrInfo.FindInt32("attr:width", index, &width) != B_OK
|
|
||||||
|| attrInfo.FindInt32("attr:alignment", index, &align) != B_OK)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
BString displayAs;
|
|
||||||
attrInfo.FindString("attr:display_as", index, &displayAs);
|
|
||||||
|
|
||||||
if (!localMenu) {
|
|
||||||
// do a lazy allocation of the menu
|
|
||||||
localMenu = new BMenu(nameToAdd);
|
|
||||||
BFont font;
|
|
||||||
menu->GetFont(&font);
|
|
||||||
localMenu->SetFont(&font);
|
|
||||||
}
|
|
||||||
localMenu->AddItem(NewAttributeMenuItem(str, attrName, type,
|
|
||||||
displayAs.String(), width, align, editable, false));
|
|
||||||
}
|
|
||||||
if (localMenu) {
|
|
||||||
BMessage *message = new BMessage(kMIMETypeItem);
|
|
||||||
message->AddString("mimetype", signature);
|
|
||||||
menu->AddItem(new IconMenuItem(localMenu, message, signature, B_MINI_ICON));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ class BContainerWindow : public BWindow {
|
|||||||
// calls for inheriting window size, attribute layout, etc.
|
// calls for inheriting window size, attribute layout, etc.
|
||||||
// deprecated
|
// deprecated
|
||||||
|
|
||||||
|
BMenu* CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
||||||
|
BMenu* menu, int32 start, int32 count);
|
||||||
virtual void AddMimeTypesToMenu(BMenu *);
|
virtual void AddMimeTypesToMenu(BMenu *);
|
||||||
void AddMimeTypesToMenu();
|
void AddMimeTypesToMenu();
|
||||||
virtual void MarkAttributeMenu(BMenu *);
|
virtual void MarkAttributeMenu(BMenu *);
|
||||||
|
|||||||
Reference in New Issue
Block a user