BFilePanel: reset to home dir if volume unmounted
* Fix bug reported by humdinger: when the volume which is currently shown in the file panel is unmounted, the file panel's window was closed and even deleted. This is not only inconvenient but also a use-after-free bug waiting to happen: an application which keeps the BFilePanel around to show it again later (as recommended in the BeBook) cannot know that it has become invalid while it was hidden (the destruction of the window happens even when it's not shown). * When receiving an unmount event for the currently shown volume, we now reset the view to the home directory.
This commit is contained in:
parent
a9c1157a2a
commit
615417e5ba
@ -1740,12 +1740,12 @@ BFilePanelPoseView::StopWatching()
|
||||
bool
|
||||
BFilePanelPoseView::FSNotification(const BMessage* message)
|
||||
{
|
||||
if (IsDesktopView()) {
|
||||
// Pretty much copied straight from DesktopPoseView.
|
||||
// Would be better if the code could be shared somehow.
|
||||
switch (message->FindInt32("opcode")) {
|
||||
case B_DEVICE_MOUNTED:
|
||||
{
|
||||
switch (message->FindInt32("opcode")) {
|
||||
case B_DEVICE_MOUNTED:
|
||||
{
|
||||
if (IsDesktopView()) {
|
||||
// Pretty much copied straight from DesktopPoseView.
|
||||
// Would be better if the code could be shared somehow.
|
||||
dev_t device;
|
||||
if (message->FindInt32("new device", &device) != B_OK)
|
||||
break;
|
||||
@ -1766,6 +1766,21 @@ BFilePanelPoseView::FSNotification(const BMessage* message)
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user