Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Rustam.Vishnyakov
2010-09-01 19:27:50 +04:00
78 changed files with 1103 additions and 120 deletions
@@ -24,6 +24,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.file.JavaDirectoryServiceImpl;
import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
import com.intellij.refactoring.JavaRefactoringSettings;
import com.intellij.refactoring.RefactoringBundle;
@@ -33,6 +34,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.openapi.project.Project;
import com.intellij.refactoring.util.RadioUpDownListener;
import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.Nullable;
@@ -294,4 +296,17 @@ public class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate {
}
return false;
}
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
if (target instanceof PsiDirectory && source instanceof PsiClass) {
try {
JavaDirectoryServiceImpl.checkCreateClassOrInterface((PsiDirectory)target, ((PsiClass)source).getName());
}
catch (IncorrectOperationException e) {
return true;
}
}
return super.isMoveRedundant(source, target);
}
}
@@ -15,11 +15,20 @@
*/
package com.intellij.refactoring.move.moveFilesOrDirectories;
import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.impl.file.JavaDirectoryServiceImpl;
import com.intellij.refactoring.copy.JavaCopyFilesOrDirectoriesHandler;
import com.intellij.refactoring.move.MoveCallback;
import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public class JavaMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHandler {
@Override
@@ -55,7 +64,70 @@ public class JavaMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHan
}
@Override
public void doMove(Project project, PsiElement[] elements, PsiElement targetContainer, MoveCallback callback) {
super.doMove(project, elements, targetContainer, callback);
public void doMove(final Project project, PsiElement[] elements, PsiElement targetContainer, MoveCallback callback) {
MoveFilesOrDirectoriesUtil
.doMove(project, elements, new PsiElement[]{targetContainer}, callback, new Function<PsiElement[], PsiElement[]>() {
@Override
public PsiElement[] fun(final PsiElement[] elements) {
return new WriteCommandAction<PsiElement[]>(project, "Regrouping ...") {
@Override
protected void run(Result<PsiElement[]> result) throws Throwable {
final List<PsiElement> adjustedElements = new ArrayList<PsiElement>();
for (PsiElement element : elements) {
if (element instanceof PsiClass) {
final PsiFile containingFile = obtainContainingFile(element, elements);
if (containingFile != null && !adjustedElements.contains(containingFile)) {
adjustedElements.add(containingFile);
}
}
else {
adjustedElements.add(element);
}
}
result.setResult(adjustedElements.toArray(new PsiElement[adjustedElements.size()]));
}
}.execute().getResultObject();
}
});
}
@Nullable
private static PsiFile obtainContainingFile(PsiElement element, PsiElement[] elements) {
final PsiClass[] classes = ((PsiClassOwner)element.getParent()).getClasses();
final Set<PsiClass> nonMovedClasses = new HashSet<PsiClass>();
for (PsiClass aClass : classes) {
if (ArrayUtil.find(elements, aClass) < 0) {
nonMovedClasses.add(aClass);
}
}
final PsiFile containingFile = element.getContainingFile();
if (nonMovedClasses.isEmpty()) {
return containingFile;
}
else {
final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
if (containingDirectory != null) {
try {
JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName());
final PsiElement createdClass = containingDirectory.add(element);
element.delete();
return createdClass.getContainingFile();
}
catch (IncorrectOperationException e) {
final Iterator<PsiClass> iterator = nonMovedClasses.iterator();
final PsiClass nonMovedClass = iterator.next();
final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile();
nonMovedClass.delete();
while (iterator.hasNext()) {
final PsiClass currentClass = iterator.next();
createdFile.add(currentClass);
currentClass.delete();
}
return containingFile;
}
}
}
return null;
}
}
@@ -0,0 +1,2 @@
package d;
public class MyClass{}
@@ -0,0 +1,5 @@
package d;
public class MyClass{}
class Second{}
@@ -0,0 +1,5 @@
package t;
class MyClass{}
class MyOneMoreClass{}
@@ -0,0 +1,3 @@
package s;
class MyClass{}
class MyOneMoreClass{}
@@ -0,0 +1,3 @@
package s;
class MyLocal{}
@@ -0,0 +1,2 @@
package t;
public class MyClass{}
@@ -0,0 +1,3 @@
package s;
public class MyClass{}
class MyLocal{}
@@ -0,0 +1,2 @@
package s;
public class MyClass{}
@@ -0,0 +1,3 @@
package t;
class MyLocal{}
@@ -0,0 +1,3 @@
package s;
public class MyClass{}
class MyLocal{}
@@ -0,0 +1,52 @@
package com.intellij.refactoring;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.refactoring.move.MoveHandler;
import com.intellij.testFramework.PsiTestUtil;
import org.jetbrains.annotations.Nullable;
/**
* User: anna
* Date: Aug 31, 2010
*/
public class DndMoveTest extends CodeInsightTestCase {
protected String getTestRoot() {
return "/refactoring/dndMove/";
}
public void testPublicJavaClass() throws Exception {
doTest("d", new Computable<PsiElement>() {
@Nullable
@Override
public PsiElement compute() {
return JavaPsiFacade.getInstance(getProject()).findClass("d.MyClass");
}
}, true);
}
public void testSecondJavaClass() throws Exception {
doTest("d", new Computable<PsiElement>() {
@Nullable
@Override
public PsiElement compute() {
return JavaPsiFacade.getInstance(getProject()).findClass("d.Second");
}
}, false);
}
private void doTest(final String targetDirName, final Computable<PsiElement> source, final boolean expected) throws Exception {
String testName = getTestName(true);
String root = getTestDataPath() + getTestRoot() + testName;
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);
PsiTestUtil.addSourceContentToRoots(myModule, rootDir);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final VirtualFile child1 = rootDir.findChild(targetDirName);
assertNotNull("File " + targetDirName + " not found", child1);
final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1);
assertEquals(expected, MoveHandler.isMoveRedundant(source.compute(), targetDirectory));
}
}
@@ -0,0 +1,86 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.refactoring;
/**
* User: anna
* Date: Aug 31, 2010
*/
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.refactoring.move.moveFilesOrDirectories.JavaMoveFilesOrDirectoriesHandler;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PsiTestUtil;
import java.io.File;
public class MoveClassAndFileTest extends CodeInsightTestCase {
public void testAllClassesInFile() throws Exception {
doTest("allClassesInFile", "t", "txt2move.txt", "s.MyClass", "s.MyOneMoreClass");
}
public void testOnlyPackageLocalClass() throws Exception {
doTest("onlyPackageLocalClass", "t", "txt2move.txt", "s.MyLocal");
}
public void testLeavePackageLocalClass() throws Exception {
doTest("leavePackageLocalClass", "t", "txt2move.txt", "s.MyClass");
}
private void doTest(String testName, String newPackageName, String fileNameNearFirstClass, String... classNames) throws Exception {
String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassAndFile/" + testName;
String rootBefore = root + "/before";
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
performAction(newPackageName, fileNameNearFirstClass, classNames);
String rootAfter = root + "/after";
VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER);
}
private void performAction(String newPackageName, String fileName, String... classNames) throws Exception{
final PsiElement[] elements = new PsiElement[classNames.length + 1];
for(int i = 0; i < classNames.length; i++){
String className = classNames[i];
elements[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject()));
assertNotNull("Class " + className + " not found", elements[i]);
}
elements[classNames.length] = elements[0].getContainingFile().getContainingDirectory().findFile(fileName);
PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
assertNotNull("Package " + newPackageName + " not found", aPackage);
final PsiDirectory[] dirs = aPackage.getDirectories();
assertEquals(dirs.length, 1);
new JavaMoveFilesOrDirectoriesHandler().doMove(getProject(), elements, dirs[0], null);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
FileDocumentManager.getInstance().saveAllDocuments();
}
}
@@ -182,8 +182,4 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements
}
}
public boolean needAdditionalConsole() {
return true;
}
}
@@ -16,20 +16,19 @@
package com.intellij.application.options.colors;
import com.intellij.ide.DataManager;
import com.intellij.ide.util.scopeChooser.EditScopesDialog;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.options.newEditor.OptionsEditor;
import com.intellij.ide.DataManager;
import com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class ScopeColorsPageFactory implements ColorAndFontPanelFactory {
public NewColorAndFontPanel createPanel(ColorAndFontOptions options) {
@@ -72,9 +71,7 @@ class ScopeColorsPageFactory implements ColorAndFontPanelFactory {
final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext());
if (optionsEditor != null) {
try {
final ScopeChooserConfigurable projectConfigurable =
ShowSettingsUtil.getInstance().findProjectConfigurable(project, ScopeChooserConfigurable.class);
optionsEditor.select(projectConfigurable);
optionsEditor.select(ScopeChooserConfigurable.class);
} catch (IllegalStateException ex) {
EditScopesDialog.editConfigurable(project, null);
}
@@ -39,7 +39,6 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.event.*;
import com.intellij.openapi.editor.ex.EditorEventMulticasterEx;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapHelper;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -315,26 +314,27 @@ public class DaemonListeners implements Disposable {
if (LOG.isDebugEnabled()) {
LOG.debug("cancelling code highlighting by write action:" + action);
}
if (containsDocumentWorthBothering(action)) {
stopDaemon(false);
}
}
private boolean containsDocumentWorthBothering(Object action) {
if (action instanceof DocumentRunnable) {
if (action instanceof DocumentRunnable.IgnoreDocumentRunnable) return false;
Document document = ((DocumentRunnable)action).getDocument();
if (!worthBothering(document, ((DocumentRunnable)action).getProject())) {
return;
return false;
}
}
stopDaemon(false);
return true;
}
public void writeActionFinished(Object action) {
if (myDaemonCodeAnalyzer.isRunning()) {
return;
if (myDaemonCodeAnalyzer.isRunning()) return;
if (containsDocumentWorthBothering(action)) {
stopDaemon(true);
}
if (action instanceof DocumentRunnable) {
Document document = ((DocumentRunnable)action).getDocument();
if (!worthBothering(document, ((DocumentRunnable)action).getProject())) {
return;
}
}
stopDaemon(true);
}
}
@@ -145,7 +145,7 @@ public class HectorComponent extends JPanel {
}
if (!DaemonCodeAnalyzer.getInstance(myFile.getProject()).isHighlightingAvailable(myFile)) return;
final Project project = myFile.getProject();
final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project);
final ErrorsConfigurable errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project);
assert errorsConfigurable != null;
ShowSettingsUtil.getInstance().editConfigurable(project, errorsConfigurable);
}
@@ -93,7 +93,7 @@ public class EditInspectionToolsSettingsAction implements IntentionAction, Icona
errorsConfigurable = new IDEInspectionToolsConfigurable(InspectionProjectProfileManager.getInstance(project), InspectionProfileManager.getInstance());
}
else {
errorsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project);
errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project);
}
return settingsUtil.editConfigurable(project, errorsConfigurable, new Runnable() {
public void run() {
@@ -523,7 +523,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
}
final FileType type = language.getAssociatedFileType();
@NonNls final String name = getTitle() + "." + (type == null ? "txt" : type.getDefaultExtension());
@NonNls final String name = getTitle();
final LightVirtualFile newVFile = new LightVirtualFile(name, language, myEditorDocument.getText());
FileDocumentManagerImpl.registerDocument(myEditorDocument, newVFile);
myFile = ((PsiFileFactoryImpl)PsiFileFactory.getInstance(myProject)).trySetupPsiForFile(newVFile, language, true, false);
@@ -27,7 +27,6 @@ import com.intellij.psi.*;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.refactoring.RefactoringActionHandlerFactory;
import com.intellij.refactoring.actions.BaseRefactoringAction;
import com.intellij.refactoring.actions.MoveAction;
import com.intellij.refactoring.copy.CopyHandler;
import com.intellij.refactoring.move.MoveHandler;
import org.jetbrains.annotations.NonNls;
@@ -326,7 +325,7 @@ class MoveDropTargetListener implements DropTargetListener {
}
public boolean isDropRedundant(@NotNull TreeNode sourceNode, @NotNull TreeNode targetNode) {
return sourceNode.getParent() == targetNode;
return sourceNode.getParent() == targetNode || MoveHandler.isMoveRedundant(getPsiElement(sourceNode), getPsiElement(targetNode));
}
public boolean shouldDelegateToParent(TreeNode[] sourceNodes, @NotNull final TreeNode targetNode) {
@@ -17,8 +17,9 @@
package com.intellij.profile.codeInspection.ui;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -37,10 +38,12 @@ public interface ErrorsConfigurable extends Configurable {
}
@Nullable
public static ErrorsConfigurable getInstance(Project project) {
ErrorsConfigurable profileConfigurable = ShowSettingsUtil.getInstance().findProjectConfigurable(project, ErrorsConfigurable.class);
if (profileConfigurable != null) return profileConfigurable;
return ShowSettingsUtil.getInstance().findApplicationConfigurable(ErrorsConfigurable.class);
public static ErrorsConfigurable createConfigurable(@NotNull Project project) {
Configurable configurable = ConfigurableExtensionPointUtil.createProjectConfigurableForProvider(project, ErrorsConfigurableProvider.class);
if (configurable == null) {
configurable = ConfigurableExtensionPointUtil.createApplicationConfigurableForProvider(ErrorsConfigurableProvider.class);
}
return (ErrorsConfigurable)configurable;
}
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.profile.codeInspection.ui;
import com.intellij.openapi.options.ConfigurableProvider;
/**
* @author nik
*/
public abstract class ErrorsConfigurableProvider extends ConfigurableProvider {
@Override
public abstract ErrorsConfigurable createConfigurable();
}
@@ -0,0 +1,26 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.profile.codeInspection.ui;
/**
* @author nik
*/
public class PlatformInspectionsConfigurableProvider extends ErrorsConfigurableProvider {
@Override
public ErrorsConfigurable createConfigurable() {
return new PlatformInspectionsConfigurable();
}
}
@@ -22,20 +22,13 @@ package com.intellij.profile.codeInspection.ui;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
public class ProjectInspectionToolsConfigurable extends InspectionToolsConfigurable {
public static ProjectInspectionToolsConfigurable getInstance(Project project) {
return ShowSettingsUtil.getInstance().findProjectConfigurable(project, ProjectInspectionToolsConfigurable.class);
}
public ProjectInspectionToolsConfigurable(InspectionProfileManager profileManager, InspectionProjectProfileManager projectProfileManager) {
super(projectProfileManager, profileManager);
}
protected InspectionProfileImpl getCurrentProfile() {
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.profile.codeInspection.ui;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
/**
* @author nik
*/
public class ProjectInspectionToolsConfigurableProvider extends ErrorsConfigurableProvider {
private InspectionProfileManager myProfileManager;
private InspectionProjectProfileManager myProjectProfileManager;
public ProjectInspectionToolsConfigurableProvider(InspectionProfileManager profileManager,
InspectionProjectProfileManager projectProfileManager) {
myProfileManager = profileManager;
myProjectProfileManager = projectProfileManager;
}
@Override
public ErrorsConfigurable createConfigurable() {
return new ProjectInspectionToolsConfigurable(myProfileManager, myProjectProfileManager);
}
}
@@ -173,4 +173,11 @@ public class MoveHandler implements RefactoringActionHandler {
return false;
}
public static boolean isMoveRedundant(PsiElement source, PsiElement target) {
for(MoveHandlerDelegate delegate: Extensions.getExtensions(MoveHandlerDelegate.EP_NAME)) {
if (delegate.isMoveRedundant(source, target)) return true;
}
return false;
}
}
@@ -60,4 +60,8 @@ public abstract class MoveHandlerDelegate {
public void collectFilesOrDirsFromContext(DataContext dataContext, Set<PsiElement> filesOrDirs){
}
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
return false;
}
}
@@ -17,6 +17,7 @@
package com.intellij.refactoring.move.moveFilesOrDirectories;
import com.intellij.ide.util.DirectoryChooserUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -24,6 +25,7 @@ import com.intellij.psi.*;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.move.MoveCallback;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nullable;
@@ -59,9 +61,22 @@ public class MoveFilesOrDirectoriesUtil {
final PsiElement[] elements,
final PsiElement[] targetElement,
final MoveCallback moveCallback) {
for (PsiElement element : elements) {
if (!(element instanceof PsiFile) && !(element instanceof PsiDirectory)) {
throw new IllegalArgumentException("unexpected element type: " + element);
doMove(project, elements, targetElement, moveCallback, null);
}
/**
* @param elements should contain PsiDirectories or PsiFiles only if adjustElements == null
*/
public static void doMove(final Project project,
final PsiElement[] elements,
final PsiElement[] targetElement,
final MoveCallback moveCallback,
final Function<PsiElement[], PsiElement[]> adjustElements) {
if (adjustElements == null) {
for (PsiElement element : elements) {
if (!(element instanceof PsiFile) && !(element instanceof PsiDirectory)) {
throw new IllegalArgumentException("unexpected element type: " + element);
}
}
}
@@ -72,21 +87,21 @@ public class MoveFilesOrDirectoriesUtil {
final MoveFilesOrDirectoriesDialog.Callback doRun = new MoveFilesOrDirectoriesDialog.Callback() {
public void run(final MoveFilesOrDirectoriesDialog moveDialog) {
final PsiDirectory targetDirectory = moveDialog.getTargetDirectory();
final PsiDirectory targetDirectory = moveDialog != null ? moveDialog.getTargetDirectory() : initialTargetDirectory;
LOG.assertTrue(targetDirectory != null);
PsiElement[] newElements = adjustElements != null ? adjustElements.fun(elements) : elements;
targetElement[0] = targetDirectory;
PsiManager manager = PsiManager.getInstance(project);
try {
for (PsiElement psiElement : elements) {
for (PsiElement psiElement : newElements) {
manager.checkMove(psiElement, targetDirectory);
}
new MoveFilesOrDirectoriesProcessor(project, elements, targetDirectory, false, false, moveCallback, new Runnable() {
new MoveFilesOrDirectoriesProcessor(project, newElements, targetDirectory, false, false, moveCallback, new Runnable() {
public void run() {
moveDialog.close(DialogWrapper.CANCEL_EXIT_CODE);
if (moveDialog != null) moveDialog.close(DialogWrapper.CANCEL_EXIT_CODE);
}
}).run();
}
@@ -97,9 +112,14 @@ public class MoveFilesOrDirectoriesUtil {
}
};
final MoveFilesOrDirectoriesDialog moveDialog = new MoveFilesOrDirectoriesDialog(project, doRun);
moveDialog.setData(elements, initialTargetDirectory, "refactoring.moveFile");
moveDialog.show();
if (ApplicationManager.getApplication().isUnitTestMode()) {
doRun.run(null);
}
else {
final MoveFilesOrDirectoriesDialog moveDialog = new MoveFilesOrDirectoriesDialog(project, doRun);
moveDialog.setData(elements, initialTargetDirectory, "refactoring.moveFile");
moveDialog.show();
}
}
@Nullable
@@ -16,7 +16,7 @@
package com.intellij.openapi.editor;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author cdr
@@ -25,7 +25,7 @@ public abstract class DocumentRunnable implements Runnable {
private final Document myDocument;
private final Project myProject;
public DocumentRunnable(@NotNull Document document, Project project) {
public DocumentRunnable(@Nullable Document document, Project project) {
myDocument = document;
myProject = project;
}
@@ -37,4 +37,10 @@ public abstract class DocumentRunnable implements Runnable {
public Project getProject() {
return myProject;
}
public abstract static class IgnoreDocumentRunnable extends DocumentRunnable {
public IgnoreDocumentRunnable() {
super(null, null);
}
}
}
@@ -105,8 +105,8 @@ public class SaveAndSyncHandler implements ApplicationComponent {
return !LaterInvocator.isInModalContext() && !ProgressManager.getInstance().hasModalProgressIndicator();
}
private static void saveProjectsAndDocuments() {
// made public for tests
public static void saveProjectsAndDocuments() {
if (LOG.isDebugEnabled()) {
LOG.debug("enter: save()");
}
@@ -1018,7 +1018,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
myDispatcher.getMulticaster().writeActionFinished(action);
}
public void _saveSettings() { // for testing purposes
public void _saveSettings() { // public for testing purposes
if (mySaveSettingsIsInProgress.compareAndSet(false, true)) {
try {
doSave();
@@ -25,6 +25,7 @@ import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.StateStorage;
import com.intellij.openapi.components.TrackingPathMacroSubstitutor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.DocumentRunnable;
import com.intellij.openapi.options.StreamProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
@@ -101,7 +102,8 @@ public class StorageUtil {
file.renameTo(backupFile);
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
// mark this action as modifying the file which daemon analyzer should ignore
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable.IgnoreDocumentRunnable() {
public void run() {
if (!file.exists()) {
file.createParentDirs();
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.impl.stores.StorageUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.DocumentRunnable;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
@@ -543,10 +544,7 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
@Nullable
private Document writeSchemeToDocument(final E scheme) throws WriteExternalException {
if (!isShared(scheme)) {
return myProcessor.writeScheme(scheme);
}
else {
if (isShared(scheme)) {
String originalPath = scheme.getExternalInfo().getOriginalPath();
if (originalPath != null) {
Element root = new Element(SHARED_SCHEME);
@@ -564,6 +562,9 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
return null;
}
}
else {
return myProcessor.writeScheme(scheme);
}
}
public void updateConfigFilesFromStreamProviders() {
@@ -721,19 +722,7 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
}
if (myVFSBaseDir != null) {
final WriteExternalException[] ex = new WriteExternalException[1];
ApplicationManager.getApplication().runWriteAction(new Runnable(){
public void run() {
try {
doSave();
}
catch (WriteExternalException e) {
ex[0] = e;
}
}
});
if (ex[0] != null) throw ex[0];
doSave();
}
}
@@ -755,10 +744,9 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
private boolean myInsideSave = false;
private void doSave() throws WriteExternalException {
myInsideSave = true;
try {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable.IgnoreDocumentRunnable() {
public void run() {
((NewVirtualFile)myVFSBaseDir).markDirtyRecursively();
myVFSBaseDir.refresh(false, true);
@@ -772,16 +760,18 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
reserveUsingFileNames(schemes, fileNameProvider);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable.IgnoreDocumentRunnable() {
public void run() {
deleteFilesFromDeletedSchemes();
}
});
saveSchemes(schemes, fileNameProvider);
if (myDeletedNames.size() > 0) {
if (myDeletedNames.isEmpty()) {
deleteServerFiles(DELETED_XML);
}
else {
for (StreamProvider provider : getEnabledProviders()) {
try {
StorageUtil.sendContent(provider, getFileFullPath(DELETED_XML), createDeletedDocument(), myRoamingType, true);
@@ -791,10 +781,6 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
}
}
}
else {
deleteServerFiles(DELETED_XML);
}
}
finally {
myInsideSave = false;
@@ -859,7 +845,6 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
}
});
}
}
}
}
@@ -18,6 +18,7 @@ package com.intellij.openapi.options.ex;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurableEP;
import com.intellij.openapi.options.ConfigurableProvider;
import com.intellij.openapi.options.OptionalConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.ContainerUtil;
@@ -79,4 +80,27 @@ public class ConfigurableExtensionPointUtil {
}
throw new IllegalArgumentException("Cannot find configurable of " + configurableClass);
}
@Nullable
public static Configurable createProjectConfigurableForProvider(@NotNull Project project, Class<? extends ConfigurableProvider> providerClass) {
return createConfigurableForProvider(project.getExtensions(PROJECT_CONFIGURABLES), providerClass);
}
@Nullable
public static Configurable createApplicationConfigurableForProvider(Class<? extends ConfigurableProvider> providerClass) {
return createConfigurableForProvider(APPLICATION_CONFIGURABLES.getExtensions(), providerClass);
}
@Nullable
private static Configurable createConfigurableForProvider(ConfigurableEP[] extensions, Class<? extends ConfigurableProvider> providerClass) {
for (ConfigurableEP extension : extensions) {
if (extension.providerClass != null) {
final Class<Object> aClass = extension.findClassNoExceptions(extension.providerClass);
if (aClass != null && providerClass.isAssignableFrom(aClass)) {
return extension.createConfigurable();
}
}
}
return null;
}
}
@@ -243,6 +243,19 @@ public class OptionsEditor extends JPanel implements DataProvider, Place.Navigat
});
}
public ActionCallback select(Class<? extends Configurable> configurableClass) {
final Configurable configurable = findConfigurable(configurableClass);
if (configurable == null) {
return new ActionCallback.Rejected();
}
return select(configurable);
}
@Nullable
public <T extends Configurable> T findConfigurable(Class<T> configurableClass) {
return myTree.findConfigurable(configurableClass);
}
public ActionCallback select(Configurable configurable) {
myFilter.refilterFor("", false, true);
return myTree.select(configurable);
@@ -263,6 +263,16 @@ public class OptionsTree extends JPanel implements Disposable, OptionsEditorColl
return myConfigurable2Node.get(toSelect);
}
@Nullable
public <T extends Configurable> T findConfigurable(Class<T> configurableClass) {
for (Configurable configurable : myConfigurable2Node.keySet()) {
if (configurableClass.isInstance(configurable)) {
return configurableClass.cast(configurable);
}
}
return null;
}
class Renderer extends GroupedElementsRenderer.Tree implements TreeCellRenderer {
@@ -79,7 +79,7 @@
<getDataRule key="context.ProjectFileDirectory" implementationClass="com.intellij.platform.PlatformFileProjectDirectoryRule"/>
<applicationConfigurable implementation="com.intellij.profile.codeInspection.ui.PlatformInspectionsConfigurable" order="before intentions"/>
<applicationConfigurable provider="com.intellij.profile.codeInspection.ui.PlatformInspectionsConfigurableProvider" order="before intentions"/>
<checkoutCompletedListener implementation="com.intellij.openapi.vcs.checkout.PlatformProjectCheckoutListener"/>
@@ -19,6 +19,7 @@ import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.execution.testframework.Printable;
import com.intellij.execution.testframework.Printer;
import com.intellij.execution.ui.ConsoleViewContentType;
import org.jetbrains.annotations.NotNull;
public class MockPrinter implements Printer {
private boolean myShouldReset = false;
@@ -81,7 +82,7 @@ public class MockPrinter implements Printer {
return myHasPrinted;
}
public void onNewAvailable(Printable printable) {
public void onNewAvailable(@NotNull Printable printable) {
printable.printOn(this);
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.actionSystem.DataKey;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.pom.Navigatable;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -59,7 +60,7 @@ public abstract class AbstractTestProxy extends CompositePrintable {
public abstract List<? extends AbstractTestProxy> getAllTests();
public void fireOnNewPrintable(final Printable printable) {
public void fireOnNewPrintable(@NotNull final Printable printable) {
if (myPrinter != null) {
myPrinter.onNewAvailable(printable);
}
@@ -78,7 +79,7 @@ public abstract class AbstractTestProxy extends CompositePrintable {
* @param printable Printable info
*/
@Override
public void addLast(final Printable printable) {
public void addLast(@NotNull final Printable printable) {
super.addLast(printable);
fireOnNewPrintable(printable);
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.io.IOUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.ArrayList;
@@ -63,7 +64,7 @@ public class CompositePrintable implements Printable, Disposable {
}
}
public void addLast(final Printable printable) {
public void addLast(@NotNull final Printable printable) {
synchronized (myNestedPrintables) {
myNestedPrintables.add(printable);
}
@@ -132,7 +133,7 @@ public class CompositePrintable implements Printable, Disposable {
}
@Override
public void onNewAvailable(Printable printable11) {
public void onNewAvailable(@NotNull Printable printable11) {
}
@Override
@@ -18,6 +18,7 @@ package com.intellij.execution.testframework;
import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.execution.ui.ConsoleViewContentType;
import org.jetbrains.annotations.NotNull;
public class DeferingPrinter implements Printer {
private CompositePrintable myCompositePrintable;
@@ -34,7 +35,7 @@ public class DeferingPrinter implements Printer {
});
}
public void onNewAvailable(final Printable printable) {
public void onNewAvailable(@NotNull final Printable printable) {
myCompositePrintable.addLast(printable);
}
@@ -17,10 +17,11 @@ package com.intellij.execution.testframework;
import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.execution.ui.ConsoleViewContentType;
import org.jetbrains.annotations.NotNull;
public interface Printer {
void print(String text, ConsoleViewContentType contentType);
void onNewAvailable(Printable printable);
void onNewAvailable(@NotNull Printable printable);
void printHyperlink(String text, HyperlinkInfo info);
void mark();
}
@@ -24,6 +24,7 @@ import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Ref;
import com.intellij.util.PairProcessor;
import org.jetbrains.annotations.NotNull;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@@ -157,7 +158,7 @@ public class TestResultsXmlFormatter {
}
@Override
public void onNewAvailable(Printable printable) {
public void onNewAvailable(@NotNull Printable printable) {
}
@Override
@@ -21,6 +21,7 @@ import com.intellij.execution.testframework.*;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.Disposable;
import org.jetbrains.annotations.NotNull;
public class TestsOutputConsolePrinter implements Printer, Disposable {
private final ConsoleView myConsole;
@@ -67,7 +68,7 @@ public class TestsOutputConsolePrinter implements Printer, Disposable {
myConsole.print(text, contentType);
}
public void onNewAvailable(final Printable printable) {
public void onNewAvailable(@NotNull final Printable printable) {
if (myPaused) {
printable.printOn(myPausedPrinter);
} else {
@@ -41,7 +41,7 @@ public class VcsGuess {
@Nullable
public AbstractVcs getVcsForDirty(final VirtualFile file) {
if (!file.isInLocalFileSystem() || myExcludedFileIndex == null) {
if (!file.isInLocalFileSystem()) {
return null;
}
if (myExcludedFileIndex.isInContent(file) || isFileInBaseDir(file) ||
@@ -82,7 +82,7 @@ public abstract class DebuggerSessionTabBase implements DebuggerLogConsoleManage
}
protected void initLogConsoles(final RunProfile runConfiguration, final ProcessHandler processHandler) {
if (runConfiguration instanceof RunConfigurationBase && ((RunConfigurationBase)runConfiguration).needAdditionalConsole()) {
if (runConfiguration instanceof RunConfigurationBase) {
myManager.initLogConsoles((RunConfigurationBase)runConfiguration, processHandler);
}
}
@@ -123,7 +123,7 @@ public class ProjectSettingsPanel extends PanelWithButtons {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext());
if (optionsEditor != null) {
optionsEditor.select(ScopeChooserConfigurable.getInstance(myProject));
optionsEditor.select(ScopeChooserConfigurable.class);
}
}
}
@@ -734,10 +734,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl implements
}
public boolean isReferenceTo(PsiElement element) {
if (element instanceof PsiNamedElement) {
return getManager().areElementsEquivalent(element, GroovyTargetElementEvaluator.correctSearchTargets(resolve()));
}
return false;
return getManager().areElementsEquivalent(element, GroovyTargetElementEvaluator.correctSearchTargets(resolve()));
}
@NotNull
@@ -16,11 +16,14 @@
package com.intellij.lang.properties.projectView;
import com.intellij.lang.properties.ResourceBundle;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.move.MoveHandlerDelegate;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
@@ -36,6 +39,10 @@ public class ResourceBundleMoveProvider extends MoveHandlerDelegate {
return ResourceBundle.ARRAY_DATA_KEY.getData(dataContext) != null;
}
public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) {
return false;
}
@Override
public void collectFilesOrDirsFromContext(DataContext dataContext, Set<PsiElement> filesOrDirs) {
@@ -45,4 +52,12 @@ public class ResourceBundleMoveProvider extends MoveHandlerDelegate {
filesOrDirs.addAll(bundle.getPropertiesFiles(PlatformDataKeys.PROJECT.getData(dataContext)));
}
}
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
if (source instanceof PropertiesFile && target instanceof PsiDirectory) {
return source.getParent() == target;
}
return super.isMoveRedundant(source, target);
}
}
@@ -66,16 +66,16 @@ public class SpellCheckerSettingsPane implements Disposable {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext());
final ErrorsConfigurable toolsConfigurable = ErrorsConfigurable.SERVICE.getInstance(project);
if (optionsEditor != null && toolsConfigurable != null) {
optionsEditor.select(toolsConfigurable).doWhenDone(new Runnable() {
public void run() {
toolsConfigurable.selectInspectionTool("SpellCheckingInspection");
}
});
if (optionsEditor != null) {
final ErrorsConfigurable errorsConfigurable = optionsEditor.findConfigurable(ErrorsConfigurable.class);
if (errorsConfigurable != null) {
optionsEditor.select(errorsConfigurable).doWhenDone(new Runnable() {
public void run() {
errorsConfigurable.selectInspectionTool("SpellCheckingInspection");
}
});
}
}
}
}
});
@@ -266,10 +266,6 @@ public class TestNGConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
return group;
}
public boolean needAdditionalConsole() {
return false;
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (data.TEST_OBJECT.equals(TestType.CLASS.getType()) || data.TEST_OBJECT.equals(TestType.METHOD.getType())) {
@@ -18,10 +18,13 @@ package com.intellij.uiDesigner.projectView;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.refactoring.move.MoveHandlerDelegate;
import com.intellij.uiDesigner.GuiFormFileType;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
@@ -37,6 +40,10 @@ public class FormMoveProvider extends MoveHandlerDelegate {
return forms != null && forms.length > 0;
}
public boolean canMove(PsiElement[] elements, @Nullable final PsiElement targetContainer) {
return false;
}
@Override
public void collectFilesOrDirsFromContext(DataContext dataContext, Set<PsiElement> filesOrDirs) {
Form[] forms = Form.DATA_KEY.getData(dataContext);
@@ -55,4 +62,15 @@ public class FormMoveProvider extends MoveHandlerDelegate {
}
}
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
if (source instanceof PsiFile && source.getParent() == target) {
final VirtualFile virtualFile = ((PsiFile)source).getVirtualFile();
if (virtualFile != null && virtualFile.getFileType() instanceof GuiFormFileType) {
return true;
}
}
return super.isMoveRedundant(source, target);
}
}
+1 -1
View File
@@ -631,7 +631,7 @@
<!-- Errors -->
<!-- Show full error options configurable only in full IDEA - platform supports only default IDE profile for now -->
<projectConfigurable implementation="com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable"/>
<projectConfigurable provider="com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurableProvider"/>
<!-- Project Structure -->
<projectConfigurable instance="com.intellij.compiler.options.CompilerConfigurable" order="after project"/>
@@ -0,0 +1,30 @@
<idea-plugin version="2">
<name>DocumentFiles</name>
<description>This plugin illustrates how to work with document files.</description>
<version>1.0</version>
<vendor>JetBrains</vendor>
<!--
<idea-version since-build="8000"/>
-->
<application-components>
<!-- Add your application components here -->
</application-components>
<project-components>
<!-- Add your project components here -->
</project-components>
<actions>
<!-- Add your actions here -->
<action id="documentFiles.myActionID" class="myDocumentFiles.MyActionClass" text="Text _Editor"
description="a sample custom editor of text files.">
<add-to-group group-id="FileMenu" anchor="after" relative-to-action="PowerSaveGroup"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl F10"/>
</action>
</actions>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
</idea-plugin>
@@ -0,0 +1,18 @@
package myDocumentFiles;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
/**
* Created by IntelliJ IDEA.
* User: Alexey.Chursin
* Date: Aug 30, 2010
* Time: 6:29:02 PM
*/
public class MyActionClass extends AnAction {
public void actionPerformed(AnActionEvent e) {
MyVisualPanel myEditor = new MyVisualPanel(false);
myEditor.getPeer().setTitle("Sample Text File Editor");
myEditor.show();
}
}
@@ -0,0 +1,137 @@
package myDocumentFiles;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
/**
* Created by IntelliJ IDEA.
* User: Alexey.Chursin
* Date: Aug 30, 2010
* Time: 1:42:38 PM
*/
public class MyVisualPanel extends DialogWrapper {
private JTabbedPane viewFileTab;
private JTextField fileName;
private JButton buttonBrowse;
private JTextField directoryName;
private JFileChooser fileChooser = new JFileChooser("");
private VirtualFile selectedVFile;
private Document docFile;
// Set maximum allowed number of lines in a text file to edit.
private final int maxNumberofLines = 250;
private JPanel myVisualUI;
private JEditorPane myFileEditor;
private JPanel viewFilePanel;
private String initialFileContent = null;
private boolean nFocus;
public MyVisualPanel(boolean canBeParent) {
super(canBeParent);
init();
// The Browse button listener.
buttonBrowse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (OpenFile()) {
if (docFile.getLineCount() > maxNumberofLines) {
Messages.showMessageDialog("File too long! Maximum allowed number of lines: " +
String.valueOf(maxNumberofLines) + ".\n"+
"To change this setting, modify the MyVisualPanel.maxNumberofLines field.", "Error", Messages.getErrorIcon());
return;
}
// Read the text file content.
initialFileContent = docFile.getText();
// Enable the View File tab
viewFileTab.setEnabled(true);
// Fill the "File name" and "Directory" text fields.
fileName.setText(selectedVFile.getName());
directoryName.setText(selectedVFile.getParent().getUrl());
myFileEditor.setText(initialFileContent);
}
}
});
// The file editor focus listener.
myFileEditor.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
if (!docFile.isWritable() && nFocus) {
nFocus = false;
Messages.showMessageDialog("This file is read-only. You cannot save your changes.", "Warning",
Messages.getWarningIcon());
return;
} else return;
}
});
}
// Display the Open dialog and open the selected file.
public boolean OpenFile() {
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", "txt");
fileChooser.setFileFilter(filter);
//... Open a file dialog.
int retval = fileChooser.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
// Get virtual file
selectedVFile = LocalFileSystem.getInstance().findFileByIoFile(fileChooser.getSelectedFile());
// Get document file
docFile = FileDocumentManager.getInstance().getDocument(selectedVFile);
nFocus = true;
return true;
}
viewFilePanel.setEnabled(false);
return false;
}
public JComponent createCenterPanel() {
return (JComponent) myVisualUI;
}
// The OK button handler.
protected void doOKAction() {
if (initialFileContent == null) {
this.close(0);
return;
}
if (!initialFileContent.equals(myFileEditor.getText())) {
if (Messages.showYesNoDialog("The file " + selectedVFile.getName() +
" has been changed. Are you sure you want to overwrite it?", "File Changed", Messages.getQuestionIcon()) == 0) {
if (docFile.isWritable()) {
docFile.setText(myFileEditor.getText());
} else {
Messages.showMessageDialog("This file is read-only! You cannot save your changes.", "Error", Messages.getErrorIcon());
return;
}
} else return;
}
this.close(0);
this.dispose();
}
}
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="myDocumentFiles.MyVisualPanel">
<grid id="27dc6" binding="myVisualUI" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="1176" height="400"/>
</constraints>
<properties>
<name value=""/>
<visible value="true"/>
</properties>
<border type="none" title-justification="2" title-position="1"/>
<children>
<tabbedpane id="7b4c" binding="viewFileTab">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="200" height="200"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
<inheritsPopupMenu value="false"/>
<name value="ffff"/>
</properties>
<border type="none"/>
<children>
<grid id="57ce9" layout-manager="GridLayoutManager" row-count="5" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Open File"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="32d8d">
<constraints>
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="89e63" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="File name:"/>
</properties>
</component>
<component id="a784e" class="javax.swing.JTextField" binding="fileName">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="300" height="-1"/>
<maximum-size width="300" height="30"/>
</grid>
</constraints>
<properties>
<background color="-2697514"/>
<enabled value="false"/>
<text value=""/>
</properties>
</component>
<hspacer id="7e5cb">
<constraints>
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="b3f9e" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Directory name:"/>
</properties>
</component>
<component id="1bada" class="javax.swing.JTextField" binding="directoryName">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="300" height="-1"/>
<maximum-size width="300" height="30"/>
</grid>
</constraints>
<properties>
<background color="-2697514"/>
<enabled value="false"/>
<text value=""/>
</properties>
</component>
<component id="37758" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Click Browse to select a text file. To view/edit file, open the View File tab. "/>
</properties>
</component>
<vspacer id="4385">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="ab2fa" class="javax.swing.JButton" binding="buttonBrowse">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Browse"/>
</properties>
</component>
</children>
</grid>
<grid id="c2756" binding="viewFilePanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="View File"/>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children>
<vspacer id="ad8c6">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<scrollpane id="ecde2">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6cada" class="javax.swing.JEditorPane" binding="myFileEditor">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</tabbedpane>
</children>
</grid>
</form>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/src/META-INF/plugin.xml" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA IC-96.1068" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+203
View File
@@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
</component>
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions>
<entry name=".+\.(properties|xml|html|dtd|tld)" />
<entry name=".+\.(gif|png|jpeg|jpg)" />
</resourceExtensions>
<wildcardResourcePatterns>
<entry name="?*.properties" />
<entry name="?*.xml" />
<entry name="?*.gif" />
<entry name="?*.png" />
<entry name="?*.jpeg" />
<entry name="?*.jpg" />
<entry name="?*.html" />
<entry name="?*.dtd" />
<entry name="?*.tld" />
<entry name="?*.ftl" />
</wildcardResourcePatterns>
<annotationProcessing enabled="false" useClasspath="true" />
</component>
<component name="CopyrightManager" default="">
<module2copyright />
</component>
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
<component name="Git.Settings">
<option name="GIT_EXECUTABLE" value="C:\Program Files (x86)\Git\bin\git.exe" />
<option name="CHECKOUT_INCLUDE_TAGS" value="false" />
<option name="UPDATE_CHANGES_POLICY" value="STASH" />
</component>
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" />
<option name="OPTION_SCOPE" value="protected" />
<option name="OPTION_HIERARCHY" value="true" />
<option name="OPTION_NAVIGATOR" value="true" />
<option name="OPTION_INDEX" value="true" />
<option name="OPTION_SEPARATE_INDEX" value="true" />
<option name="OPTION_DOCUMENT_TAG_USE" value="false" />
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
<option name="OPTION_DEPRECATED_LIST" value="true" />
<option name="OTHER_OPTIONS" value="" />
<option name="HEAP_SIZE" />
<option name="LOCALE" />
<option name="OPEN_IN_BROWSER" value="true" />
</component>
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/textEditor.iml" filepath="$PROJECT_DIR$/textEditor.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IC-96.1068" project-jdk-type="IDEA JDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnConfiguration" maxAnnotateRevisions="500">
<option name="USER" value="" />
<option name="PASSWORD" value="" />
<option name="LAST_MERGED_REVISION" />
<option name="UPDATE_RUN_STATUS" value="false" />
<option name="MERGE_DRY_RUN" value="false" />
<option name="MERGE_DIFF_USE_ANCESTRY" value="true" />
<option name="UPDATE_LOCK_ON_DEMAND" value="false" />
<option name="IGNORE_SPACES_IN_MERGE" value="false" />
<option name="DETECT_NESTED_COPIES" value="true" />
<option name="CHECK_NESTED_FOR_QUICK_MERGE" value="false" />
<option name="IGNORE_SPACES_IN_ANNOTATE" value="true" />
<option name="SHOW_MERGE_SOURCES_IN_ANNOTATE" value="true" />
<myIsUseDefaultProxy>false</myIsUseDefaultProxy>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>