Tracker and Open Target Folder: fix for containers
Containers meaning directories, queries, and virtual directories Open Target Folder was basically rewritten to work with BEntry's that are not BDirectory's which makes it work not only for regular directories, but also for symlinks in virtual directories and even symlinks in queries (which also didn't work, and now does). Update version to 1.0.1 and copyright. Fixes the rest of #11091
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
/*
|
||||
* Copyright 2003-2008, Axel Dörfler, [email protected].
|
||||
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Axel Dörfler, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
@@ -14,7 +16,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <Messenger.h>
|
||||
#include <Path.h>
|
||||
@@ -26,36 +27,53 @@
|
||||
extern "C" void
|
||||
process_refs(entry_ref directoryRef, BMessage* message, void*)
|
||||
{
|
||||
BDirectory directory(&directoryRef);
|
||||
uint32 errors = 0;
|
||||
entry_ref ref;
|
||||
|
||||
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
|
||||
BSymLink link(&ref);
|
||||
if (link.InitCheck() != B_OK || !link.IsSymLink()) {
|
||||
errors++;
|
||||
continue;
|
||||
BAlert* alert = new BAlert("Open Target Folder",
|
||||
"This add-on can only be used on symbolic links.\n"
|
||||
"It opens the folder of the link target in Tracker.",
|
||||
"OK");
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
BEntry targetEntry;
|
||||
BPath path;
|
||||
if (link.MakeLinkedPath(&directory, &path) < B_OK
|
||||
|| targetEntry.SetTo(path.Path()) != B_OK
|
||||
|| targetEntry.GetParent(&targetEntry) != B_OK) {
|
||||
BEntry targetEntry(&directoryRef, true);
|
||||
if (targetEntry.InitCheck() != B_OK) {
|
||||
BAlert* alert = new BAlert("Open Target Folder",
|
||||
"Cannot open target folder. Maybe this link is broken?",
|
||||
"Cannot open target entry. Maybe this link is broken?",
|
||||
"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
BEntry parentEntry;
|
||||
if (targetEntry.GetParent(&parentEntry) != B_OK) {
|
||||
BAlert* alert = new BAlert("Open Target Folder",
|
||||
"Cannot open target entry folder. Maybe this link is broken?",
|
||||
"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
entry_ref parent;
|
||||
if (parentEntry.GetRef(&parent) != B_OK) {
|
||||
BAlert* alert = new BAlert("Open Target Folder",
|
||||
"Unable to locate entry_ref for the target entry folder.",
|
||||
"OK");
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
// create Tracker message...
|
||||
entry_ref target;
|
||||
targetEntry.GetRef(&target);
|
||||
|
||||
BMessage trackerMessage(B_REFS_RECEIVED);
|
||||
trackerMessage.AddRef("refs", &target);
|
||||
trackerMessage.AddRef("refs", &parent);
|
||||
|
||||
// ...and send it
|
||||
BMessenger messenger(kTrackerSignature);
|
||||
@@ -63,15 +81,6 @@ process_refs(entry_ref directoryRef, BMessage* message, void*)
|
||||
|
||||
// TODO: select entry via scripting?
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
BAlert* alert = new BAlert("Open Target Folder",
|
||||
"This add-on can only be used on symbolic links.\n"
|
||||
"It opens the folder of the link target in Tracker.",
|
||||
"OK");
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,13 +5,15 @@ resource app_flags B_SINGLE_LAUNCH;
|
||||
resource app_version {
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
minor = 1,
|
||||
|
||||
variety = B_APPV_FINAL,
|
||||
internal = 1,
|
||||
|
||||
short_info = "Opens the link target's folder",
|
||||
long_info = "Open Target Folder, Copyright 2003-2008 Axel Dörfler"
|
||||
long_info = "Open Target Folder, "
|
||||
"Copyright 2003-2008 Axel Dörfler, "
|
||||
"Copyright 2015 Haiku, Inc."
|
||||
};
|
||||
|
||||
resource file_types message {
|
||||
|
||||
@@ -3222,8 +3222,12 @@ BContainerWindow::LoadAddOn(BMessage* message)
|
||||
|
||||
refs->AddMessenger("TrackerViewToken", BMessenger(PoseView()));
|
||||
|
||||
const entry_ref* modelRef = TargetModel()->IsContainer()
|
||||
? selectionList->ItemAt(0)->TargetModel()->EntryRef()
|
||||
: TargetModel()->EntryRef();
|
||||
|
||||
LaunchInNewThread("Add-on", B_NORMAL_PRIORITY, &AddOnThread, refs,
|
||||
addonRef, *TargetModel()->EntryRef());
|
||||
addonRef, *modelRef);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user