diff --git a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInExplorerTarget.java b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInExplorerTarget.java index 85fd3cc026b6..9bad545b07cd 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInExplorerTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInExplorerTarget.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. @@ -19,9 +19,12 @@ import com.intellij.ide.SelectInContext; import com.intellij.ide.SelectInTarget; import com.intellij.ide.StandardTargetWeights; import com.intellij.ide.actions.RevealFileAction; +import com.intellij.ide.actions.ShowFilePathAction; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.vfs.VirtualFile; +import java.io.File; + /** * @author Roman.Chernyatchik */ @@ -35,9 +38,7 @@ public class ProjectViewSelectInExplorerTarget implements SelectInTarget, DumbAw @Override public void selectIn(final SelectInContext context, final boolean requestFocus) { final VirtualFile file = context.getVirtualFile(); - assert file != null; - - RevealFileAction.revealFile(file); + ShowFilePathAction.openFile(new File(file.getPresentableUrl())); } @Override diff --git a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java index 3daced89af04..a939c88f6204 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorageImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 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. @@ -142,7 +142,7 @@ public class ChangeListStorageImpl implements ChangeListStorage { } else { File file = new File(logFile); - ShowFilePathAction.open(file, new File(logFile)); + ShowFilePathAction.openFile(file); } } }), null); diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java index af9cb589f8e3..bc7140cd40f1 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -470,7 +470,7 @@ public abstract class HistoryDialog extends FrameW myModel.createPatch(p.getFileName(), p.isReversePatch()); showNotification(LocalHistoryBundle.message("message.patch.created")); - ShowFilePathAction.open(new File(p.getFileName()), null); + ShowFilePathAction.openFile(new File(p.getFileName())); } catch (VcsException e) { showError(message("message.error.during.create.patch", e)); @@ -481,7 +481,7 @@ public abstract class HistoryDialog extends FrameW } private File getDefaultPatchFile() { - return FileUtil.findSequentNonexistentFile(new File(myProject.getBaseDir().getPath()), "local_history", "patch"); + return FileUtil.findSequentNonexistentFile(new File(myProject.getBasePath()), "local_history", "patch"); } private boolean showAsDialog(CreatePatchConfigurationPanel p) { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java b/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java index 668b6182cd68..cbfaa06466b8 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/RevealFileAction.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. @@ -48,15 +48,10 @@ public class RevealFileAction extends DumbAwareAction { public void actionPerformed(AnActionEvent e) { final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); assert file != null; - revealFile(file); } - public static void revealFile(@NotNull final VirtualFile file) { - File ioFile = new File(file.getPresentableUrl()); - if (!ioFile.isDirectory()) { - ioFile = ioFile.getParentFile(); - } - ShowFilePathAction.open(ioFile, new File(file.getPresentableUrl())); + private static void revealFile(@NotNull final VirtualFile file) { + ShowFilePathAction.openFile(new File(file.getPresentableUrl())); } } 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 35e5a2fe2b8f..efac566b6deb 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java @@ -35,7 +35,6 @@ 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.Ref; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -147,22 +146,14 @@ public class ShowFilePathAction extends AnAction { @Override public PopupStep onChosen(final VirtualFile selectedValue, final boolean finalChoice) { - final Ref open = new Ref(); - final Ref toSelect = new Ref(); - final File selectedIoFile = new File(getPresentableUrl(selectedValue)); - if (files.indexOf(selectedValue) == 0 && files.size() > 1) { - open.set(new File(getPresentableUrl(files.get(1)))); - toSelect.set(selectedIoFile); + final File selectedFile = new File(getPresentableUrl(selectedValue)); + if (selectedFile.exists()) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + openFile(selectedFile); + } + }); } - else { - open.set(selectedIoFile); - } - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - public void run() { - if (!open.get().exists()) return; - open(open.get(), toSelect.get()); - } - }); return FINAL_CHOICE; } }; @@ -176,33 +167,73 @@ public class ShowFilePathAction extends AnAction { SystemInfo.hasXdgOpen || SystemInfo.isGnome || SystemInfo.isKDE; } + /** @deprecated use {@linkplain #openFile(java.io.File)} (to remove in IDEA 13) */ public static void open(@NotNull final File ioFile, @Nullable final File toSelect) { + openFile(toSelect != null && toSelect.exists() ? toSelect : ioFile); + } + + /** + * Shows system file manager with given file's parent directory open and the file highlighted in it
+ * (note that not all platforms support highlighting). + * + * @param file a file or directory to show and highlight in a file manager. + */ + public static void openFile(@NotNull final File file) { + if (!file.exists()) return; try { - final String path = (SystemInfo.isWindows || SystemInfo.isMac) && toSelect != null && toSelect.exists() ? - toSelect.getCanonicalPath() : ioFile.getCanonicalPath(); - doOpen(path); + doOpen(file.getParentFile(), file); } catch (Exception e) { LOG.warn(e); } } - private static void doOpen(@NotNull final String path) throws IOException, ExecutionException { + /** + * Shows system file manager with given directory open in it. + * + * @param directory a directory to show in a file manager. + */ + public static void openDirectory(@NotNull final File directory) { + if (!directory.isDirectory()) return; + try { + doOpen(directory, null); + } + catch (Exception e) { + LOG.warn(e); + } + } + + private static void doOpen(@NotNull final File dir, @Nullable final File toSelect) throws IOException, ExecutionException { if (SystemInfo.isWindows) { - new GeneralCommandLine("explorer", "/select,", path).createProcess(); + if (toSelect != null) { + new GeneralCommandLine("explorer", "/select,", toSelect.getCanonicalPath()).createProcess(); + } + else { + new GeneralCommandLine("explorer", "/root,", dir.getCanonicalPath()).createProcess(); + } return; } if (SystemInfo.isMac) { - final String script = String.format( - "tell application \"Finder\"\n" + - "\treveal {\"%s\"} as POSIX file\n" + - "\tactivate\n" + - "end tell", path); - new GeneralCommandLine(ExecUtil.getOsascriptPath(), "-e", script).createProcess(); + if (toSelect != null) { + final String script = String.format( + "tell application \"Finder\"\n" + + "\treveal {\"%s\"} as POSIX file\n" + + "\tactivate\n" + + "end tell", toSelect.getCanonicalPath()); + new GeneralCommandLine(ExecUtil.getOsascriptPath(), "-e", script).createProcess(); + } + else { + new GeneralCommandLine("open", dir.getCanonicalPath()).createProcess(); + } return; } + String path = dir.getCanonicalPath(); + if (!dir.isDirectory()) { + path = dir.getParentFile().getCanonicalPath(); + } + if (SystemInfo.hasXdgOpen) { new GeneralCommandLine("/usr/bin/xdg-open", path).createProcess(); } @@ -263,7 +294,7 @@ public class ShowFilePathAction extends AnAction { }; if (Messages.showOkCancelDialog(project, message, title, RevealFileAction.getActionName(), IdeBundle.message("action.close"), Messages.getInformationIcon(), option) == 0) { - open(file, file); + openFile(file); } return ref[0]; } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java index a9af13d51712..1c99f828dcf8 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowLogAction.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. @@ -31,9 +31,8 @@ import java.io.File; public class ShowLogAction extends AnAction implements DumbAware { @Override public void actionPerformed(AnActionEvent e) { - final String logPath = PathManager.getLogPath(); - final File logDir = new File(logPath, "idea.log"); - ShowFilePathAction.open(logDir.getParentFile(), logDir); + final File logFile = new File(PathManager.getLogPath(), "idea.log"); + ShowFilePathAction.openFile(logFile); } @Override @@ -47,5 +46,4 @@ public class ShowLogAction extends AnAction implements DumbAware { public static String getActionName() { return "Reveal Log in " + SystemInfo.nativeFileManagerName; } - } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java index ea4349f159c3..e11872c5a048 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.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. @@ -274,7 +274,7 @@ public class FileWatcher { notifyOnFailure("File watcher is not executable: " + execPath +"", new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - ShowFilePathAction.open(exec, exec); + ShowFilePathAction.openFile(exec); } }); return; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java index 2137173fe79a..fa00e90cb4f7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -208,7 +208,7 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr public void run() { final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); if (Boolean.TRUE.equals(configuration.SHOW_PATCH_IN_EXPLORER)) { - ShowFilePathAction.open(file, file); + ShowFilePathAction.openFile(file); } else if (Boolean.FALSE.equals(configuration.SHOW_PATCH_IN_EXPLORER)) { return; } else {