diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index 27aaaa83e498..f753d2500923 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,11 +101,25 @@ public class ExecUtil { CapturingProcessHandler processHandler = new CapturingProcessHandler(process); return processHandler.runProcess(); } - + + @Nullable + public static String execAndReadLine(@NotNull final List command) { + try { + final ProcessOutput output = execAndGetOutput(command, null); + final List lines = output.getStdoutLines(); + if (lines.size() > 0) { + return lines.get(0); + } + } + catch (Exception ignored) { } + return null; + } + public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt) throws IOException, ExecutionException, ScriptException, InterruptedException { return sudoAndGetOutput(scriptPath, prompt, null); } + public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, @NotNull final String prompt, @Nullable String workDir) throws IOException, ExecutionException, ScriptException, InterruptedException { if (SystemInfo.isMac) { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java index efac566b6deb..c7a065c40589 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java @@ -36,6 +36,7 @@ import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.awt.RelativePoint; @@ -50,6 +51,7 @@ import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; public class ShowFilePathAction extends AnAction { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.ShowFilePathAction"); @@ -164,7 +166,7 @@ public class ShowFilePathAction extends AnAction { public static boolean isSupported() { return SystemInfo.isWindows || Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN) || - SystemInfo.hasXdgOpen || SystemInfo.isGnome || SystemInfo.isKDE; + SystemInfo.hasXdgOpen || SystemInfo.hasNautilus; } /** @deprecated use {@linkplain #openFile(java.io.File)} (to remove in IDEA 13) */ @@ -229,19 +231,22 @@ public class ShowFilePathAction extends AnAction { return; } - String path = dir.getCanonicalPath(); - if (!dir.isDirectory()) { - path = dir.getParentFile().getCanonicalPath(); + if (Registry.is("ide.use.nautilus3") && SystemInfo.hasNautilus && hasNautilusV3()) { + if (toSelect != null) { + new GeneralCommandLine("nautilus", toSelect.getCanonicalPath()).createProcess(); + } + else { + new GeneralCommandLine("nautilus", dir.getCanonicalPath()).createProcess(); + } + return; } + final String path = dir.getCanonicalPath(); if (SystemInfo.hasXdgOpen) { new GeneralCommandLine("/usr/bin/xdg-open", path).createProcess(); } - else if (SystemInfo.isGnome) { - new GeneralCommandLine("gnome-open", path).createProcess(); - } - else if (SystemInfo.isKDE) { - new GeneralCommandLine("kfmclient", "exec", path).createProcess(); + else if (SystemInfo.hasNautilus) { + new GeneralCommandLine("nautilus", path).createProcess(); } else if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { Desktop.getDesktop().open(new File(path)); @@ -251,6 +256,16 @@ public class ShowFilePathAction extends AnAction { } } + private static Boolean hasNautilusV3 = null; + + private static boolean hasNautilusV3() { + if (hasNautilusV3 == null) { + final String version = ExecUtil.execAndReadLine(Arrays.asList("nautilus", "--version")); + hasNautilusV3 = version != null && version.startsWith("GNOME nautilus 3"); + } + return hasNautilusV3; + } + @Nullable private static VirtualFile getFile(final AnActionEvent e) { return PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index bef41869798c..8ea41c1133c1 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -203,3 +203,6 @@ type.ahead.logging.enabled=false fast.tree.expand.in.structure.view=false python.exported.names.local.cache=false + +ide.use.nautilus3=true +ide.use.nautilus3.description=Use Nautilus if available diff --git a/platform/util/src/com/intellij/openapi/util/SystemInfo.java b/platform/util/src/com/intellij/openapi/util/SystemInfo.java index 10c7490d2cf7..c62c32b6a71e 100644 --- a/platform/util/src/com/intellij/openapi/util/SystemInfo.java +++ b/platform/util/src/com/intellij/openapi/util/SystemInfo.java @@ -51,6 +51,7 @@ public class SystemInfo extends SystemInfoRt { public static final boolean isKDE = _SUN_DESKTOP.contains("kde"); public static final boolean isGnome = _SUN_DESKTOP.contains("gnome"); + public static final boolean hasNautilus = isUnix && new File("/usr/bin/nautilus").canExecute(); public static final boolean hasXdgOpen = isUnix && new File("/usr/bin/xdg-open").canExecute(); public static final boolean isMacSystemMenu = isMac && "true".equals(System.getProperty("apple.laf.useScreenMenuBar")); @@ -65,9 +66,8 @@ public class SystemInfo extends SystemInfoRt { public static final boolean isMacIntel64 = isMac && "x86_64".equals(OS_ARCH); public static final String nativeFileManagerName = isMac ? "Finder" : - isGnome ? "Nautilus" : - isKDE ? "Konqueror" : isWindows ? "Explorer" : + hasNautilus ? "Nautilus" : "File Manager"; /**