From d57510c0ff71136ec888ad34abeefad21c3a98e7 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 25 Aug 2023 12:42:19 -0400 Subject: [PATCH] Tracker: Reduce differences between NavMenu and SlowContextPopup. No functional change intended. Change-Id: Iaa9b821462ec97b74de538aa2c489762bf413311 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6872 Reviewed-by: waddlesplash Tested-by: Commit checker robot --- src/kits/tracker/NavMenu.cpp | 14 +++---- src/kits/tracker/SlowContextPopup.cpp | 56 +++++++++++++-------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/kits/tracker/NavMenu.cpp b/src/kits/tracker/NavMenu.cpp index afdc3c32ac..959125b518 100644 --- a/src/kits/tracker/NavMenu.cpp +++ b/src/kits/tracker/NavMenu.cpp @@ -392,9 +392,7 @@ BNavMenu::ClearMenuBuildingState() // item list is non-owning, need to delete the items because // they didn't get added to the menu if (fItemList != NULL) { - int32 count = fItemList->CountItems(); - for (int32 index = count - 1; index >= 0; index--) - delete RemoveItem(index); + RemoveItems(0, fItemList->CountItems(), true); delete fItemList; fItemList = NULL; @@ -429,14 +427,14 @@ BNavMenu::StartBuildingItemList() if (startModel.InitCheck() != B_OK || !startModel.IsContainer()) return false; - if (startModel.IsQuery()) + if (startModel.IsQuery()) { fContainer = new QueryEntryListCollection(&startModel); - else if (startModel.IsVirtualDirectory()) + } else if (startModel.IsVirtualDirectory()) { fContainer = new VirtualDirectoryEntryList(&startModel); - else if (startModel.IsDesktop()) { + } else if (startModel.IsDesktop()) { fIteratingDesktop = true; - fContainer = DesktopPoseView::InitDesktopDirentIterator( - 0, startModel.EntryRef()); + fContainer = DesktopPoseView::InitDesktopDirentIterator(0, + startModel.EntryRef()); AddRootItemsIfNeeded(); AddTrashItem(); } else if (startModel.IsTrash()) { diff --git a/src/kits/tracker/SlowContextPopup.cpp b/src/kits/tracker/SlowContextPopup.cpp index 8876a97330..bd73972a3f 100644 --- a/src/kits/tracker/SlowContextPopup.cpp +++ b/src/kits/tracker/SlowContextPopup.cpp @@ -126,6 +126,7 @@ BSlowContextMenu::DetachedFromWindow() { // see note above in AttachedToWindow fIsShowing = false; + // does this need to set this to null? // the parent, handling dnd should set this // appropriately @@ -236,11 +237,12 @@ BSlowContextMenu::StartBuildingItemList() return false; } + fItemList = new BObjectList(50); + fIteratingDesktop = false; BDirectory parent; status_t err = entry.GetParent(&parent); - fItemList = new BObjectList(50); // if ref is the root item then build list of volume root dirs fVolsOnly = (err == B_ENTRY_NOT_FOUND); @@ -249,36 +251,34 @@ BSlowContextMenu::StartBuildingItemList() return true; Model startModel(&entry, true); - if (startModel.InitCheck() == B_OK) { - if (!startModel.IsContainer()) - return false; + if (startModel.InitCheck() != B_OK || !startModel.IsContainer()) + return false; - if (startModel.IsQuery()) - fContainer = new QueryEntryListCollection(&startModel); - else if (startModel.IsVirtualDirectory()) - fContainer = new VirtualDirectoryEntryList(&startModel); - else if (startModel.IsDesktop()) { - fIteratingDesktop = true; - fContainer = DesktopPoseView::InitDesktopDirentIterator(0, - startModel.EntryRef()); - AddRootItemsIfNeeded(); - AddTrashItem(); - } else { - BDirectory* directory = dynamic_cast( - startModel.Node()); + if (startModel.IsQuery()) { + fContainer = new QueryEntryListCollection(&startModel); + } else if (startModel.IsVirtualDirectory()) { + fContainer = new VirtualDirectoryEntryList(&startModel); + } else if (startModel.IsDesktop()) { + fIteratingDesktop = true; + fContainer = DesktopPoseView::InitDesktopDirentIterator(0, + startModel.EntryRef()); + AddRootItemsIfNeeded(); + AddTrashItem(); + } else { + BDirectory* directory = dynamic_cast( + startModel.Node()); - ASSERT(directory != NULL); + ASSERT(directory != NULL); - if (directory != NULL) - fContainer = new DirectoryEntryList(*directory); - } - - if (fContainer->InitCheck() != B_OK) - return false; - - fContainer->Rewind(); + if (directory != NULL) + fContainer = new DirectoryEntryList(*directory); } + if (fContainer->InitCheck() != B_OK) + return false; + + fContainer->Rewind(); + return true; } @@ -290,13 +290,13 @@ BSlowContextMenu::AddRootItemsIfNeeded() roster.Rewind(); BVolume volume; while (roster.GetNextVolume(&volume) == B_OK) { - BDirectory root; BEntry entry; if (!volume.IsPersistent() || volume.GetRootDirectory(&root) != B_OK - || root.GetEntry(&entry) != B_OK) + || root.GetEntry(&entry) != B_OK) { continue; + } Model model(&entry); AddOneItem(&model);