* Renamed CreateMimeMenu() to AddMimeMenu(), as it now also adds the menu to
its parent. The item count of the parent is now actually adjusted, so that additional entries are found. * AddMimeMenu() now returns the menu of an already existing MIME type. Hence, we don't add the supertype menu twice anymore for each type, or don't add the second type at all when called again. * Cleaned up naming, consistent use of "* " vs. " *". git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27142 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3110,29 +3110,32 @@ BContainerWindow::AddMimeTypesToMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create a menu for a specific MIME type.
|
/*! Adds a menu for a specific MIME type if it doesn't exist already.
|
||||||
|
Returns the menu, if it existed or not.
|
||||||
|
*/
|
||||||
BMenu*
|
BMenu*
|
||||||
BContainerWindow::CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
BContainerWindow::AddMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
||||||
BMenu* menu, int32 start, int32 count)
|
BMenu* menu, int32 start, int32& count)
|
||||||
{
|
{
|
||||||
// Check if we already have an entry for this MIME type in the menu.
|
// Check if we already have an entry for this MIME type in the menu.
|
||||||
for (int32 subindex = start; subindex < count; subindex++) {
|
for (int32 i = start; i < count; i++) {
|
||||||
BMenuItem *item = menu->ItemAt(subindex);
|
BMenuItem* item = menu->ItemAt(i);
|
||||||
if (!item)
|
if (item == NULL)
|
||||||
continue;
|
continue;
|
||||||
BMessage *message = item->Message();
|
BMessage* message = item->Message();
|
||||||
if (!message)
|
if (message == NULL)
|
||||||
continue;
|
continue;
|
||||||
const char *str;
|
|
||||||
if (message->FindString("mimetype", &str) == B_OK
|
const char* type;
|
||||||
&& strcmp(mimeType.Type(), str) == 0) {
|
if (message->FindString("mimetype", &type) == B_OK
|
||||||
return NULL;
|
&& !strcmp(mimeType.Type(), type)) {
|
||||||
|
return item->Submenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage attrInfo;
|
BMessage attrInfo;
|
||||||
char description[B_MIME_TYPE_LENGTH];
|
char description[B_MIME_TYPE_LENGTH];
|
||||||
const char *nameToAdd = mimeType.Type();
|
const char* label = mimeType.Type();
|
||||||
|
|
||||||
if (!mimeType.IsInstalled())
|
if (!mimeType.IsInstalled())
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -3141,25 +3144,24 @@ BContainerWindow::CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
|||||||
if (mimeType.GetAttrInfo(&attrInfo) != B_OK)
|
if (mimeType.GetAttrInfo(&attrInfo) != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (mimeType.GetShortDescription(description) == B_OK
|
if (mimeType.GetShortDescription(description) == B_OK && description[0])
|
||||||
&& description[0])
|
label = description;
|
||||||
nameToAdd = description;
|
|
||||||
|
|
||||||
// go through each field in meta mime and add it to a menu
|
// go through each field in meta mime and add it to a menu
|
||||||
BMenu *localMenu = NULL;
|
BMenu* mimeMenu = NULL;
|
||||||
int32 index = -1;
|
|
||||||
const char *str;
|
|
||||||
|
|
||||||
if (isSuperType) {
|
if (isSuperType) {
|
||||||
// If it is a supertype, we create the menu anyway as it may have
|
// If it is a supertype, we create the menu anyway as it may have
|
||||||
// submenus later on.
|
// submenus later on.
|
||||||
localMenu = new BMenu(nameToAdd);
|
mimeMenu = new BMenu(label);
|
||||||
BFont font;
|
BFont font;
|
||||||
menu->GetFont(&font);
|
menu->GetFont(&font);
|
||||||
localMenu->SetFont(&font);
|
mimeMenu->SetFont(&font);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (attrInfo.FindString("attr:public_name", ++index, &str) == B_OK) {
|
int32 index = -1;
|
||||||
|
const char* publicName;
|
||||||
|
while (attrInfo.FindString("attr:public_name", ++index, &publicName)
|
||||||
|
== B_OK) {
|
||||||
if (!attrInfo.FindBool("attr:viewable", index)) {
|
if (!attrInfo.FindBool("attr:viewable", index)) {
|
||||||
// don't add if attribute not viewable
|
// don't add if attribute not viewable
|
||||||
continue;
|
continue;
|
||||||
@@ -3169,8 +3171,7 @@ BContainerWindow::CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
|||||||
int32 align;
|
int32 align;
|
||||||
int32 width;
|
int32 width;
|
||||||
bool editable;
|
bool editable;
|
||||||
const char *attrName;
|
const char* attrName;
|
||||||
|
|
||||||
if (attrInfo.FindString("attr:name", index, &attrName) != B_OK
|
if (attrInfo.FindString("attr:name", index, &attrName) != B_OK
|
||||||
|| attrInfo.FindInt32("attr:type", index, &type) != B_OK
|
|| attrInfo.FindInt32("attr:type", index, &type) != B_OK
|
||||||
|| attrInfo.FindBool("attr:editable", index, &editable) != B_OK
|
|| attrInfo.FindBool("attr:editable", index, &editable) != B_OK
|
||||||
@@ -3181,18 +3182,27 @@ BContainerWindow::CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
|||||||
BString displayAs;
|
BString displayAs;
|
||||||
attrInfo.FindString("attr:display_as", index, &displayAs);
|
attrInfo.FindString("attr:display_as", index, &displayAs);
|
||||||
|
|
||||||
if (!localMenu) {
|
if (mimeMenu == NULL) {
|
||||||
// do a lazy allocation of the menu
|
// do a lazy allocation of the menu
|
||||||
localMenu = new BMenu(nameToAdd);
|
mimeMenu = new BMenu(label);
|
||||||
BFont font;
|
BFont font;
|
||||||
menu->GetFont(&font);
|
menu->GetFont(&font);
|
||||||
localMenu->SetFont(&font);
|
mimeMenu->SetFont(&font);
|
||||||
}
|
}
|
||||||
localMenu->AddItem(NewAttributeMenuItem(str, attrName, type,
|
mimeMenu->AddItem(NewAttributeMenuItem(publicName, attrName, type,
|
||||||
displayAs.String(), width, align, editable, false));
|
displayAs.String(), width, align, editable, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return localMenu;
|
if (mimeMenu == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
BMessage* message = new BMessage(kMIMETypeItem);
|
||||||
|
message->AddString("mimetype", mimeType.Type());
|
||||||
|
menu->AddItem(new IconMenuItem(mimeMenu, message, mimeType.Type(),
|
||||||
|
B_MINI_ICON));
|
||||||
|
count++;
|
||||||
|
|
||||||
|
return mimeMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3242,34 +3252,25 @@ BContainerWindow::AddMimeTypesToMenu(BMenu *menu)
|
|||||||
BMimeType superType;
|
BMimeType superType;
|
||||||
mimeType.GetSupertype(&superType);
|
mimeType.GetSupertype(&superType);
|
||||||
|
|
||||||
BMenu* levelOneMenu = CreateMimeMenu(superType, true, menu, start, count);
|
BMenu* superMenu = AddMimeMenu(superType, true, menu, start, count);
|
||||||
if (levelOneMenu) {
|
if (superMenu != NULL) {
|
||||||
// We have a supertype menu.
|
// We have a supertype menu.
|
||||||
BMenu* levelTwoMenu = CreateMimeMenu(mimeType, false, levelOneMenu, start,
|
int32 subCount = superMenu->CountItems();
|
||||||
count);
|
AddMimeMenu(mimeType, false, superMenu, 0, subCount);
|
||||||
if (levelTwoMenu) {
|
}
|
||||||
// And also one for the main MIME type. Adde them to the menu
|
}
|
||||||
// hierarchy.
|
|
||||||
BMessage *message1 = new BMessage(kMIMETypeItem);
|
|
||||||
message1->AddString("mimetype", mimeType.Type());
|
|
||||||
levelOneMenu->AddItem(new IconMenuItem(levelTwoMenu, message1,
|
|
||||||
mimeType.Type(), B_MINI_ICON));
|
|
||||||
|
|
||||||
BMessage *message2 = new BMessage(kMIMETypeItem);
|
// remove empty super menus
|
||||||
message2->AddString("mimetype", superType.Type());
|
|
||||||
menu->AddItem(new IconMenuItem(levelOneMenu, message2,
|
for (int32 index = 0; index < typeCount; index++) {
|
||||||
superType.Type(), B_MINI_ICON));
|
BMimeType mimeType(PoseView()->MimeTypeAt(index));
|
||||||
} else {
|
BMimeType superType;
|
||||||
if (levelOneMenu->CountItems() == 0) {
|
mimeType.GetSupertype(&superType);
|
||||||
// Our supertype menu is empty, so we remove it now.
|
|
||||||
delete levelOneMenu;
|
BMenu* superMenu = AddMimeMenu(superType, true, menu, start, count);
|
||||||
} else {
|
if (superMenu != NULL && superMenu->ItemAt(0) == NULL) {
|
||||||
BMessage *message2 = new BMessage(kMIMETypeItem);
|
menu->RemoveItem(superMenu->Superitem());
|
||||||
message2->AddString("mimetype", superType.Type());
|
delete superMenu->Superitem();
|
||||||
menu->AddItem(new IconMenuItem(levelOneMenu, message2,
|
|
||||||
superType.Type(), B_MINI_ICON));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,8 +146,6 @@ 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 *);
|
||||||
@@ -241,6 +239,9 @@ class BContainerWindow : public BWindow {
|
|||||||
|
|
||||||
virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context);
|
virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context);
|
||||||
|
|
||||||
|
BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType,
|
||||||
|
BMenu* menu, int32 start, int32& count);
|
||||||
|
|
||||||
BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32,
|
BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32,
|
||||||
const char *);
|
const char *);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user