mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
</java>
|
||||
|
||||
<java classname="com.intellij.util.io.zip.ReorderJarsMain" fork="true">
|
||||
<jvmarg line="-Djava.awt.headless=true"/>
|
||||
<arg value="${build}/order.txt"/>
|
||||
<arg value="@{deploy}"/>
|
||||
<arg value="@{deploy}"/>
|
||||
|
||||
+3
-3
@@ -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());
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<ProjectTemplate>());
|
||||
ArrayList<ProjectTemplate> templates = new ArrayList<ProjectTemplate>();
|
||||
templates.add(new ProjectCategoryTemplate(category));
|
||||
myTemplatesMap.put(new TemplatesGroup(category), templates);
|
||||
}
|
||||
if (context.isCreatingNewProject()) {
|
||||
MultiMap<String, ProjectTemplate> 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());
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<FrameworkSupportInModuleProvider> 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<FrameworkSupportInModuleProvider> providers, @Nullable ProjectTemplate template) {
|
||||
if (!(template instanceof ProjectCategoryTemplate)) return;
|
||||
ProjectCategory category = ((ProjectCategoryTemplate)template).getCategory();
|
||||
for (Iterator<FrameworkSupportInModuleProvider> iterator = providers.iterator(); iterator.hasNext(); ) {
|
||||
FrameworkSupportInModuleProvider provider = iterator.next();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return ICON;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,11 +173,6 @@ public class UISettings implements PersistentStateComponent<UISettings>, Exporta
|
||||
}
|
||||
|
||||
private static Pair<String, Integer> getSystemFontFaceAndSize() {
|
||||
final Pair<String,Integer> 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<UISettings>, Exporta
|
||||
}
|
||||
}
|
||||
|
||||
final Pair<String,Integer> fontData = UIUtil.getSystemFontData();
|
||||
if (fontData != null) {
|
||||
return fontData;
|
||||
}
|
||||
|
||||
return Pair.create("Dialog", 12);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Listener> 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");
|
||||
}
|
||||
|
||||
@@ -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<PasteProvider> 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<Transferable> 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<Transferable> 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<Transferable>() {
|
||||
@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<Transferable> transferableFunction) {
|
||||
Transferable content = transferableFunction.produce();
|
||||
final Producer<Transferable> 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<CopyPastePostProcessor, TextBlockTransferableData> extraData = new HashMap<CopyPastePostProcessor, TextBlockTransferableData>();
|
||||
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<Boolean> indented = new Ref<Boolean>(Boolean.FALSE);
|
||||
for(Map.Entry<CopyPastePostProcessor, TextBlockTransferableData> e: extraData.entrySet()) {
|
||||
for (Map.Entry<CopyPastePostProcessor, TextBlockTransferableData> 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");
|
||||
|
||||
@@ -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 : "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<File> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Transferable> transferableProducer = (Producer<Transferable>)dataContext.getData(PasteHandler.TRANSFERABLE_PROVIDER);
|
||||
if (transferableProducer == null) return null;
|
||||
private static String getCopiedFqn(final DataContext context) {
|
||||
Producer<Transferable> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<File> fileList = FileCopyPasteUtil.getFileListFromAttachedObject(attached);
|
||||
if (!fileList.isEmpty()) {
|
||||
getDropHandler(dropAction).doDropFiles(fileList, targetNode);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+111
-86
@@ -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<Transferable> 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<Transferable> 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<Transferable> 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<Transferable>() {
|
||||
@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<Transferable>)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<Transferable>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Transferable produce() {
|
||||
return content;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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> T getContents(@NotNull DataFlavor flavor);
|
||||
|
||||
public abstract Transferable[] getAllContents();
|
||||
|
||||
public abstract void setContents(@NotNull Transferable content);
|
||||
@@ -56,11 +65,11 @@ public abstract class CopyPasteManager {
|
||||
* <p/>
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -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<Transferable> result = new Ref<Transferable>();
|
||||
|
||||
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<DataFlavor> contents = checkContentsQuick();
|
||||
Collection<DataFlavor> 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<DataFlavor> contents, DataFlavor... flavors) {
|
||||
for (DataFlavor flavor : flavors) {
|
||||
if (contents.contains(flavor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Transferable> myData = new ArrayList<Transferable>();
|
||||
private final EventDispatcher<ContentChangedListener> 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; <code>null</code> 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; <code>null</code> 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> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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<String, Integer> systemFont = UIUtil.getSystemFontData();
|
||||
final UISettings ui = UISettings.getInstance();
|
||||
Pair<String, Integer> systemFont = SystemInfo.isWindows ? Pair.create(ui.FONT_FACE, ui.FONT_SIZE) : UIUtil.getSystemFontData();
|
||||
if (systemFont != null) {
|
||||
LafManagerImpl.initFontDefaults(defaults, systemFont.first, systemFont.second);
|
||||
}
|
||||
|
||||
+3
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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()));
|
||||
|
||||
@@ -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<Producer<Transferable>> 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<Transferable> producer = (Producer<Transferable>)dataContext.getData(TRANSFERABLE_PROVIDER);
|
||||
|
||||
Producer<Transferable> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-19
@@ -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<Transferable>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Transferable produce() {
|
||||
return content;
|
||||
}
|
||||
});
|
||||
editor.putUserData(EditorEx.LAST_PASTED_REGION, range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-20
@@ -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<Transferable> producer = (Producer<Transferable>) dataContext.getData(PasteAction.TRANSFERABLE_PROVIDER);
|
||||
|
||||
Producer<Transferable> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Transferable>() {
|
||||
((EditorTextInsertHandler)pasteHandler).execute(editor, editor.getDataContext(), new Producer<Transferable>() {
|
||||
@Override
|
||||
public Transferable produce() {
|
||||
return t;
|
||||
|
||||
+7
-10
@@ -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<File> fileList = FileCopyPasteUtil.getFileList(t);
|
||||
if (fileList != null) {
|
||||
openFiles(project, fileList, editorWindow);
|
||||
if (project != null) {
|
||||
final List<File> fileList = FileCopyPasteUtil.getFileList(t);
|
||||
if (fileList != null) {
|
||||
openFiles(project, fileList, editorWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
-3
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -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<String,String> 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());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+22
-38
@@ -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 <caret>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testInTheMiddle() throws IOException {
|
||||
doTest(
|
||||
"th<caret>is is a string",
|
||||
@@ -86,7 +87,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase {
|
||||
"this is a string<caret>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testAtWhiteSpaceAtLineEnd() throws IOException {
|
||||
doTest(
|
||||
"this is the first string <caret> \n" +
|
||||
@@ -94,7 +95,7 @@ public class KillToWordEndActionTest extends LightPlatformCodeInsightTestCase {
|
||||
"this is the first string <caret>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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+2
-1
@@ -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 {
|
||||
|
||||
@@ -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<HgChange> changes = statusCommand.execute(repo);
|
||||
for (HgChange change : changes) {
|
||||
|
||||
@@ -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<HgChange> 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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<Assembla shared="false" url="http://www.assembla.com">
|
||||
<commitMessageFormat>{id} {summary}</commitMessageFormat>
|
||||
<commitMessageFormat>#{id} {summary}</commitMessageFormat>
|
||||
<option name="downloadTasksInSeparateRequests" value="false" />
|
||||
<password/>
|
||||
<option name="loginAnonymously" value="false" />
|
||||
@@ -9,7 +9,7 @@
|
||||
<XPathResponseHandler>
|
||||
<selectors>
|
||||
<selector name="tasks" path="/tickets/ticket" />
|
||||
<selector name="id" path="id" />
|
||||
<selector name="id" path="number" />
|
||||
<selector name="summary" path="summary" />
|
||||
<selector name="description" path="description" />
|
||||
<selector name="updated" path="updated-at" />
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class AssemblaIntegrationTest extends GenericSubtypeTestCase {
|
||||
Task[] tasks = myRepository.getActiveResponseHandler().parseIssues(TASK_LIST_RESPONSE, 50);
|
||||
assertTasksEqual(
|
||||
new Task[]{
|
||||
new TaskBuilder("50351983", "\u041F\u0440\u0438\u0432\u0435\u0442", myRepository)
|
||||
new TaskBuilder("1", "\u041F\u0440\u0438\u0432\u0435\u0442", myRepository)
|
||||
.withDescription("")
|
||||
.withUpdated("2013-04-01T10:48:19+03:00")
|
||||
.withCreated("2013-04-01T10:45:06+03:00")
|
||||
|
||||
@@ -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.
|
||||
@@ -44,7 +44,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
@@ -74,7 +73,7 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Ter
|
||||
registerKeymapActions(this);
|
||||
|
||||
addFocusListener(this);
|
||||
|
||||
|
||||
mySettingsProvider.addListener(this);
|
||||
}
|
||||
|
||||
@@ -170,11 +169,7 @@ public class JBTerminalPanel extends TerminalPanel implements FocusListener, Ter
|
||||
|
||||
@Override
|
||||
protected String getClipboardContent() throws IOException, UnsupportedFlavorException {
|
||||
Transferable contents = CopyPasteManager.getInstance().getContents();
|
||||
if (contents == null) {
|
||||
return null;
|
||||
}
|
||||
return (String)contents.getTransferData(DataFlavor.stringFlavor);
|
||||
return CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-15
@@ -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.
|
||||
@@ -40,7 +40,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -260,17 +259,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
|
||||
@Nullable
|
||||
private String getSerializedComponentData() {
|
||||
try {
|
||||
CopyPasteManager copyPasteManager = CopyPasteManager.getInstance();
|
||||
if (!copyPasteManager.isDataFlavorAvailable(DATA_FLAVOR)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Transferable content = copyPasteManager.getContents();
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object transferData = content.getTransferData(DATA_FLAVOR);
|
||||
Object transferData = CopyPasteManager.getInstance().getContents(DATA_FLAVOR);
|
||||
if (transferData instanceof SerializedComponentData) {
|
||||
SerializedComponentData data = (SerializedComponentData)transferData;
|
||||
String xmlComponents = data.getSerializedComponents();
|
||||
@@ -279,8 +268,7 @@ public class CommonEditActionsProvider implements DeleteProvider, CopyProvider,
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
}
|
||||
catch (Throwable ignored) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -39,7 +39,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -165,7 +164,7 @@ public final class CutCopyPasteSupport implements CopyProvider, CutProvider, Pas
|
||||
if (parentLayout != null) {
|
||||
container.setLayoutManager(parentLayout);
|
||||
}
|
||||
|
||||
|
||||
final int x = Integer.parseInt(e.getAttributeValue(ATTRIBUTE_X));
|
||||
final int y = Integer.parseInt(e.getAttributeValue(ATTRIBUTE_Y));
|
||||
|
||||
@@ -204,17 +203,7 @@ public final class CutCopyPasteSupport implements CopyProvider, CutProvider, Pas
|
||||
@Nullable
|
||||
private static String getSerializedComponents() {
|
||||
try {
|
||||
final CopyPasteManager copyPasteManager = CopyPasteManager.getInstance();
|
||||
if (!copyPasteManager.isDataFlavorAvailable(ourDataFlavor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Transferable content = copyPasteManager.getContents();
|
||||
if (content == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Object transferData = content.getTransferData(ourDataFlavor);
|
||||
final Object transferData = CopyPasteManager.getInstance().getContents(ourDataFlavor);
|
||||
if (!(transferData instanceof SerializedComponentData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<patterns.patternClass className="com.jetbrains.python.patterns.PythonPatterns" alias="py"/>
|
||||
<multiHostInjector implementation="com.jetbrains.python.intelliLang.PyCommentInjector"/>
|
||||
<multiHostInjector implementation="com.jetbrains.python.intelliLang.PyConfigurationInjector"/>
|
||||
<multiHostInjector implementation="com.jetbrains.python.intelliLang.PyTemporaryInjector"/>
|
||||
</extensions>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import sys
|
||||
|
||||
from tcunittest import TeamcityTestRunner
|
||||
from tcunittest import TeamcityTestRunner, TeamcityTestResult
|
||||
from tcmessages import TeamcityServiceMessages
|
||||
|
||||
import sys
|
||||
from pycharm_run_utils import adjust_django_sys_path
|
||||
adjust_django_sys_path()
|
||||
|
||||
@@ -52,10 +50,41 @@ except ImportError:
|
||||
def __init__(self, stream=sys.stdout, **options):
|
||||
TeamcityTestRunner.__init__(self, stream)
|
||||
|
||||
|
||||
def strclass(cls):
|
||||
if not cls.__name__:
|
||||
return cls.__module__
|
||||
return "%s.%s" % (cls.__module__, cls.__name__)
|
||||
|
||||
class DjangoTeamcityTestResult(TeamcityTestResult):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DjangoTeamcityTestResult, self).__init__()
|
||||
|
||||
def _getSuite(self, test):
|
||||
if hasattr(test, "suite"):
|
||||
suite = strclass(test.suite)
|
||||
suite_location = test.suite.location
|
||||
location = test.suite.abs_location
|
||||
if hasattr(test, "lineno"):
|
||||
location = location + ":" + str(test.lineno)
|
||||
else:
|
||||
location = location + ":" + str(test.test.lineno)
|
||||
else:
|
||||
|
||||
suite = strclass(test.__class__)
|
||||
suite_location = "django_testid://" + suite
|
||||
location = "django_testid://" + str(test.id())
|
||||
|
||||
return (suite, location, suite_location)
|
||||
|
||||
|
||||
class DjangoTeamcityTestRunner(BaseRunner):
|
||||
def __init__(self, stream=sys.stdout, **options):
|
||||
super(DjangoTeamcityTestRunner, self).__init__(stream)
|
||||
|
||||
def _makeResult(self, **kwargs):
|
||||
return DjangoTeamcityTestResult(self.stream, **kwargs)
|
||||
|
||||
def build_suite(self, *args, **kwargs):
|
||||
EXCLUDED_APPS = getattr(settings, 'TEST_EXCLUDE', [])
|
||||
suite = super(DjangoTeamcityTestRunner, self).build_suite(*args, **kwargs)
|
||||
|
||||
@@ -137,8 +137,8 @@ public class PyNames {
|
||||
|
||||
public static final String FORMAT = "format";
|
||||
|
||||
public static final String ABSTRACTMETHOD = "abc.abstractmethod";
|
||||
public static final String ABSTRACTPROPERTY = "abc.abstractproperty";
|
||||
public static final String ABSTRACTMETHOD = "abstractmethod";
|
||||
public static final String ABSTRACTPROPERTY = "abstractproperty";
|
||||
|
||||
public static final String TUPLE = "tuple";
|
||||
public static final String SET = "set";
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
|
||||
<runConfigurationProducer implementation="com.jetbrains.python.testing.unittest.PythonUnitTestConfigurationProducer"/>
|
||||
<testSrcLocator implementation="com.jetbrains.python.testing.PythonUnitTestTestIdUrlProvider"/>
|
||||
<testSrcLocator implementation="com.jetbrains.django.testRunner.DjangoTestTestIdUrlProvider"/>
|
||||
<testSrcLocator implementation="com.jetbrains.python.testing.nosetest.PythonNoseTestUrlProvider"/>
|
||||
|
||||
<runConfigurationProducer implementation="com.jetbrains.python.testing.pytest.PyTestConfigurationProducer"/>
|
||||
|
||||
@@ -156,7 +156,8 @@ public class PyOverrideImplementUtil {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement anchor = null;
|
||||
for (PyStatement statement: statementList.getStatements()) {
|
||||
if (statement.getTextRange().getStartOffset() < offset) {
|
||||
if (statement.getTextRange().getStartOffset() < offset ||
|
||||
(statement instanceof PyExpressionStatement && ((PyExpressionStatement)statement).getExpression() instanceof PyStringLiteralExpression)) {
|
||||
anchor = statement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,10 @@ public class PyArgumentEqualDefaultInspection extends PyInspection {
|
||||
if (key.getText().equals(defaultValue.getText()))
|
||||
return true;
|
||||
}
|
||||
if (key instanceof PyBinaryExpression && defaultValue instanceof PyBinaryExpression) {
|
||||
if (key.getText().equals(defaultValue.getText()))
|
||||
return true;
|
||||
}
|
||||
else if (key instanceof PyStringLiteralExpression && defaultValue instanceof PyStringLiteralExpression) {
|
||||
if (((PyStringLiteralExpression)key).getStringValue().equals(((PyStringLiteralExpression)defaultValue).getStringValue()))
|
||||
return true;
|
||||
|
||||
@@ -22,10 +22,10 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import com.intellij.util.containers.hash.HashSet;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.jetbrains.python.psi.search.PySuperMethodsSearch;
|
||||
import com.jetbrains.python.psi.types.PyModuleType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
@@ -137,7 +137,7 @@ public class PyPep8NamingInspection extends PyInspection {
|
||||
final String asName = node.getAsName();
|
||||
final QualifiedName importedQName = node.getImportedQName();
|
||||
if (importedQName == null) return;
|
||||
final String name = importedQName.toString();
|
||||
final String name = importedQName.getLastComponent();
|
||||
|
||||
if (asName == null || name == null) return;
|
||||
if (UPPERCASE_REGEX.matcher(name).matches()) {
|
||||
|
||||
@@ -476,7 +476,8 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
}
|
||||
addAddSelfFix(node, refex, actions);
|
||||
PyCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PyCallExpression.class);
|
||||
if (callExpression != null) {
|
||||
if (callExpression != null && (!(callExpression.getCallee() instanceof PyQualifiedExpression) ||
|
||||
((PyQualifiedExpression)callExpression.getCallee()).getQualifier() == null)) {
|
||||
actions.add(new UnresolvedRefCreateFunctionQuickFix(callExpression, refex));
|
||||
}
|
||||
PyFunction parentFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
|
||||
|
||||
@@ -149,15 +149,15 @@ public class AddCallSuperQuickFix implements LocalQuickFix {
|
||||
for (int i = 1; i != parameters.length; i++) {
|
||||
PyParameter p = parameters[i];
|
||||
if (p.getDefaultValue() != null) continue;
|
||||
String param;
|
||||
param = p.getText();
|
||||
if (param.startsWith("**")) {
|
||||
final String param = p.getName();
|
||||
String paramText = p.getText();
|
||||
if (paramText.startsWith("**")) {
|
||||
addDouble = true;
|
||||
if (doubleStarName == null)
|
||||
doubleStarName = p.getText();
|
||||
continue;
|
||||
}
|
||||
if (param.startsWith("*")) {
|
||||
if (paramText.startsWith("*")) {
|
||||
addStar = true;
|
||||
if (starName == null)
|
||||
starName = p.getText();
|
||||
|
||||
@@ -52,16 +52,38 @@ public class ConvertDictCompQuickFix implements LocalQuickFix {
|
||||
}
|
||||
|
||||
private static void replaceComprehension(Project project, PyDictCompExpression expression) {
|
||||
List<ComprhForComponent> forComponents = expression.getForComponents();
|
||||
if (expression.getResultExpression() instanceof PyKeyValueExpression) {
|
||||
PyKeyValueExpression keyValueExpression = (PyKeyValueExpression)expression.getResultExpression();
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
final PyKeyValueExpression keyValueExpression = (PyKeyValueExpression)expression.getResultExpression();
|
||||
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
assert keyValueExpression.getValue() != null;
|
||||
expression.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyExpressionStatement.class,
|
||||
"dict([(" + keyValueExpression.getKey().getText() + ", " +
|
||||
keyValueExpression.getValue().getText() + ") for " +
|
||||
forComponents.get(0).getIteratorVariable().getText() + " in " +
|
||||
forComponents.get(0).getIteratedList().getText() + "])"));
|
||||
|
||||
final List<ComprehensionComponent> components = expression.getComponents();
|
||||
final StringBuilder replacement = new StringBuilder("dict([(" + keyValueExpression.getKey().getText() + ", " +
|
||||
keyValueExpression.getValue().getText() + ")");
|
||||
int slashNum = 1;
|
||||
for (ComprehensionComponent component : components) {
|
||||
if (component instanceof ComprhForComponent) {
|
||||
replacement.append("for ");
|
||||
replacement.append(((ComprhForComponent)component).getIteratorVariable().getText());
|
||||
replacement.append(" in ");
|
||||
replacement.append(((ComprhForComponent)component).getIteratedList().getText());
|
||||
replacement.append(" ");
|
||||
}
|
||||
if (component instanceof ComprhIfComponent) {
|
||||
final PyExpression test = ((ComprhIfComponent)component).getTest();
|
||||
if (test != null) {
|
||||
replacement.append("if ");
|
||||
replacement.append(test.getText());
|
||||
replacement.append(" ");
|
||||
}
|
||||
}
|
||||
for (int i = 0; i != slashNum; ++i)
|
||||
replacement.append("\t");
|
||||
++slashNum;
|
||||
}
|
||||
replacement.append("])");
|
||||
|
||||
expression.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyExpressionStatement.class, replacement.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -701,7 +701,7 @@ public class PyUtil {
|
||||
final QualifiedName qualifiedName = decorator.getQualifiedName();
|
||||
if (qualifiedName != null) {
|
||||
final String name = qualifiedName.toString();
|
||||
if (PyNames.ABSTRACTMETHOD.equals(name) || PyNames.ABSTRACTPROPERTY.equals(name)) {
|
||||
if (name.endsWith(PyNames.ABSTRACTMETHOD) || name.endsWith(PyNames.ABSTRACTPROPERTY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Example1:
|
||||
def __init__(self, field1: str):
|
||||
self.field1 = field1
|
||||
|
||||
|
||||
class Example2(Example1):
|
||||
def <warning descr="Call to __init__ of super class is missed">__i<caret>nit__</warning>(self): ## Missed call to __init__ of super class
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
class Example1:
|
||||
def __init__(self, field1: str):
|
||||
self.field1 = field1
|
||||
|
||||
|
||||
class Example2(Example1):
|
||||
def __init__(self, field1):
|
||||
super().__init__(field1)
|
||||
@@ -0,0 +1 @@
|
||||
var = <warning descr="Python version 2.4, 2.5, 2.6, 3.0 do not support dictionary comprehensions">{k: v for k, v in zip('abc', <caret>range(3)) if k % 2}</warning>
|
||||
@@ -0,0 +1 @@
|
||||
var = dict([(k, v) for k, v in zip('abc', range(3)) if k % 2])
|
||||
@@ -67,3 +67,9 @@ kw['customerPaymentProfileId'] = kw.get("customerPaymentProfileId",
|
||||
|
||||
{1: 2}.get('foo', None) #pass
|
||||
{1: 2}.pop('foo', None) #pass
|
||||
|
||||
def a(foo=1*1024):
|
||||
print foo
|
||||
|
||||
a( 1024*1024)
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from x import TestX as <weak_warning descr="CamelCase variable imported as lowercase">test</weak_warning>
|
||||
import Exceptions.tt as user_defined_properties
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<error descr="Unresolved reference 'my_ref'">my_<caret>ref</error>.do_smth(1, 2)
|
||||
@@ -0,0 +1,9 @@
|
||||
class Abstract(object):
|
||||
|
||||
@abstractmethod
|
||||
def foo(self, bar):
|
||||
pass
|
||||
|
||||
|
||||
class Concrete(Abstract):
|
||||
"""The docstring."""
|
||||
@@ -0,0 +1,12 @@
|
||||
class Abstract(object):
|
||||
|
||||
@abstractmethod
|
||||
def foo(self, bar):
|
||||
pass
|
||||
|
||||
|
||||
class Concrete(Abstract):
|
||||
"""The docstring."""
|
||||
|
||||
def foo(self, bar):
|
||||
<selection>super(Concrete, self).foo(bar)</selection>
|
||||
@@ -130,6 +130,10 @@ public class PyOverrideTest extends PyTestCase {
|
||||
doTest3k();
|
||||
}
|
||||
|
||||
public void testDocstring() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-10229
|
||||
public void testInstanceCheck() {
|
||||
myFixture.configureByFile("override/" + getTestName(true) + ".py");
|
||||
|
||||
@@ -266,6 +266,15 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
PyBundle.message("QFIX.unresolved.reference.create.function.$0", "ref"), true, true);
|
||||
}
|
||||
|
||||
public void testUnresolvedRefNoCreateFunction() {
|
||||
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
|
||||
myFixture.configureByFile("UnresolvedRefNoCreateFunction.py");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
final IntentionAction intentionAction = myFixture.getAvailableIntention(
|
||||
PyBundle.message("QFIX.unresolved.reference.create.function.$0", "ref"));
|
||||
assertNull(intentionAction);
|
||||
}
|
||||
|
||||
public void testReplaceNotEqOperator() {
|
||||
doInspectionTest("ReplaceNotEqOperator.py", PyCompatibilityInspection.class,
|
||||
PyBundle.message("INTN.replace.noteq.operator"), true, true);
|
||||
@@ -306,6 +315,17 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
PyBundle.message("QFIX.add.super"), true, true);
|
||||
}
|
||||
|
||||
public void testAddCallSuperAnnotations() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON33, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doInspectionTest("AddCallSuperAnnotations.py",
|
||||
PyMissingConstructorInspection.class,
|
||||
PyBundle.message("QFIX.add.super"), true, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testAddCallSuperPass() { //PY-8654
|
||||
doInspectionTest("AddCallSuperPass.py", PyMissingConstructorInspection.class,
|
||||
PyBundle.message("QFIX.add.super"), true, true);
|
||||
@@ -342,6 +362,11 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
PyBundle.message("QFIX.replace.function.set.with.literal"), true, true);
|
||||
}
|
||||
|
||||
public void testDictComprehensionToCall() {
|
||||
doInspectionTest("DictComprehensionToCall.py", PyCompatibilityInspection.class,
|
||||
PyBundle.message("INTN.convert.dict.comp.to"), true, true);
|
||||
}
|
||||
|
||||
public void testDocstringParams() { //PY-3394
|
||||
PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
|
||||
documentationSettings.setFormat(DocStringFormat.EPYTEXT);
|
||||
|
||||
Reference in New Issue
Block a user