diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index e5b044bc8d..fc9649e375 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -130,7 +130,6 @@ class DraggableContainerIcon : public BView { struct AddOneAddonParams { BObjectList *primaryList; BObjectList *secondaryList; - BObjectList *mimeTypes; }; struct StaggerOneParams { @@ -2814,33 +2813,33 @@ BContainerWindow::AddTrashContextMenus(BMenu *menu) void BContainerWindow::EachAddon(bool (*eachAddon)(const Model *, const char *, - uint32 shortcut, bool primary, void *context), void *passThru) + uint32 shortcut, bool primary, void *context), void *passThru, + BObjectList &mimeTypes) { BObjectList uniqueList(10, true); BPath path; bool bail = false; if (find_directory(B_BEOS_ADDONS_DIRECTORY, &path) == B_OK) - bail = EachAddon(path, eachAddon, &uniqueList, passThru); + bail = EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes); if (!bail && find_directory(B_USER_ADDONS_DIRECTORY, &path) == B_OK) - bail = EachAddon(path, eachAddon, &uniqueList, passThru); + bail = EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes); if (!bail && find_directory(B_COMMON_ADDONS_DIRECTORY, &path) == B_OK) - EachAddon(path, eachAddon, &uniqueList, passThru); + EachAddon(path, eachAddon, &uniqueList, passThru, mimeTypes); } bool BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, const char *, uint32 shortcut, bool primary, void *), - BObjectList *uniqueList, void *params) + BObjectList *uniqueList, void *params, + BObjectList &mimeTypes) { path.Append("Tracker"); BDirectory dir; BEntry entry; - - BObjectList *mimeTypes = ((AddOneAddonParams *)params)->mimeTypes; if (dir.SetTo(path.Path()) != B_OK) return false; @@ -2866,7 +2865,7 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, bool primary = false; - if (mimeTypes->CountItems()) { + if (mimeTypes.CountItems()) { BFile file(&entry, B_READ_ONLY); if (file.InitCheck() == B_OK) { BAppFileInfo info(&file); @@ -2884,8 +2883,8 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, // check all supported types if it has some set if (!secondary) { - for (int32 i = mimeTypes->CountItems(); !primary && i-- > 0;) { - BString *type = mimeTypes->ItemAt(i); + for (int32 i = mimeTypes.CountItems(); !primary && i-- > 0;) { + BString *type = mimeTypes.ItemAt(i); if (info.IsSupportedType(type->String())) { BMimeType mimeType(type->String()); if (info.Supports(&mimeType)) @@ -2923,6 +2922,32 @@ BContainerWindow::EachAddon(BPath &path, bool (*eachAddon)(const Model *, } +void +BContainerWindow::BuildMimeTypeList(BObjectList &mimeTypes) +{ + int32 count = PoseView()->SelectionList()->CountItems(); + if (!count) { + // just add the type of the current directory + AddMimeTypeString(mimeTypes, TargetModel()); + } else { + _UpdateSelectionMIMEInfo(); + for (int32 index = 0; index < count; index++) { + BPose *pose = PoseView()->SelectionList()->ItemAt(index); + AddMimeTypeString(mimeTypes, pose->TargetModel()); + // If it's a symlink, resolves it and add the Target's MimeType + if (pose->TargetModel()->IsSymLink()) { + Model* resolved = new Model( + pose->TargetModel()->EntryRef(), true, true); + if (resolved->InitCheck() == B_OK) { + AddMimeTypeString(mimeTypes, resolved); + } + delete resolved; + } + } + } +} + + void BContainerWindow::BuildAddOnMenu(BMenu *menu) { @@ -2952,44 +2977,21 @@ BContainerWindow::BuildAddOnMenu(BMenu *menu) BObjectList primaryList; BObjectList secondaryList; + BObjectList mimeTypes(10, true); + BuildMimeTypeList(mimeTypes); AddOneAddonParams params; params.primaryList = &primaryList; params.secondaryList = &secondaryList; // build a list of the MIME types of the selected items - BObjectList mimeTypes(10, true); - int32 count = PoseView()->SelectionList()->CountItems(); - if (!count) { - // just add the type of the current directory - AddMimeTypeString(mimeTypes, TargetModel()); - } else { - _UpdateSelectionMIMEInfo(); - for (int32 index = 0; index < count; index++) { - BPose *pose = PoseView()->SelectionList()->ItemAt(index); - - AddMimeTypeString(mimeTypes, pose->TargetModel()); - // If it's a symlink, resolves it and add the Target's MimeType - if (pose->TargetModel()->IsSymLink()) { - Model* resolved = new Model( - pose->TargetModel()->EntryRef(), true, true); - if (resolved->InitCheck() == B_OK) { - AddMimeTypeString(mimeTypes, resolved); - } - delete resolved; - } - } - } - - params.mimeTypes = &mimeTypes; - - EachAddon(AddOneAddon, ¶ms); + EachAddon(AddOneAddon, ¶ms, mimeTypes); primaryList.SortItems(CompareLabels); secondaryList.SortItems(CompareLabels); - count = primaryList.CountItems(); + int32 count = primaryList.CountItems(); for (int32 index = 0; index < count; index++) menu->AddItem(primaryList.ItemAt(index)); diff --git a/src/kits/tracker/ContainerWindow.h b/src/kits/tracker/ContainerWindow.h index 373b81a7a1..e312ab213e 100644 --- a/src/kits/tracker/ContainerWindow.h +++ b/src/kits/tracker/ContainerWindow.h @@ -169,7 +169,8 @@ class BContainerWindow : public BWindow { bool createNew = false, bool createFolder = true); // add-on iteration - void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *); + void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, + bool primary, void *), void *, BObjectList &); BPopUpMenu *ContextMenu(); @@ -233,6 +234,7 @@ class BContainerWindow : public BWindow { virtual void SetUpDiskMenu(BMenu *); virtual void BuildAddOnMenu(BMenu *); + void BuildMimeTypeList(BObjectList& mimeTypes); enum UpdateMenuContext { kMenuBarContext, @@ -249,7 +251,7 @@ class BContainerWindow : public BWindow { const char *); bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *), - BObjectList *, void *); + BObjectList *, void *, BObjectList &); void LoadAddOn(BMessage *); BPopUpMenu *fFileContextMenu; diff --git a/src/kits/tracker/DeskWindow.cpp b/src/kits/tracker/DeskWindow.cpp index fa16d62c56..bddc16471c 100644 --- a/src/kits/tracker/DeskWindow.cpp +++ b/src/kits/tracker/DeskWindow.cpp @@ -204,7 +204,11 @@ BDeskWindow::MenusBeginning() AddOneShortcutParams params; params.window = this; params.currentAddonShortcuts = &fCurrentAddonShortcuts; - EachAddon(&AddOneShortcut, ¶ms); + + BObjectList mimeTypes(10, true); + BuildMimeTypeList(mimeTypes); + + EachAddon(&AddOneShortcut, ¶ms, mimeTypes); } }