зеркало из https://github.com/mozilla/gecko-dev.git
Bug 417952 - Open Containing Folder doesn't highlight/select file in Nautilus. r=karlt
If the File Manager DBus Interface[1] is present, use it to launch file manager and select the file, otherwise fallback to existing code for backwards compatibility. [1] http://www.freedesktop.org/wiki/Specifications/file-manager-interface/
This commit is contained in:
Родитель
7d0adeab24
Коммит
4ede47ab1e
|
@ -11,6 +11,7 @@ EXTRA_DSO_LDOPTS += \
|
|||
$(MOZ_GNOMEVFS_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(MOZ_GIO_LIBS) \
|
||||
$(MOZ_DBUS_GLIB_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/components/build/
|
||||
|
@ -22,6 +23,7 @@ CXXFLAGS += \
|
|||
$(MOZ_GNOMEVFS_CFLAGS) \
|
||||
$(MOZ_GIO_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(MOZ_DBUS_GLIB_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_GTK
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <gio/gio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
|
||||
char *
|
||||
|
@ -377,6 +379,56 @@ nsGIOService::ShowURIForInput(const nsACString& aUri)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGIOService::OrgFreedesktopFileManager1ShowItems(const nsACString& aPath)
|
||||
{
|
||||
GError* error = nullptr;
|
||||
static bool org_freedesktop_FileManager1_exists = true;
|
||||
|
||||
if (!org_freedesktop_FileManager1_exists) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
DBusGConnection* dbusGConnection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
|
||||
|
||||
if (!dbusGConnection) {
|
||||
if (error) {
|
||||
g_printerr("Failed to open connection to session bus: %s\n", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
char *uri = g_filename_to_uri(PromiseFlatCString(aPath).get(), nullptr, nullptr);
|
||||
if (uri == NULL) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
DBusConnection* dbusConnection = dbus_g_connection_get_connection(dbusGConnection);
|
||||
// Make sure we do not exit the entire program if DBus connection get lost.
|
||||
dbus_connection_set_exit_on_disconnect(dbusConnection, false);
|
||||
|
||||
DBusGProxy* dbusGProxy = dbus_g_proxy_new_for_name(dbusGConnection,
|
||||
"org.freedesktop.FileManager1",
|
||||
"/org/freedesktop/FileManager1",
|
||||
"org.freedesktop.FileManager1");
|
||||
|
||||
const char *uris[2] = { uri, nullptr };
|
||||
gboolean rv_dbus_call = dbus_g_proxy_call (dbusGProxy, "ShowItems", nullptr, G_TYPE_STRV, uris,
|
||||
G_TYPE_STRING, "", G_TYPE_INVALID, G_TYPE_INVALID);
|
||||
|
||||
g_object_unref(dbusGProxy);
|
||||
dbus_g_connection_unref(dbusGConnection);
|
||||
g_free(uri);
|
||||
|
||||
if (!rv_dbus_call) {
|
||||
org_freedesktop_FileManager1_exists = false;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or find already existing application info for specified command
|
||||
* and application name.
|
||||
|
|
|
@ -1782,6 +1782,8 @@ nsLocalFile::Reveal()
|
|||
else
|
||||
/* Fallback to GnomeVFS */
|
||||
return gnomevfs->ShowURIForInput(mPath);
|
||||
} else if (giovfs && NS_SUCCEEDED(giovfs->OrgFreedesktopFileManager1ShowItems(mPath))) {
|
||||
return NS_OK;
|
||||
} else {
|
||||
nsCOMPtr<nsIFile> parentDir;
|
||||
nsAutoCString dirPath;
|
||||
|
|
|
@ -72,6 +72,9 @@ interface nsIGIOService : nsISupports
|
|||
/* Open the given URI in the default application */
|
||||
void showURI(in nsIURI uri);
|
||||
[noscript] void showURIForInput(in ACString uri);
|
||||
|
||||
/* Open path in file manager using org.freedesktop.FileManager1 interface */
|
||||
[noscript] void orgFreedesktopFileManager1ShowItems(in ACString path);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
Загрузка…
Ссылка в новой задаче