diff --git a/build/update.xml b/build/update.xml index b3a49ccffe80..e06cfce3ee93 100644 --- a/build/update.xml +++ b/build/update.xml @@ -43,6 +43,7 @@ + diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/BuilderBasedProjectType.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleTypeCategory.java similarity index 76% rename from java/idea-ui/src/com/intellij/ide/projectWizard/BuilderBasedProjectType.java rename to java/idea-ui/src/com/intellij/ide/projectWizard/ModuleTypeCategory.java index bb1b224542a6..ed2665d199ba 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/BuilderBasedProjectType.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ModuleTypeCategory.java @@ -9,11 +9,11 @@ import org.jetbrains.annotations.NotNull; * @author Dmitry Avdeev * Date: 20.09.13 */ -public class BuilderBasedProjectType extends ProjectCategory { +public class ModuleTypeCategory extends ProjectCategory { private final ModuleType myModuleType; - public BuilderBasedProjectType(ModuleType moduleType) { + public ModuleTypeCategory(ModuleType moduleType) { myModuleType = moduleType; } @@ -23,7 +23,7 @@ public class BuilderBasedProjectType extends ProjectCategory { return myModuleType.createModuleBuilder(); } - public static class Java extends BuilderBasedProjectType { + public static class Java extends ModuleTypeCategory { public Java() { super(JavaModuleType.getModuleType()); diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java index 7ef2e82feab3..d5c9b09ce19b 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java @@ -64,6 +64,9 @@ public abstract class ProjectCategory { return new FrameworkRole[] {createModuleBuilder().getDefaultAcceptableRole()}; } + /** + * Describes "main" frameworks to be shown on top of the tree + */ @NotNull public String[] getAssociatedFrameworkIds() { return ArrayUtil.EMPTY_STRING_ARRAY; diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategoryTemplate.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategoryTemplate.java new file mode 100644 index 000000000000..1e5a05b2af06 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategoryTemplate.java @@ -0,0 +1,42 @@ +/* + * 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. + * 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.ide.projectWizard; + +import com.intellij.platform.templates.BuilderBasedTemplate; +import org.jetbrains.annotations.NotNull; + +/** + * @author Dmitry Avdeev + */ +public class ProjectCategoryTemplate extends BuilderBasedTemplate { + + private final ProjectCategory myCategory; + + public ProjectCategoryTemplate(ProjectCategory category) { + super(category.createModuleBuilder()); + myCategory = category; + } + + @NotNull + @Override + public String getName() { + return myCategory.getDisplayName(); + } + + public ProjectCategory getCategory() { + return myCategory; + } +} diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java index 69d674cf07be..3402e6f56377 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java @@ -135,7 +135,9 @@ public class ProjectTypeStep extends ModuleWizardStep implements Disposable, Act myTemplatesMap.putAllValues(CreateFromTemplateMode.getTemplatesMap(context)); for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) { - myTemplatesMap.put(new TemplatesGroup(category), new ArrayList()); + ArrayList templates = new ArrayList(); + templates.add(new ProjectCategoryTemplate(category)); + myTemplatesMap.put(new TemplatesGroup(category), templates); } if (context.isCreatingNewProject()) { MultiMap localTemplates = loadLocalTemplates(); @@ -380,8 +382,10 @@ public class ProjectTypeStep extends ModuleWizardStep implements Disposable, Act } private void updateSelection() { - ModuleBuilder builder = getSelectedBuilder(); - if (builder != null) { + ProjectTemplate template = getSelectedTemplate(); + if (template != null) { + myContext.setProjectTemplate(template); + ModuleBuilder builder = myBuilders.get(template); myContext.setProjectBuilder(builder); myWizard.getSequence().setType(builder.getBuilderId()); } diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java b/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java deleted file mode 100644 index e9eefe505881..000000000000 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2000-2013 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.ide.projectWizard; - -import com.intellij.ide.util.projectWizard.ModuleBuilder; -import com.intellij.platform.ProjectTemplate; -import com.intellij.platform.templates.LocalArchivedTemplate; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.net.URL; - -/** - * @author Dmitry Avdeev - * Date: 20.09.13 - */ -public class TemplateBasedProjectType extends ProjectCategory { - - private final ProjectTemplate myTemplate; - - public TemplateBasedProjectType(String templatePath) { - URL resource = getClass().getResource(templatePath); - assert resource != null : templatePath; - myTemplate = new LocalArchivedTemplate(resource, getClass().getClassLoader()); - } - - public TemplateBasedProjectType(ProjectTemplate template) { - myTemplate = template; - } - - @NotNull - @Override - public ModuleBuilder createModuleBuilder() { - return (ModuleBuilder)myTemplate.createModuleBuilder(); - } - - @Override - public String getId() { - return getDisplayName(); - } - - @Override - public String getDisplayName() { - return myTemplate.getName(); - } - - @Override - public String getDescription() { - return myTemplate.getDescription(); - } - - @Override - public Icon getIcon() { - return myTemplate.getIcon(); - } -} diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SupportForFrameworksStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SupportForFrameworksStep.java index 74badcc38f69..9f0e4dd00942 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SupportForFrameworksStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SupportForFrameworksStep.java @@ -18,6 +18,8 @@ package com.intellij.ide.util.newProjectWizard; import com.intellij.CommonBundle; import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider; +import com.intellij.ide.projectWizard.ProjectCategory; +import com.intellij.ide.projectWizard.ProjectCategoryTemplate; import com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil; import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase; import com.intellij.ide.util.projectWizard.ModuleBuilder; @@ -32,10 +34,13 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContaine import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.platform.ProjectTemplate; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.Iterator; import java.util.List; /** @@ -54,6 +59,7 @@ public class SupportForFrameworksStep extends ModuleWizardStep { myContext = context; myBuilder = builder; List providers = FrameworkSupportUtil.getProviders(builder); + filterByCategory(providers, context.getProjectTemplate()); myFrameworkSupportModel = new FrameworkSupportModelInWizard(librariesContainer, builder); mySupportForFrameworksPanel = new AddSupportForFrameworksPanel(providers, myFrameworkSupportModel, false); myConfigurationUpdater = new ModuleBuilder.ModuleConfigurationUpdater() { @@ -69,6 +75,15 @@ public class SupportForFrameworksStep extends ModuleWizardStep { return path != null ? FileUtil.toSystemIndependentName(path) : ""; } + private static void filterByCategory(List providers, @Nullable ProjectTemplate template) { + if (!(template instanceof ProjectCategoryTemplate)) return; + ProjectCategory category = ((ProjectCategoryTemplate)template).getCategory(); + for (Iterator iterator = providers.iterator(); iterator.hasNext(); ) { + FrameworkSupportInModuleProvider provider = iterator.next(); + + } + } + public Icon getIcon() { return ICON; } diff --git a/java/java-impl/src/com/intellij/ide/JavaFilePasteProvider.java b/java/java-impl/src/com/intellij/ide/JavaFilePasteProvider.java index 06b1828f787c..f56df6418b39 100644 --- a/java/java-impl/src/com/intellij/ide/JavaFilePasteProvider.java +++ b/java/java-impl/src/com/intellij/ide/JavaFilePasteProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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,9 +15,10 @@ */ package com.intellij.ide; -import com.intellij.lang.StdLanguages; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.DataKeys; +import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; @@ -33,15 +34,14 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author yole */ public class JavaFilePasteProvider implements PasteProvider { public void performPaste(@NotNull final DataContext dataContext) { - final Project project = DataKeys.PROJECT.getData(dataContext); - final IdeView ideView = DataKeys.IDE_VIEW.getData(dataContext); + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); if (project == null || ideView == null) return; final PsiJavaFile javaFile = createJavaFileFromClipboardContent(project); if (javaFile == null) return; @@ -59,7 +59,7 @@ public class JavaFilePasteProvider implements PasteProvider { final PsiClass mainClass = publicClass; new WriteCommandAction(project, "Paste class '" + mainClass.getName() + "'") { @Override - protected void run(Result result) throws Throwable { + protected void run(@NotNull Result result) throws Throwable { PsiFile file; try { file = targetDir.createFile(mainClass.getName() + ".java"); @@ -68,8 +68,10 @@ public class JavaFilePasteProvider implements PasteProvider { return; } final Document document = PsiDocumentManager.getInstance(project).getDocument(file); - document.setText(javaFile.getText()); - PsiDocumentManager.getInstance(project).commitDocument(document); + if (document != null) { + document.setText(javaFile.getText()); + PsiDocumentManager.getInstance(project).commitDocument(document); + } if (file instanceof PsiJavaFile) { updatePackageStatement((PsiJavaFile) file, targetDir); } @@ -113,8 +115,8 @@ public class JavaFilePasteProvider implements PasteProvider { } public boolean isPasteEnabled(@NotNull final DataContext dataContext) { - final Project project = DataKeys.PROJECT.getData(dataContext); - final IdeView ideView = DataKeys.IDE_VIEW.getData(dataContext); + final Project project = CommonDataKeys.PROJECT.getData(dataContext); + final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); if (project == null || ideView == null || ideView.getDirectories().length == 0) { return false; } @@ -124,20 +126,7 @@ public class JavaFilePasteProvider implements PasteProvider { @Nullable private static PsiJavaFile createJavaFileFromClipboardContent(final Project project) { - PsiJavaFile file = null; - Transferable content = CopyPasteManager.getInstance().getContents(); - if (content != null) { - String text = null; - try { - text = (String)content.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception e) { - // ignore; - } - if (text != null) { - file = (PsiJavaFile) PsiFileFactory.getInstance(project).createFileFromText("A.java", StdLanguages.JAVA, text); - } - } - return file; + String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); + return text != null ? (PsiJavaFile)PsiFileFactory.getInstance(project).createFileFromText("A.java", JavaLanguage.INSTANCE, text) : null; } } diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java index 2b7b3eb64594..881f68d837f8 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java @@ -173,11 +173,6 @@ public class UISettings implements PersistentStateComponent, Exporta } private static Pair getSystemFontFaceAndSize() { - final Pair fontData = UIUtil.getSystemFontData(); - if (fontData != null) { - return fontData; - } - if (SystemInfo.isWindows) { //noinspection HardCodedStringLiteral final Font font = (Font)Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font"); @@ -186,6 +181,11 @@ public class UISettings implements PersistentStateComponent, Exporta } } + final Pair fontData = UIUtil.getSystemFontData(); + if (fontData != null) { + return fontData; + } + return Pair.create("Dialog", 12); } diff --git a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java index fde32d08f71d..67513572535a 100644 --- a/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java +++ b/platform/lang-api/src/com/intellij/ide/util/projectWizard/WizardContext.java @@ -24,6 +24,7 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.platform.ProjectTemplate; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -46,6 +47,7 @@ public class WizardContext extends UserDataHolderBase { private String myCompilerOutputDirectory; private Sdk myProjectJdk; private ProjectBuilder myProjectBuilder; + private ProjectTemplate myProjectTemplate; private final List myListeners = ContainerUtil.createLockFreeCopyOnWriteList(); private StorageScheme myProjectStorageFormat = StorageScheme.DIRECTORY_BASED; private boolean myNewWizard; @@ -163,6 +165,15 @@ public class WizardContext extends UserDataHolderBase { myProjectBuilder = projectBuilder; } + @Nullable + public ProjectTemplate getProjectTemplate() { + return myProjectTemplate; + } + + public void setProjectTemplate(ProjectTemplate projectTemplate) { + myProjectTemplate = projectTemplate; + } + public String getPresentationName() { return myProject == null ? IdeBundle.message("project.new.wizard.project.identification") : IdeBundle.message("project.new.wizard.module.identification"); } diff --git a/platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java b/platform/lang-api/src/com/intellij/platform/ProjectTemplate.java similarity index 100% rename from platform/platform-impl/src/com/intellij/platform/ProjectTemplate.java rename to platform/lang-api/src/com/intellij/platform/ProjectTemplate.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index 65655c4a468f..93c53deac63f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInsight.editorActions; import com.intellij.codeInsight.CodeInsightSettings; @@ -22,13 +21,13 @@ import com.intellij.ide.PasteProvider; import com.intellij.lang.LanguageFormatting; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.editor.actionSystem.EditorActionManager; import com.intellij.openapi.editor.actionSystem.EditorTextInsertHandler; +import com.intellij.openapi.editor.actions.PasteAction; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.Extensions; @@ -49,6 +48,7 @@ import com.intellij.util.Producer; import com.intellij.util.containers.HashMap; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; @@ -56,37 +56,37 @@ import java.util.Map; public class PasteHandler extends EditorActionHandler implements EditorTextInsertHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.editorActions.PasteHandler"); - - public static final String TRANSFERABLE_PROVIDER = "PasteTransferableProvider"; - - private final EditorActionHandler myOriginalHandler; - private static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.customPasteProvider"); + private final EditorActionHandler myOriginalHandler; + public PasteHandler(EditorActionHandler originalAction) { myOriginalHandler = originalAction; } @Override - public void execute(final Editor editor, final DataContext dataContext, final Producer transferableProvider) { - if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; - final Document document = editor.getDocument(); + public void execute(final Editor editor, final DataContext dataContext) { + execute(editor, dataContext, null); + } + @Override + public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer producer) { + if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; + + final Document document = editor.getDocument(); if (!FileDocumentManager.getInstance().requestWriting(document, CommonDataKeys.PROJECT.getData(dataContext))) { return; } - DataContext context = new DataContext() { - @Override - public Object getData(@NonNls String dataId) { - if (TRANSFERABLE_PROVIDER.equals(dataId)) { - return transferableProvider; + DataContext context = dataContext; + if (producer != null) { + context = new DataContext() { + @Override + public Object getData(@NonNls String dataId) { + return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? producer : dataContext.getData(dataId); } - - return dataContext.getData(dataId); - } - }; - + }; + } final Project project = editor.getProject(); if (project == null || editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection()) { @@ -95,9 +95,8 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } return; } - - final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); + final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); if (file == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, context); @@ -107,13 +106,13 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser document.startGuardedBlockChecking(); try { - for(PasteProvider provider: Extensions.getExtensions(EP_NAME)) { + for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) { if (provider.isPasteEnabled(context)) { provider.performPaste(context); return; } } - doPaste(editor, project, file, document, transferableProvider); + doPaste(editor, project, file, document, producer); } catch (ReadOnlyFragmentModificationException e) { EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e); @@ -123,28 +122,26 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } } - @Override - public void execute(final Editor editor, final DataContext dataContext) { - execute(editor, dataContext, new Producer() { - @Override - public Transferable produce() { - CopyPasteManager copyPasteManager = CopyPasteManager.getInstance(); - Transferable contents = copyPasteManager.getContents(); - if (contents != null) { - copyPasteManager.stopKillRings(); - } - - return contents; - } - }); - } - private static void doPaste(final Editor editor, final Project project, final PsiFile file, final Document document, - final Producer transferableFunction) { - Transferable content = transferableFunction.produce(); + final Producer producer) { + Transferable content = null; + + if (producer != null) { + content = producer.produce(); + } + else { + CopyPasteManager manager = CopyPasteManager.getInstance(); + if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) { + content = manager.getContents(); + if (content != null) { + manager.stopKillRings(); + } + } + } + if (content != null) { String text = null; try { @@ -158,7 +155,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final CodeInsightSettings settings = CodeInsightSettings.getInstance(); final Map extraData = new HashMap(); - for(CopyPastePostProcessor processor: Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) { + for (CopyPastePostProcessor processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) { TextBlockTransferableData data = processor.extractTransferableData(content); if (data != null) { extraData.put(processor, data); @@ -170,7 +167,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final CaretModel caretModel = editor.getCaretModel(); final SelectionModel selectionModel = editor.getSelectionModel(); final int col = caretModel.getLogicalPosition().column; - + // There is a possible case that we want to perform paste while there is an active selection at the editor and caret is located // inside it (e.g. Ctrl+A is pressed while caret is not at the zero column). We want to insert the text at selection start column // then, hence, inserted block of text should be indented according to the selection start as well. @@ -182,24 +179,12 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser else { blockIndentAnchorColumn = col; } - - // We assume that EditorModificationUtil.insertStringAtCaret() is smart enough to understand that text that is currently - // selected at editor (if any) should be removed. - // - //if (selectionModel.hasSelection()) { - // ApplicationManager.getApplication().runWriteAction( - // new Runnable() { - // public void run() { - // EditorModificationUtil.deleteSelectedText(editor); - // } - // } - // ); - //} + + // We assume that EditorModificationUtil.insertStringAtCaret() is smart enough to remove currently selected text (if any). RawText rawText = RawText.fromTransferable(content); - String newText = text; - for(CopyPastePreProcessor preProcessor: Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) { + for (CopyPastePreProcessor preProcessor : Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) { newText = preProcessor.preprocessOnPaste(project, file, editor, newText, rawText); } int indentOptions = text.equals(newText) ? settings.REFORMAT_ON_PASTE : CodeInsightSettings.REFORMAT_BLOCK; @@ -209,18 +194,17 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser indentOptions = CodeInsightSettings.INDENT_BLOCK; } - int length = text.length(); - final String text1 = text; - + final String _text = text; ApplicationManager.getApplication().runWriteAction( new Runnable() { @Override public void run() { - EditorModificationUtil.insertStringAtCaret(editor, text1, false, true); + EditorModificationUtil.insertStringAtCaret(editor, _text, false, true); } } ); + int length = text.length(); int offset = caretModel.getOffset() - length; if (offset < 0) { length += offset; @@ -233,12 +217,12 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser selectionModel.removeSelection(); final Ref indented = new Ref(Boolean.FALSE); - for(Map.Entry e: extraData.entrySet()) { + for (Map.Entry e : extraData.entrySet()) { //noinspection unchecked e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue()); } - boolean pastedTextContainsWhiteSpacesOnly = + boolean pastedTextContainsWhiteSpacesOnly = CharArrayUtil.shiftForward(document.getCharsSequence(), bounds.getStartOffset(), " \n\t") >= bounds.getEndOffset(); VirtualFile virtualFile = file.getVirtualFile(); @@ -254,13 +238,13 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser indentBlock(project, editor, bounds.getStartOffset(), bounds.getEndOffset(), blockIndentAnchorColumn); } break; - + case CodeInsightSettings.INDENT_EACH_LINE: if (!indented.get()) { indentEachLine(project, editor, bounds.getStartOffset(), bounds.getEndOffset()); } break; - + case CodeInsightSettings.REFORMAT_BLOCK: indentEachLine(project, editor, bounds.getStartOffset(), bounds.getEndOffset()); // this is needed for example when inserting a comment before method reformatBlock(project, editor, bounds.getStartOffset(), bounds.getEndOffset()); @@ -294,42 +278,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } else { indentPlainTextBlock(document, startOffset, endOffset, originalCaretCol); - } - - - //boolean hasNewLine = false; - //for (int i = endOffset - 1; i >= startOffset; i--) { - // char c = chars.charAt(i); - // if (c == '\n' || c == '\r') { - // hasNewLine = true; - // break; - // } - // if (c != ' ' && c != '\t') return; // do not indent if does not end with line separator - //} - // - //if (!hasNewLine) return; - //int lineStart = CharArrayUtil.shiftBackwardUntil(chars, startOffset - 1, "\n\r") + 1; - //int spaceEnd = CharArrayUtil.shiftForward(chars, lineStart, " \t"); - //if (startOffset <= spaceEnd) { // we are in starting spaces - // if (lineStart != startOffset) { - // String deletedS = chars.subSequence(lineStart, startOffset).toString(); - // document.deleteString(lineStart, startOffset); - // startOffset = lineStart; - // endOffset -= deletedS.length(); - // document.insertString(endOffset, deletedS); - // LogicalPosition pos = new LogicalPosition(editor.getCaretModel().getLogicalPosition().line, originalCaretCol); - // editor.getCaretModel().moveToLogicalPosition(pos); - // } - // - // PsiDocumentManager.getInstance(project).commitAllDocuments(); - // PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); - // if (LanguageFormatting.INSTANCE.forContext(file) != null) { - // indentBlockWithFormatter(project, document, startOffset, endOffset, file); - // } - // else { - // indentPlainTextBlock(document, startOffset, endOffset, originalCaretCol); - // } - //} + } } private static void indentEachLine(Project project, Editor editor, int startOffset, int endOffset) { @@ -350,7 +299,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser // int i = 1; // int j = 1; // } - // + // // // We get the following on paste then: // if (true) { @@ -409,17 +358,17 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } linesToAdjustIndent++; } - + String indentString = StringUtil.repeatSymbol(' ', indentLevel); for (; linesToAdjustIndent > 0; linesToAdjustIndent--) { int lineStartOffset = document.getLineStartOffset(++line); document.insertString(lineStartOffset, indentString); - } + } } private static void indentBlockWithFormatter(Project project, Document document, int startOffset, int endOffset, PsiFile file) { - + // Algorithm: the main idea is to process the first line of the pasted block, adjust its indent if necessary, calculate indent // adjustment string and apply to each line of the pasted block starting from the second one. // @@ -449,12 +398,12 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser // Example: // [pasted line 1 // pasted line 2] - // We adjust the first line via formatter then and apply first line's indent to all subsequent pasted lines. - + // We adjust the first line via formatter then and apply first line's indent to all subsequent pasted lines. + CharSequence chars = document.getCharsSequence(); final int firstLine = document.getLineNumber(startOffset); final int firstLineStart = document.getLineStartOffset(firstLine); - + // There is a possible case that we paste block that ends with new line that is empty or contains only white space symbols. // We want to preserve indent for the original document line where paste was performed. // Example: @@ -478,7 +427,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser break; } } - + final int lastLine; if (saveLastLineIndent) { lastLine = document.getLineNumber(endOffset) - 1; @@ -491,7 +440,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser document.deleteString(start, i); } } - + // Insert white space from the start line of the pasted block. int indentToKeepEndOffset = Math.min(startOffset, CharArrayUtil.shiftForward(chars, firstLineStart, " \t")); if (indentToKeepEndOffset > firstLineStart) { @@ -500,10 +449,10 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } else { lastLine = document.getLineNumber(endOffset); - } - + } + final int i = CharArrayUtil.shiftBackward(chars, startOffset - 1, " \t"); - + // Handle a situation when pasted block doesn't start a new line. if (chars.charAt(startOffset) != '\n' && i > 0 && chars.charAt(i) != '\n') { int firstNonWsOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); @@ -511,7 +460,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser CharSequence toInsert = chars.subSequence(firstLineStart, firstNonWsOffset); for (int line = firstLine + 1; line <= lastLine; line++) { document.insertString(document.getLineStartOffset(line), toInsert); - } + } } return; } @@ -522,7 +471,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser return; } CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); - + final int j = CharArrayUtil.shiftForward(chars, startOffset, " \t\n"); if (j >= endOffset) { // Pasted text contains white space/line feed symbols only, do nothing. @@ -532,7 +481,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final int anchorLine = document.getLineNumber(j); final int anchorLineStart = document.getLineStartOffset(anchorLine); codeStyleManager.adjustLineIndent(file, j); - + // Handle situation when pasted block starts with non-white space symbols. if (anchorLine == firstLine && j == startOffset) { int indentOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); @@ -544,7 +493,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } return; } - + // Handle situation when pasted block starts from white space symbols. Assume that the pasted text started at the line start, // i.e. correct indentation level is stored at the blocks structure. final int firstNonWsOffset = CharArrayUtil.shiftForward(chars, anchorLineStart, " \t"); @@ -559,7 +508,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } return; } - + // We've pasted text to the non-first column and exact white space between the line start and caret position on the moment of paste // has been removed by formatter during 'adjust line indent' // Example: @@ -582,8 +531,8 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser } else { desiredSymbolsToRemove = -diff; - } - + } + for (int line = anchorLine + 1; line <= lastLine; line++) { int currentLineStart = document.getLineStartOffset(line); int currentLineIndentOffset = CharArrayUtil.shiftForward(chars, currentLineStart, " \t"); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClipboardMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClipboardMacro.java index 01f0800ea7db..f1c3906e7385 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClipboardMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/ClipboardMacro.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. @@ -20,9 +20,6 @@ import com.intellij.codeInsight.template.ExpressionContext; import com.intellij.openapi.ide.CopyPasteManager; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; /** * @author yole @@ -34,20 +31,7 @@ public class ClipboardMacro extends SimpleMacro { @Override protected String evaluateSimpleMacro(Expression[] params, ExpressionContext context) { - Transferable contents = CopyPasteManager.getInstance().getContents(); - if (contents != null) { - String result = ""; - try { - result = (String) contents.getTransferData(DataFlavor.stringFlavor); - } - catch (UnsupportedFlavorException ignored) { - } - catch (IOException ignored) { - } - if (result != null) { - return result; - } - } - return ""; + String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); + return text != null ? text : ""; } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index 24b037da2202..c5ad2799230e 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -79,7 +79,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; import java.awt.event.MouseEvent; import java.io.IOException; import java.util.*; @@ -661,7 +660,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo if (cycleUsed) { clearHyperlinkAndFoldings(); } - + CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { @Override public void run() { @@ -1262,15 +1261,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo private static class PasteHandler extends ConsoleAction { @Override public void execute(final ConsoleViewImpl consoleView, final DataContext context) { - final Transferable content = CopyPasteManager.getInstance().getContents(); - if (content == null) return; - String s = null; - try { - s = (String)content.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception e) { - consoleView.getToolkit().beep(); - } + String s = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); if (s == null) return; ApplicationManager.getApplication().assertIsDispatchThread(); Editor editor = consoleView.myEditor; diff --git a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java index 16a19ebba113..8d3a2005ff1e 100644 --- a/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/FileListPasteProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -21,7 +21,6 @@ import com.intellij.ide.dnd.LinuxDragAndDropSupport; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.LocalFileSystem; @@ -50,6 +49,8 @@ public class FileListPasteProvider implements PasteProvider { final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); if (project == null || ideView == null) return; + if (!FileCopyPasteUtil.isFileListFlavorAvailable()) return; + final Transferable contents = CopyPasteManager.getInstance().getContents(); if (contents == null) return; final List fileList = FileCopyPasteUtil.getFileList(contents); @@ -88,8 +89,7 @@ public class FileListPasteProvider implements PasteProvider { @Override public boolean isPasteEnabled(@NotNull DataContext dataContext) { - final Transferable contents = CopyPasteManager.getInstance().getContents(); - final IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext); - return contents != null && FileCopyPasteUtil.isFileListFlavorSupported(contents) && ideView != null; + return LangDataKeys.IDE_VIEW.getData(dataContext) != null && + FileCopyPasteUtil.isFileListFlavorAvailable(); } } diff --git a/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java b/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java index f42623be4218..d94bc7bbdb9f 100644 --- a/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.java +++ b/platform/lang-impl/src/com/intellij/ide/PsiCopyPasteManager.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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide; import com.intellij.ide.dnd.LinuxDragAndDropSupport; @@ -67,26 +66,10 @@ public class PsiCopyPasteManager { }); } - @Nullable public PsiElement[] getElements(boolean[] isCopied) { try { - Transferable content = myCopyPasteManager.getContents(); - if (content == null) { - return null; - } - - Object transferData; - try { - transferData = content.getTransferData(ourDataFlavor); - } - catch (UnsupportedFlavorException e) { - return null; - } - catch (IOException e) { - return null; - } - + Object transferData = myCopyPasteManager.getContents(ourDataFlavor); if (!(transferData instanceof MyData)) { return null; } @@ -100,9 +83,7 @@ public class PsiCopyPasteManager { return myRecentData.getElements(); } catch (Exception e) { - if (LOG.isDebugEnabled()) { - LOG.debug(e); - } + LOG.debug(e); return null; } } @@ -128,19 +109,13 @@ public class PsiCopyPasteManager { } public void clear() { - Transferable old = myCopyPasteManager.getContents(); myRecentData = null; - StringSelection _new = new StringSelection(""); - myCopyPasteManager.setSystemClipboardContent(_new); - myCopyPasteManager.fireContentChanged(old, _new); + myCopyPasteManager.setContents(new StringSelection("")); } public void setElements(PsiElement[] elements, boolean copied) { - Transferable old = myCopyPasteManager.getContents(); myRecentData = new MyData(elements, copied); - MyTransferable _new = new MyTransferable(myRecentData); - myCopyPasteManager.setSystemClipboardContent(_new); - myCopyPasteManager.fireContentChanged(old, _new); + myCopyPasteManager.setContents(new MyTransferable(myRecentData)); } public boolean isCutElement(Object element) { @@ -278,7 +253,7 @@ public class PsiCopyPasteManager { } } else if (flavor.equals(LinuxDragAndDropSupport.kdeCutMarkFlavor) && !myDataProxy.isCopied()) { - return new ByteArrayInputStream("1".getBytes()); + return new ByteArrayInputStream("1".getBytes(CharsetToolkit.UTF8_CHARSET)); } return null; diff --git a/platform/lang-impl/src/com/intellij/ide/actions/PasteReferenceProvider.java b/platform/lang-impl/src/com/intellij/ide/actions/PasteReferenceProvider.java index c3a685c956f8..00322d26b48c 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/PasteReferenceProvider.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/PasteReferenceProvider.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. @@ -13,21 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.actions; import com.intellij.codeInsight.FileModificationService; -import com.intellij.codeInsight.editorActions.PasteHandler; import com.intellij.ide.IdeBundle; import com.intellij.ide.PasteProvider; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; +import com.intellij.openapi.editor.actions.PasteAction; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; @@ -114,30 +112,20 @@ public class PasteReferenceProvider implements PasteProvider { } @Nullable - private static String getCopiedFqn(final DataContext dataContext) { - @SuppressWarnings("unchecked") - final Producer transferableProducer = (Producer)dataContext.getData(PasteHandler.TRANSFERABLE_PROVIDER); - if (transferableProducer == null) return null; + private static String getCopiedFqn(final DataContext context) { + Producer producer = PasteAction.TRANSFERABLE_PROVIDER.getData(context); - final Transferable transferable = transferableProducer.produce(); - if (transferable != null) { - try { - return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor); - } - catch (Exception ignored) { } - } - - final CopyPasteManager manager = CopyPasteManager.getInstance(); - if (manager.isDataFlavorAvailable(CopyReferenceAction.ourFlavor)) { - final Transferable contents = manager.getContents(); - if (contents != null) { + if (producer != null) { + Transferable transferable = producer.produce(); + if (transferable != null) { try { - return (String)contents.getTransferData(CopyReferenceAction.ourFlavor); + return (String)transferable.getTransferData(CopyReferenceAction.ourFlavor); } catch (Exception ignored) { } } + return null; } - return null; + return CopyPasteManager.getInstance().getContents(CopyReferenceAction.ourFlavor); } } diff --git a/platform/lang-impl/src/com/intellij/ide/macro/ClipboardContentMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/ClipboardContentMacro.java index 8e926537ea8f..a758507c8a50 100644 --- a/platform/lang-impl/src/com/intellij/ide/macro/ClipboardContentMacro.java +++ b/platform/lang-impl/src/com/intellij/ide/macro/ClipboardContentMacro.java @@ -1,20 +1,31 @@ +/* + * 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. + * 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.ide.macro; import com.intellij.ide.IdeBundle; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ide.CopyPasteManager; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author nik */ public class ClipboardContentMacro extends Macro { - private static final Logger LOG = Logger.getInstance(ClipboardContentMacro.class); - @Override public String getName() { return "ClipboardContent"; @@ -28,15 +39,6 @@ public class ClipboardContentMacro extends Macro { @Nullable @Override public String expand(DataContext dataContext) throws ExecutionCancelledException { - Transferable contents = CopyPasteManager.getInstance().getContents(); - if (contents == null) return null; - - try { - return (String)contents.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception e) { - LOG.info(e); - return null; - } + return CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java index ce9de80aff35..369301ab1e76 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewDropTarget.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -81,7 +81,7 @@ class ProjectViewDropTarget implements DnDNativeTarget { if (targetNode == null || (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { return false; } - else if (sourceNodes == null && !FileCopyPasteUtil.isFileListFlavorSupported(event)) { + else if (sourceNodes == null && !FileCopyPasteUtil.isFileListFlavorAvailable(event)) { return false; } else if (sourceNodes != null && ArrayUtilRt.find(sourceNodes, targetNode) != -1) { @@ -124,7 +124,7 @@ class ProjectViewDropTarget implements DnDNativeTarget { assert targetNode != null; final int dropAction = event.getAction().getActionId(); if (sourceNodes == null) { - if (FileCopyPasteUtil.isFileListFlavorSupported(event)) { + if (FileCopyPasteUtil.isFileListFlavorAvailable(event)) { List fileList = FileCopyPasteUtil.getFileListFromAttachedObject(attached); if (!fileList.isEmpty()) { getDropHandler(dropAction).doDropFiles(fileList, targetNode); diff --git a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java index 6bf36675a6ac..eaf4e0e7b5bd 100644 --- a/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java +++ b/platform/lang-impl/src/com/intellij/unscramble/AnalyzeStacktraceUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -48,7 +48,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author yole @@ -67,16 +66,7 @@ public class AnalyzeStacktraceUtil { @Nullable public static String getTextInClipboard() { - final CopyPasteManager copyPasteManager = CopyPasteManager.getInstance(); - if (copyPasteManager.isDataFlavorAvailable(DataFlavor.stringFlavor)) { - final Transferable contents = copyPasteManager.getContents(); - if (contents != null) { - try { - return (String)contents.getTransferData(DataFlavor.stringFlavor); - } catch (Exception ignore) { } - } - } - return null; + return CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); } public interface ConsoleFactory { diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java index ff1e8a82aa34..7507cf525ef6 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java @@ -23,8 +23,8 @@ import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.LineTokenizer; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; +import com.intellij.util.Producer; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; @@ -34,7 +34,7 @@ import java.io.IOException; import java.util.List; public class EditorModificationUtil { - private EditorModificationUtil() {} + private EditorModificationUtil() { } public static void deleteSelectedText(Editor editor) { SelectionModel selectionModel = editor.getSelectionModel(); @@ -133,97 +133,86 @@ public class EditorModificationUtil { } @Nullable - public static TextRange pasteFromClipboard(Editor editor) { - return pasteFromTransferrable(CopyPasteManager.getInstance().getContents(), editor); + public static TextRange pasteTransferable(Editor editor, @Nullable Producer producer) { + String text = getStringContent(producer); + if (text == null) return null; + + int caretOffset = editor.getCaretModel().getOffset(); + insertStringAtCaret(editor, text, false, true); + return new TextRange(caretOffset, caretOffset + text.length()); + } + + public static void pasteTransferableAsBlock(Editor editor, @Nullable Producer producer) { + String text = getStringContent(producer); + if (text == null) return; + + int caretLine = editor.getCaretModel().getLogicalPosition().line; + int originalCaretLine = caretLine; + int selectedLinesCount = 0; + + final SelectionModel selectionModel = editor.getSelectionModel(); + if (selectionModel.hasBlockSelection()) { + final LogicalPosition start = selectionModel.getBlockStart(); + final LogicalPosition end = selectionModel.getBlockEnd(); + assert start != null; + assert end != null; + LogicalPosition caret = new LogicalPosition(Math.min(start.line, end.line), Math.min(start.column, end.column)); + selectedLinesCount = Math.abs(end.line - start.line); + caretLine = caret.line; + + deleteSelectedText(editor); + editor.getCaretModel().moveToLogicalPosition(caret); + } + + LogicalPosition caretToRestore = editor.getCaretModel().getLogicalPosition(); + + String[] lines = LineTokenizer.tokenize(text.toCharArray(), false); + if (lines.length > 1 || selectedLinesCount == 0) { + int longestLineLength = 0; + for (int i = 0; i < lines.length; i++) { + String line = lines[i]; + longestLineLength = Math.max(longestLineLength, line.length()); + editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(caretLine + i, caretToRestore.column)); + insertStringAtCaret(editor, line, false, true); + } + caretToRestore = new LogicalPosition(originalCaretLine, caretToRestore.column + longestLineLength); + } + else { + for (int i = 0; i <= selectedLinesCount; i++) { + editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(caretLine + i, caretToRestore.column)); + insertStringAtCaret(editor, text, false, true); + } + caretToRestore = new LogicalPosition(originalCaretLine, caretToRestore.column + text.length()); + } + + editor.getCaretModel().moveToLogicalPosition(caretToRestore); + zeroWidthBlockSelectionAtCaretColumn(editor, caretLine, caretLine + selectedLinesCount); } @Nullable - public static TextRange pasteFromTransferrable(Transferable content, Editor editor) { - if (content != null) { - try { - String s = getStringContent(content); - - int caretOffset = editor.getCaretModel().getOffset(); - insertStringAtCaret(editor, s, false, true); - return new TextRange(caretOffset, caretOffset + s.length()); - } catch (Exception exception) { - editor.getComponent().getToolkit().beep(); - } - } - - return null; - } - - private static String getStringContent(final Transferable content) throws UnsupportedFlavorException, IOException { - RawText raw = RawText.fromTransferable(content); - String s; - if (raw != null) { - s = raw.rawText; + private static String getStringContent(@Nullable Producer producer) { + Transferable content = null; + if (producer != null) { + content = producer.produce(); } else { - s = (String)content.getTransferData(DataFlavor.stringFlavor); - } - - s = StringUtil.convertLineSeparators(s); - return s; - } - - public static void pasteFromClipboardAsBlock(Editor editor) { - pasteTransferableAsBlock(editor, null); - } - - public static void pasteTransferableAsBlock(Editor editor, @Nullable Transferable content) { - if (content == null) { - content = CopyPasteManager.getInstance().getContents(); - } - - if (content != null) { - try { - int caretLine = editor.getCaretModel().getLogicalPosition().line; - int originalCaretLine = caretLine; - - int selectedLinesCount = 0; - final SelectionModel selectionModel = editor.getSelectionModel(); - if (selectionModel.hasBlockSelection()) { - final LogicalPosition start = selectionModel.getBlockStart(); - final LogicalPosition end = selectionModel.getBlockEnd(); - assert start != null; - assert end != null; - LogicalPosition caret = new LogicalPosition(Math.min(start.line, end.line), Math.min(start.column, end.column)); - selectedLinesCount = Math.abs(end.line - start.line); - caretLine = caret.line; - - deleteSelectedText(editor); - editor.getCaretModel().moveToLogicalPosition(caret); - } - - LogicalPosition caretToRestore = editor.getCaretModel().getLogicalPosition(); - String s = getStringContent(content); - - String[] lines = LineTokenizer.tokenize(s.toCharArray(), false); - if (lines.length > 1 || selectedLinesCount == 0) { - int longestLineLength = 0; - for (int i = 0; i < lines.length; i++) { - String line = lines[i]; - longestLineLength = Math.max(longestLineLength, line.length()); - editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(caretLine + i, caretToRestore.column)); - insertStringAtCaret(editor, line, false, true); - } - caretToRestore = new LogicalPosition(originalCaretLine, caretToRestore.column + longestLineLength); - } - else { - for (int i = 0; i <= selectedLinesCount; i++) { - editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(caretLine + i, caretToRestore.column)); - insertStringAtCaret(editor, s, false, true); - } - caretToRestore = new LogicalPosition(originalCaretLine, caretToRestore.column + s.length()); - } - editor.getCaretModel().moveToLogicalPosition(caretToRestore); - zeroWidthBlockSelectionAtCaretColumn(editor, caretLine, caretLine + selectedLinesCount); - } catch (Exception exception) { - editor.getComponent().getToolkit().beep(); + CopyPasteManager manager = CopyPasteManager.getInstance(); + if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) { + content = manager.getContents(); } } + if (content == null) return null; + + RawText raw = RawText.fromTransferable(content); + if (raw != null) return raw.rawText; + + try { + return (String)content.getTransferData(DataFlavor.stringFlavor); + } + catch (UnsupportedFlavorException ignore) { } + catch (IOException ignore) { } + + return null; } /** @@ -361,4 +350,40 @@ public class EditorModificationUtil { insertStringAtCaret(editor, str, toProcessOverwriteMode, true); } } + + /** @deprecated use {@link #pasteTransferable(Editor, Producer)} (to remove in IDEA 14) */ + @SuppressWarnings("UnusedDeclaration") + public static TextRange pasteFromClipboard(Editor editor) { + return pasteTransferable(editor, null); + } + + /** @deprecated use {@link #pasteTransferable(Editor, Producer)} (to remove in IDEA 14) */ + @SuppressWarnings("SpellCheckingInspection,UnusedDeclaration") + public static TextRange pasteFromTransferrable(final Transferable content, Editor editor) { + return pasteTransferable(editor, new Producer() { + @Nullable + @Override + public Transferable produce() { + return content; + } + }); + } + + @SuppressWarnings("UnusedDeclaration") + /** @deprecated use {@link #pasteTransferableAsBlock(Editor, Producer)} (to remove in IDEA 14) */ + public static void pasteFromClipboardAsBlock(Editor editor) { + pasteTransferableAsBlock(editor, (Producer)null); + } + + @SuppressWarnings("UnusedDeclaration") + /** @deprecated use {@link #pasteTransferableAsBlock(Editor, Producer)} (to remove in IDEA 14) */ + public static void pasteTransferableAsBlock(Editor editor, @Nullable final Transferable content) { + pasteTransferableAsBlock(editor, new Producer() { + @Nullable + @Override + public Transferable produce() { + return content; + } + }); + } } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/RawText.java b/platform/platform-api/src/com/intellij/openapi/editor/RawText.java index 5f4ca25828fa..5d69d1fa2efe 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/RawText.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/RawText.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -13,13 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Created by IntelliJ IDEA. - * User: max - * Date: Sep 5, 2006 - * Time: 9:31:06 PM - */ package com.intellij.openapi.editor; import org.jetbrains.annotations.NonNls; @@ -31,8 +24,14 @@ import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; import java.io.Serializable; +/** + * @author max + * @since Sep 5, 2006 + */ public class RawText implements Cloneable, Serializable { + /** @deprecated use {@link #getDataFlavor()} (to make private in IDEA 14) */ public static @NonNls DataFlavor ourFlavor; + public String rawText; public RawText(final String rawText) { @@ -40,45 +39,41 @@ public class RawText implements Cloneable, Serializable { } public Object clone() { - try{ + try { return super.clone(); } - catch(CloneNotSupportedException e){ + catch (CloneNotSupportedException e) { throw new RuntimeException(); } } + @SuppressWarnings("deprecation") public static DataFlavor getDataFlavor() { - if (ourFlavor != null) { - return ourFlavor; - } + if (ourFlavor != null) return ourFlavor; + try { - ourFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" + RawText.class.getName(), "Raw Text"); + DataFlavor flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" + RawText.class.getName(), "Raw Text"); + ourFlavor = flavor; + return flavor; } - catch (NoClassDefFoundError e) { - return null; - } - catch (IllegalArgumentException e) { - return null; - } - return ourFlavor; + catch (NoClassDefFoundError ignore) { } + catch (IllegalArgumentException ignore) { } + + return null; } @Nullable public static RawText fromTransferable(Transferable content) { - RawText raw = null; - final DataFlavor flavor = getDataFlavor(); + DataFlavor flavor = getDataFlavor(); + if (flavor != null) { try { - raw = (RawText)content.getTransferData(flavor); - } - catch (UnsupportedFlavorException e) { - // OK. raw will be null and we'll get plain string - } - catch (IOException e) { - // OK. raw will be null and we'll get plain string + return (RawText)content.getTransferData(flavor); } + catch (UnsupportedFlavorException ignore) { } + catch (IOException ignore) { } } - return raw; + + return null; } } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java b/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java index 51f67a6d04ca..c96ce0ae3f81 100644 --- a/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.java +++ b/platform/platform-api/src/com/intellij/openapi/ide/CopyPasteManager.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. @@ -39,11 +39,20 @@ public abstract class CopyPasteManager { public abstract void removeContentChangedListener(ContentChangedListener listener); - public abstract boolean isDataFlavorAvailable(@Nullable DataFlavor flavor); + /** @deprecated use {@link #getContents(DataFlavor)} or {@link #areDataFlavorsAvailable(DataFlavor...)} (to remove in IDEA 14) */ + @SuppressWarnings("unused") + public boolean isDataFlavorAvailable(@Nullable DataFlavor flavor) { + return flavor != null && areDataFlavorsAvailable(flavor); + } + + public abstract boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors); @Nullable public abstract Transferable getContents(); + @Nullable + public abstract T getContents(@NotNull DataFlavor flavor); + public abstract Transferable[] getAllContents(); public abstract void setContents(@NotNull Transferable content); @@ -56,11 +65,11 @@ public abstract class CopyPasteManager { *

* However, there are situations when all 'kill rings' should be stopped manually (e.g. on undo). Hence, we need * a handle to ask for that. This method works like such a handle. - * + * * @see KillRingTransferable */ public abstract void stopKillRings(); - + public interface ContentChangedListener extends EventListener { void contentChanged(@Nullable final Transferable oldTransferable, final Transferable newTransferable); } diff --git a/platform/platform-impl/src/com/intellij/ide/ClipboardSynchronizer.java b/platform/platform-impl/src/com/intellij/ide/ClipboardSynchronizer.java index d46b868f8d02..562afc37ea15 100644 --- a/platform/platform-impl/src/com/intellij/ide/ClipboardSynchronizer.java +++ b/platform/platform-impl/src/com/intellij/ide/ClipboardSynchronizer.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. @@ -26,7 +26,6 @@ import com.intellij.openapi.util.registry.Registry; import com.intellij.ui.mac.foundation.Foundation; import com.intellij.ui.mac.foundation.ID; import com.sun.jna.IntegerType; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import sun.awt.datatransfer.DataTransferer; @@ -56,10 +55,6 @@ import java.util.Set; public class ClipboardSynchronizer implements ApplicationComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.ClipboardSynchronizer"); - @NonNls private static final String DATA_TRANSFER_TIMEOUT_PROPERTY = "sun.awt.datatransfer.timeout"; - @NonNls private static final String LONG_TIMEOUT = "2000"; - @NonNls private static final String SHORT_TIMEOUT = "100"; - private final ClipboardHandler myClipboardHandler; public static ClipboardSynchronizer getInstance() { @@ -97,9 +92,9 @@ public class ClipboardSynchronizer implements ApplicationComponent { return "ClipboardSynchronizer"; } - public boolean isDataFlavorAvailable(@NotNull final DataFlavor dataFlavor) { + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { try { - return myClipboardHandler.isDataFlavorAvailable(dataFlavor); + return myClipboardHandler.areDataFlavorsAvailable(flavors); } catch (IllegalStateException e) { LOG.info(e); @@ -128,14 +123,18 @@ public class ClipboardSynchronizer implements ApplicationComponent { private static class ClipboardHandler { - public void init() { - } + public void init() { } - public void dispose() { - } + public void dispose() { } - public boolean isDataFlavorAvailable(@NotNull final DataFlavor dataFlavor) { - return Toolkit.getDefaultToolkit().getSystemClipboard().isDataFlavorAvailable(dataFlavor); + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + for (DataFlavor flavor : flavors) { + if (clipboard.isDataFlavorAvailable(flavor)) { + return true; + } + } + return false; } @Nullable @@ -197,9 +196,9 @@ public class ClipboardSynchronizer implements ApplicationComponent { } @Override - public boolean isDataFlavorAvailable(@NotNull final DataFlavor dataFlavor) { - final Transferable contents = getContents(); - return contents != null && contents.isDataFlavorSupported(dataFlavor); + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { + Transferable contents = getContents(); + return contents != null && ClipboardSynchronizer.areDataFlavorsAvailable(contents, flavors); } @Override @@ -251,7 +250,7 @@ public class ClipboardSynchronizer implements ApplicationComponent { } @Nullable - public static Transferable getContentsSafe() { + private static Transferable getContentsSafe() { final Ref result = new Ref(); Foundation.executeOnMainThread(new Runnable() { @@ -308,6 +307,9 @@ public class ClipboardSynchronizer implements ApplicationComponent { private static class XWinClipboardHandler extends ClipboardHandler { + private static final String DATA_TRANSFER_TIMEOUT_PROPERTY = "sun.awt.datatransfer.timeout"; + private static final String LONG_TIMEOUT = "2000"; + private static final String SHORT_TIMEOUT = "100"; private static final FlavorTable FLAVOR_MAP = (FlavorTable)SystemFlavorMap.getDefaultFlavorMap(); private volatile Transferable myCurrentContent = null; @@ -325,19 +327,19 @@ public class ClipboardSynchronizer implements ApplicationComponent { } @Override - public boolean isDataFlavorAvailable(@NotNull final DataFlavor dataFlavor) { - final Transferable currentContent = myCurrentContent; + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { + Transferable currentContent = myCurrentContent; if (currentContent != null) { - return currentContent.isDataFlavorSupported(dataFlavor); + return ClipboardSynchronizer.areDataFlavorsAvailable(currentContent, flavors); } try { - final Collection contents = checkContentsQuick(); + Collection contents = checkContentsQuick(); if (contents != null) { - return contents.contains(dataFlavor); + return ClipboardSynchronizer.areDataFlavorsAvailable(contents, flavors); } - return super.isDataFlavorAvailable(dataFlavor); + return super.areDataFlavorsAvailable(flavors); } catch (NullPointerException e) { LOG.warn("Java bug #6322854", e); @@ -438,9 +440,9 @@ public class ClipboardSynchronizer implements ApplicationComponent { private volatile Transferable myContent = null; @Override - public boolean isDataFlavorAvailable(@NotNull final DataFlavor dataFlavor) { - final Transferable content = myContent; - return content != null && content.isDataFlavorSupported(dataFlavor); + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { + Transferable content = myContent; + return content != null && ClipboardSynchronizer.areDataFlavorsAvailable(content, flavors); } @Override @@ -458,4 +460,23 @@ public class ClipboardSynchronizer implements ApplicationComponent { myContent = null; } } + + + private static boolean areDataFlavorsAvailable(Transferable contents, DataFlavor... flavors) { + for (DataFlavor flavor : flavors) { + if (contents.isDataFlavorSupported(flavor)) { + return true; + } + } + return false; + } + + private static boolean areDataFlavorsAvailable(Collection contents, DataFlavor... flavors) { + for (DataFlavor flavor : flavors) { + if (contents.contains(flavor)) { + return true; + } + } + return false; + } } diff --git a/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java b/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java index d6f998d492be..d4bd50adf117 100644 --- a/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.java +++ b/platform/platform-impl/src/com/intellij/ide/CopyPasteManagerEx.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. @@ -36,6 +36,7 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn private final List myData = new ArrayList(); private final EventDispatcher myDispatcher = EventDispatcher.create(ContentChangedListener.class); private final ClipboardSynchronizer myClipboardSynchronizer; + private boolean myOwnContent = false; public static CopyPasteManagerEx getInstanceEx() { return (CopyPasteManagerEx)getInstance(); @@ -45,43 +46,50 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn myClipboardSynchronizer = clipboardSynchronizer; } + @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { + myOwnContent = false; myClipboardSynchronizer.resetContent(); fireContentChanged(contents, null); } - void fireContentChanged(@Nullable final Transferable oldTransferable, @Nullable final Transferable _new) { - myDispatcher.getMulticaster().contentChanged(oldTransferable, _new); + private void fireContentChanged(@Nullable Transferable oldContent, @Nullable Transferable newContent) { + myDispatcher.getMulticaster().contentChanged(oldContent, newContent); } + @Override public void addContentChangedListener(ContentChangedListener listener) { myDispatcher.addListener(listener); } + @Override public void addContentChangedListener(final ContentChangedListener listener, Disposable parentDisposable) { myDispatcher.addListener(listener, parentDisposable); } + @Override public void removeContentChangedListener(ContentChangedListener listener) { myDispatcher.removeListener(listener); } @Override - public boolean isDataFlavorAvailable(@Nullable DataFlavor flavor) { - return flavor != null && myClipboardSynchronizer.isDataFlavorAvailable(flavor); + public boolean areDataFlavorsAvailable(@NotNull DataFlavor... flavors) { + return flavors.length > 0 && myClipboardSynchronizer.areDataFlavorsAvailable(flavors); } - public void setContents(@NotNull final Transferable content) { - Transferable old = getContents(); - Transferable contentToUse = addNewContentToStack(content); + @Override + public void setContents(@NotNull Transferable content) { + Transferable oldContent = myOwnContent && !myData.isEmpty() ? myData.get(0) : null; + Transferable contentToUse = addNewContentToStack(content); setSystemClipboardContent(contentToUse); - fireContentChanged(old, contentToUse); + fireContentChanged(oldContent, contentToUse); } + @Override public boolean isCutElement(@Nullable final Object element) { - for(CutElementMarker marker: Extensions.getExtensions(CutElementMarker.EP_NAME)) { + for (CutElementMarker marker : Extensions.getExtensions(CutElementMarker.EP_NAME)) { if (marker.isCutElement(element)) return true; } return false; @@ -96,16 +104,17 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn } } - void setSystemClipboardContent(final Transferable content) { + private void setSystemClipboardContent(Transferable content) { myClipboardSynchronizer.setContent(content, this); + myOwnContent = true; } /** * Stores given content within the current manager. It is merged with already stored ones * if necessary (see {@link KillRingTransferable}). - * - * @param content content to store - * @return content that is either the given one or the one that was assembled from it and already stored one + * + * @param content content to store + * @return content that is either the given one or the one that was assembled from it and already stored one */ @NotNull private Transferable addNewContentToStack(@NotNull Transferable content) { @@ -114,7 +123,7 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn if (clipString == null) { return content; } - + if (content instanceof KillRingTransferable) { KillRingTransferable killRingContent = (KillRingTransferable)content; if (killRingContent.isReadyToCombine() && !myData.isEmpty()) { @@ -132,7 +141,7 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn return killRingContent; } } - + Transferable same = null; for (Transferable old : myData) { if (clipString.equals(getStringContent(old))) { @@ -145,7 +154,7 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn addToTheTopOfTheStack(content); } else { - moveContentTopStackTop(same); + moveContentToStackTop(same); } } catch (UnsupportedFlavorException ignore) { } @@ -157,29 +166,28 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn myData.add(0, content); deleteAfterAllowedMaximum(); } - + /** * Merges given new data with the given old one and returns merge result in case of success. - * - * @param newData new data to merge - * @param oldData old data to merge - * @return merge result of the given data if possible; null otherwise - * @throws IOException as defined by {@link Transferable#getTransferData(DataFlavor)} - * @throws UnsupportedFlavorException as defined by {@link Transferable#getTransferData(DataFlavor)} + * + * @param newData new data to merge + * @param oldData old data to merge + * @return merge result of the given data if possible; null otherwise + * @throws IOException as defined by {@link Transferable#getTransferData(DataFlavor)} + * @throws UnsupportedFlavorException as defined by {@link Transferable#getTransferData(DataFlavor)} */ @Nullable private static Transferable merge(@NotNull KillRingTransferable newData, @NotNull KillRingTransferable oldData) - throws IOException, UnsupportedFlavorException - { + throws IOException, UnsupportedFlavorException { if (!oldData.isReadyToCombine() || !newData.isReadyToCombine()) { return null; } - + Document document = newData.getDocument(); if (document == null || document != oldData.getDocument()) { return null; } - + Object newDataText = newData.getTransferData(DataFlavor.stringFlavor); Object oldDataText = oldData.getTransferData(DataFlavor.stringFlavor); if (newDataText == null || oldDataText == null) { @@ -193,24 +201,29 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn ); } } - + if (newData.getStartOffset() == oldData.getEndOffset()) { return new KillRingTransferable( oldDataText.toString() + newDataText, document, oldData.getStartOffset(), newData.getEndOffset(), false ); } - + if (newData.getEndOffset() == oldData.getStartOffset()) { return new KillRingTransferable( newDataText.toString() + oldDataText, document, newData.getStartOffset(), oldData.getEndOffset(), false ); } - + return null; } - - private static String getStringContent(Transferable content) throws UnsupportedFlavorException, IOException { - return (String) content.getTransferData(DataFlavor.stringFlavor); + + private static String getStringContent(Transferable content) { + try { + return (String)content.getTransferData(DataFlavor.stringFlavor); + } + catch (UnsupportedFlavorException ignore) { } + catch (IOException ignore) { } + return null; } private void deleteAfterAllowedMaximum() { @@ -220,55 +233,61 @@ public class CopyPasteManagerEx extends CopyPasteManager implements ClipboardOwn } } + @Override public Transferable getContents() { return myClipboardSynchronizer.getContents(); } - public Transferable[] getAllContents() { - deleteAfterAllowedMaximum(); - - Transferable content = getContents(); - if (content != null) { + @Nullable + @Override + public T getContents(@NotNull DataFlavor flavor) { + if (areDataFlavorsAvailable(flavor)) { try { - String clipString = getStringContent(content); - String dataString = null; - - if (!myData.isEmpty()) { - dataString = getStringContent(myData.get(0)); - } - - if (clipString != null && clipString.length() > 0 && !Comparing.equal(clipString, dataString)) { - myData.add(0, content); + Transferable contents = getContents(); + if (contents != null) { + @SuppressWarnings("unchecked") T data = (T)contents.getTransferData(flavor); + return data; } } catch (UnsupportedFlavorException ignore) { } catch (IOException ignore) { } } + return null; + } + + @Override + public Transferable[] getAllContents() { + String clipString = getContents(DataFlavor.stringFlavor); + if (clipString != null && (myData.isEmpty() || !Comparing.equal(clipString, getStringContent(myData.get(0))))) { + addToTheTopOfTheStack(new StringSelection(clipString)); + } return myData.toArray(new Transferable[myData.size()]); } public void removeContent(Transferable t) { - Transferable old = getContents(); - boolean isCurrentClipboardContent = myData.indexOf(t) == 0; + Transferable current = myData.isEmpty() ? null : myData.get(0); myData.remove(t); - Transferable _new = null; - if (isCurrentClipboardContent) { - if (!myData.isEmpty()) { - _new = myData.get(0); - setSystemClipboardContent(_new); - } - else { - _new = new StringSelection(""); - setSystemClipboardContent(_new); - } + if (Comparing.equal(t, current)) { + Transferable newContent = !myData.isEmpty() ? myData.get(0) : new StringSelection(""); + setSystemClipboardContent(newContent); + fireContentChanged(current, newContent); } - fireContentChanged(old, _new); } + /** @deprecated use {@link #moveContentToStackTop(Transferable)} (to remove in IDEA 14) */ + @SuppressWarnings("UnusedDeclaration") public void moveContentTopStackTop(Transferable t) { - setSystemClipboardContent(t); - myData.remove(t); - myData.add(0, t); + moveContentToStackTop(t); + } + + public void moveContentToStackTop(Transferable t) { + Transferable current = myData.isEmpty() ? null : myData.get(0); + if (!Comparing.equal(t, current)) { + myData.remove(t); + myData.add(0, t); + setSystemClipboardContent(t); + fireContentChanged(current, t); + } } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/SearchWebAction.java b/platform/platform-impl/src/com/intellij/ide/actions/SearchWebAction.java index 6678247832e5..88868fcf53d5 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/SearchWebAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/SearchWebAction.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. @@ -23,7 +23,6 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.util.text.StringUtil; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; import java.net.URLEncoder; public class SearchWebAction extends AnAction implements DumbAware { @@ -34,14 +33,7 @@ public class SearchWebAction extends AnAction implements DumbAware { return; } provider.performCopy(dataContext); - Transferable contents = CopyPasteManager.getInstance().getContents(); - String string; - try { - string = contents == null? null : (String)contents.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception ex) { - return; - } + String string = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); if (StringUtil.isNotEmpty(string)) { BrowserUtil.launchBrowser("http://www.google.com/search?q="+ URLEncoder.encode(string)); } diff --git a/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java b/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java index 0ebdccb36cdb..cecde708b61b 100644 --- a/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/dnd/FileCopyPasteUtil.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. @@ -16,9 +16,9 @@ package com.intellij.ide.dnd; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.fileTypes.UnknownFileType; +import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; @@ -36,9 +36,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -/** - * todo: migrate all CCP/DnD support classes to JDK6 TransferHandlers (IDEA 12?) - */ public class FileCopyPasteUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.dnd.FileCopyPasteUtil"); @@ -77,19 +74,19 @@ public class FileCopyPasteUtil { return createDataFlavor(DataFlavor.javaJVMLocalObjectMimeType, klass, false); } - public static boolean isFileListFlavorSupported(@NotNull final Transferable transferable) { - return transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || - transferable.isDataFlavorSupported(LinuxDragAndDropSupport.uriListFlavor) || - transferable.isDataFlavorSupported(LinuxDragAndDropSupport.gnomeFileListFlavor); + public static boolean isFileListFlavorAvailable() { + return CopyPasteManager.getInstance().areDataFlavorsAvailable( + DataFlavor.javaFileListFlavor, LinuxDragAndDropSupport.uriListFlavor, LinuxDragAndDropSupport.gnomeFileListFlavor + ); } - public static boolean isFileListFlavorSupported(@NotNull final DnDEvent event) { + public static boolean isFileListFlavorAvailable(@NotNull DnDEvent event) { return event.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || event.isDataFlavorSupported(LinuxDragAndDropSupport.uriListFlavor) || event.isDataFlavorSupported(LinuxDragAndDropSupport.gnomeFileListFlavor); } - public static boolean isFileListFlavorSupported(@NotNull final DataFlavor[] transferFlavors) { + public static boolean isFileListFlavorAvailable(@NotNull DataFlavor[] transferFlavors) { for (DataFlavor flavor : transferFlavors) { if (flavor != null && (flavor.equals(DataFlavor.javaFileListFlavor) || flavor.equals(LinuxDragAndDropSupport.uriListFlavor) || diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java index 47558feddc74..e03e3c33482a 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/IdeaLaf.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. @@ -16,7 +16,9 @@ package com.intellij.ide.ui.laf; import com.intellij.icons.AllIcons; +import com.intellij.ide.ui.UISettings; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.SystemInfo; import com.intellij.ui.ColoredSideBorder; import com.intellij.ui.plaf.beg.*; import com.intellij.util.ui.UIUtil; @@ -41,7 +43,8 @@ public final class IdeaLaf extends MetalLookAndFeel { LafManagerImpl.initInputMapDefaults(defaults); initIdeaDefaults(defaults); - Pair systemFont = UIUtil.getSystemFontData(); + final UISettings ui = UISettings.getInstance(); + Pair systemFont = SystemInfo.isWindows ? Pair.create(ui.FONT_FACE, ui.FONT_SIZE) : UIUtil.getSystemFontData(); if (systemFont != null) { LafManagerImpl.initFontDefaults(defaults, systemFont.first, systemFont.second); } diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/actions/ClipboardVsValueContents.java b/platform/platform-impl/src/com/intellij/openapi/diff/actions/ClipboardVsValueContents.java index 966ed4685833..583fd3afc70f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/actions/ClipboardVsValueContents.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/actions/ClipboardVsValueContents.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. @@ -26,7 +26,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author Jeka @@ -72,15 +71,7 @@ public class ClipboardVsValueContents extends DiffRequest { @Nullable public static DiffContent createClipboardContent() { - Transferable content = CopyPasteManager.getInstance().getContents(); - if (content != null) { - try { - String text = (String)(content.getTransferData(DataFlavor.stringFlavor)); - return text != null ? new SimpleContent(text) : null; - } - catch (Exception ignored) { - } - } - return null; + String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); + return text != null ? new SimpleContent(text) : null; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java index 416c0a9d7eff..f2d26ef0b4e6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -92,7 +92,7 @@ public class MultiplePasteAction extends AnAction implements DumbAware { if (chooser.isOK()) { final int[] selectedIndices = chooser.getSelectedIndices(); if (selectedIndices.length == 1) { - copyPasteManager.moveContentTopStackTop(chooser.getAllContents().get(selectedIndices[0])); + copyPasteManager.moveContentToStackTop(chooser.getAllContents().get(selectedIndices[0])); } else { copyPasteManager.setContents(new StringSelection(chooser.getSelectedText())); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java index a0d99d815549..7851070f9d95 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -13,30 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Created by IntelliJ IDEA. - * User: max - * Date: May 13, 2002 - * Time: 7:50:36 PM - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). - */ package com.intellij.openapi.editor.actions; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.util.TextRange; import com.intellij.util.Producer; import java.awt.datatransfer.Transferable; +/** + * @author max + * @since May 13, 2002 + */ public class PasteAction extends EditorAction { - public static final String TRANSFERABLE_PROVIDER = "PasteTransferableProvider"; - + public static final DataKey> TRANSFERABLE_PROVIDER = DataKey.create("PasteTransferableProvider"); + public PasteAction() { super(new Handler()); } @@ -44,15 +41,13 @@ public class PasteAction extends EditorAction { private static class Handler extends EditorWriteActionHandler { @Override public void executeWriteAction(Editor editor, DataContext dataContext) { - Producer producer = (Producer)dataContext.getData(TRANSFERABLE_PROVIDER); - + Producer producer = TRANSFERABLE_PROVIDER.getData(dataContext); if (editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection()) { - EditorModificationUtil.pasteTransferableAsBlock(editor, producer == null ? null : producer.produce()); + EditorModificationUtil.pasteTransferableAsBlock(editor, producer); } else { - editor.putUserData(EditorEx.LAST_PASTED_REGION, - producer == null ? EditorModificationUtil.pasteFromClipboard(editor) : - EditorModificationUtil.pasteFromTransferrable(producer.produce(), editor)); + TextRange range = EditorModificationUtil.pasteTransferable(editor, producer); + editor.putUserData(EditorEx.LAST_PASTED_REGION, range); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java index fcd7b9799360..3e20ba800dae 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.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. @@ -18,18 +18,18 @@ package com.intellij.openapi.editor.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.editor.event.EditorMouseEventArea; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.TextRange; +import com.intellij.util.Producer; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -74,21 +74,27 @@ public class PasteFromX11Action extends EditorAction { public static class Handler extends EditorWriteActionHandler { @Override public void executeWriteAction(Editor editor, DataContext dataContext) { - final Clipboard clip = editor.getComponent().getToolkit().getSystemSelection(); - if (clip != null) { - Transferable res = null; - try { - res = clip.getContents(null); - } - catch (Exception e) { - if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { - LOG.info(e); - Messages.showErrorDialog(editor.getProject(), "Cannot paste from X11 clipboard: " + e.getLocalizedMessage(), "Cannot Paste"); - return; - } - } - editor.putUserData(EditorEx.LAST_PASTED_REGION, EditorModificationUtil.pasteFromTransferrable(res, editor)); + Clipboard clip = editor.getComponent().getToolkit().getSystemSelection(); + if (clip == null) return; + + final Transferable content; + try { + content = clip.getContents(null); } + catch (Exception e) { + LOG.info(e); + return; + } + if (content == null) return; + + TextRange range = EditorModificationUtil.pasteTransferable(editor, new Producer() { + @Nullable + @Override + public Transferable produce() { + return content; + } + }); + editor.putUserData(EditorEx.LAST_PASTED_REGION, range); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java index 40a9adbfa2dc..a19a9a85a7e5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -13,29 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * Created by IntelliJ IDEA. - * User: max - * Date: May 13, 2002 - * Time: 7:50:36 PM - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). - */ package com.intellij.openapi.editor.actions; import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.util.TextRange; import com.intellij.util.Producer; import java.awt.datatransfer.Transferable; +/** + * @author max + * @since May 13, 2002 + */ public class SimplePasteAction extends EditorAction { public SimplePasteAction() { super(new Handler()); @@ -45,23 +42,21 @@ public class SimplePasteAction extends EditorAction { public void update(AnActionEvent e) { super.update(e); if (ActionPlaces.isPopupPlace(e.getPlace())) { - e.getPresentation().setVisible(e.getPresentation().isEnabled()); + Presentation presentation = e.getPresentation(); + presentation.setVisible(presentation.isEnabled()); } } private static class Handler extends EditorWriteActionHandler { @Override public void executeWriteAction(Editor editor, DataContext dataContext) { - Producer producer = (Producer) dataContext.getData(PasteAction.TRANSFERABLE_PROVIDER); - + Producer producer = PasteAction.TRANSFERABLE_PROVIDER.getData(dataContext); if (editor.isColumnMode()) { - EditorModificationUtil.pasteTransferableAsBlock(editor, producer == null ? null : producer.produce()); - } else { - editor.putUserData(EditorEx.LAST_PASTED_REGION, - producer == null ? - EditorModificationUtil.pasteFromClipboard(editor) - : EditorModificationUtil.pasteFromTransferrable(producer.produce(), editor)); - + EditorModificationUtil.pasteTransferableAsBlock(editor, producer); + } + else { + TextRange range = EditorModificationUtil.pasteTransferable(editor, producer); + editor.putUserData(EditorEx.LAST_PASTED_REGION, range); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index f92ded0fd1bc..0f2bd2070d60 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -5981,6 +5981,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi public void run() { try { editor.getSelectionModel().removeSelection(); + final int offset; if (myDraggedRange != null) { editor.getCaretModel().moveToOffset(caretOffset); @@ -5989,16 +5990,15 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi else { offset = editor.getCaretModel().getOffset(); } - if (editor.getDocument().getRangeGuard(offset, offset) != null) return; - - EditorActionHandler pasteHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_PASTE); + if (editor.getDocument().getRangeGuard(offset, offset) != null) { + return; + } editor.putUserData(LAST_PASTED_REGION, null); + EditorActionHandler pasteHandler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_PASTE); LOG.assertTrue(pasteHandler instanceof EditorTextInsertHandler); - - EditorTextInsertHandler handler = (EditorTextInsertHandler)pasteHandler; - handler.execute(editor, editor.getDataContext(), new Producer() { + ((EditorTextInsertHandler)pasteHandler).execute(editor, editor.getDataContext(), new Producer() { @Override public Transferable produce() { return t; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/FileDropHandler.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/FileDropHandler.java index 972ac670b7bd..342cb0959f88 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/FileDropHandler.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/text/FileDropHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -44,21 +44,18 @@ public class FileDropHandler implements EditorDropHandler { myEditor = editor; } - @Override public boolean canHandleDrop(final DataFlavor[] transferFlavors) { - return transferFlavors != null && FileCopyPasteUtil.isFileListFlavorSupported(transferFlavors); + return transferFlavors != null && FileCopyPasteUtil.isFileListFlavorAvailable(transferFlavors); } @Override public void handleDrop(@NotNull final Transferable t, @Nullable final Project project, EditorWindow editorWindow) { - if (project == null || !FileCopyPasteUtil.isFileListFlavorSupported(t)) { - return; - } - - final List fileList = FileCopyPasteUtil.getFileList(t); - if (fileList != null) { - openFiles(project, fileList, editorWindow); + if (project != null) { + final List fileList = FileCopyPasteUtil.getFileList(t); + if (fileList != null) { + openFiles(project, fileList, editorWindow); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java index 09dd985b04b6..18c5f76b670a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginAdvertiserEditorNotificationProvider.java @@ -117,7 +117,7 @@ public class PluginAdvertiserEditorNotificationProvider extends EditorNotificati try { myAllPlugins = RepositoryHelper.loadPluginsFromRepository(indicator); for (IdeaPluginDescriptor loadedPlugin : myAllPlugins) { - if (plugins.contains(new PluginsAdvertiser.Plugin(loadedPlugin.getPluginId(), loadedPlugin.getName(), false))) { + if (plugins.contains(new PluginsAdvertiser.Plugin(loadedPlugin.getPluginId(), null, false))) { myPlugins.add(PluginDownloader.createDownloader(loadedPlugin)); } } diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java index b9cf1e39fdb7..3954b2b3579b 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java @@ -120,6 +120,8 @@ public class MacMessagesImpl extends MacMessages { // invoke(invoke(alert, "buttons"), "objectAtIndex:", count == 1 ? 0 : 1)); //} + enableEscapeToCloseTheMessage(alert); + String doNotAsk = toStringViaUTF8(doNotAskText); if (!"-1".equals(doNotAsk)) { invoke(alert, "setShowsSuppressionButton:", 1); @@ -161,10 +163,10 @@ public class MacMessagesImpl extends MacMessages { //invoke(window, "makeFirstResponder:", // invoke(invoke(alert, "buttons"), "objectAtIndex:", alternateExist ? 2 : otherExist ? 1 : 0)); // - ////it is impossible to override ESCAPE key behavior -> key should be named "Cancel" to be bound to ESC - //if (!alternateExist) { - // invoke(invoke(invoke(alert, "buttons"), "objectAtIndex:", 1), "setKeyEquivalent:", nsString("\\e")); - //} + + if (!alternateExist) { + enableEscapeToCloseTheMessage(alert); + } String doNotAsk = toStringViaUTF8(doNotAskText); if (!"-1".equals(doNotAsk)) { @@ -200,6 +202,11 @@ public class MacMessagesImpl extends MacMessages { } } + private static ID enableEscapeToCloseTheMessage(ID alert) { + return invoke(invoke(invoke(alert, "buttons"), "objectAtIndex:", + invoke(invoke(alert, "buttons"), "count").intValue() - 1), "setKeyEquivalent:", nsString("\033")); + } + private MacMessagesImpl() {} private static final Callback windowDidBecomeMainCallback = new Callback() { diff --git a/platform/platform-resources-en/src/messages/FindBundle.properties b/platform/platform-resources-en/src/messages/FindBundle.properties index 5b88202519a6..0151999e5eb7 100644 --- a/platform/platform-resources-en/src/messages/FindBundle.properties +++ b/platform/platform-resources-en/src/messages/FindBundle.properties @@ -66,7 +66,7 @@ find.text.dialog.title=Find Text find.button=Find find.all.button=Find &All find.text.to.find.label=Text to &find: -find.replace.with.label=&Replace with: +find.replace.with.label=Replace &with: find.filter.file.name.group=File name filter find.filter.file.mask.checkbox=File m&ask(s) find.directory.not.found.error=Directory {0} is not found diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/CopyActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/CopyActionTest.java index 3f16747ea5a3..254437d71254 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/CopyActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/CopyActionTest.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. @@ -52,10 +52,10 @@ public class CopyActionTest extends LightPlatformCodeInsightTestCase { configureFromFileText(getTestName(false) + ".txt", documentContents); } - private void verifyResult(String expectedDocumentContents, String expectedClipboardContents) throws Exception { + private void verifyResult(String expectedDocumentContents, String expectedClipboardContents) { checkResultByText(expectedDocumentContents); assertEquals("Clipboard contents mismatch", expectedClipboardContents, - CopyPasteManager.getInstance().getContents().getTransferData(DataFlavor.stringFlavor).toString()); + CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor)); } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java index 818257c04443..2c05207653e1 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRegionActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -20,7 +20,6 @@ import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author Denis Zhdanov @@ -33,11 +32,10 @@ public class KillRegionActionTest extends AbstractRegionToKillRingTest { Pair parseResult = parse(); killRegion(); if (parseResult.first != null) { - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertNotNull(contents); - assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor)); + String contents = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); + assertEquals(parseResult.first, contents); } - + assertEquals(parseResult.second, myEditor.getDocument().getText()); } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java index 21c9e780625b..f436175166df 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillRingSaveActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -20,7 +20,6 @@ import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; /** * @author Denis Zhdanov @@ -37,9 +36,8 @@ public class KillRingSaveActionTest extends AbstractRegionToKillRingTest { return; } - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertNotNull(contents); - assertEquals(parseResult.first, contents.getTransferData(DataFlavor.stringFlavor)); + String contents = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor); + assertEquals(parseResult.first, contents); assertEquals(textBefore, myEditor.getDocument().getText()); } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java index be8c80afe336..3246c789ae99 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/KillToWordEndActionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 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. @@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; /** @@ -43,7 +44,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { "this is a " ); } - + public void testInTheMiddle() throws IOException { doTest( "this is a string", @@ -86,7 +87,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { "this is a string" ); } - + public void testAtWhiteSpaceAtLineEnd() throws IOException { doTest( "this is the first string \n" + @@ -94,7 +95,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { "this is the first string this is the second string" ); } - + private void doTest(@NotNull String before, @NotNull String after) throws IOException { configureFromFileText(getTestName(false) + ".txt", before); killToWordEnd(); @@ -106,13 +107,11 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { configureFromFileText(getTestName(false) + ".txt", text); killToWordEnd(); checkResultByText(" second third"); - + getEditor().getCaretModel().moveCaretRelatively(1, 0, false, false, false); getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, false); killToWordEnd(); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals(" second", string); } @@ -123,9 +122,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { killToWordEnd(); checkResultByText(" third"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("first second", string); } @@ -144,9 +141,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " public Insets getBorderInsets( }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("Component c) {\n }\n", string); } @@ -185,9 +180,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " public Insets getBorderInsets( }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("Component c) {\n }\n", string); } @@ -203,9 +196,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { killToWordEnd(); checkResultByText(" third"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("first second", string); } finally { @@ -227,9 +218,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("\n" + " }", string); } @@ -247,9 +236,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("\n" + " }", string); } @@ -267,9 +254,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " public Insets getBorderInsets( }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals(" }\n", string); } @@ -286,9 +271,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { checkResultByText("public class ParentCopy {\n" + " public Insets getBorderInsets( }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("}\n", string); } @@ -306,9 +289,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { " public Insets getBorderInsets( }\n" + " }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("\n" + " \n", string); } @@ -328,11 +309,14 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase { " \n" + " }"); - Transferable contents = CopyPasteManager.getInstance().getContents(); - assertTrue(contents instanceof KillRingTransferable); - Object string = contents.getTransferData(DataFlavor.stringFlavor); + Object string = getContents(); assertEquals("\n" + " }", string); } + private static String getContents() throws UnsupportedFlavorException, IOException { + Transferable contents = CopyPasteManager.getInstance().getContents(); + assertTrue(contents instanceof KillRingTransferable); + return (String)contents.getTransferData(DataFlavor.stringFlavor); + } } diff --git a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java index 6f4ca1bf1b60..2976c03f50c0 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExplorer.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. @@ -854,7 +854,7 @@ public class AntExplorer extends SimpleToolWindowPanel implements DataProvider, @Override public boolean canImport(final TransferSupport support) { - return FileCopyPasteUtil.isFileListFlavorSupported(support.getDataFlavors()); + return FileCopyPasteUtil.isFileListFlavorAvailable(support.getDataFlavors()); } private VirtualFile[] getAntFiles(final TransferSupport support) { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java index f12de5460942..285070ca8722 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java @@ -182,7 +182,8 @@ public class GradleExecutionHelper { return f.fun(connection); } catch (Throwable e) { - throw new ExternalSystemException(ExceptionUtil.getMessage(e)); + Throwable rootCause = ExceptionUtil.getRootCause(e); + throw new ExternalSystemException(ExceptionUtil.getMessage(rootCause)); } finally { try { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java index 6cf3bcadf500..b0b4c7a0ab56 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/provider/update/HgRegularUpdater.java @@ -268,7 +268,7 @@ public class HgRegularUpdater implements HgUpdater { if (parentAfterUpdate.equals(parentBeforeUpdate)) { // nothing to update => returning not to capture local uncommitted changes return; } - HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).baseRevision(parentBeforeUpdate).targetRevision( + HgStatusCommand statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).baseRevision(parentBeforeUpdate).targetRevision( parentAfterUpdate).build(project); Set changes = statusCommand.execute(repo); for (HgChange change : changes) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java index 910aae8d14b1..cacf3257335a 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgUtil.java @@ -470,13 +470,15 @@ public abstract class HgUtil { if (rev1 != null) { revNumber1 = rev1.getRevisionNumber(); //rev2==null means "compare with local version" - statusCommand = new HgStatusCommand.Builder(true).copySource(false).baseRevision(revNumber1) + statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(false).baseRevision(revNumber1) .targetRevision(rev2 != null ? rev2.getRevisionNumber() : null).build(project); } else { LOG.assertTrue(rev2 != null, "revision1 and revision2 can't both be null. Path: " + path); //rev1 and rev2 can't be null both// //get initial changes// - statusCommand = new HgStatusCommand.Builder(true).copySource(false).baseRevision(rev2.getRevisionNumber()).build(project); + statusCommand = + new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(false).baseRevision(rev2.getRevisionNumber()) + .build(project); } Collection hgChanges = statusCommand.execute(root, Collections.singleton(path)); @@ -484,11 +486,11 @@ public abstract class HgUtil { //convert output changes to standart Change class for (HgChange hgChange : hgChanges) { FileStatus status = convertHgDiffStatus(hgChange.getStatus()); - if (status != FileStatus.UNKNOWN && status!= FileStatus.IGNORED) { + if (status != FileStatus.UNKNOWN) { changes.add(createChange(project, root, hgChange.beforeFile().getRelativePath(), revNumber1, hgChange.afterFile().getRelativePath(), rev2 != null ? rev2.getRevisionNumber() : null, status)); - } + } } return changes; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java index 525f0e74b3d7..86761532f6a0 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -318,7 +318,7 @@ public class MavenProjectsNavigatorPanel extends SimpleToolWindowPanel implement @Override public boolean canImport(final TransferSupport support) { - return FileCopyPasteUtil.isFileListFlavorSupported(support.getDataFlavors()); + return FileCopyPasteUtil.isFileListFlavorAvailable(support.getDataFlavors()); } } } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java index 821ff57ee614..54d1e8ad7b78 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/OpenTaskDialog.java @@ -107,7 +107,9 @@ public class OpenTaskDialog extends DialogWrapper { myCreateChangelist.setSelected(manager.getState().createChangelist); myCreateBranch.setSelected(manager.getState().createBranch); - if (vcs.getType() != VcsType.distributed) { + // In git 'master' branch appears (in .git/refs/heads/master) only after at least one commit was made in it. + // Before that feature branches can't be created normally. + if (vcs.getType() != VcsType.distributed || !branchesExist(project)) { myCreateBranch.setSelected(false); myCreateBranch.setVisible(false); myBranchName.setVisible(false); @@ -162,6 +164,15 @@ public class OpenTaskDialog extends DialogWrapper { init(); } + private static boolean branchesExist(Project project) { + for (VcsTaskHandler handler : VcsTaskHandler.getAllHandlers(project)) { + if (handler.getCurrentTasks().length != 0) { + return true; + } + } + return false; + } + private void updateFields() { myBranchName.setEnabled(myCreateBranch.isSelected()); myChangelistName.setEnabled(myCreateChangelist.isSelected()); diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/generic/connectors/assembla.xml b/plugins/tasks/tasks-core/src/com/intellij/tasks/generic/connectors/assembla.xml index da466a6014c8..744d80a6fe6b 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/generic/connectors/assembla.xml +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/generic/connectors/assembla.xml @@ -1,5 +1,5 @@ - {id} {summary} + #{id} {summary}