2 * Copyright 2003-2008, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2015 Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
7 * Axel Dörfler, axeld@pinc-software.de
8 * John Scipione, jscipione@gmail.com
12 //! Open Target Folder - opens the folder of the link target in Tracker
20 #include <Messenger.h>
24 #include <tracker_private.h>
27 using namespace BPrivate
;
30 process_refs(entry_ref directoryRef
, BMessage
* message
, void*)
33 uint32 selectCount
= 0;
35 // create Tracker messenger...
36 BMessenger
messenger(kTrackerSignature
);
38 // create select message...
39 BMessage
selectMessage(kSelect
);
41 for (int32 i
= 0; message
->FindRef("refs", i
, &ref
) == B_OK
; i
++) {
43 if (link
.InitCheck() != B_OK
|| !link
.IsSymLink()) {
44 BAlert
* alert
= new BAlert("Open Target Folder",
45 "This add-on can only be used on symbolic links.\n"
46 "It opens the folder of the link target in Tracker.",
48 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
53 BEntry
targetEntry(&ref
, true);
54 if (targetEntry
.InitCheck() != B_OK
) {
55 BAlert
* alert
= new BAlert("Open Target Folder",
56 "Cannot open target entry. Maybe this link is broken?",
57 "OK", NULL
, NULL
, B_WIDTH_AS_USUAL
, B_WARNING_ALERT
);
58 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
64 if (targetEntry
.GetParent(&parentEntry
) != B_OK
) {
65 BAlert
* alert
= new BAlert("Open Target Folder",
66 "Cannot open target entry folder. Maybe this link is broken?",
67 "OK", NULL
, NULL
, B_WIDTH_AS_USUAL
, B_WARNING_ALERT
);
68 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
74 if (parentEntry
.GetRef(&parent
) != B_OK
) {
75 BAlert
* alert
= new BAlert("Open Target Folder",
76 "Unable to locate entry_ref for the target entry folder.",
78 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
83 // create Tracker message...
84 BMessage
trackerMessage(B_REFS_RECEIVED
);
85 trackerMessage
.AddRef("refs", &parent
);
88 messenger
.SendMessage(&trackerMessage
);
91 if (targetEntry
.GetRef(&target
) != B_OK
) {
92 // don't alert, selection is not critical
96 // add ref to selection message
97 selectMessage
.AddRef("refs", &target
);
103 messenger
.SendMessage(&selectMessage
);
108 main(int /*argc*/, char** /*argv*/)
110 fprintf(stderr
, "This can only be used as a Tracker add-on.\n");