From 5ed12849944289b71e6362c256c4d1ffc5b5c9cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sun, 31 Oct 2004 12:10:01 +0000 Subject: [PATCH] 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 --- src/apps/bin/open.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/apps/bin/open.cpp b/src/apps/bin/open.cpp index b2b6cfec79..96a2ac21b3 100644 --- a/src/apps/bin/open.cpp +++ b/src/apps/bin/open.cpp @@ -18,6 +18,7 @@ int main(int argc, char **argv) { char *progName = argv[0]; + char *openWith = "application/x-vnd.Be-TRAK"; if (strrchr(progName, '/')) progName = strrchr(progName, '/') + 1; @@ -27,24 +28,36 @@ main(int argc, char **argv) BRoster roster; while (*++argv) { - status_t rc; + status_t rc = B_OK; + argc--; BEntry entry(*argv); if ((rc = entry.InitCheck()) == B_OK && entry.Exists()) { entry_ref ref; entry.GetRef(&ref); - BMessenger tracker("application/x-vnd.Be-TRAK"); - if (tracker.IsValid()) { + BMessenger target(openWith); + if (target.IsValid()) { BMessage message(B_REFS_RECEIVED); message.AddRef("refs", &ref); - - tracker.SendMessage(&message); + /* tell the app to open the file */ + rc = target.SendMessage(&message); } else rc = roster.Launch(&ref); } else if (!strncasecmp("application/", *argv, 12)) { // maybe it's an application-mimetype? - rc = roster.Launch(*argv); + + // 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); } else if (strstr(*argv, ":")) { BString mimetype = "application/x-vnd.Be.URL."; BString arg(*argv);