mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83028 (better defined behavior)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<T extends HistoryDialogModel> 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<T extends HistoryDialogModel> 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) {
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<File> open = new Ref<File>();
|
||||
final Ref<File> toSelect = new Ref<File>();
|
||||
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<br/>
|
||||
* (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];
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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: <a href=\"" + execPath + "\">" + execPath +"</a>", new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
|
||||
ShowFilePathAction.open(exec, exec);
|
||||
ShowFilePathAction.openFile(exec);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user