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 <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
John Scipione
2025-11-30 19:05:25 +00:00
parent 1584b1ecab
commit d7022afd57
5 changed files with 49 additions and 151 deletions
+12 -59
View File
@@ -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 bool
DesktopPoseView::AddPosesThreadValid(const entry_ref*) const 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 bool
DesktopPoseView::Represents(const node_ref* ref) const DesktopPoseView::Represents(const node_ref* ref) const
{ {
@@ -265,11 +216,12 @@ DesktopPoseView::Represents(const entry_ref* ref) const
void void
DesktopPoseView::StartSettingsWatch() DesktopPoseView::StartSettingsWatch()
{ {
if (be_app->LockLooper()) { TTracker* tracker = dynamic_cast<TTracker*>(be_app);
be_app->StartWatching(this, kShowDisksIconChanged); if (tracker != NULL && tracker->LockLooper()) {
be_app->StartWatching(this, kVolumesOnDesktopChanged); tracker->StartWatching(this, kShowDisksIconChanged);
be_app->StartWatching(this, kDesktopIntegrationChanged); tracker->StartWatching(this, kVolumesOnDesktopChanged);
be_app->UnlockLooper(); tracker->StartWatching(this, kDesktopIntegrationChanged);
tracker->UnlockLooper();
} }
} }
@@ -277,11 +229,12 @@ DesktopPoseView::StartSettingsWatch()
void void
DesktopPoseView::StopSettingsWatch() DesktopPoseView::StopSettingsWatch()
{ {
if (be_app->LockLooper()) { TTracker* tracker = dynamic_cast<TTracker*>(be_app);
be_app->StopWatching(this, kShowDisksIconChanged); if (tracker != NULL && tracker->LockLooper()) {
be_app->StopWatching(this, kVolumesOnDesktopChanged); tracker->StopWatching(this, kShowDisksIconChanged);
be_app->StopWatching(this, kDesktopIntegrationChanged); tracker->StopWatching(this, kVolumesOnDesktopChanged);
be_app->UnlockLooper(); tracker->StopWatching(this, kDesktopIntegrationChanged);
tracker->UnlockLooper();
} }
} }
-3
View File
@@ -62,11 +62,8 @@ public:
protected: protected:
virtual EntryListBase* InitDirentIterator(const entry_ref*); virtual EntryListBase* InitDirentIterator(const entry_ref*);
virtual bool FSNotification(const BMessage*);
virtual bool AddPosesThreadValid(const entry_ref*) const; virtual bool AddPosesThreadValid(const entry_ref*) const;
virtual void AddPosesCompleted();
virtual void AddPoses(Model* model = NULL);
virtual bool IsDesktopView() const; virtual bool IsDesktopView() const;
+1 -63
View File
@@ -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 void
BFilePanelPoseView::RestoreState(AttributeStreamNode* node) BFilePanelPoseView::RestoreState(AttributeStreamNode* node)
{ {
@@ -1836,26 +1789,11 @@ BFilePanelPoseView::InitDirentIterator(const entry_ref* ref)
void void
BFilePanelPoseView::AddPosesCompleted() BFilePanelPoseView::AddPosesCompleted()
{ {
_inherited::AddPosesCompleted();
if (IsDesktop())
CreateTrashPose();
// the menu that adds these shortcuts may not exist initially // the menu that adds these shortcuts may not exist initially
Window()->AddShortcut('D', B_COMMAND_KEY, new BMessage(kSwitchToDesktop)); Window()->AddShortcut('D', B_COMMAND_KEY, new BMessage(kSwitchToDesktop));
Window()->AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome)); Window()->AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome));
UpdateScrollRange(); _inherited::AddPosesCompleted();
}
void
BFilePanelPoseView::AddPoses(Model* model)
{
if (IsDesktop())
AddVolumePoses();
_inherited::AddPoses(model);
} }
-3
View File
@@ -178,8 +178,6 @@ public:
BFilePanelPoseView(Model*); BFilePanelPoseView(Model*);
virtual bool IsFilePanel() const; virtual bool IsFilePanel() const;
virtual bool FSNotification(const BMessage*);
virtual bool IsDesktop() const { return fIsDesktop; }; virtual bool IsDesktop() const { return fIsDesktop; };
void SetIsDesktop(bool on) { fIsDesktop = on; }; void SetIsDesktop(bool on) { fIsDesktop = on; };
@@ -195,7 +193,6 @@ protected:
virtual EntryListBase* InitDirentIterator(const entry_ref*); virtual EntryListBase* InitDirentIterator(const entry_ref*);
virtual void AddPosesCompleted(); virtual void AddPosesCompleted();
virtual void AddPoses(Model* model = NULL);
virtual bool IsVolumesRoot() const { return fIsDesktop; }; virtual bool IsVolumesRoot() const { return fIsDesktop; };
void AdaptToVolumeChange(BMessage*); void AdaptToVolumeChange(BMessage*);
+36 -23
View File
@@ -1285,7 +1285,8 @@ BPoseView::AddPoses(Model* model)
if (TargetModel()->IsRoot()) { if (TargetModel()->IsRoot()) {
AddVolumePoses(); AddVolumePoses();
return; return;
} } else if (IsVolumesRoot())
AddVolumePoses();
ShowBarberPole(); ShowBarberPole();
@@ -1701,6 +1702,10 @@ BPoseView::AddPosesCompleted()
if (window != NULL && window->ShouldAddMenus()) if (window != NULL && window->ShouldAddMenus())
window->AddMimeTypesToMenu(); 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 // 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 // were "auto" placed to see if they overlap with other icons
if (ViewMode() != kListMode) if (ViewMode() != kListMode)
@@ -1716,6 +1721,9 @@ BPoseView::AddPosesCompleted()
float lastItemTop = (CurrentPoseList()->CountItems() - 1) * fListElemHeight; float lastItemTop = (CurrentPoseList()->CountItems() - 1) * fListElemHeight;
if (bounds.top > lastItemTop) if (bounds.top > lastItemTop)
_inherited::ScrollTo(bounds.left, std::max(lastItemTop, 0.0f)); _inherited::ScrollTo(bounds.left, std::max(lastItemTop, 0.0f));
SortPoses();
Invalidate();
} }
} }
@@ -5397,6 +5405,7 @@ BPoseView::FSNotification(const BMessage* message)
node_ref itemNode; node_ref itemNode;
dev_t device; dev_t device;
Model* targetModel = TargetModel(); Model* targetModel = TargetModel();
TrackerSettings settings;
switch (message->GetInt32("opcode", 0)) { switch (message->GetInt32("opcode", 0)) {
case B_ENTRY_CREATED: case B_ENTRY_CREATED:
@@ -5414,7 +5423,6 @@ BPoseView::FSNotification(const BMessage* message)
// Query windows can get notices on different dirNodes // Query windows can get notices on different dirNodes
// The Disks window can too // The Disks window can too
// So can the Desktop, as long as the integrate flag is on // So can the Desktop, as long as the integrate flag is on
TrackerSettings settings;
if (targetModel != NULL && dirNode != *targetModel->NodeRef() if (targetModel != NULL && dirNode != *targetModel->NodeRef()
&& !targetModel->IsQuery() && !targetModel->IsQuery()
&& !targetModel->IsVirtualDirectory() && !targetModel->IsVirtualDirectory()
@@ -5529,16 +5537,19 @@ BPoseView::FSNotification(const BMessage* message)
if (message->FindInt32("new device", &device) != B_OK) if (message->FindInt32("new device", &device) != B_OK)
break; break;
if (targetModel != NULL && targetModel->IsRoot()) { BVolume volume(device);
BVolume volume(device); if (volume.InitCheck() != B_OK)
if (volume.InitCheck() == B_OK) break;
CreateVolumePose(&volume);
} else if (TargetModel()->IsTrash()) {
// add trash items from newly mounted volume
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; BDirectory trashDir;
BEntry entry; BEntry entry;
BVolume volume(device);
if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK
&& trashDir.GetEntry(&entry) == B_OK) { && trashDir.GetEntry(&entry) == B_OK) {
Model model(&entry); Model model(&entry);
@@ -5560,14 +5571,19 @@ BPoseView::FSNotification(const BMessage* message)
case B_DEVICE_UNMOUNTED: case B_DEVICE_UNMOUNTED:
if (message->FindInt32("device", &device) == B_OK) { if (message->FindInt32("device", &device) == B_OK) {
if (targetModel != NULL ASSERT(targetModel != NULL);
&& targetModel->NodeRef()->device == device) { if (targetModel->NodeRef()->device == device) {
// close the window from a volume that is gone if (IsFilePanel()) {
DisableSaveLocation(); // reset location to home directory
Window()->Close(); BMessage message(kSwitchToHome);
} else if (targetModel != NULL) { Window()->PostMessage(&message, this);
EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted, } else {
this, device); // close the window from a volume that is gone
DisableSaveLocation();
Window()->Close();
}
} else {
EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted, this, device);
} }
} }
break; break;
@@ -9608,12 +9624,9 @@ BPoseView::SortPoses()
PRINT(("===================\n")); PRINT(("===================\n"));
#endif #endif
BPose** poses = reinterpret_cast<BPose**>(fPoseList->AsBList()->Items()); PoseList* poseList = CurrentPoseList();
std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this)); BPose** poses = reinterpret_cast<BPose**>(poseList->AsBList()->Items());
if (IsFiltering()) { std::stable_sort(poses, &poses[poseList->CountItems()], PoseComparator(this));
poses = reinterpret_cast<BPose**>(fFilteredPoseList->AsBList()->Items());
std::stable_sort(poses, &poses[fFilteredPoseList->CountItems()], PoseComparator(this));
}
} }