From d7022afd57b23949832639587704bd93c911f15d Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 16 Nov 2025 14:19:39 -0500 Subject: [PATCH] Tracker: Simplify adding/removing poses when mounting/unmounting ... and sorting. Change-Id: Ia72e85d12682d4f77200629f3f5f278a9a40c423 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9890 Reviewed-by: John Scipione Tested-by: Commit checker robot --- src/kits/tracker/DesktopPoseView.cpp | 71 +++++----------------------- src/kits/tracker/DesktopPoseView.h | 3 -- src/kits/tracker/FilePanelPriv.cpp | 64 +------------------------ src/kits/tracker/FilePanelPriv.h | 3 -- src/kits/tracker/PoseView.cpp | 59 ++++++++++++++--------- 5 files changed, 49 insertions(+), 151 deletions(-) diff --git a/src/kits/tracker/DesktopPoseView.cpp b/src/kits/tracker/DesktopPoseView.cpp index 54f84b1e73..5348a8b0d4 100644 --- a/src/kits/tracker/DesktopPoseView.cpp +++ b/src/kits/tracker/DesktopPoseView.cpp @@ -186,36 +186,6 @@ DesktopPoseView::InitDirentIterator(const entry_ref* ref) } -bool -DesktopPoseView::FSNotification(const BMessage* message) -{ - switch (message->GetInt32("opcode", 0)) { - case B_DEVICE_MOUNTED: - { - dev_t device; - if (message->FindInt32("new device", &device) != B_OK) - break; - - ASSERT(TargetModel()); - TrackerSettings settings; - - BVolume volume(device); - if (volume.InitCheck() != B_OK) - break; - - if (settings.MountVolumesOntoDesktop() - && (!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())) { - // place an icon for the volume onto the desktop - CreateVolumePose(&volume); - } - } - break; - } - - return _inherited::FSNotification(message); -} - - bool DesktopPoseView::AddPosesThreadValid(const entry_ref*) const { @@ -223,25 +193,6 @@ DesktopPoseView::AddPosesThreadValid(const entry_ref*) const } -void -DesktopPoseView::AddPosesCompleted() -{ - _inherited::AddPosesCompleted(); - - CreateTrashPose(); - CheckAutoPlacedPoses(); -} - - -void -DesktopPoseView::AddPoses(Model* model) -{ - AddVolumePoses(); - - _inherited::AddPoses(model); -} - - bool DesktopPoseView::Represents(const node_ref* ref) const { @@ -265,11 +216,12 @@ DesktopPoseView::Represents(const entry_ref* ref) const void DesktopPoseView::StartSettingsWatch() { - if (be_app->LockLooper()) { - be_app->StartWatching(this, kShowDisksIconChanged); - be_app->StartWatching(this, kVolumesOnDesktopChanged); - be_app->StartWatching(this, kDesktopIntegrationChanged); - be_app->UnlockLooper(); + TTracker* tracker = dynamic_cast(be_app); + if (tracker != NULL && tracker->LockLooper()) { + tracker->StartWatching(this, kShowDisksIconChanged); + tracker->StartWatching(this, kVolumesOnDesktopChanged); + tracker->StartWatching(this, kDesktopIntegrationChanged); + tracker->UnlockLooper(); } } @@ -277,11 +229,12 @@ DesktopPoseView::StartSettingsWatch() void DesktopPoseView::StopSettingsWatch() { - if (be_app->LockLooper()) { - be_app->StopWatching(this, kShowDisksIconChanged); - be_app->StopWatching(this, kVolumesOnDesktopChanged); - be_app->StopWatching(this, kDesktopIntegrationChanged); - be_app->UnlockLooper(); + TTracker* tracker = dynamic_cast(be_app); + if (tracker != NULL && tracker->LockLooper()) { + tracker->StopWatching(this, kShowDisksIconChanged); + tracker->StopWatching(this, kVolumesOnDesktopChanged); + tracker->StopWatching(this, kDesktopIntegrationChanged); + tracker->UnlockLooper(); } } diff --git a/src/kits/tracker/DesktopPoseView.h b/src/kits/tracker/DesktopPoseView.h index bef9ebb904..eba9a16938 100644 --- a/src/kits/tracker/DesktopPoseView.h +++ b/src/kits/tracker/DesktopPoseView.h @@ -62,11 +62,8 @@ public: protected: virtual EntryListBase* InitDirentIterator(const entry_ref*); - virtual bool FSNotification(const BMessage*); virtual bool AddPosesThreadValid(const entry_ref*) const; - virtual void AddPosesCompleted(); - virtual void AddPoses(Model* model = NULL); virtual bool IsDesktopView() const; diff --git a/src/kits/tracker/FilePanelPriv.cpp b/src/kits/tracker/FilePanelPriv.cpp index 0b96d73dec..4c158a26a0 100644 --- a/src/kits/tracker/FilePanelPriv.cpp +++ b/src/kits/tracker/FilePanelPriv.cpp @@ -1755,53 +1755,6 @@ BFilePanelPoseView::StopWatching() } -bool -BFilePanelPoseView::FSNotification(const BMessage* message) -{ - switch (message->GetInt32("opcode", 0)) { - case B_DEVICE_MOUNTED: - { - if (!IsDesktop() && !TargetModel()->IsRoot()) - break; - - dev_t device; - if (message->FindInt32("new device", &device) != B_OK) - break; - - ASSERT(TargetModel() != NULL); - TrackerSettings settings; - - BVolume volume(device); - if (volume.InitCheck() != B_OK) - break; - - // place volume icon onto Desktop or Root - if ((!volume.IsShared() || settings.MountSharedVolumesOntoDesktop()) - && ((IsVolumesRoot() && settings.MountVolumesOntoDesktop()) - || TargetModel()->IsRoot())) { - CreateVolumePose(&volume); - } - break; - } - - case B_DEVICE_UNMOUNTED: - { - dev_t device; - if (message->FindInt32("device", &device) == B_OK) { - if (TargetModel() != NULL && TargetModel()->NodeRef()->device == device) { - // Volume currently shown in this file panel - // disappeared, reset location to home directory - BMessage message(kSwitchToHome); - MessageReceived(&message); - } - } - break; - } - } - return _inherited::FSNotification(message); -} - - void BFilePanelPoseView::RestoreState(AttributeStreamNode* node) { @@ -1836,26 +1789,11 @@ BFilePanelPoseView::InitDirentIterator(const entry_ref* ref) void BFilePanelPoseView::AddPosesCompleted() { - _inherited::AddPosesCompleted(); - - if (IsDesktop()) - CreateTrashPose(); - // the menu that adds these shortcuts may not exist initially Window()->AddShortcut('D', B_COMMAND_KEY, new BMessage(kSwitchToDesktop)); Window()->AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome)); - UpdateScrollRange(); -} - - -void -BFilePanelPoseView::AddPoses(Model* model) -{ - if (IsDesktop()) - AddVolumePoses(); - - _inherited::AddPoses(model); + _inherited::AddPosesCompleted(); } diff --git a/src/kits/tracker/FilePanelPriv.h b/src/kits/tracker/FilePanelPriv.h index 0a99f845a5..c189792e8c 100644 --- a/src/kits/tracker/FilePanelPriv.h +++ b/src/kits/tracker/FilePanelPriv.h @@ -178,8 +178,6 @@ public: BFilePanelPoseView(Model*); virtual bool IsFilePanel() const; - virtual bool FSNotification(const BMessage*); - virtual bool IsDesktop() const { return fIsDesktop; }; void SetIsDesktop(bool on) { fIsDesktop = on; }; @@ -195,7 +193,6 @@ protected: virtual EntryListBase* InitDirentIterator(const entry_ref*); virtual void AddPosesCompleted(); - virtual void AddPoses(Model* model = NULL); virtual bool IsVolumesRoot() const { return fIsDesktop; }; void AdaptToVolumeChange(BMessage*); diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 519548e508..160c90f4c0 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -1285,7 +1285,8 @@ BPoseView::AddPoses(Model* model) if (TargetModel()->IsRoot()) { AddVolumePoses(); return; - } + } else if (IsVolumesRoot()) + AddVolumePoses(); ShowBarberPole(); @@ -1701,6 +1702,10 @@ BPoseView::AddPosesCompleted() if (window != NULL && window->ShouldAddMenus()) window->AddMimeTypesToMenu(); + // add Trash icon to Desktop + if (IsVolumesRoot()) + CreateTrashPose(); + // if we're not in icon mode then we need to check for poses that // were "auto" placed to see if they overlap with other icons if (ViewMode() != kListMode) @@ -1716,6 +1721,9 @@ BPoseView::AddPosesCompleted() float lastItemTop = (CurrentPoseList()->CountItems() - 1) * fListElemHeight; if (bounds.top > lastItemTop) _inherited::ScrollTo(bounds.left, std::max(lastItemTop, 0.0f)); + + SortPoses(); + Invalidate(); } } @@ -5397,6 +5405,7 @@ BPoseView::FSNotification(const BMessage* message) node_ref itemNode; dev_t device; Model* targetModel = TargetModel(); + TrackerSettings settings; switch (message->GetInt32("opcode", 0)) { case B_ENTRY_CREATED: @@ -5414,7 +5423,6 @@ BPoseView::FSNotification(const BMessage* message) // Query windows can get notices on different dirNodes // The Disks window can too // So can the Desktop, as long as the integrate flag is on - TrackerSettings settings; if (targetModel != NULL && dirNode != *targetModel->NodeRef() && !targetModel->IsQuery() && !targetModel->IsVirtualDirectory() @@ -5529,16 +5537,19 @@ BPoseView::FSNotification(const BMessage* message) if (message->FindInt32("new device", &device) != B_OK) break; - if (targetModel != NULL && targetModel->IsRoot()) { - BVolume volume(device); - if (volume.InitCheck() == B_OK) - CreateVolumePose(&volume); - } else if (TargetModel()->IsTrash()) { - // add trash items from newly mounted volume + BVolume volume(device); + if (volume.InitCheck() != B_OK) + break; + ASSERT(targetModel != NULL); + if (targetModel->IsRoot() // always create volume poses on root + || ((IsVolumesRoot() && settings.MountVolumesOntoDesktop()) + && ((!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())))) { + CreateVolumePose(&volume); + } else if (targetModel->IsTrash()) { + // add trash items from newly mounted volume BDirectory trashDir; BEntry entry; - BVolume volume(device); if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK && trashDir.GetEntry(&entry) == B_OK) { Model model(&entry); @@ -5560,14 +5571,19 @@ BPoseView::FSNotification(const BMessage* message) case B_DEVICE_UNMOUNTED: if (message->FindInt32("device", &device) == B_OK) { - if (targetModel != NULL - && targetModel->NodeRef()->device == device) { - // close the window from a volume that is gone - DisableSaveLocation(); - Window()->Close(); - } else if (targetModel != NULL) { - EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted, - this, device); + ASSERT(targetModel != NULL); + if (targetModel->NodeRef()->device == device) { + if (IsFilePanel()) { + // reset location to home directory + BMessage message(kSwitchToHome); + Window()->PostMessage(&message, this); + } else { + // close the window from a volume that is gone + DisableSaveLocation(); + Window()->Close(); + } + } else { + EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted, this, device); } } break; @@ -9608,12 +9624,9 @@ BPoseView::SortPoses() PRINT(("===================\n")); #endif - BPose** poses = reinterpret_cast(fPoseList->AsBList()->Items()); - std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this)); - if (IsFiltering()) { - poses = reinterpret_cast(fFilteredPoseList->AsBList()->Items()); - std::stable_sort(poses, &poses[fFilteredPoseList->CountItems()], PoseComparator(this)); - } + PoseList* poseList = CurrentPoseList(); + BPose** poses = reinterpret_cast(poseList->AsBList()->Items()); + std::stable_sort(poses, &poses[poseList->CountItems()], PoseComparator(this)); }