show RefCardAction if RefCard is available

This commit is contained in:
Gregory.Shrago
2014-06-10 23:44:15 +04:00
parent 32c0a96382
commit e08cded5f0
@@ -24,7 +24,8 @@ import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.NonNls;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -32,17 +33,15 @@ import java.io.File;
* @author Vladimir Kondratyev
*/
public class RefCardAction extends AnAction implements DumbAware {
@NonNls private static final String KEYMAP_URL = PathManager.getHomePath() + "/help/" + (SystemInfo.isMac ? "ReferenceCardForMac.pdf" : "ReferenceCard.pdf");
private static final String REF_CARD_PATH = PathManager.getHomePath() + "/help/" + (SystemInfo.isMac ? "ReferenceCardForMac.pdf" : "ReferenceCard.pdf");
public void actionPerformed(AnActionEvent e) {
final String url = KEYMAP_URL;
File file = new File(url);
File file = getRefCardFile();
if (file.isFile()) {
BrowserUtil.browse(file);
}
else {
final ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
String webUrl = SystemInfo.isMac ? appInfo.getMacKeymapUrl() : appInfo.getWinKeymapUrl();
String webUrl = getKeymapUrl();
if (webUrl != null) {
BrowserUtil.browse(webUrl);
}
@@ -50,8 +49,22 @@ public class RefCardAction extends AnAction implements DumbAware {
}
public void update(AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabledAndVisible(isRefCardAvailable());
boolean atWelcome = ActionPlaces.WELCOME_SCREEN.equals(e.getPlace());
e.getPresentation().setIcon(atWelcome ? AllIcons.General.DefaultKeymap : null);
}
private static boolean isRefCardAvailable() {
return getRefCardFile().exists() || getKeymapUrl() != null;
}
private static String getKeymapUrl() {
final ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
return SystemInfo.isMac ? appInfo.getMacKeymapUrl() : appInfo.getWinKeymapUrl();
}
@NotNull
private static File getRefCardFile() {
return new File(FileUtil.toSystemDependentName(REF_CARD_PATH));
}
}