From 1dea1566c80edf9cffde036f70b2401aeb9ffb8f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 27 Jun 2008 14:14:13 +0000 Subject: [PATCH] Added mostly empty wxLaunchDefaultApplication git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54383 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/utils.h | 3 +++ src/common/utilscmn.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/wx/utils.h b/include/wx/utils.h index 0458210efd..868e744809 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -578,6 +578,9 @@ enum // Launch url in the user's default internet browser WXDLLIMPEXP_CORE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); +// Launch document in the user's default application +WXDLLIMPEXP_CORE bool wxLaunchDefaultApplication(const wxString& path, int flags = 0); + // ---------------------------------------------------------------------------- // Menu accelerators related things // ---------------------------------------------------------------------------- diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 42d60c2c4d..fad395b800 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -933,6 +933,32 @@ void wxQsort(void *const pbase, size_t total_elems, #if wxUSE_GUI +// ---------------------------------------------------------------------------- +// Launch document with default app +// ---------------------------------------------------------------------------- + +bool wxLaunchDefaultApplication(const wxString &document, int flags) +{ + wxUnusedVar(flags); + +#ifdef __UNIX__ + // Our best best is to use xdg-open from freedesktop.org cross-desktop + // compatibility suite xdg-utils + // (see http://portland.freedesktop.org/wiki/) -- this is installed on + // most modern distributions and may be tweaked by them to handle + // distribution specifics. + wxString path, xdg_open; + if ( wxGetEnv("PATH", &path) && + wxFindFileInPath(&xdg_open, path, "xdg-open") ) + { + if ( wxExecute(xdg_open + " " + document) ) + return true; + } +#endif + + return false; +} + // ---------------------------------------------------------------------------- // Launch default browser // ---------------------------------------------------------------------------- -- 2.45.2