[gnome-shell] Bug 577380 - Use the default application for the mime type to open the document
- From: Marina Zhurakhinskaya <marinaz src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-shell] Bug 577380 - Use the default application for the mime type to open the document
- Date: Tue, 5 May 2009 15:53:34 -0400 (EDT)
commit d67c88e4dcacc4353709f7d71a4bb335602ee1a6
Author: Marina Zhurakhinskaya <marinaz redhat com>
Date: Tue May 5 15:40:52 2009 -0400
Bug 577380 - Use the default application for the mime type to open the document
Using appExec for the last application that registered the document was failing
in certain cases, such as for the Open Office for which the application
execution string is being registered as "soffice %u" in ~/.recently-used.xbel.
In general, using the default application for the mime type seems to be a more
predictable way to open documents. We still fall back to using the appExect
for the last application if the default application for a given mime type was
not found.
---
js/ui/docDisplay.js | 58 ++++++++++++++++++++++++++++++--------------------
1 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/js/ui/docDisplay.js b/js/ui/docDisplay.js
index 4ea163f..a1fa17c 100644
--- a/js/ui/docDisplay.js
+++ b/js/ui/docDisplay.js
@@ -65,30 +65,42 @@ DocDisplayItem.prototype = {
// Opens a document represented by this display item.
launch : function() {
- let appName = this._docInfo.last_application();
- let [success, appExec, count, time] = this._docInfo.get_application_info(appName);
- if (success) {
- log("Will open a document with the following command: " + appExec);
- // TODO: Change this once better support for creating GAppInfo is added to
- // GtkRecentInfo, as right now this relies on the fact that the file uri is
- // already a part of appExec, so we don't supply any files to appInfo.launch().
-
- // The 'command line' passed to create_from_command_line is allowed to contain
- // '%<something>' macros that are exapnded to file name / icon name, etc,
- // so we need to escape % as %%
- appExec = appExec.replace(/%/g, "%%");
-
- let appInfo = Gio.app_info_create_from_commandline(appExec, null, 0, null);
-
- // The point of passing an app launch context to launch() is mostly to get
- // startup notification and associated benefits like the app appearing
- // on the right desktop; but it doesn't really work for now because we aren't
- // reading the application's desktop file, and thus don't find the
- // StartupNotify=true in it. So, despite passing the app launch context,
- // no startup notification occurs.
- appInfo.launch([], Main.createAppLaunchContext());
+ // While using Gio.app_info_launch_default_for_uri() would be shorter
+ // in terms of lines of code, we are not doing so because that would
+ // duplicate the work of retrieving the mime type.
+ let mimeType = this._docInfo.get_mime_type();
+ let appInfo = Gio.app_info_get_default_for_type(mimeType, true);
+
+ if (appInfo != null) {
+ appInfo.launch_uris([this._docInfo.get_uri()], Main.createAppLaunchContext());
} else {
- log("Failed to get application info for " + this._docInfo.get_uri());
+ log("Failed to get default application info for mime type " + mimeType +
+ ". Will try to use the last application that registered the document.");
+ let appName = this._docInfo.last_application();
+ let [success, appExec, count, time] = this._docInfo.get_application_info(appName);
+ if (success) {
+ log("Will open a document with the following command: " + appExec);
+ // TODO: Change this once better support for creating GAppInfo is added to
+ // GtkRecentInfo, as right now this relies on the fact that the file uri is
+ // already a part of appExec, so we don't supply any files to appInfo.launch().
+
+ // The 'command line' passed to create_from_command_line is allowed to contain
+ // '%<something>' macros that are expanded to file name / icon name, etc,
+ // so we need to escape % as %%
+ appExec = appExec.replace(/%/g, "%%");
+
+ let appInfo = Gio.app_info_create_from_commandline(appExec, null, 0, null);
+
+ // The point of passing an app launch context to launch() is mostly to get
+ // startup notification and associated benefits like the app appearing
+ // on the right desktop; but it doesn't really work for now because with
+ // the way we create the appInfo we aren't reading the application's desktop
+ // file, and thus don't find the StartupNotify=true in it. So, despite passing
+ // the app launch context, no startup notification occurs.
+ appInfo.launch([], Main.createAppLaunchContext());
+ } else {
+ log("Failed to get application info for " + this._docInfo.get_uri());
+ }
}
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]