From e32d782cb46130f314d737d96d5bb3ddaf5b1c87 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Tue, 15 Jul 2025 09:53:56 -0400 Subject: [PATCH] Tracker: Allow draggable container icon on Root, Trash and Printers Use new DraggableContainerIcon name when invalidating icon. Create a ShouldHaveDraggableFolderIcon() method on BContainerWindow to consolidate the gating logic to a method. We alert if you try and copy, move or create link to any of these directories, however you may drag the icon in some instances such as to change the directory in a file panel or to open the directory up in FileTypes. You may create a link to the printers directory. Set the Printer icon on the printers directory. Fixes #3385 Tracker: Disks menu in CountView * Open Disks directory on click. * Skip volumes with no capacity (e.g. system, config) from Root and Desktop menus (still shown in Home and volumes though). * No Trash on volumes, add only to Desktop. * Declare some variables outside loop. * Rename originatingWindow to source. Fixes #3549 Change-Id: I66318d2485a5a8405f5459c355a467f34e19ecc5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9499 Reviewed-by: John Scipione Tested-by: Commit checker robot --- headers/private/tracker/DirMenu.h | 4 +- src/kits/tracker/ContainerWindow.cpp | 38 +++++----- src/kits/tracker/ContainerWindow.h | 4 + src/kits/tracker/CountView.cpp | 46 ++++++------ src/kits/tracker/DeskWindow.h | 2 + src/kits/tracker/DirMenu.cpp | 43 +++++------ src/kits/tracker/DraggableContainerIcon.cpp | 3 +- src/kits/tracker/FSUtils.cpp | 48 ++++++++---- src/kits/tracker/FilePanelPriv.h | 2 + src/kits/tracker/IconCache.cpp | 25 +++++++ src/kits/tracker/IconCache.h | 5 ++ src/kits/tracker/NavMenu.cpp | 83 +++++++++------------ src/kits/tracker/OpenWithWindow.h | 2 + src/kits/tracker/PoseView.cpp | 6 +- 14 files changed, 181 insertions(+), 130 deletions(-) diff --git a/headers/private/tracker/DirMenu.h b/headers/private/tracker/DirMenu.h index e054ade9ad..2b84e6e815 100644 --- a/headers/private/tracker/DirMenu.h +++ b/headers/private/tracker/DirMenu.h @@ -49,11 +49,11 @@ public: const char* entryName = 0); virtual ~BDirMenu(); - void Populate(const BEntry* startDir, BWindow* originatingWindow, + void Populate(const BEntry* startDir, BWindow* source, bool includeStartDir = false, bool select = false, bool reverse = false, bool addShortcuts = false, bool navMenuEntries = false); - void AddItemToDirMenu(const BEntry*, BWindow* originatingWindow, + void AddItemToDirMenu(const BEntry*, BWindow* source, bool atEnd, bool addShortcuts, bool navMenuEntries = false); void AddDisksIconToMenu(bool reverse = false); diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index 8b322d14cd..17c1ae716f 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -761,7 +761,7 @@ BContainerWindow::Init(const BMessage* message) fMenuContainer->GroupLayout()->AddView(fMenuBar); AddMenus(); - if (!TargetModel()->IsRoot() && !TargetModel()->IsTrash()) + if (ShouldHaveDraggableFolderIcon()) _AddFolderIcon(); } else { // add equivalents of the menu shortcuts to the menuless @@ -997,23 +997,20 @@ BContainerWindow::SwitchDirectory(const entry_ref* ref) SetSingleWindowBrowseShortcuts(settings.SingleWindowBrowse()); // Update draggable folder icon - if (fMenuBar != NULL) { - if (!TargetModel()->IsRoot() && !TargetModel()->IsTrash()) { - // Folder icon should be visible, but in single - // window navigation, it might not be. - if (fDraggableIcon != NULL) { - IconCache::sIconCache->IconChanged(TargetModel()); - if (fDraggableIcon->IsHidden()) - fDraggableIcon->Show(); - fDraggableIcon->Invalidate(); - } else { - // draggable icon visible - _AddFolderIcon(); - } - } else if (fDraggableIcon != NULL) { - // hide for Root or Trash - fDraggableIcon->Hide(); + if (ShouldHaveDraggableFolderIcon()) { + // Folder icon should be visible, but in single + // window navigation, it might not be. + if (fDraggableIcon != NULL) { + IconCache::sIconCache->IconChanged(TargetModel()); + if (fDraggableIcon->IsHidden()) + fDraggableIcon->Show(); + fDraggableIcon->Invalidate(); + } else { + // draggable icon visible + _AddFolderIcon(); } + } else if (fMenuBar != NULL && fDraggableIcon != NULL) { + fDraggableIcon->Hide(); } UpdateTitle(); @@ -3153,6 +3150,13 @@ BContainerWindow::ShouldHaveAddOnMenus() } +bool +BContainerWindow::ShouldHaveDraggableFolderIcon() +{ + return fMenuBar != NULL; +} + + // #pragma mark - BContainerWindow private methods diff --git a/src/kits/tracker/ContainerWindow.h b/src/kits/tracker/ContainerWindow.h index ab1136258d..5218e7618f 100644 --- a/src/kits/tracker/ContainerWindow.h +++ b/src/kits/tracker/ContainerWindow.h @@ -301,6 +301,10 @@ protected: bool ShouldHaveNewFolderItem(); bool ShouldHaveAddOnMenus(); +public: + virtual bool ShouldHaveDraggableFolderIcon(); + +protected: BGroupLayout* fRootLayout; BGroupView* fMenuContainer; BGridView* fPoseContainer; diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp index 7927c039dd..d3bce534c5 100644 --- a/src/kits/tracker/CountView.cpp +++ b/src/kits/tracker/CountView.cpp @@ -74,8 +74,13 @@ BCountView::BCountView(BPoseView* view) fTypeAheadString(""), fFilterString("") { - GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, - R_BarberPoleBitmap, &fBarberPoleMap); + GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, R_BarberPoleBitmap, &fBarberPoleMap); + + SetFont(be_plain_font); + SetFontSize(std::max(kMinFontSize, ceilf(be_plain_font->Size() * 0.75f))); + + SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + SetLowUIColor(ViewUIColor()); } @@ -291,35 +296,28 @@ BCountView::MouseDown(BPoint) if (fPoseView->IsFilePanel() || fPoseView->TargetModel() == NULL) return; - if (!window->TargetModel()->IsRoot()) { - BDirMenu* menu = new BDirMenu(NULL, be_app, B_REFS_RECEIVED); - BEntry entry; - if (entry.SetTo(window->TargetModel()->EntryRef()) == B_OK) - menu->Populate(&entry, Window(), false, false, true, false, true); - else - menu->Populate(NULL, Window(), false, false, true, false, true); + if (window->TargetModel()->IsRoot()) + return; - BPoint point = Bounds().LeftBottom(); - point.y += 3; - ConvertToScreen(&point); - BRect clickToOpenRect(Bounds()); - ConvertToScreen(&clickToOpenRect); - menu->Go(point, true, true, clickToOpenRect); - delete menu; - } + BDirMenu menu(NULL, be_app, B_REFS_RECEIVED); + BEntry entry; + if (entry.SetTo(window->TargetModel()->EntryRef()) == B_OK) + menu.Populate(&entry, Window(), false, false, true, false, true); + else + menu.Populate(NULL, Window(), false, false, true, false, true); + + BPoint point = Bounds().LeftBottom(); + point.y += 3; + ConvertToScreen(&point); + BRect clickToOpenRect(Bounds()); + ConvertToScreen(&clickToOpenRect); + menu.Go(point, true, true, clickToOpenRect); } void BCountView::AttachedToWindow() { - SetFont(be_plain_font); - SetFontSize(std::max(kMinFontSize, - ceilf(be_plain_font->Size() * 0.75f))); - - SetViewUIColor(B_PANEL_BACKGROUND_COLOR); - SetLowUIColor(ViewUIColor()); - CheckCount(); } diff --git a/src/kits/tracker/DeskWindow.h b/src/kits/tracker/DeskWindow.h index dc63f34b0f..ebb5dd0946 100644 --- a/src/kits/tracker/DeskWindow.h +++ b/src/kits/tracker/DeskWindow.h @@ -70,6 +70,8 @@ public: void SaveDesktopPoseLocations(); + virtual bool ShouldHaveDraggableFolderIcon() { return false; }; + protected: virtual BPoseView* NewPoseView(Model*, uint32); diff --git a/src/kits/tracker/DirMenu.cpp b/src/kits/tracker/DirMenu.cpp index c91cc633bf..ac4350765e 100644 --- a/src/kits/tracker/DirMenu.cpp +++ b/src/kits/tracker/DirMenu.cpp @@ -83,7 +83,7 @@ BDirMenu::~BDirMenu() void -BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, +BDirMenu::Populate(const BEntry* startEntry, BWindow* source, bool includeStartEntry, bool select, bool reverse, bool addShortcuts, bool navMenuEntries) { @@ -96,7 +96,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, ModelMenuItem* menu = NULL; - if (fMenuBar) { + if (fMenuBar != NULL) { menu = new ModelMenuItem(&model, this, true, true); fMenuBar->AddItem(menu); } @@ -115,8 +115,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, BDirectory parent; BDirectory dir(&entry); - if (!showDesktop && dir.InitCheck() == B_OK - && dir.IsRootDirectory()) { + if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" parent.SetTo("/"); @@ -143,8 +142,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, bool hitRoot = false; BDirectory dir(&entry); - if (!showDesktop && dir.InitCheck() == B_OK - && dir.IsRootDirectory()) { + if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) { // if we're at the root directory skip "mnt" and // go straight to "/" hitRoot = true; @@ -167,8 +165,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, if (result == kReadAttrFailed || !info.fInvisible || (showDesktop && desktopEntry == entry)) { - AddItemToDirMenu(&entry, originatingWindow, reverse, - addShortcuts, navMenuEntries); + AddItemToDirMenu(&entry, source, reverse, addShortcuts, navMenuEntries); } if (hitRoot) { @@ -186,8 +183,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, if (!select) return; - ModelMenuItem* item - = dynamic_cast(ItemAt(CountItems() - 1)); + ModelMenuItem* item = dynamic_cast(ItemAt(CountItems() - 1)); if (item != NULL) { item->SetMarked(true); if (menu) { @@ -207,7 +203,7 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* originatingWindow, void -BDirMenu::AddItemToDirMenu(const BEntry* entry, BWindow* originatingWindow, +BDirMenu::AddItemToDirMenu(const BEntry* entry, BWindow* source, bool atEnd, bool addShortcuts, bool navMenuEntries) { Model model(entry); @@ -219,16 +215,14 @@ BDirMenu::AddItemToDirMenu(const BEntry* entry, BWindow* originatingWindow, // add reference to the container windows model so that we can // close the window if - BContainerWindow* window = originatingWindow ? - dynamic_cast(originatingWindow) : 0; + BContainerWindow* window = dynamic_cast(source); if (window != NULL) { message->AddData("nodeRefsToClose", B_RAW_TYPE, - window->TargetModel()->NodeRef(), sizeof (node_ref)); + window->TargetModel()->NodeRef(), sizeof(node_ref)); } ModelMenuItem* item; if (navMenuEntries) { - BNavMenu* subMenu = new BNavMenu(model.Name(), B_REFS_RECEIVED, - fTarget, window); + BNavMenu* subMenu = new BNavMenu(model.Name(), fCommand, fTarget, source); entry_ref ref; entry->GetRef(&ref); subMenu->SetNavDir(&ref); @@ -254,8 +248,7 @@ BDirMenu::AddItemToDirMenu(const BEntry* entry, BWindow* originatingWindow, item->SetTarget(fTarget); if (fMenuBar != NULL) { - ModelMenuItem* menu - = dynamic_cast(fMenuBar->ItemAt(0)); + ModelMenuItem* menu = dynamic_cast(fMenuBar->ItemAt(0)); if (menu != NULL) { ThrowOnError(menu->SetEntry(entry)); item->SetMarked(true); @@ -272,13 +265,21 @@ BDirMenu::AddDisksIconToMenu(bool atEnd) if (model.InitCheck() != B_OK) return; + entry_ref ref; + entry.GetRef(&ref); BMessage* message = new BMessage(fCommand); - message->AddRef(fEntryName.String(), model.EntryRef()); + message->AddRef(fEntryName.String(), &ref); + + BNavMenu* subMenu = new BNavMenu(model.Name(), fCommand, fTarget); + subMenu->SetNavDir(&ref); + ModelMenuItem* item = new ModelMenuItem(&model, subMenu); + item->SetLabel(model.Name()); + item->SetMessage(message); - ModelMenuItem* item = new ModelMenuItem(&model, - B_TRANSLATE(B_DISKS_DIR_NAME), message); if (atEnd) AddItem(item); else AddItem(item, 0); + + item->SetTarget(fTarget); } diff --git a/src/kits/tracker/DraggableContainerIcon.cpp b/src/kits/tracker/DraggableContainerIcon.cpp index 7979b05faf..00887ada48 100644 --- a/src/kits/tracker/DraggableContainerIcon.cpp +++ b/src/kits/tracker/DraggableContainerIcon.cpp @@ -71,8 +71,7 @@ DraggableContainerIcon::MouseDown(BPoint where) if (window == NULL) return; - // we don't like the Trash icon (because it cannot be moved) - if (window->TargetModel()->IsTrash() || window->TargetModel()->IsPrintersDir()) + if (!window->ShouldHaveDraggableFolderIcon()) return; if (window->CurrentMessage() == NULL) diff --git a/src/kits/tracker/FSUtils.cpp b/src/kits/tracker/FSUtils.cpp index c099a86e86..34238413c2 100644 --- a/src/kits/tracker/FSUtils.cpp +++ b/src/kits/tracker/FSUtils.cpp @@ -624,7 +624,7 @@ ConfirmChangeIfWellKnownDirectory(const BEntry* entry, DestructiveAction action, if (confirmedAlready && *confirmedAlready == kConfirmedAll) return true; - if (FSIsDeskDir(entry) || FSIsTrashDir(entry) || FSIsRootDir(entry)) + if (FSIsDeskDir(entry) || FSIsPrintersDir(entry) || FSIsRootDir(entry) || FSIsTrashDir(entry)) return false; if ((!DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY) @@ -891,26 +891,44 @@ InitCopy(CopyLoopControl* loopControl, uint32 moveMode, BEntry entry((entry_ref*)srcList->ItemAt(index)); if (FSIsRootDir(&entry)) { BString errorStr; - if (moveMode == kCreateLink) { - errorStr.SetTo( - B_TRANSLATE("You cannot create a link to the root " - "directory.")); - } else { - errorStr.SetTo( - B_TRANSLATE("You cannot copy or move the root " - "directory.")); - } + if (moveMode == kCreateLink || moveMode == kCreateRelativeLink) + errorStr.SetTo(B_TRANSLATE("You cannot create a link to the root directory.")); + else + errorStr.SetTo(B_TRANSLATE("You cannot copy or move the root directory.")); - BAlert* alert = new BAlert("", errorStr.String(), - B_TRANSLATE("Cancel"), 0, 0, B_WIDTH_AS_USUAL, - B_WARNING_ALERT); + BAlert* alert = new BAlert("", errorStr.String(), B_TRANSLATE("Cancel"), 0, 0, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); + + return B_ERROR; + } else if (FSIsTrashDir(&entry)) { + BString errorStr; + if (moveMode == kCreateLink || moveMode == kCreateRelativeLink) + errorStr.SetTo(B_TRANSLATE("You cannot create a link to the Trash directory.")); + else + errorStr.SetTo(B_TRANSLATE("You cannot copy or move the Trash directory.")); + + BAlert* alert = new BAlert("", errorStr.String(), B_TRANSLATE("Cancel"), 0, 0, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); + alert->Go(); + + return B_ERROR; + } else if (FSIsPrintersDir(&entry) + && (moveMode == kCopySelectionTo || moveMode == kMoveSelectionTo)) { + BString errorStr(B_TRANSLATE("You cannot copy or move the Printers directory.")); + + BAlert* alert = new BAlert("", errorStr.String(), B_TRANSLATE("Cancel"), 0, 0, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); + alert->Go(); + return B_ERROR; } + if (moveMode == kMoveSelectionTo - && !ConfirmChangeIfWellKnownDirectory(&entry, kMove, - false, &askOnceOnly)) { + && !ConfirmChangeIfWellKnownDirectory(&entry, kMove, false, &askOnceOnly)) { return B_ERROR; } } diff --git a/src/kits/tracker/FilePanelPriv.h b/src/kits/tracker/FilePanelPriv.h index 5344fe016e..0a99f845a5 100644 --- a/src/kits/tracker/FilePanelPriv.h +++ b/src/kits/tracker/FilePanelPriv.h @@ -104,6 +104,8 @@ public: // a default state file the last time it ran. bool DefaultStateRestored() const { return fDefaultStateRestored; } + virtual bool ShouldHaveDraggableFolderIcon() { return false; }; + protected: BPoseView* NewPoseView(Model* model, uint32); virtual void Init(const BMessage* message = NULL); diff --git a/src/kits/tracker/IconCache.cpp b/src/kits/tracker/IconCache.cpp index b934cd1d60..187958d935 100644 --- a/src/kits/tracker/IconCache.cpp +++ b/src/kits/tracker/IconCache.cpp @@ -667,6 +667,22 @@ IconCache::GetRootIcon(AutoLock*, } +IconCacheEntry* +IconCache::GetPrinterIcon(AutoLock*, + AutoLock* sharedCacheLocker, + AutoLock** resultingOpenCache, + Model*, IconSource &source, IconDrawMode mode, + BSize size, LazyBitmapAllocator* lazyBitmap) +{ + *resultingOpenCache = sharedCacheLocker; + (*resultingOpenCache)->Lock(); + + source = kTrackerSupplied; + + return GetIconFromMetaMime(B_PRINTER_MIMETYPE, mode, size, lazyBitmap, 0); +} + + IconCacheEntry* IconCache::GetWellKnownIcon(AutoLock*, AutoLock* sharedCacheLocker, @@ -945,6 +961,10 @@ IconCache::Preload(AutoLock* nodeCacheLocker, &resultingOpenCache, model, source, mode, size, &lazyBitmap); } + } else if (model->IsPrintersDir()) { + entry = GetPrinterIcon(nodeCacheLocker, sharedCacheLocker, + &resultingOpenCache, model, source, mode, size, &lazyBitmap); + ASSERT(entry != NULL); } else { if (source == kUnknownSource) { // look for node icons first @@ -1001,6 +1021,11 @@ IconCache::Preload(AutoLock* nodeCacheLocker, &resultingOpenCache, model, source, mode, size, &lazyBitmap); break; + } else if (model->IsPrintersDir()) { + entry = GetPrinterIcon(nodeCacheLocker, sharedCacheLocker, + &resultingOpenCache, model, source, mode, size, + &lazyBitmap); + break; } else { entry = GetWellKnownIcon(nodeCacheLocker, sharedCacheLocker, &resultingOpenCache, model, diff --git a/src/kits/tracker/IconCache.h b/src/kits/tracker/IconCache.h index e088ae3675..adc8cb58a6 100644 --- a/src/kits/tracker/IconCache.h +++ b/src/kits/tracker/IconCache.h @@ -446,6 +446,11 @@ private: AutoLock** resultingLockedCache, Model*, IconSource&, IconDrawMode mode, BSize size, LazyBitmapAllocator*); + IconCacheEntry* GetPrinterIcon(AutoLock* nodeCache, + AutoLock* sharedCache, + AutoLock** resultingLockedCache, + Model*, IconSource&, IconDrawMode mode, + BSize size, LazyBitmapAllocator*); IconCacheEntry* GetWellKnownIcon(AutoLock *nodeCache, AutoLock* sharedCache, AutoLock** resultingLockedCache, diff --git a/src/kits/tracker/NavMenu.cpp b/src/kits/tracker/NavMenu.cpp index 00baf3131f..c053a3324c 100644 --- a/src/kits/tracker/NavMenu.cpp +++ b/src/kits/tracker/NavMenu.cpp @@ -280,11 +280,10 @@ BNavMenu::BNavMenu(const char* title, uint32 message, const BHandler* target, // add the parent window to the invocation message so that it // can be closed if option modifier held down during invocation - BContainerWindow* originatingWindow = - dynamic_cast(fParentWindow); - if (originatingWindow != NULL) { + BContainerWindow* source = dynamic_cast(fParentWindow); + if (source != NULL) { fMessage.AddData("nodeRefsToClose", B_RAW_TYPE, - originatingWindow->TargetModel()->NodeRef(), sizeof(node_ref)); + source->TargetModel()->NodeRef(), sizeof(node_ref)); } // too long to have triggers @@ -313,11 +312,10 @@ BNavMenu::BNavMenu(const char* title, uint32 message, // add the parent window to the invocation message so that it // can be closed if option modifier held down during invocation - BContainerWindow* originatingWindow = - dynamic_cast(fParentWindow); - if (originatingWindow != NULL) { + BContainerWindow* source = dynamic_cast(fParentWindow); + if (source != NULL) { fMessage.AddData("nodeRefsToClose", B_RAW_TYPE, - originatingWindow->TargetModel()->NodeRef(), sizeof (node_ref)); + source->TargetModel()->NodeRef(), sizeof(node_ref)); } // too long to have triggers @@ -417,9 +415,8 @@ BNavMenu::StartBuildingItemList() status_t status = entry.GetParent(&parent); // if ref is the root item then build list of volume root dirs - fFlags = uint8((fFlags & ~kVolumesOnly) - | (status == B_ENTRY_NOT_FOUND ? kVolumesOnly : 0)); - if (fFlags & kVolumesOnly) + fFlags = uint8((fFlags & ~kVolumesOnly) | (status == B_ENTRY_NOT_FOUND ? kVolumesOnly : 0)); + if ((fFlags & kVolumesOnly) != 0) return true; Model startModel(&entry, true); @@ -432,9 +429,9 @@ BNavMenu::StartBuildingItemList() fContainer = new VirtualDirectoryEntryList(&startModel); } else if (startModel.IsDesktop()) { fIteratingDesktop = true; - fContainer = DesktopPoseView::InitDesktopDirentIterator(0, - startModel.EntryRef()); - AddRootItemsIfNeeded(); + fContainer = DesktopPoseView::InitDesktopDirentIterator(0, startModel.EntryRef()); + if (TrackerSettings().MountVolumesOntoDesktop()) + AddRootItemsIfNeeded(); AddTrashItem(); } else if (startModel.IsTrash()) { // the trash window needs to display a union of all the @@ -445,26 +442,20 @@ BNavMenu::StartBuildingItemList() fContainer = new EntryIteratorList(); while (volRoster.GetNextVolume(&volume) == B_OK) { - if (volume.IsReadOnly() || !volume.IsPersistent()) + if (volume.IsReadOnly() || !volume.IsPersistent() || volume.Capacity() == 0) continue; BDirectory trashDir; - if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) { - EntryIteratorList* iteratorList - = dynamic_cast(fContainer); - + EntryIteratorList* iteratorList = dynamic_cast(fContainer); ASSERT(iteratorList != NULL); - if (iteratorList != NULL) iteratorList->AddItem(new DirectoryEntryList(trashDir)); } } } else { BDirectory* directory = dynamic_cast(startModel.Node()); - ASSERT(directory != NULL); - if (directory != NULL) fContainer = new DirectoryEntryList(*directory); } @@ -483,17 +474,19 @@ BNavMenu::AddRootItemsIfNeeded() { BVolumeRoster roster; roster.Rewind(); + BVolume volume; + BDirectory root; + BEntry entry; + Model model; + while (roster.GetNextVolume(&volume) == B_OK) { - BDirectory root; - BEntry entry; - if (!volume.IsPersistent() - || volume.GetRootDirectory(&root) != B_OK - || root.GetEntry(&entry) != B_OK) { + if (volume.InitCheck() != B_OK || !volume.IsPersistent() || volume.Capacity() == 0 + || volume.GetRootDirectory(&root) != B_OK || root.GetEntry(&entry) != B_OK) { continue; } - Model model(&entry); + model.SetTo(&entry); AddOneItem(&model); } } @@ -537,8 +530,11 @@ BNavMenu::AddNextItem() return true; } - QueryEntryListCollection* queryContainer - = dynamic_cast(fContainer); + // skip Trash + if (model.IsTrash()) + return true; + + QueryEntryListCollection* queryContainer = dynamic_cast(fContainer); if (queryContainer != NULL && !queryContainer->ShowResultsFromTrash() && FSInTrashDir(model.EntryRef())) { // query entry is in trash and shall not be shown @@ -547,18 +543,14 @@ BNavMenu::AddNextItem() ssize_t size = -1; PoseInfo poseInfo; - if (model.Node() != NULL) { - size = model.Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0, - &poseInfo, sizeof(poseInfo)); - } + if (model.Node() != NULL) + size = model.Node()->ReadAttr(kAttrPoseInfo, B_RAW_TYPE, 0, &poseInfo, sizeof(poseInfo)); model.CloseNode(); // item might be in invisible - if (size == sizeof(poseInfo) - && !BPoseView::PoseVisible(&model, &poseInfo)) { + if (size == sizeof(poseInfo) && !BPoseView::PoseVisible(&model, &poseInfo)) return true; - } AddOneItem(&model); @@ -676,16 +668,17 @@ void BNavMenu::BuildVolumeMenu() { BVolumeRoster roster; - BVolume volume; - roster.Rewind(); + + BVolume volume; + BDirectory startDir; + BEntry entry; + while (roster.GetNextVolume(&volume) == B_OK) { - if (!volume.IsPersistent()) + if (volume.InitCheck() != B_OK || !volume.IsPersistent() || volume.Capacity() == 0) continue; - BDirectory startDir; if (volume.GetRootDirectory(&startDir) == B_OK) { - BEntry entry; startDir.GetEntry(&entry); Model* model = new Model(&entry); @@ -755,12 +748,10 @@ BNavMenu::DoneBuildingItemList() if ((fFlags & kShowParent) != 0) { BDirectory directory(&fNavDir); BEntry entry(&fNavDir); - if (!directory.IsRootDirectory() - && entry.GetParent(&entry) == B_OK) { + if (!directory.IsRootDirectory() && entry.GetParent(&entry) == B_OK) { Model model(&entry, true); BLooper* looper; - AddNavParentDir(&model, fMessage.what, - fMessenger.Target(&looper)); + AddNavParentDir(&model, fMessage.what, fMessenger.Target(&looper)); } } diff --git a/src/kits/tracker/OpenWithWindow.h b/src/kits/tracker/OpenWithWindow.h index 87fc7d8ec0..730603a2dd 100644 --- a/src/kits/tracker/OpenWithWindow.h +++ b/src/kits/tracker/OpenWithWindow.h @@ -152,6 +152,8 @@ public: void SetCanSetAppAsDefault(bool); void SetCanOpen(bool); + virtual bool ShouldHaveDraggableFolderIcon() { return false; }; + OpenWithPoseView* PoseView() const; protected: diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 970e7ddb01..b4da07e75d 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -5838,14 +5838,14 @@ BPoseView::AttributeChanged(const BMessage* message) attrName = NULL; Model* targetModel = TargetModel(); - if (targetModel != NULL && *targetModel->NodeRef() == itemNode - && targetModel->IsNodeOpen() + if (ContainerWindow()->ShouldHaveDraggableFolderIcon() && targetModel != NULL + && *targetModel->NodeRef() == itemNode && targetModel->IsNodeOpen() && targetModel->AttrChanged(attrName)) { // the icon of our target has changed, update drag icon // TODO: make this simpler (i.e. store the icon with the window) BView* view = Window()->FindView("MenuBar"); if (view != NULL) { - view = view->FindView("ThisContainer"); + view = view->FindView("DraggableContainerIcon"); if (view != NULL) { IconCache::sIconCache->IconChanged(targetModel); view->Invalidate();