Tracker: Add Trash pose to Desktop in file panels again.
Make sure pose attributes are set correctly and fix dir menu warping. Change-Id: Ia623517ee19a66dd9b74cbf477ceb258cce1c8d0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/10861 Tested-by: Commit checker robot <[email protected]> Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
@@ -204,31 +204,6 @@ DesktopPoseView::AddPosesCompleted()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DesktopPoseView::CreateTrashPose()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_TRASH_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
BDirectory trashDir(path.Path());
|
||||
BEntry entry;
|
||||
if (trashDir.GetEntry(&entry) != B_OK)
|
||||
return;
|
||||
|
||||
// redraw Trash icon when attribute changes
|
||||
node_ref nref;
|
||||
if (entry.GetNodeRef(&nref) == B_OK)
|
||||
WatchNewNode(&nref, B_WATCH_ATTR, BMessenger(this));
|
||||
|
||||
Model* trashModel = new Model(&entry);
|
||||
PoseInfo poseInfo;
|
||||
ReadPoseInfo(trashModel, &poseInfo);
|
||||
|
||||
CreatePose(trashModel, &poseInfo, false, NULL, NULL, true);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DesktopPoseView::Represents(const node_ref* ref) const
|
||||
{
|
||||
|
||||
@@ -65,7 +65,6 @@ protected:
|
||||
|
||||
virtual bool AddPosesThreadValid(const entry_ref*) const;
|
||||
virtual void AddPosesCompleted();
|
||||
virtual void CreateTrashPose();
|
||||
|
||||
virtual bool IsDesktopView() const;
|
||||
|
||||
|
||||
@@ -103,32 +103,42 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* source,
|
||||
|
||||
BEntry entry(*startEntry);
|
||||
|
||||
bool showDesktop, showDisksIcon;
|
||||
bool desktopIsRoot, showDisksIcon;
|
||||
{
|
||||
TrackerSettings settings;
|
||||
showDesktop = settings.DesktopFilePanelRoot();
|
||||
desktopIsRoot = settings.DesktopFilePanelRoot();
|
||||
showDisksIcon = settings.ShowDisksIcon();
|
||||
}
|
||||
|
||||
// might start one level above startEntry
|
||||
if (!includeStartEntry) {
|
||||
if (!desktopIsRoot) {
|
||||
BDirectory startDir(&entry);
|
||||
if (startDir.InitCheck() == B_OK && startDir.IsRootDirectory()) {
|
||||
// if we're at the root directory skip "/mnt" and go straight to "/"
|
||||
BDirectory parent;
|
||||
BDirectory dir(&entry);
|
||||
|
||||
if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) {
|
||||
// if we're at the root directory skip "mnt" and
|
||||
// go straight to "/"
|
||||
parent.SetTo("/");
|
||||
parent.GetEntry(&entry);
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
// set start entry to parent directory
|
||||
FSGetParentVirtualDirectoryAware(entry, entry);
|
||||
}
|
||||
}
|
||||
|
||||
BDirectory desktopDir;
|
||||
FSGetDeskDir(&desktopDir);
|
||||
BEntry desktopEntry;
|
||||
desktopDir.GetEntry(&desktopEntry);
|
||||
|
||||
BVolume boot;
|
||||
BVolumeRoster volumeRoster;
|
||||
volumeRoster.GetBootVolume(&boot);
|
||||
BDirectory trashDir;
|
||||
FSGetTrashDir(&trashDir, boot.Device());
|
||||
BEntry trashEntry;
|
||||
trashDir.GetEntry(&trashEntry);
|
||||
|
||||
for (;;) {
|
||||
BNode node(&entry);
|
||||
ThrowOnInitCheckError(&node);
|
||||
@@ -141,35 +151,43 @@ BDirMenu::Populate(const BEntry* startEntry, BWindow* source,
|
||||
BEntry parentEntry;
|
||||
bool hitRoot = false;
|
||||
|
||||
BDirectory dir(&entry);
|
||||
if (!showDesktop && dir.InitCheck() == B_OK && dir.IsRootDirectory()) {
|
||||
// if we're at the root directory skip "mnt" and
|
||||
// go straight to "/"
|
||||
BDirectory startDir(&entry);
|
||||
if (!desktopIsRoot && startDir.InitCheck() == B_OK && startDir.IsRootDirectory()) {
|
||||
// if we're at the root directory skip "mnt" and go straight to "/"
|
||||
hitRoot = true;
|
||||
parentEntry.SetTo("/");
|
||||
} else
|
||||
} else {
|
||||
// set parent entry
|
||||
FSGetParentVirtualDirectoryAware(entry, parentEntry);
|
||||
}
|
||||
|
||||
if (showDesktop) {
|
||||
BEntry root("/");
|
||||
// warp from "/" to Desktop properly
|
||||
if (entry == root) {
|
||||
if (entry == trashEntry) {
|
||||
// Trash appears to be on Desktop
|
||||
parentEntry = desktopEntry;
|
||||
// warp from Trash to Desktop
|
||||
}
|
||||
|
||||
if (desktopIsRoot) {
|
||||
BEntry rootEntry("/");
|
||||
if (entry == rootEntry) {
|
||||
// Disks appears to be on Desktop
|
||||
if (showDisksIcon)
|
||||
AddDisksIconToMenu(reverse);
|
||||
entry = desktopEntry;
|
||||
// warp from "/" to Desktop
|
||||
}
|
||||
|
||||
if (entry == desktopEntry)
|
||||
hitRoot = true;
|
||||
}
|
||||
|
||||
if (result == kReadAttrFailed || !info.fInvisible
|
||||
|| (showDesktop && desktopEntry == entry)) {
|
||||
if (result == kReadAttrFailed || (!info.fInvisible || entry == trashEntry)
|
||||
|| (desktopIsRoot && entry == desktopEntry)) {
|
||||
AddItemToDirMenu(&entry, source, reverse, addShortcuts, navMenuEntries);
|
||||
}
|
||||
|
||||
if (hitRoot) {
|
||||
if (!showDesktop && showDisksIcon && *startEntry != "/")
|
||||
if (!desktopIsRoot && showDisksIcon && *startEntry != "/")
|
||||
AddDisksIconToMenu(reverse);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -561,15 +561,7 @@ TFilePanel::SwitchDirectory(const entry_ref* ref)
|
||||
|
||||
PoseView()->SetIsDesktop(isDesktop);
|
||||
_inherited::SwitchDirectory(&setToRef);
|
||||
|
||||
if (PoseView()->IsDesktop())
|
||||
PoseView()->AddVolumePoses();
|
||||
|
||||
AddShortcut('D', B_COMMAND_KEY, new BMessage(kSwitchToDesktop));
|
||||
AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome));
|
||||
// our shortcut got possibly removed because the home
|
||||
// menu item got removed - we shouldn't really have to do
|
||||
// this - this is a workaround for a kit bug.
|
||||
// calls AddPosesCompleted() for the rest
|
||||
|
||||
// update the menu field
|
||||
for (int32 index = fDirMenu->CountItems() - 1; index >= 0; index--)
|
||||
@@ -1807,6 +1799,12 @@ BFilePanelPoseView::AddPosesCompleted()
|
||||
Window()->AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome));
|
||||
|
||||
_inherited::AddPosesCompleted();
|
||||
|
||||
// add volume poses and Trash to Desktop
|
||||
if (IsVolumesRoot()) {
|
||||
AddVolumePoses();
|
||||
CreateTrashPose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -539,13 +539,8 @@ BPoseView::RestoreState(AttributeStreamNode* node)
|
||||
const char* viewStateAttr;
|
||||
const char* viewStateAttrForeign;
|
||||
|
||||
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
|
||||
viewStateAttr = kAttrDisksViewState;
|
||||
viewStateAttrForeign = kAttrDisksViewStateForeign;
|
||||
} else {
|
||||
viewStateAttr = ViewStateAttributeName();
|
||||
viewStateAttrForeign = ForeignViewStateAttributeName();
|
||||
}
|
||||
|
||||
bool wrongEndian = false;
|
||||
const char* name = viewStateAttr;
|
||||
@@ -657,15 +652,28 @@ BPoseView::SetupDefaultColumnsIfNeeded()
|
||||
const char*
|
||||
BPoseView::ViewStateAttributeName() const
|
||||
{
|
||||
return IsDesktopView() ? kAttrDesktopViewState : kAttrViewState;
|
||||
if (IsDesktopView())
|
||||
return kAttrDesktopViewState;
|
||||
else if (TargetModel()->IsRoot())
|
||||
return kAttrDisksPoseInfo;
|
||||
else if (TargetModel()->IsTrash())
|
||||
return kAttrTrashPoseInfo;
|
||||
else
|
||||
return kAttrViewState;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
BPoseView::ForeignViewStateAttributeName() const
|
||||
{
|
||||
return IsDesktopView() ? kAttrDesktopViewStateForeign
|
||||
: kAttrViewStateForeign;
|
||||
if (IsDesktopView())
|
||||
return kAttrDesktopViewStateForeign;
|
||||
else if (TargetModel()->IsRoot())
|
||||
return kAttrDisksPoseInfoForeign;
|
||||
else if (TargetModel()->IsTrash())
|
||||
return kAttrTrashPoseInfoForeign;
|
||||
else
|
||||
return kAttrViewStateForeign;
|
||||
}
|
||||
|
||||
|
||||
@@ -721,13 +729,8 @@ BPoseView::SaveState(AttributeStreamNode* node)
|
||||
|
||||
const char* viewStateAttr;
|
||||
const char* viewStateAttrForeign;
|
||||
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
|
||||
viewStateAttr = kAttrDisksViewState;
|
||||
viewStateAttrForeign = kAttrDisksViewStateForeign;
|
||||
} else {
|
||||
viewStateAttr = ViewStateAttributeName();
|
||||
viewStateAttrForeign = ForeignViewStateAttributeName();
|
||||
}
|
||||
|
||||
node->Write(viewStateAttr, viewStateAttrForeign, B_RAW_TYPE,
|
||||
stream.Position(), stream.Buffer());
|
||||
@@ -802,7 +805,7 @@ BPoseView::SavePoseLocations(BRect* frameIfDesktop)
|
||||
poseInfo.fInitedDirectory = model->EntryRef()->directory;
|
||||
|
||||
// Trash pose should be invisible except on the Desktop
|
||||
if (model->IsTrash() && !isDesktop)
|
||||
if (model->IsTrash() && !IsVolumesRoot())
|
||||
poseInfo.fInvisible = true;
|
||||
|
||||
poseInfo.fLocation = pose->Location(this);
|
||||
@@ -1735,6 +1738,31 @@ BPoseView::AddPosesCompleted()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPoseView::CreateTrashPose()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_TRASH_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
|
||||
BDirectory trashDir(path.Path());
|
||||
BEntry entry;
|
||||
if (trashDir.GetEntry(&entry) != B_OK)
|
||||
return;
|
||||
|
||||
// redraw Trash icon when attribute changes
|
||||
node_ref nref;
|
||||
if (entry.GetNodeRef(&nref) == B_OK)
|
||||
WatchNewNode(&nref, B_WATCH_ATTR, BMessenger(this));
|
||||
|
||||
Model* trashModel = new Model(&entry);
|
||||
PoseInfo poseInfo;
|
||||
ReadPoseInfo(trashModel, &poseInfo);
|
||||
|
||||
CreatePose(trashModel, &poseInfo, false, NULL, NULL, true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BPoseView::CreateVolumePose(BVolume* volume)
|
||||
{
|
||||
@@ -2974,7 +3002,7 @@ BPoseView::ReadPoseInfo(Model* model, PoseInfo* poseInfo)
|
||||
|
||||
// special case the "root" disks icon
|
||||
// as well as the Trash on Desktop
|
||||
if (model->IsRoot() || (model->IsTrash() && IsDesktopView())) {
|
||||
if (model->IsRoot() || (model->IsTrash() && IsVolumesRoot())) {
|
||||
BDirectory desktopDir;
|
||||
if (FSGetDeskDir(&desktopDir) == B_OK) {
|
||||
const char* poseInfoAttr = model->IsTrash()
|
||||
|
||||
@@ -643,6 +643,7 @@ protected:
|
||||
// background AddPoses task calls
|
||||
static status_t AddPosesTask(void*);
|
||||
virtual void AddPosesCompleted();
|
||||
virtual void CreateTrashPose();
|
||||
bool IsValidAddPosesThread(thread_id) const;
|
||||
|
||||
// typeahead filtering
|
||||
|
||||
Reference in New Issue
Block a user