Tracker & Deskbar: Use BStringList instead of BObjectList<BString>.

It's more efficient, and conveys ownership semantics more clearly.

Change-Id: Ia42b018faaa7c8c7347020afbf1be9dfafe0fed8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8913
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-02-06 00:06:32 +00:00
committed by waddlesplash
parent 49d3b2a142
commit 3e245f7b20
8 changed files with 82 additions and 103 deletions
+9 -9
View File
@@ -75,9 +75,9 @@ struct TrackingHookData {
class BNavMenu : public BSlowMenu {
public:
BNavMenu(const char* title, uint32 message, const BHandler*,
BWindow* parentWindow = NULL, const BObjectList<BString>* list = NULL);
BWindow* parentWindow = NULL, const BStringList* list = NULL);
BNavMenu(const char* title, uint32 message, const BMessenger&,
BWindow* parentWindow = NULL, const BObjectList<BString>* list = NULL);
BWindow* parentWindow = NULL, const BStringList* list = NULL);
// parentWindow, if specified, will be closed if nav menu item invoked
// with option held down
@@ -95,8 +95,8 @@ public:
void SetTarget(const BMessenger&);
BMessenger Target();
void SetTypesList(const BObjectList<BString>* list);
const BObjectList<BString>* TypesList() const;
void SetTypesList(const BStringList* list);
const BStringList* TypesList() const;
void AddNavDir(const Model* model, uint32 what, BHandler* target,
bool populateSubmenu);
@@ -113,7 +113,7 @@ public:
static ModelMenuItem* NewModelItem(Model*, const BMessage*,
const BMessenger&, bool suppressFolderHierarchy = false,
BContainerWindow* = NULL, const BObjectList<BString>* typeslist = NULL,
BContainerWindow* = NULL, const BStringList* typeslist = NULL,
TrackingHookData* hook = NULL);
TrackingHookData* InitTrackingHook(bool (*hookfunction)(BMenu*, void*),
@@ -143,7 +143,7 @@ protected:
EntryListBase* fContainer;
bool fIteratingDesktop;
BObjectList<BString>* fTypesList;
BStringList* fTypesList;
TrackingHookData fTrackingHook;
};
@@ -180,11 +180,11 @@ private:
_IMPEXP_TRACKER bool SpringLoadedFolderCompareMessages(const BMessage *incoming,
const BMessage *dragmessage);
_IMPEXP_TRACKER void SpringLoadedFolderSetMenuStates(const BMenu *menu,
const BObjectList<BString> *typeslist);
const BStringList *typeslist);
_IMPEXP_TRACKER void SpringLoadedFolderAddUniqueTypeToList(entry_ref *ref,
BObjectList<BString> *typeslist);
BStringList *typeslist);
_IMPEXP_TRACKER void SpringLoadedFolderCacheDragData(const BMessage *incoming,
BMessage **, BObjectList<BString> **typeslist);
BMessage **, BStringList **typeslist);
} // namespace BPrivate
+4 -3
View File
@@ -46,6 +46,7 @@ All rights reserved.
#include <Roster.h>
#include <Screen.h>
#include <String.h>
#include <StringList.h>
#include "icons.h"
#include "BarApp.h"
@@ -1019,7 +1020,7 @@ TBarView::AppCanHandleTypes(const char* signature)
}
if (!signature || strlen(signature) == 0
|| !fCachedTypesList || fCachedTypesList->CountItems() == 0)
|| !fCachedTypesList || fCachedTypesList->CountStrings() == 0)
return false;
if (strcasecmp(signature, kTrackerSignature) == 0) {
@@ -1042,9 +1043,9 @@ TBarView::AppCanHandleTypes(const char* signature)
// supports anything in the list
// only one item needs to match in the list of refs
int32 count = fCachedTypesList->CountItems();
int32 count = fCachedTypesList->CountStrings();
for (int32 i = 0 ; i < count ; i++) {
if (fileinfo.IsSupportedType(fCachedTypesList->ItemAt(i)->String()))
if (fileinfo.IsSupportedType(fCachedTypesList->StringAt(i).String()))
return true;
}
+3 -3
View File
@@ -126,7 +126,7 @@ public:
TrackingHookData* GetTrackingHookData();
bool Dragging() const;
const BMessage* DragMessage() const;
BObjectList<BString>* CachedTypesList() const;
BStringList* CachedTypesList() const;
bool AppCanHandleTypes(const char* signature);
void SetDragOverride(bool);
bool DragOverride();
@@ -209,7 +209,7 @@ private:
bigtime_t fPulseRate;
bool fRefsRcvdOnly;
BMessage* fDragMessage;
BObjectList<BString>* fCachedTypesList;
BStringList* fCachedTypesList;
TrackingHookData fTrackingHookData;
uint32 fMaxRecentDocs;
@@ -250,7 +250,7 @@ TBarView::DragMessage() const
}
inline BObjectList<BString>*
inline BStringList*
TBarView::CachedTypesList() const
{
return fCachedTypesList;
+14 -14
View File
@@ -134,7 +134,7 @@ SpringLoadedFolderCompareMessages(const BMessage* incoming,
void
SpringLoadedFolderSetMenuStates(const BMenu* menu,
const BObjectList<BString>* typeslist)
const BStringList* typeslist)
{
if (menu == NULL || typeslist == NULL || typeslist->IsEmpty())
return;
@@ -183,7 +183,7 @@ SpringLoadedFolderSetMenuStates(const BMenu* menu,
void
SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref,
BObjectList<BString>* typeslist)
BStringList* typeslist)
{
if (ref == NULL || typeslist == NULL)
return;
@@ -212,23 +212,23 @@ SpringLoadedFolderAddUniqueTypeToList(entry_ref* ref,
}
// scan the current list, don't add dups
bool isUnique = true;
int32 count = typeslist->CountItems();
int32 count = typeslist->CountStrings();
for (int32 index = 0 ; index < count ; index++) {
if (typeslist->ItemAt(index)->Compare(mimestr) == 0) {
if (typeslist->StringAt(index).Compare(mimestr) == 0) {
isUnique = false;
break;
}
}
if (isUnique)
typeslist->AddItem(new BString(mimestr));
typeslist->Add(mimestr);
}
}
void
SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
BObjectList<BString>** typeslist)
BStringList** typeslist)
{
if (incoming == NULL)
return;
@@ -237,7 +237,7 @@ SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
delete* typeslist;
BMessage* localMessage = new BMessage(*incoming);
BObjectList<BString>* localTypesList = new BObjectList<BString>(10, true);
BStringList* localTypesList = new BStringList(10);
for (int32 index = 0; incoming->HasRef("refs", index); index++) {
entry_ref ref;
@@ -262,7 +262,7 @@ SpringLoadedFolderCacheDragData(const BMessage* incoming, BMessage** message,
BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
BWindow* parentWindow, const BObjectList<BString>* list)
BWindow* parentWindow, const BStringList* list)
:
BSlowMenu(title),
fMessage(message),
@@ -272,7 +272,7 @@ BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
fItemList(NULL),
fContainer(NULL),
fIteratingDesktop(false),
fTypesList(new BObjectList<BString>(10, true))
fTypesList(new BStringList(10))
{
if (list != NULL)
*fTypesList = *list;
@@ -295,7 +295,7 @@ BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target,
BNavMenu::BNavMenu(const char* title, uint32 message,
const BMessenger& messenger, BWindow* parentWindow,
const BObjectList<BString>* list)
const BStringList* list)
:
BSlowMenu(title),
fMessage(message),
@@ -305,7 +305,7 @@ BNavMenu::BNavMenu(const char* title, uint32 message,
fItemList(NULL),
fContainer(NULL),
fIteratingDesktop(false),
fTypesList(new BObjectList<BString>(10, true))
fTypesList(new BStringList(10))
{
if (list != NULL)
*fTypesList = *list;
@@ -582,7 +582,7 @@ BNavMenu::AddOneItem(Model* model)
ModelMenuItem*
BNavMenu::NewModelItem(Model* model, const BMessage* invokeMessage,
const BMessenger& target, bool suppressFolderHierarchy,
BContainerWindow* parentWindow, const BObjectList<BString>* typeslist,
BContainerWindow* parentWindow, const BStringList* typeslist,
TrackingHookData* hook)
{
if (model->InitCheck() != B_OK)
@@ -844,7 +844,7 @@ BNavMenu::SetShowParent(bool show)
void
BNavMenu::SetTypesList(const BObjectList<BString>* list)
BNavMenu::SetTypesList(const BStringList* list)
{
if (list != NULL)
*fTypesList = *list;
@@ -853,7 +853,7 @@ BNavMenu::SetTypesList(const BObjectList<BString>* list)
}
const BObjectList<BString>*
const BStringList*
BNavMenu::TypesList() const
{
return fTypesList;
+17 -27
View File
@@ -184,20 +184,10 @@ OpenWithContainerWindow::OpenWithSelection()
}
static const BString*
FindOne(const BString* element, void* castToString)
{
if (strcasecmp(element->String(), (const char*)castToString) == 0)
return element;
return 0;
}
static const entry_ref*
AddOneUniqueDocumentType(const entry_ref* ref, void* castToList)
{
BObjectList<BString>* list = (BObjectList<BString>*)castToList;
BStringList* list = (BStringList*)castToList;
BEntry entry(ref, true);
// traverse symlinks
@@ -212,24 +202,24 @@ AddOneUniqueDocumentType(const entry_ref* ref, void* castToList)
if (info.GetType(type) != B_OK)
return 0;
if (list->EachElement(FindOne, &type))
if (list->HasString(type, true))
// type already in list, bail
return 0;
// add type to list
list->AddItem(new BString(type));
list->Add(type);
return 0;
}
static const BString*
SetDefaultAppForOneType(const BString* element, void* castToEntryRef)
static bool
SetDefaultAppForOneType(const BString& element, void* castToEntryRef)
{
const entry_ref* appRef = (const entry_ref*)castToEntryRef;
// set entry as default handler for one mime string
BMimeType mime(element->String());
BMimeType mime(element.String());
if (!mime.IsInstalled())
return 0;
@@ -279,12 +269,12 @@ OpenWithContainerWindow::MakeDefaultAndOpen()
return;
// collect all the types of all the opened documents into a list
BObjectList<BString> openedFileTypes(10, true);
BStringList openedFileTypes(10);
EachEntryRef(EntryList(), AddOneUniqueDocumentType, &openedFileTypes, 100);
// set the default application to be the selected pose for all the
// mime types in the list
openedFileTypes.EachElement(SetDefaultAppForOneType,
openedFileTypes.DoForEach(SetDefaultAppForOneType,
(void*)selectedAppPose->TargetModel()->EntryRef());
// done setting the default application, now launch the app with the
@@ -1371,7 +1361,7 @@ OpenWithMenu::ClearMenuBuildingState()
SearchForSignatureEntryList::SearchForSignatureEntryList(bool canAddAllApps)
:
fIteratorList(NULL),
fSignatures(20, true),
fSignatures(20),
fPreferredAppCount(0),
fPreferredAppForFileCount(0),
fGenericFilesOnly(true),
@@ -1391,10 +1381,10 @@ void
SearchForSignatureEntryList::PushUniqueSignature(const char* str)
{
// do a unique add
if (fSignatures.EachElement(FindOne, (void*)str))
if (fSignatures.HasString(str, true))
return;
fSignatures.AddItem(new BString(str));
fSignatures.Add(str);
}
@@ -1426,17 +1416,17 @@ struct AddOneTermParams {
};
static const BString*
AddOnePredicateTerm(const BString* item, void* castToParams)
static bool
AddOnePredicateTerm(const BString& item, void* castToParams)
{
AddOneTermParams* params = (AddOneTermParams*)castToParams;
if (!params->first)
(*params->result) << " || ";
(*params->result) << kAttrAppSignature << " = " << item->String();
(*params->result) << kAttrAppSignature << " = " << item.String();
params->first = false;
return 0;
return false;
}
@@ -1446,7 +1436,7 @@ SearchForSignatureEntryList::Rewind()
if (fIteratorList)
return fIteratorList->Rewind();
if (!fSignatures.CountItems())
if (!fSignatures.CountStrings())
return ENOENT;
// build up the iterator
@@ -1462,7 +1452,7 @@ SearchForSignatureEntryList::Rewind()
params.result = &predicateString;
params.first = true;
fSignatures.EachElement(AddOnePredicateTerm, &params);
fSignatures.DoForEach(AddOnePredicateTerm, &params);
ASSERT(predicateString.Length());
// PRINT(("query predicate %s\n", predicateString.String()));
+1 -1
View File
@@ -124,7 +124,7 @@ private:
// Open With window
CachedEntryIteratorList* fIteratorList;
BObjectList<BString> fSignatures;
BStringList fSignatures;
entry_ref fPreferredRef;
int32 fPreferredAppCount;
+30 -42
View File
@@ -234,7 +234,7 @@ BPoseView::BPoseView(Model* model, uint32 viewMode)
fFilteredPoseList(new PoseList()),
fVSPoseList(new PoseList()),
fSelectionList(new PoseList()),
fMimeTypesInSelectionCache(20, true),
fMimeTypesInSelectionCache(20),
fZombieList(new BObjectList<Model>(10, true)),
fColumnList(new BObjectList<BColumn>(4, true)),
fMimeTypeList(new BObjectList<BString>(10, true)),
@@ -271,7 +271,7 @@ BPoseView::BPoseView(Model* model, uint32 viewMode)
fHasPosesInClipboard(false),
fCursorCheck(false),
fTypeAheadFiltering(false),
fFilterStrings(4, true),
fFilterStrings(4),
fLastFilterStringCount(1),
fLastFilterStringLength(0),
fLastKeyTime(0),
@@ -299,7 +299,6 @@ BPoseView::~BPoseView()
delete fVSPoseList;
delete fColumnList;
delete fSelectionList;
delete fMimeTypeList;
delete fZombieList;
delete fViewState;
delete fModel;
@@ -2057,7 +2056,7 @@ BPoseView::MimeTypeAt(int32 index)
if (fMimeTypeListIsDirty)
RefreshMimeTypeList();
return fMimeTypeList->ItemAt(index)->String();
return fMimeTypeList.StringAt(index).String();
}
@@ -2067,27 +2066,27 @@ BPoseView::CountMimeTypes()
if (fMimeTypeListIsDirty)
RefreshMimeTypeList();
return fMimeTypeList->CountItems();
return fMimeTypeList.CountStrings();
}
void
BPoseView::AddMimeType(const char* mimeType)
{
int32 count = fMimeTypeList->CountItems();
int32 count = fMimeTypeList.CountStrings();
for (int32 index = 0; index < count; index++) {
if (*fMimeTypeList->ItemAt(index) == mimeType)
if (fMimeTypeList.StringAt(index) == mimeType)
return;
}
fMimeTypeList->AddItem(new BString(mimeType));
fMimeTypeList.Add(mimeType);
}
void
BPoseView::RefreshMimeTypeList()
{
fMimeTypeList->MakeEmpty();
fMimeTypeList.MakeEmpty();
fMimeTypeListIsDirty = false;
for (int32 index = 0;; index++) {
@@ -4116,13 +4115,6 @@ BPoseView::EachItemInDraggedSelection(const BMessage* message,
}
static bool
ContainsOne(BString* string, const char* matchString)
{
return strcmp(string->String(), matchString) == 0;
}
bool
BPoseView::FindDragNDropAction(const BMessage* dragMessage, bool &canCopy,
bool &canMove, bool &canLink, bool &canErase)
@@ -4250,7 +4242,7 @@ BPoseView::CanHandleDragSelection(const Model* target,
if (!lock)
return false;
BObjectList<BString>* mimeTypeList
BStringList* mimeTypeList
= srcWindow->PoseView()->MimeTypesInSelection();
if (mimeTypeList->IsEmpty()) {
PoseList* selectionList = srcWindow->PoseView()->SelectionList();
@@ -4275,11 +4267,8 @@ BPoseView::CanHandleDragSelection(const Model* target,
mime.GetType(mimeType);
// add unique type string
if (!WhileEachListItem(mimeTypeList, ContainsOne,
(const char*)mimeType)) {
BString* newMimeString = new BString(mimeType);
mimeTypeList->AddItem(newMimeString);
}
if (!mimeTypeList->HasString(mimeType))
mimeTypeList->Add(mimeType);
}
}
}
@@ -4340,14 +4329,14 @@ BPoseView::CreateClippingFile(BPoseView* poseView, BFile &result,
static int32
RunMimeTypeDestinationMenu(const char* actionText,
const BObjectList<BString>* types,
const BObjectList<BString>* specificItems, BPoint where)
const BStringList* types,
const BStringList* specificItems, BPoint where)
{
int32 count;
if (types != NULL)
count = types->CountItems();
count = types->CountStrings();
else
count = specificItems->CountItems();
count = specificItems->CountStrings();
if (count == 0)
return 0;
@@ -4357,8 +4346,7 @@ RunMimeTypeDestinationMenu(const char* actionText,
for (int32 index = 0; index < count; index++) {
const char* embedTypeAs = NULL;
char buffer[256];
if (types) {
types->ItemAt(index)->String();
if (types != NULL) {
BMimeType mimeType(embedTypeAs);
if (mimeType.GetShortDescription(buffer) == B_OK)
@@ -4366,8 +4354,8 @@ RunMimeTypeDestinationMenu(const char* actionText,
}
BString description;
if (specificItems->ItemAt(index)->Length()) {
description << (const BString &)(*specificItems->ItemAt(index));
if (specificItems->StringAt(index).Length()) {
description << specificItems->StringAt(index);
if (embedTypeAs)
description << " (" << embedTypeAs << ")";
@@ -4504,7 +4492,7 @@ BPoseView::HandleDropCommon(BMessage* message, Model* targetModel,
// handle the promise style drag&drop
// fish for specification of specialized menu items
BObjectList<BString> actionSpecifiers(10, true);
BStringList actionSpecifiers(10);
for (int32 index = 0; ; index++) {
const char* string;
if (message->FindString("be:actionspecifier", index,
@@ -4513,12 +4501,12 @@ BPoseView::HandleDropCommon(BMessage* message, Model* targetModel,
}
ASSERT(string != NULL);
actionSpecifiers.AddItem(new BString(string));
actionSpecifiers.Add(string);
}
// build the list of types the drag originator offers
BObjectList<BString> types(10, true);
BObjectList<BString> typeNames(10, true);
BStringList types(10);
BStringList typeNames(10);
for (int32 index = 0; ; index++) {
const char* string;
if (message->FindString("be:filetypes", index, &string)
@@ -4527,12 +4515,12 @@ BPoseView::HandleDropCommon(BMessage* message, Model* targetModel,
}
ASSERT(string != NULL);
types.AddItem(new BString(string));
types.Add(string);
const char* typeName = "";
message->FindString("be:type_descriptions", index,
&typeName);
typeNames.AddItem(new BString(typeName));
typeNames.Add(typeName);
}
int32 specificTypeIndex = -1;
@@ -4541,14 +4529,14 @@ BPoseView::HandleDropCommon(BMessage* message, Model* targetModel,
// if control down, run a popup menu
if (canCopy
&& SecondaryMouseButtonDown(modifiers(), buttons)) {
if (actionSpecifiers.CountItems() > 0) {
if (actionSpecifiers.CountStrings() > 0) {
specificActionIndex = RunMimeTypeDestinationMenu(NULL,
NULL, &actionSpecifiers,
view->ConvertToScreen(dropPoint));
if (specificActionIndex == -1)
return false;
} else if (types.CountItems() > 0) {
} else if (types.CountStrings() > 0) {
specificTypeIndex = RunMimeTypeDestinationMenu(
B_TRANSLATE("Create %s clipping"),
&types, &typeNames,
@@ -4576,18 +4564,18 @@ BPoseView::HandleDropCommon(BMessage* message, Model* targetModel,
if (specificTypeIndex != -1) {
// we had the user pick a specific type from a menu, use it
reply.AddString("be:filetypes",
types.ItemAt(specificTypeIndex)->String());
types.StringAt(specificTypeIndex).String());
if (typeNames.ItemAt(specificTypeIndex)->Length()) {
if (typeNames.StringAt(specificTypeIndex).Length()) {
reply.AddString("be:type_descriptions",
typeNames.ItemAt(specificTypeIndex)->String());
typeNames.StringAt(specificTypeIndex).String());
}
}
if (specificActionIndex != -1) {
// we had the user pick a specific type from a menu, use it
reply.AddString("be:actionspecifier",
actionSpecifiers.ItemAt(specificActionIndex)->String());
actionSpecifiers.StringAt(specificActionIndex).String());
}
reply.AddRef("directory", targetModel->EntryRef());
+4 -4
View File
@@ -314,7 +314,7 @@ public:
void SetSelectionHandler(BLooper* looper);
BObjectList<BString>*MimeTypesInSelection();
BStringList* MimeTypesInSelection();
// pose selection
void SelectPose(BPose*, int32 index, bool scrollIntoView = true);
@@ -746,11 +746,11 @@ private:
PoseList* fVSPoseList;
PoseList* fSelectionList;
HashSet<node_ref_key> fInsertedNodes;
BObjectList<BString> fMimeTypesInSelectionCache;
BStringList fMimeTypesInSelectionCache;
// used for mime string based icon highliting during a drag
BObjectList<Model>* fZombieList;
BObjectList<BColumn>* fColumnList;
BObjectList<BString>* fMimeTypeList;
BStringList fMimeTypeList;
BObjectList<Model>* fBrokenLinks;
bool fMimeTypeListIsDirty;
BCountView* fCountView;
@@ -937,7 +937,7 @@ BPoseView::CountSelected() const
return fSelectionList->CountItems();
}
inline BObjectList<BString>*
inline BStringList*
BPoseView::MimeTypesInSelection()
{
return &fMimeTypesInSelectionCache;