IDEA-97238 (use default file manager; encapsulate gory Nautilus details)

This commit is contained in:
Roman Shevchenko
2013-02-12 20:27:52 +01:00
parent 2465e0cfab
commit fefcc08e27
7 changed files with 74 additions and 36 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -41,7 +41,7 @@ public class RevealFileAction extends DumbAwareAction {
@NotNull
public static String getActionName() {
return SystemInfo.isMac ? "Reveal in Finder" : "Show in " + SystemInfo.getFileManagerName();
return SystemInfo.isMac ? "Reveal in Finder" : "Show in " + ShowFilePathAction.getFileManagerName();
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -35,9 +35,9 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
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.AtomicNotNullLazyValue;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -59,17 +59,51 @@ import java.util.regex.Pattern;
public class ShowFilePathAction extends AnAction {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.ShowFilePathAction");
private static NotNullLazyValue<Boolean> hasNautilusV3 = new NotNullLazyValue<Boolean>() {
private static NotNullLazyValue<Boolean> canUseNautilus = new NotNullLazyValue<Boolean>() {
@NotNull
@Override
protected Boolean compute() {
final String version = ExecUtil.execAndReadLine("nautilus", "--version");
if (!SystemInfo.isUnix || !SystemInfo.hasXdgMime() || !new File("/usr/bin/nautilus").canExecute()) {
return false;
}
String fileManager = ExecUtil.execAndReadLine("xdg-mime", "query", "default", "inode/directory");
if (fileManager == null || !fileManager.contains("nautilus.desktop")) return false;
String version = ExecUtil.execAndReadLine("nautilus", "--version");
if (version == null) return false;
final Matcher m = Pattern.compile("GNOME nautilus ([0-9.]+)").matcher(version);
Matcher m = Pattern.compile("GNOME nautilus ([0-9.]+)").matcher(version);
return m.find() && StringUtil.compareVersionNumbers(m.group(1), "3") >= 0;
}
};
private static final NotNullLazyValue<String> fileManagerName = new AtomicNotNullLazyValue<String>() {
@NotNull
@Override
protected String compute() {
if (SystemInfo.isMac) {
return "Finder";
}
if (SystemInfo.isWindows) {
return "Explorer";
}
if (SystemInfo.isUnix && SystemInfo.hasXdgMime()) {
String fileManager = ExecUtil.execAndReadLine("xdg-mime", "query", "default", "inode/directory");
if (fileManager != null) {
Matcher m = Pattern.compile("(.+)\\.desktop").matcher(fileManager);
if (m.find()) {
return StringUtil.capitalize(m.group(1));
}
}
}
return "File Manager";
}
};
@Override
public void update(final AnActionEvent e) {
if (SystemInfo.isMac || !isSupported()) {
@@ -180,7 +214,12 @@ public class ShowFilePathAction extends AnAction {
public static boolean isSupported() {
return SystemInfo.isWindows ||
Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN) ||
SystemInfo.hasXdgOpen() || SystemInfo.hasNautilus();
SystemInfo.hasXdgOpen() || canUseNautilus.getValue();
}
@NotNull
public static String getFileManagerName() {
return fileManagerName.getValue();
}
/** @deprecated use {@linkplain #openFile(java.io.File)} (to remove in IDEA 13) */
@@ -224,7 +263,7 @@ public class ShowFilePathAction extends AnAction {
}
}
private static void doOpen(@NotNull final File dir, @Nullable final File toSelect) throws IOException, ExecutionException {
private static void doOpen(@NotNull File dir, @Nullable File toSelect) throws IOException, ExecutionException {
if (SystemInfo.isWindows) {
String cmd;
if (toSelect != null) {
@@ -253,23 +292,15 @@ public class ShowFilePathAction extends AnAction {
return;
}
if (Registry.is("ide.use.nautilus3") && SystemInfo.hasNautilus() && hasNautilusV3.getValue()) {
if (toSelect != null) {
new GeneralCommandLine("nautilus", toSelect.getAbsolutePath()).createProcess();
}
else {
new GeneralCommandLine("nautilus", dir.getAbsolutePath()).createProcess();
}
if (canUseNautilus.getValue()) {
new GeneralCommandLine("nautilus", (toSelect != null ? toSelect : dir).getAbsolutePath()).createProcess();
return;
}
final String path = dir.getAbsolutePath();
String path = dir.getAbsolutePath();
if (SystemInfo.hasXdgOpen()) {
new GeneralCommandLine("/usr/bin/xdg-open", 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));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -44,6 +44,6 @@ public class ShowLogAction extends AnAction implements DumbAware {
@NotNull
public static String getActionName() {
return "Reveal Log in " + SystemInfo.getFileManagerName();
return SystemInfo.isMac ? "Reveal in Finder" : "Show in " + ShowFilePathAction.getFileManagerName();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.fileEditor.impl;
import com.intellij.ide.actions.ShowFilePathAction;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.actionSystem.Shortcut;
@@ -42,9 +43,7 @@ import com.intellij.ui.components.JBPanel;
import com.intellij.ui.docking.DockManager;
import com.intellij.ui.tabs.JBTabs;
import com.intellij.util.Alarm;
import com.intellij.util.IconUtil;
import com.intellij.util.PairFunction;
import com.intellij.util.PlatformUtils;
import com.intellij.util.containers.ArrayListSet;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
@@ -174,7 +173,7 @@ public class EditorsSplitters extends JBPanel {
painter.appendLine("Open a file by name with " + getActionShortcutText("GotoFile")).smaller().withBullet()
.appendLine("Open Recent files with " + getActionShortcutText("RecentFiles")).smaller().withBullet()
.appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")).smaller().withBullet()
.appendLine("Drag'n'Drop file(s) here from " + SystemInfo.getFileManagerName()).smaller().withBullet()
.appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName()).smaller().withBullet()
.draw(g, new PairFunction<Integer, Integer, Pair<Integer, Integer>>() {
@Override
public Pair<Integer, Integer> fun(Integer width, Integer height) {
@@ -238,10 +238,6 @@ enable.animation.on.dialogs=false
type.ahead.logging.enabled=false
fast.tree.expand.in.structure.view=false
ide.use.nautilus3=true
# suppress inspection "UnusedProperty"
ide.use.nautilus3.description=Use Nautilus (if available) for 'Show fine in %OS_file_manager_name%' actions.
ide.goto.implementation.show.interfaces=true
# suppress inspection "UnusedProperty"
ide.goto.implementation.show.interfaces.description=Whether to show sub-interfaces when invoking\
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -93,6 +93,17 @@ public class SystemInfo extends SystemInfoRt {
return ourHasXdgOpen.getValue();
}
private static final NotNullLazyValue<Boolean> ourHasXdgMime = new AtomicNotNullLazyValue<Boolean>() {
@NotNull
@Override
protected Boolean compute() {
return isUnix && new File("/usr/bin/xdg-mime").canExecute();
}
};
public static boolean hasXdgMime() {
return ourHasXdgOpen.getValue();
}
private static final NotNullLazyValue<Boolean> hasNautilus = new AtomicNotNullLazyValue<Boolean>() {
@NotNull
@Override
@@ -100,11 +111,12 @@ public class SystemInfo extends SystemInfoRt {
return isUnix && new File("/usr/bin/nautilus").canExecute();
}
};
/** @deprecated implementation details (to remove in IDEA 13) */
public static boolean hasNautilus() {
return hasNautilus.getValue();
}
/** @deprecated use {@linkplain #getFileManagerName()} (to remove in IDEA 13) */
/** @deprecated implementation details (to remove in IDEA 13) */
public static final String nativeFileManagerName = "File Manager";
private static final NotNullLazyValue<String> ourFileManagerName = new AtomicNotNullLazyValue<String>() {
@NotNull
@@ -112,11 +124,10 @@ public class SystemInfo extends SystemInfoRt {
protected String compute() {
return isMac ? "Finder" :
isWindows ? "Explorer" :
hasNautilus() ? "Nautilus" :
"File Manager";
}
};
@NotNull
/** @deprecated implementation details (to remove in IDEA 13) */
public static String getFileManagerName() {
return ourFileManagerName.getValue();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.configurable;
import com.intellij.ide.actions.ShowFilePathAction;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
@@ -96,7 +97,7 @@ public class VcsGeneralConfigurationPanel implements SearchableConfigurable {
myPromptsPanel.setSize(myPromptsPanel.getPreferredSize()); // todo check text!
myOnPatchCreation.setName((SystemInfo.isMac ? "Reveal patch in" : "Show patch in ") +
SystemInfo.getFileManagerName() + " after creation:");
ShowFilePathAction.getFileManagerName() + " after creation:");
}
public void apply() throws ConfigurationException {