Make it so open application/foo file opens file with foo,

and don't open foo again if it's running and we have files to give it.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9675 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2004-10-31 12:10:01 +00:00
parent d4af15a04b
commit 5ed1284994
+18 -5
View File
@@ -18,6 +18,7 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *progName = argv[0]; char *progName = argv[0];
char *openWith = "application/x-vnd.Be-TRAK";
if (strrchr(progName, '/')) if (strrchr(progName, '/'))
progName = strrchr(progName, '/') + 1; progName = strrchr(progName, '/') + 1;
@@ -27,23 +28,35 @@ main(int argc, char **argv)
BRoster roster; BRoster roster;
while (*++argv) { while (*++argv) {
status_t rc; status_t rc = B_OK;
argc--;
BEntry entry(*argv); BEntry entry(*argv);
if ((rc = entry.InitCheck()) == B_OK && entry.Exists()) { if ((rc = entry.InitCheck()) == B_OK && entry.Exists()) {
entry_ref ref; entry_ref ref;
entry.GetRef(&ref); entry.GetRef(&ref);
BMessenger tracker("application/x-vnd.Be-TRAK"); BMessenger target(openWith);
if (tracker.IsValid()) { if (target.IsValid()) {
BMessage message(B_REFS_RECEIVED); BMessage message(B_REFS_RECEIVED);
message.AddRef("refs", &ref); message.AddRef("refs", &ref);
/* tell the app to open the file */
tracker.SendMessage(&message); rc = target.SendMessage(&message);
} else } else
rc = roster.Launch(&ref); rc = roster.Launch(&ref);
} else if (!strncasecmp("application/", *argv, 12)) { } else if (!strncasecmp("application/", *argv, 12)) {
// maybe it's an application-mimetype? // maybe it's an application-mimetype?
// subsequent files are open with that app
openWith = *argv;
// in the case the app is already started,
// don't start it twice if we have other args
BList teams;
if (argc > 1) {
roster.GetAppList(*argv, &teams);
}
if (teams.IsEmpty())
rc = roster.Launch(*argv); rc = roster.Launch(*argv);
} else if (strstr(*argv, ":")) { } else if (strstr(*argv, ":")) {
BString mimetype = "application/x-vnd.Be.URL."; BString mimetype = "application/x-vnd.Be.URL.";