summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/ide/actions
diff options
context:
space:
mode:
Diffstat (limited to 'platform/platform-impl/src/com/intellij/ide/actions')
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/BaseNavigateToSourceAction.java41
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java11
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java117
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java87
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java115
-rw-r--r--platform/platform-impl/src/com/intellij/ide/actions/ViewSourceAction.java12
6 files changed, 202 insertions, 181 deletions
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/BaseNavigateToSourceAction.java b/platform/platform-impl/src/com/intellij/ide/actions/BaseNavigateToSourceAction.java
index 1c7855d2eedb..709c3b458112 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/BaseNavigateToSourceAction.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/BaseNavigateToSourceAction.java
@@ -19,7 +19,9 @@ import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.pom.Navigatable;
import com.intellij.pom.NavigatableWithText;
+import com.intellij.pom.PomTargetPsiElement;
import com.intellij.util.OpenSourceUtil;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class BaseNavigateToSourceAction extends AnAction implements DumbAware {
@@ -37,7 +39,7 @@ public abstract class BaseNavigateToSourceAction extends AnAction implements Dum
public void update(AnActionEvent event) {
DataContext dataContext = event.getDataContext();
- final Navigatable target = getTarget(dataContext);
+ final Navigatable target = findTargetForUpdate(dataContext);
boolean enabled = target != null;
if (ActionPlaces.isPopupPlace(event.getPlace())) {
event.getPresentation().setVisible(enabled);
@@ -49,36 +51,21 @@ public abstract class BaseNavigateToSourceAction extends AnAction implements Dum
else {
event.getPresentation().setEnabled(enabled);
}
- if (target != null && target instanceof NavigatableWithText) {
- //as myFocusEditor is always ignored - Main Menu|View always contains 2 actions with the same name and actually same behaviour
- if (!myFocusEditor) {
- event.getPresentation().setVisible(false);
- return;
- }
- final String navigateActionText = ((NavigatableWithText)target).getNavigateActionText(myFocusEditor);
- if (navigateActionText != null) {
- event.getPresentation().setText(navigateActionText);
- }
- else {
- event.getPresentation().setText(getTemplatePresentation().getText());
- }
- }
- else {
- event.getPresentation().setText(getTemplatePresentation().getText());
- }
+ //as myFocusEditor is always ignored - Main Menu|View always contains 2 actions with the same name and actually same behaviour
+ event.getPresentation().setVisible(target == null || myFocusEditor);
+ String navigateActionText = myFocusEditor && target instanceof NavigatableWithText?
+ ((NavigatableWithText)target).getNavigateActionText(true) : null;
+ event.getPresentation().setText(navigateActionText == null ? getTemplatePresentation().getText() : navigateActionText);
}
@Nullable
- private Navigatable getTarget(final DataContext dataContext) {
- if (!myFocusEditor && CommonDataKeys.EDITOR.getData(dataContext) != null) {
- // makes no sense in editor and conflicts with another action there (ctrl+enter)
- return null;
- }
-
+ private Navigatable findTargetForUpdate(@NotNull DataContext dataContext) {
Navigatable[] navigatables = getNavigatables(dataContext);
- if (navigatables != null) {
- for (Navigatable navigatable : navigatables) {
- if (navigatable.canNavigate()) return navigatable;
+ if (navigatables == null) return null;
+
+ for (Navigatable navigatable : navigatables) {
+ if (navigatable.canNavigate()) {
+ return navigatable instanceof PomTargetPsiElement ? ((PomTargetPsiElement)navigatable).getTarget() : navigatable;
}
}
return null;
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java
index 9bdc5948cffe..136f4b166e1a 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java
@@ -23,6 +23,7 @@ import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationBundle;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -104,11 +105,15 @@ public class CreateDesktopEntryAction extends DumbAwareAction {
final String message = ApplicationBundle.message("desktop.entry.success",
ApplicationNamesInfo.getInstance().getProductName());
- Notifications.Bus.notify(
- new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop entry created", message, NotificationType.INFORMATION)
- );
+ if (ApplicationManager.getApplication() != null) {
+ Notifications.Bus
+ .notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Desktop entry created", message, NotificationType.INFORMATION));
+ }
}
catch (Exception e) {
+ if (ApplicationManager.getApplication() == null) {
+ throw new RuntimeException(e);
+ }
final String message = e.getMessage();
if (!StringUtil.isEmptyOrSpaces(message)) {
LOG.warn(e);
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java
index 4cabfe9b5fe9..37b09394dd89 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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,14 +19,14 @@ import com.intellij.ide.IdeBundle;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
-import com.intellij.openapi.fileChooser.FileElement;
+import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.fileChooser.PathChooserDialog;
import com.intellij.openapi.fileChooser.impl.FileChooserUtil;
import com.intellij.openapi.fileEditor.FileEditorManager;
+import com.intellij.openapi.fileEditor.FileEditorProvider;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
import com.intellij.openapi.fileTypes.FileType;
@@ -34,7 +34,6 @@ import com.intellij.openapi.fileTypes.ex.FileTypeChooser;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -47,54 +46,20 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
public class OpenFileAction extends AnAction implements DumbAware {
+ @Override
public void actionPerformed(AnActionEvent e) {
- @Nullable final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
+ final Project project = e.getProject();
final boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
+ final FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
+ descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, showFiles);
- final FileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true) {
- @Override
- public boolean isFileSelectable(VirtualFile file) {
- if (super.isFileSelectable(file)) {
- return true;
- }
- if (file.isDirectory()) {
- return false;
- }
- return showFiles && !FileElement.isArchive(file);
- }
-
- @Override
- public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
- if (!file.isDirectory() && isFileSelectable(file)) {
- if (!showHiddenFiles && FileElement.isFileHidden(file)) return false;
- return true;
- }
- return super.isFileVisible(file, showHiddenFiles);
- }
-
- @Override
- public boolean isChooseMultiple() {
- return showFiles;
- }
- };
- descriptor.setTitle(showFiles ? "Open File or Project" : "Open Project");
-
- VirtualFile userHomeDir = null;
- if (SystemInfo.isUnix) {
- userHomeDir = VfsUtil.getUserHomeDir();
- }
-
- descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, Boolean.TRUE);
-
- FileChooser.chooseFiles(descriptor, project, userHomeDir, new Consumer<List<VirtualFile>>() {
+ FileChooser.chooseFiles(descriptor, project, VfsUtil.getUserHomeDir(), new Consumer<List<VirtualFile>>() {
@Override
public void consume(final List<VirtualFile> files) {
for (VirtualFile file : files) {
- if (!descriptor.isFileSelectable(file)) { // on Mac, it could be selected anyway
- Messages.showInfoMessage(project,
- file.getPresentableUrl() + " contains no " +
- ApplicationNamesInfo.getInstance().getFullProductName() + " project",
- "Cannot Open Project");
+ if (!descriptor.isFileSelectable(file)) {
+ String message = IdeBundle.message("error.dir.contains.no.project", file.getPresentableUrl());
+ Messages.showInfoMessage(project, message, IdeBundle.message("title.cannot.open.project"));
return;
}
}
@@ -103,9 +68,8 @@ public class OpenFileAction extends AnAction implements DumbAware {
});
}
- private static void doOpenFile(@Nullable final Project project,
- @NotNull final List<VirtualFile> result) {
- for (final VirtualFile file : result) {
+ private static void doOpenFile(@Nullable Project project, @NotNull List<VirtualFile> result) {
+ for (VirtualFile file : result) {
if (file.isDirectory()) {
Project openedProject;
if (ProjectAttachProcessor.canAttachToProject()) {
@@ -118,9 +82,8 @@ public class OpenFileAction extends AnAction implements DumbAware {
return;
}
- if (OpenProjectFileChooserDescriptor.isProjectFile(file) &&
- // if the ipr-based project is already open, just open the ipr file
- (project == null || !file.equals(project.getProjectFile()))) {
+ // try to open as a project - unless the file is an .ipr of the current one
+ if ((project == null || !file.equals(project.getProjectFile())) && OpenProjectFileChooserDescriptor.isProjectFile(file)) {
Project openedProject = ProjectUtil.openOrImport(file.getPath(), project, false);
if (openedProject != null) {
FileChooserUtil.setLastOpenedFile(openedProject, file);
@@ -143,26 +106,54 @@ public class OpenFileAction extends AnAction implements DumbAware {
}
}
- public static void openFile(final String filePath, final Project project) {
- final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(filePath);
+ public static void openFile(String filePath, @NotNull Project project) {
+ VirtualFile file = LocalFileSystem.getInstance().findFileByPath(filePath);
if (file != null && file.isValid()) {
openFile(file, project);
}
}
- public static void openFile(final VirtualFile virtualFile, final Project project) {
- FileEditorProviderManager editorProviderManager = FileEditorProviderManager.getInstance();
- if (editorProviderManager.getProviders(project, virtualFile).length == 0) {
- Messages.showMessageDialog(project,
- IdeBundle.message("error.files.of.this.type.cannot.be.opened",
- ApplicationNamesInfo.getInstance().getProductName()),
- IdeBundle.message("title.cannot.open.file"),
- Messages.getErrorIcon());
+ public static void openFile(VirtualFile file, @NotNull Project project) {
+ FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(project, file);
+ if (providers.length == 0) {
+ String message = IdeBundle.message("error.files.of.this.type.cannot.be.opened", ApplicationNamesInfo.getInstance().getProductName());
+ Messages.showErrorDialog(project, message, IdeBundle.message("title.cannot.open.file"));
return;
}
- OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
+ OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
+ private static class ProjectOnlyFileChooserDescriptor extends OpenProjectFileChooserDescriptor {
+ public ProjectOnlyFileChooserDescriptor() {
+ super(true);
+ setTitle(IdeBundle.message("title.open.project"));
+ }
+ }
+
+ // vanilla OpenProjectFileChooserDescriptor only accepts project files; this on is overridden to accept any files
+ private static class ProjectOrFileChooserDescriptor extends OpenProjectFileChooserDescriptor {
+ private final FileChooserDescriptor myStandardDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
+
+ public ProjectOrFileChooserDescriptor() {
+ super(true);
+ setTitle(IdeBundle.message("title.open.file.or.project"));
+ }
+
+ @Override
+ public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
+ return file.isDirectory() ? super.isFileVisible(file, showHiddenFiles) : myStandardDescriptor.isFileVisible(file, showHiddenFiles);
+ }
+
+ @Override
+ public boolean isFileSelectable(VirtualFile file) {
+ return file.isDirectory() ? super.isFileSelectable(file) : myStandardDescriptor.isFileSelectable(file);
+ }
+
+ @Override
+ public boolean isChooseMultiple() {
+ return true;
+ }
+ }
}
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java
index 51d6362b36d8..b462fcbc11ad 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenProjectFileChooserDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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,74 +15,91 @@
*/
package com.intellij.ide.actions;
-import com.intellij.icons.AllIcons;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
-import com.intellij.openapi.fileChooser.FileElement;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
+import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.projectImport.ProjectOpenProcessor;
-import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
import javax.swing.*;
+/**
+ * Intended for use in actions related to opening or importing existing projects.
+ * <strong>Due to a high I/O impact SHOULD NOT be used in any other cases.</strong>
+ */
public class OpenProjectFileChooserDescriptor extends FileChooserDescriptor {
private static final Icon ourProjectIcon = IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
- public OpenProjectFileChooserDescriptor(final boolean chooseFiles) {
+ public OpenProjectFileChooserDescriptor(boolean chooseFiles) {
super(chooseFiles, true, chooseFiles, chooseFiles, false, false);
}
- public boolean isFileSelectable(final VirtualFile file) {
- if (file == null) return false;
+ @Override
+ public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
+ return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || isProjectFile(file));
+ }
+
+ @Override
+ public boolean isFileSelectable(VirtualFile file) {
return isProjectDirectory(file) || isProjectFile(file);
}
- public Icon getIcon(final VirtualFile file) {
- if (isProjectDirectory(file)) {
- return dressIcon(file, ourProjectIcon);
- }
- final Icon icon = getImporterIcon(file);
- if (icon != null) {
- return dressIcon(file, icon);
+ @Override
+ public Icon getIcon(VirtualFile file) {
+ if (canInspectDirectory(file)) {
+ if (isIprFile(file) || isIdeaDirectory(file)) {
+ return dressIcon(file, ourProjectIcon);
+ }
+ Icon icon = getImporterIcon(file);
+ if (icon != null) {
+ return dressIcon(file, icon);
+ }
}
return super.getIcon(file);
}
- @Nullable
- private static Icon getImporterIcon(final VirtualFile virtualFile) {
- final ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(virtualFile);
+ private static boolean canInspectDirectory(VirtualFile file) {
+ if (file.getParent() == null) return false;
+
+ VirtualFile home = VfsUtil.getUserHomeDir();
+ if (home == null) return false; // unnatural situation
+ VirtualFile homes = home.getParent();
+ if (homes == null) return false; // another one
+ if (homes.equals(file.getParent()) || VfsUtilCore.isAncestor(file, homes, false)) return false;
+
+ return true;
+ }
+
+ private static Icon getImporterIcon(VirtualFile file) {
+ ProjectOpenProcessor provider = ProjectOpenProcessor.getImportProvider(file);
if (provider != null) {
- return virtualFile.isDirectory() && provider.lookForProjectsInDirectory() ? AllIcons.Nodes.IdeaModule : provider.getIcon(virtualFile);
+ return file.isDirectory() && provider.lookForProjectsInDirectory() ? ourProjectIcon : provider.getIcon(file);
}
return null;
}
- public boolean isFileVisible(final VirtualFile file, final boolean showHiddenFiles) {
- if (!showHiddenFiles && FileElement.isFileHidden(file)) return false;
- return isProjectFile(file) || super.isFileVisible(file, showHiddenFiles) && file.isDirectory();
+ public static boolean isProjectFile(@NotNull VirtualFile file) {
+ return !file.isDirectory() && file.isValid() && (isIprFile(file) || hasImportProvider(file));
}
- public static boolean isProjectFile(final VirtualFile file) {
- if (isIprFile(file)) return true;
- final ProjectOpenProcessor importProvider = ProjectOpenProcessor.getImportProvider(file);
- return importProvider != null;
+ private static boolean isProjectDirectory(@NotNull VirtualFile file) {
+ return file.isDirectory() && file.isValid() && (isIdeaDirectory(file) || hasImportProvider(file));
}
private static boolean isIprFile(VirtualFile file) {
- if ((!file.isDirectory() && file.getName().toLowerCase().endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION))) {
- return true;
- }
- return false;
+ return ProjectFileType.DEFAULT_EXTENSION.equalsIgnoreCase(file.getExtension());
+ }
+
+ private static boolean isIdeaDirectory(VirtualFile file) {
+ return file.findChild(Project.DIRECTORY_STORE_FOLDER) != null;
}
- private static boolean isProjectDirectory(final VirtualFile virtualFile) {
- // the root directory of any drive is never an IDEA project
- if (virtualFile.getParent() == null) return false;
- // NOTE: For performance reasons, it's very important not to iterate through all of the children here.
- if (virtualFile.isDirectory() && virtualFile.isValid() && virtualFile.findChild(Project.DIRECTORY_STORE_FOLDER) != null) return true;
- return false;
+ private static boolean hasImportProvider(VirtualFile file) {
+ return ProjectOpenProcessor.getImportProvider(file) != null;
}
}
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java
index 4df11f7261ca..2c5cc5b02282 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowSettingsUtilImpl.java
@@ -15,23 +15,20 @@
*/
package com.intellij.ide.actions;
+import com.intellij.ide.ui.search.SearchUtil;
+import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.options.Configurable;
-import com.intellij.openapi.options.ConfigurableGroup;
-import com.intellij.openapi.options.SearchableConfigurable;
-import com.intellij.openapi.options.ShowSettingsUtil;
-import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil;
-import com.intellij.openapi.options.ex.IdeConfigurablesGroup;
-import com.intellij.openapi.options.ex.MixedConfigurableGroup;
-import com.intellij.openapi.options.ex.ProjectConfigurablesGroup;
-import com.intellij.openapi.options.ex.SingleConfigurableEditor;
+import com.intellij.openapi.options.*;
+import com.intellij.openapi.options.ex.*;
+import com.intellij.openapi.options.newEditor.IdeSettingsDialog;
import com.intellij.openapi.options.newEditor.OptionsEditor;
import com.intellij.openapi.options.newEditor.OptionsEditorDialog;
-import com.intellij.openapi.options.newEditor.PreferencesDialog;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.registry.Registry;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.ui.navigation.Place;
import com.intellij.util.ui.update.Activatable;
import com.intellij.util.ui.update.UiNotifyConnector;
import org.jetbrains.annotations.NotNull;
@@ -47,7 +44,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
public class ShowSettingsUtilImpl extends ShowSettingsUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.ShowSettingsUtilImpl");
- private AtomicBoolean myShown = new AtomicBoolean(false);
+ private final AtomicBoolean myShown = new AtomicBoolean(false);
@NotNull
private static Project getProject(@Nullable Project project) {
@@ -55,12 +52,16 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
}
@NotNull
- private static DialogWrapper getDialog(@Nullable Project project, @NotNull ConfigurableGroup[] groups, @Nullable Configurable toSelect) {
+ public static DialogWrapper getDialog(@Nullable Project project, @NotNull ConfigurableGroup[] groups, @Nullable Configurable toSelect) {
+ project = getProject(project);
+ final ConfigurableGroup[] filteredGroups = filterEmptyGroups(groups);
+ if (Registry.is("ide.new.settings.dialog")) {
+ return new IdeSettingsDialog(project, filteredGroups, toSelect);
+ }
+ //noinspection deprecation
return Registry.is("ide.perProjectModality")
- ? new OptionsEditorDialog(getProject(project), filterEmptyGroups(groups), toSelect, true)
- : Registry.is("ide.new.preferences")
- ? new PreferencesDialog(getProject(project), filterEmptyGroups(groups))
- : new OptionsEditorDialog(getProject(project), filterEmptyGroups(groups), toSelect);
+ ? new OptionsEditorDialog(project, filteredGroups, toSelect, true)
+ : new OptionsEditorDialog(project, filteredGroups, toSelect);
}
@NotNull
@@ -73,7 +74,7 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
new ProjectConfigurablesGroup(project),
new IdeConfigurablesGroup()};
- return Registry.is("ide.file.settings.order.new")
+ return Registry.is("ide.new.settings.dialog")
? MixedConfigurableGroup.getGroups(getConfigurables(groups, true))
: groups;
}
@@ -139,41 +140,34 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
@Override
public void showSettingsDialog(@Nullable final Project project, @NotNull final String nameToSelect) {
- ConfigurableGroup[] group = getConfigurableGroups(project, true);
-
+ ConfigurableGroup[] groups = getConfigurableGroups(project, true);
Project actualProject = getProject(project);
- group = filterEmptyGroups(group);
+ groups = filterEmptyGroups(groups);
+ getDialog(actualProject, groups, findPreselectedByDisplayName(nameToSelect, groups)).show();
+ }
- OptionsEditorDialog dialog;
- if (Registry.is("ide.perProjectModality")) {
- dialog = new OptionsEditorDialog(actualProject, group, nameToSelect, true);
- }
- else {
- dialog = new OptionsEditorDialog(actualProject, group, nameToSelect);
+ @Nullable
+ private static Configurable findPreselectedByDisplayName(final String preselectedConfigurableDisplayName, ConfigurableGroup[] groups) {
+ final List<Configurable> all = SearchUtil.expand(groups);
+ for (Configurable each : all) {
+ if (preselectedConfigurableDisplayName.equals(each.getDisplayName())) return each;
}
- dialog.show();
+ return null;
}
public static void showSettingsDialog(@Nullable Project project, final String id2Select, final String filter) {
ConfigurableGroup[] group = getConfigurableGroups(project, true);
- Project actualProject = getProject(project);
-
group = filterEmptyGroups(group);
final Configurable configurable2Select = findConfigurable2Select(id2Select, group);
- final OptionsEditorDialog dialog;
- if (Registry.is("ide.perProjectModality")) {
- dialog = new OptionsEditorDialog(actualProject, group, configurable2Select, true);
- } else {
- dialog = new OptionsEditorDialog(actualProject, group, configurable2Select);
- }
+ final DialogWrapper dialog = getDialog(project, group, configurable2Select);
new UiNotifyConnector.Once(dialog.getContentPane(), new Activatable.Adapter() {
@Override
public void showNotify() {
- final OptionsEditor editor = (OptionsEditor)dialog.getData(OptionsEditor.KEY.getName());
+ final OptionsEditor editor = (OptionsEditor)((DataProvider)dialog).getData(OptionsEditor.KEY.getName());
LOG.assertTrue(editor != null);
editor.select(configurable2Select, filter);
}
@@ -234,37 +228,53 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
@Override
public <T extends Configurable> T findProjectConfigurable(final Project project, final Class<T> confClass) {
+ //noinspection deprecation
return ConfigurableExtensionPointUtil.findProjectConfigurable(project, confClass);
}
@Override
public boolean editConfigurable(Project project, String dimensionServiceKey, @NotNull Configurable configurable) {
- return editConfigurable(null, project, configurable, dimensionServiceKey, null);
+ return editConfigurable(project, dimensionServiceKey, configurable, isWorthToShowApplyButton(configurable));
+ }
+
+ private static boolean isWorthToShowApplyButton(@NotNull Configurable configurable) {
+ return configurable instanceof Place.Navigator ||
+ configurable instanceof Composite ||
+ configurable instanceof TabbedConfigurable;
+ }
+
+ @Override
+ public boolean editConfigurable(Project project, String dimensionServiceKey, @NotNull Configurable configurable, boolean showApplyButton) {
+ return editConfigurable(null, project, configurable, dimensionServiceKey, null, showApplyButton);
}
@Override
public boolean editConfigurable(Project project, Configurable configurable, Runnable advancedInitialization) {
- return editConfigurable(null, project, configurable, createDimensionKey(configurable), advancedInitialization);
+ return editConfigurable(null, project, configurable, createDimensionKey(configurable), advancedInitialization, isWorthToShowApplyButton(configurable));
}
@Override
- public boolean editConfigurable(Component parent, Configurable configurable) {
+ public boolean editConfigurable(@Nullable Component parent, @NotNull Configurable configurable) {
return editConfigurable(parent, configurable, null);
}
@Override
- public boolean editConfigurable(final Component parent, final Configurable configurable, @Nullable final Runnable advancedInitialization) {
- return editConfigurable(parent, null, configurable, createDimensionKey(configurable), advancedInitialization);
+ public boolean editConfigurable(@Nullable Component parent, @NotNull Configurable configurable, @Nullable Runnable advancedInitialization) {
+ return editConfigurable(parent, null, configurable, createDimensionKey(configurable), advancedInitialization, isWorthToShowApplyButton(configurable));
}
- private static boolean editConfigurable(final @Nullable Component parent, @Nullable Project project, final Configurable configurable, final String dimensionKey,
- @Nullable final Runnable advancedInitialization) {
- SingleConfigurableEditor editor;
- if (parent != null) {
- editor = new SingleConfigurableEditor(parent, configurable, dimensionKey);
+ private static boolean editConfigurable(@Nullable Component parent,
+ @Nullable Project project,
+ @NotNull Configurable configurable,
+ String dimensionKey,
+ @Nullable final Runnable advancedInitialization,
+ boolean showApplyButton) {
+ final SingleConfigurableEditor editor;
+ if (parent == null) {
+ editor = new SingleConfigurableEditor(project, configurable, dimensionKey, showApplyButton);
}
else {
- editor = new SingleConfigurableEditor(project, configurable, dimensionKey);
+ editor = new SingleConfigurableEditor(parent, configurable, dimensionKey, showApplyButton);
}
if (advancedInitialization != null) {
new UiNotifyConnector.Once(editor.getContentPane(), new Activatable.Adapter() {
@@ -278,15 +288,14 @@ public class ShowSettingsUtilImpl extends ShowSettingsUtil {
return editor.isOK();
}
- public static String createDimensionKey(Configurable configurable) {
- String displayName = configurable.getDisplayName();
- displayName = displayName.replaceAll("\n", "_").replaceAll(" ", "_");
- return "#" + displayName;
+ @NotNull
+ public static String createDimensionKey(@NotNull Configurable configurable) {
+ return '#' + StringUtil.replaceChar(StringUtil.replaceChar(configurable.getDisplayName(), '\n', '_'), ' ', '_');
}
@Override
- public boolean editConfigurable(Component parent, String dimensionServiceKey,Configurable configurable) {
- return editConfigurable(parent, null, configurable, dimensionServiceKey, null);
+ public boolean editConfigurable(Component parent, String dimensionServiceKey, Configurable configurable) {
+ return editConfigurable(parent, null, configurable, dimensionServiceKey, null, isWorthToShowApplyButton(configurable));
}
public boolean isAlreadyShown() {
diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ViewSourceAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ViewSourceAction.java
index a9461422f747..825db992b218 100644
--- a/platform/platform-impl/src/com/intellij/ide/actions/ViewSourceAction.java
+++ b/platform/platform-impl/src/com/intellij/ide/actions/ViewSourceAction.java
@@ -17,9 +17,21 @@
package com.intellij.ide.actions;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.CommonDataKeys;
public class ViewSourceAction extends BaseNavigateToSourceAction {
public ViewSourceAction() {
super(false);
}
+
+ @Override
+ public void update(AnActionEvent e) {
+ if (CommonDataKeys.EDITOR.getData(e.getDataContext()) != null) {
+ e.getPresentation().setEnabledAndVisible(false);
+ }
+ else {
+ super.update(e);
+ }
+ }
}