Author Topic: Mime types handling for Linux  (Read 4511 times)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Mime types handling for Linux
« on: October 31, 2007, 03:23:43 pm »
Contrary to popular belief there is actually a standard way to open a file with its associated application on linux. File association handling is part of the freedesktop.org standard. Freedesktop.org provide an application, xdg-open (part of the package xdg-utils, see http://portland.freedesktop.org/xdg-utils-1.0/) to perform that task. I don't know how many distros are supplying the command, but hopefully most...

Anyway, here's an untested patch to the mimetypes handler. I can't test because I don't have access to a linux box at the moment (and I haven't had time to set up a VM). Do checkbox options to "open with associated application" get disabled on Linux? If so, the patch is incomplete.

Code
Index: src/plugins/defaultmimehandler/resources/edit_files_handling.xrc
===================================================================
--- src/plugins/defaultmimehandler/resources/edit_files_handling.xrc (revision 4587)
+++ src/plugins/defaultmimehandler/resources/edit_files_handling.xrc (working copy)
@@ -56,7 +56,7 @@
  <label>To open the file</label>
  <content>
  <item>launch an external program</item>
- <item>launch the associated application (windows only)</item>
+ <item>launch the associated application</item>
  <item>open it in a Code::Blocks editor</item>
  </content>
  <style>wxRA_SPECIFY_COLS</style>
Index: src/plugins/defaultmimehandler/defaultmimehandler.cpp
===================================================================
--- src/plugins/defaultmimehandler/defaultmimehandler.cpp (revision 4587)
+++ src/plugins/defaultmimehandler/defaultmimehandler.cpp (working copy)
@@ -146,7 +146,7 @@
     {
         // not yet supported. ask the user how to open it.
         wxString choices[3] = {_("Select an external program to open it"),
-                               _("Open it with the associated application (windows only)"),
+                               _("Open it with the associated application"),
                                _("Open it inside the Code::Blocks editor")};
         wxSingleChoiceDialog dlg(Manager::Get()->GetAppWindow(),
                                 _("Code::Blocks does not yet know how to open this kind of file.\n"
@@ -265,6 +265,9 @@
         #ifdef __WXMSW__
         ShellExecute(0, wxString(_T("open")).c_str(), filename.c_str(), 0, 0, SW_SHOW);
         #endif
+        #ifdef __WXGTK__
+        wxExecute(wxString::Format(_T("xdg-open %s")),filename.c_str());
+        #endif
         return 0;
     }
     else