From cf6bfd7ef2cd4c276b40661235397a579529f43a Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Mon, 19 Jan 2015 12:44:24 +0300 Subject: [PATCH 01/19] #WEB-14743 fixed --- .../jetbrains/python/module/PyProjectStructureDetector.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/pluginSrc/com/jetbrains/python/module/PyProjectStructureDetector.java b/python/pluginSrc/com/jetbrains/python/module/PyProjectStructureDetector.java index 585ce5c16680..4e805355e83a 100644 --- a/python/pluginSrc/com/jetbrains/python/module/PyProjectStructureDetector.java +++ b/python/pluginSrc/com/jetbrains/python/module/PyProjectStructureDetector.java @@ -49,11 +49,15 @@ public class PyProjectStructureDetector extends ProjectStructureDetector { @NotNull List result) { LOG.info("Detecting roots under " + dir); for (File child : children) { - if (FileUtilRt.extensionEquals(child.getName(), "py")) { + final String name = child.getName(); + if (FileUtilRt.extensionEquals(name, "py")) { LOG.info("Found Python file " + child.getPath()); result.add(new DetectedContentRoot(dir, "Python", PythonModuleTypeBase.getInstance(), WebModuleType.getInstance())); return DirectoryProcessingResult.SKIP_CHILDREN; } + if ("node_modules".equals(name)) { + return DirectoryProcessingResult.SKIP_CHILDREN; + } } return DirectoryProcessingResult.PROCESS_CHILDREN; } From 64fd4acb59f76ff0e0bfda3663897b2da55b67a1 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 19 Jan 2015 13:38:44 +0300 Subject: [PATCH 02/19] icons integrated - DSGN-1688 Icons for Console and idea.log are identical --- platform/icons/src/debugger/console_log.png | Bin 0 -> 208 bytes platform/icons/src/debugger/console_log@2x.png | Bin 0 -> 270 bytes .../com/intellij/execution/runners/RunTab.java | 4 ++-- .../util/src/com/intellij/icons/AllIcons.java | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 platform/icons/src/debugger/console_log.png create mode 100644 platform/icons/src/debugger/console_log@2x.png diff --git a/platform/icons/src/debugger/console_log.png b/platform/icons/src/debugger/console_log.png new file mode 100644 index 0000000000000000000000000000000000000000..3e9ae80c01d41a98fd19e8a78bcc2ac7fb960569 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`(>+}rLn>}1|M>sko>^7Gr(%2l zpZE9o&Q#&K#B8pR^J(4x&SJhvEsj+W*narl_-S8sPH~cf2mhUhRjXF1D)3B6$guh& zq|dgpaizQ21A7i<(cEM0jjtZODwGnCl>8|#t#*sSgTe~ HDWM4f>JjO^#)W z764ZW(9!V_}hLdg%+P=gaXC7(B1KCm}x z%ev>o%VWZS_)j4Fgf|T*PMr9^$14X8XS>rIL@$$XIUGw$HC6Ud<&`^UCP-5nhI48Equtp@cX!g#1T2? R`9Kdcc)I$ztaD0e0sw+Wbj<(& literal 0 HcmV?d00001 diff --git a/platform/lang-impl/src/com/intellij/execution/runners/RunTab.java b/platform/lang-impl/src/com/intellij/execution/runners/RunTab.java index 6628c78f1851..7d116a0bbb1f 100644 --- a/platform/lang-impl/src/com/intellij/execution/runners/RunTab.java +++ b/platform/lang-impl/src/com/intellij/execution/runners/RunTab.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -95,7 +95,7 @@ public abstract class RunTab implements DataProvider, Disposable { logConsoleManager = new LogConsoleManagerBase(myProject, mySearchScope) { @Override protected Icon getDefaultIcon() { - return AllIcons.Debugger.Console; + return AllIcons.Debugger.Console_log; } @Override diff --git a/platform/util/src/com/intellij/icons/AllIcons.java b/platform/util/src/com/intellij/icons/AllIcons.java index 19c6e60a7c70..b6ddc195f597 100644 --- a/platform/util/src/com/intellij/icons/AllIcons.java +++ b/platform/util/src/com/intellij/icons/AllIcons.java @@ -215,6 +215,7 @@ public class AllIcons { public static final Icon Class_filter = IconLoader.getIcon("/debugger/class_filter.png"); // 16x16 public static final Icon CommandLine = IconLoader.getIcon("/debugger/commandLine.png"); // 16x16 public static final Icon Console = IconLoader.getIcon("/debugger/console.png"); // 16x16 + public static final Icon Console_log = IconLoader.getIcon("/debugger/console_log.png"); // 16x16 public static final Icon Db_array = IconLoader.getIcon("/debugger/db_array.png"); // 16x16 public static final Icon Db_db_object = IconLoader.getIcon("/debugger/db_db_object.png"); // 16x16 public static final Icon Db_dep_exception_breakpoint = IconLoader.getIcon("/debugger/db_dep_exception_breakpoint.png"); // 12x12 From d60840ee4ffcbe3720ef90952b1cbec5e6204761 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 19 Jan 2015 12:06:50 +0100 Subject: [PATCH 03/19] cleanup 'public' modifier from the interface on "pull default method" (IDEA-135292) --- .../src/com/intellij/refactoring/util/RefactoringUtil.java | 1 + java/java-tests/testData/refactoring/pullUp/AsDefault.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java index ed51aa5120b4..43758f620342 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java @@ -718,6 +718,7 @@ public class RefactoringUtil { PsiUtil.setModifierProperty(method, PsiModifier.FINAL, false); PsiUtil.setModifierProperty(method, PsiModifier.SYNCHRONIZED, false); PsiUtil.setModifierProperty(method, PsiModifier.NATIVE, false); + PsiUtil.setModifierProperty(method, PsiModifier.PUBLIC, false); removeFinalParameters(method); } diff --git a/java/java-tests/testData/refactoring/pullUp/AsDefault.java b/java/java-tests/testData/refactoring/pullUp/AsDefault.java index 3379c19a779e..05cf9b018841 100644 --- a/java/java-tests/testData/refactoring/pullUp/AsDefault.java +++ b/java/java-tests/testData/refactoring/pullUp/AsDefault.java @@ -3,5 +3,5 @@ interface Bar { } interface Base { } class Foo implements Base { - void get(Bar bar) { } + public void get(Bar bar) { } } \ No newline at end of file From 042f9c57afae8d7df8fd3a91edbafb6fcad02945 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 19 Jan 2015 14:07:47 +0300 Subject: [PATCH 04/19] IDEA-72949 Paste waits until file is checked out before taking a copy of the clipboard --- .../editorActions/PasteHandler.java | 257 +++++++++--------- .../editor/EditorModificationUtil.java | 11 + .../EditorWriteActionHandler.java | 8 +- .../editor/actions/BasePasteHandler.java | 57 ++++ .../editor/actions/MultiplePasteAction.java | 6 +- .../openapi/editor/actions/PasteAction.java | 22 +- .../editor/actions/PasteFromX11Action.java | 27 +- .../editor/actions/SimplePasteAction.java | 25 +- .../impl/EditorCopyPasteHelperImpl.java | 18 +- 9 files changed, 227 insertions(+), 204 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/actions/BasePasteHandler.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index 04f02ab9b380..0fcccb7c742e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -49,11 +49,15 @@ 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.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; public class PasteHandler extends EditorActionHandler implements EditorTextInsertHandler { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.editorActions.PasteHandler"); @@ -73,6 +77,9 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser @Override public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer producer) { + final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer); + if (transferable == null) return; + if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; final Document document = editor.getDocument(); @@ -80,15 +87,18 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser return; } - 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); - } - }; - } + DataContext context = new DataContext() { + @Override + public Object getData(@NonNls String dataId) { + return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? new Producer() { + @Nullable + @Override + public Transferable produce() { + return transferable; + } + } : dataContext.getData(dataId); + } + }; final Project project = editor.getProject(); if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) { @@ -114,7 +124,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser return; } } - doPaste(editor, project, file, document, producer); + doPaste(editor, project, file, document, transferable); } catch (ReadOnlyFragmentModificationException e) { EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e); @@ -128,152 +138,137 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final Project project, final PsiFile file, final Document document, - final Producer producer) { - Transferable content = null; + @NotNull final Transferable content) { + CopyPasteManager.getInstance().stopKillRings(); + + String text = null; + try { + text = (String)content.getTransferData(DataFlavor.stringFlavor); + } + catch (Exception e) { + editor.getComponent().getToolkit().beep(); + } + if (text == null) return; - if (producer != null) { - content = producer.produce(); + final CodeInsightSettings settings = CodeInsightSettings.getInstance(); + + final Map> extraData = new HashMap>(); + Collection allValues = new ArrayList(); + + DumbService.getInstance(project).setAlternativeResolveEnabled(true); + try { + for (CopyPastePostProcessor processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) { + List data = processor.extractTransferableData(content); + if (!data.isEmpty()) { + extraData.put(processor, data); + allValues.addAll(data); + } + } + } + finally { + DumbService.getInstance(project).setAlternativeResolveEnabled(false); + } + + text = TextBlockTransferable.convertLineSeparators(editor, text, allValues); + + 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. + final int blockIndentAnchorColumn; + final int caretOffset = caretModel.getOffset(); + if (selectionModel.hasSelection() && caretOffset >= selectionModel.getSelectionStart()) { + blockIndentAnchorColumn = editor.offsetToLogicalPosition(selectionModel.getSelectionStart()).column; } else { - CopyPasteManager manager = CopyPasteManager.getInstance(); - if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) { - content = manager.getContents(); - if (content != null) { - manager.stopKillRings(); - } - } + blockIndentAnchorColumn = col; } - if (content != null) { - String text = null; - try { - text = (String)content.getTransferData(DataFlavor.stringFlavor); - } - catch (Exception e) { - editor.getComponent().getToolkit().beep(); - } - if (text == null) return; + // We assume that EditorModificationUtil.insertStringAtCaret() is smart enough to remove currently selected text (if any). - final CodeInsightSettings settings = CodeInsightSettings.getInstance(); + RawText rawText = RawText.fromTransferable(content); + String newText = text; + 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; + text = newText; - final Map> extraData = new HashMap>(); - Collection allValues = new ArrayList(); - - DumbService.getInstance(project).setAlternativeResolveEnabled(true); - try { - for (CopyPastePostProcessor processor : Extensions.getExtensions(CopyPastePostProcessor.EP_NAME)) { - List data = processor.extractTransferableData(content); - if (!data.isEmpty()) { - extraData.put(processor, data); - allValues.addAll(data); - } + if (LanguageFormatting.INSTANCE.forContext(file) == null && indentOptions != CodeInsightSettings.NO_REFORMAT) { + indentOptions = CodeInsightSettings.INDENT_BLOCK; + } + + final String _text = text; + ApplicationManager.getApplication().runWriteAction( + new Runnable() { + @Override + public void run() { + EditorModificationUtil.insertStringAtCaret(editor, _text, false, true); } } - finally { - DumbService.getInstance(project).setAlternativeResolveEnabled(false); - } + ); - text = TextBlockTransferable.convertLineSeparators(editor, text, allValues); + int length = text.length(); + int offset = caretModel.getOffset() - length; + if (offset < 0) { + length += offset; + offset = 0; + } + final RangeMarker bounds = document.createRangeMarker(offset, offset + length); - final CaretModel caretModel = editor.getCaretModel(); - final SelectionModel selectionModel = editor.getSelectionModel(); - final int col = caretModel.getLogicalPosition().column; + caretModel.moveToOffset(bounds.getEndOffset()); + editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); + selectionModel.removeSelection(); - // 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. - final int blockIndentAnchorColumn; - final int caretOffset = caretModel.getOffset(); - if (selectionModel.hasSelection() && caretOffset >= selectionModel.getSelectionStart()) { - blockIndentAnchorColumn = editor.offsetToLogicalPosition(selectionModel.getSelectionStart()).column; - } - else { - blockIndentAnchorColumn = col; - } + final Ref indented = new Ref(Boolean.FALSE); + for (Map.Entry> e : extraData.entrySet()) { + //noinspection unchecked + e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue()); + } - // We assume that EditorModificationUtil.insertStringAtCaret() is smart enough to remove currently selected text (if any). + boolean pastedTextContainsWhiteSpacesOnly = + CharArrayUtil.shiftForward(document.getCharsSequence(), bounds.getStartOffset(), " \n\t") >= bounds.getEndOffset(); - RawText rawText = RawText.fromTransferable(content); - String newText = text; - 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; - text = newText; + VirtualFile virtualFile = file.getVirtualFile(); + if (!pastedTextContainsWhiteSpacesOnly && (virtualFile == null || !SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile))) { + final int indentOptions1 = indentOptions; - if (LanguageFormatting.INSTANCE.forContext(file) == null && indentOptions != CodeInsightSettings.NO_REFORMAT) { - indentOptions = CodeInsightSettings.INDENT_BLOCK; - } - - final String _text = text; ApplicationManager.getApplication().runWriteAction( new Runnable() { @Override public void run() { - EditorModificationUtil.insertStringAtCaret(editor, _text, false, true); + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document); + switch (indentOptions1) { + case CodeInsightSettings.INDENT_BLOCK: + if (!indented.get()) { + 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()); + break; + } } } ); + } - int length = text.length(); - int offset = caretModel.getOffset() - length; - if (offset < 0) { - length += offset; - offset = 0; - } - final RangeMarker bounds = document.createRangeMarker(offset, offset + length); - + if (bounds.isValid()) { caretModel.moveToOffset(bounds.getEndOffset()); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); selectionModel.removeSelection(); - - final Ref indented = new Ref(Boolean.FALSE); - for (Map.Entry> e : extraData.entrySet()) { - //noinspection unchecked - e.getKey().processTransferableData(project, editor, bounds, caretOffset, indented, e.getValue()); - } - - boolean pastedTextContainsWhiteSpacesOnly = - CharArrayUtil.shiftForward(document.getCharsSequence(), bounds.getStartOffset(), " \n\t") >= bounds.getEndOffset(); - - VirtualFile virtualFile = file.getVirtualFile(); - if (!pastedTextContainsWhiteSpacesOnly && (virtualFile == null || !SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile))) { - final int indentOptions1 = indentOptions; - - ApplicationManager.getApplication().runWriteAction( - new Runnable() { - @Override - public void run() { - PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document); - switch (indentOptions1) { - case CodeInsightSettings.INDENT_BLOCK: - if (!indented.get()) { - 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()); - break; - } - } - } - ); - } - - if (bounds.isValid()) { - caretModel.moveToOffset(bounds.getEndOffset()); - editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); - selectionModel.removeSelection(); - editor.putUserData(EditorEx.LAST_PASTED_REGION, TextRange.create(bounds)); - } + editor.putUserData(EditorEx.LAST_PASTED_REGION, TextRange.create(bounds)); } } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java index 003af8789fc9..fd36104424f9 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java @@ -197,6 +197,17 @@ public class EditorModificationUtil { zeroWidthBlockSelectionAtCaretColumn(editor, caretLine, caretLine); } + @Nullable + public static Transferable getContentsToPasteToEditor(@Nullable Producer producer) { + if (producer == null) { + CopyPasteManager manager = CopyPasteManager.getInstance(); + return manager.areDataFlavorsAvailable(DataFlavor.stringFlavor) ? manager.getContents() : null; + } + else { + return producer.produce(); + } + } + @Nullable public static String getStringContent(@NotNull Transferable content) { RawText raw = RawText.fromTransferable(content); diff --git a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java index ba4111af46e9..879f921afe67 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/actionSystem/EditorWriteActionHandler.java @@ -23,6 +23,10 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.Nullable; +/** + * Base class for {@link EditorActionHandler} instances, which need to modify the document. + * Implementations should override {@link #executeWriteAction(Editor, Caret, DataContext)}. + */ public abstract class EditorWriteActionHandler extends EditorActionHandler { private boolean inExecution; @@ -34,7 +38,7 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler { } @Override - public final void doExecute(final Editor editor, @Nullable final Caret caret, final DataContext dataContext) { + public void doExecute(final Editor editor, @Nullable final Caret caret, final DataContext dataContext) { if (editor.isViewer()) return; if (dataContext != null) { @@ -63,7 +67,7 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler { /** * @deprecated Use/override - * {@link #executeWriteAction(com.intellij.openapi.editor.Editor, com.intellij.openapi.editor.Caret, com.intellij.openapi.actionSystem.DataContext)} + * {@link #executeWriteAction(Editor, Caret, DataContext)} * instead. */ public void executeWriteAction(Editor editor, DataContext dataContext) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/BasePasteHandler.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/BasePasteHandler.java new file mode 100644 index 000000000000..cf3bbecae8c6 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/BasePasteHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2015 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.openapi.editor.actions; + +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.EditorCopyPasteHelper; +import com.intellij.openapi.editor.EditorModificationUtil; +import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; +import com.intellij.util.Producer; +import org.jetbrains.annotations.Nullable; + +import java.awt.datatransfer.Transferable; + +public abstract class BasePasteHandler extends EditorWriteActionHandler { + protected Transferable myTransferable; + + @Override + public void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { + // We capture the contents to paste here, so it that it won't be affected by possible clipboard operations later (e.g. during unlocking + // of current file for writing) + myTransferable = getContentsToPaste(editor, dataContext); + try { + super.doExecute(editor, caret, dataContext); + } + finally { + myTransferable = null; + } + } + + @Override + public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { + if (myTransferable != null) { + EditorCopyPasteHelper.getInstance().pasteTransferable(editor, myTransferable); + } + } + + protected Transferable getContentsToPaste(Editor editor, DataContext dataContext) { + Producer producer = PasteAction.TRANSFERABLE_PROVIDER.getData(dataContext); + return EditorModificationUtil.getContentsToPasteToEditor(producer); + } + +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java index f2d26ef0b4e6..3f779c7c1ba1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/MultiplePasteAction.java @@ -19,10 +19,9 @@ import com.intellij.ide.CopyPasteManagerEx; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.ide.CopyPasteManager; -import com.intellij.openapi.project.Project; import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.ui.UIBundle; @@ -100,9 +99,6 @@ public class MultiplePasteAction extends AnAction implements DumbAware { if (editor != null) { if (editor.isViewer()) return; - if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){ - return; - } final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE); AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(), diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java index 8f7cea0fc61d..1ba31dac63e2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteAction.java @@ -17,10 +17,10 @@ package com.intellij.openapi.editor.actions; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorModificationUtil; +import com.intellij.openapi.editor.EditorCopyPasteHelper; 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; @@ -38,17 +38,17 @@ public class PasteAction extends EditorAction { super(new Handler()); } - private static class Handler extends EditorWriteActionHandler { + private static class Handler extends BasePasteHandler { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { - Producer producer = TRANSFERABLE_PROVIDER.getData(dataContext); - if (!editor.getCaretModel().supportsMultipleCarets() && editor.isColumnMode()) { - EditorModificationUtil.pasteTransferableAsBlock(editor, producer); - } - else { - TextRange range = EditorModificationUtil.pasteTransferable(editor, producer); - editor.putUserData(EditorEx.LAST_PASTED_REGION, range); + public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { + TextRange range = null; + if (myTransferable != null) { + TextRange[] ranges = EditorCopyPasteHelper.getInstance().pasteTransferable(editor, myTransferable); + if (ranges != null && ranges.length == 1) { + range = ranges[0]; + } } + editor.putUserData(EditorEx.LAST_PASTED_REGION, range); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java index 3e20ba800dae..e95ba62ad394 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/PasteFromX11Action.java @@ -21,15 +21,9 @@ import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.Presentation; 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.util.SystemInfo; -import com.intellij.openapi.util.TextRange; -import com.intellij.util.Producer; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; @@ -71,30 +65,19 @@ public class PasteFromX11Action extends EditorAction { } } - public static class Handler extends EditorWriteActionHandler { + public static class Handler extends BasePasteHandler { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { + protected Transferable getContentsToPaste(Editor editor, DataContext dataContext) { Clipboard clip = editor.getComponent().getToolkit().getSystemSelection(); - if (clip == null) return; + if (clip == null) return null; - final Transferable content; try { - content = clip.getContents(null); + return clip.getContents(null); } catch (Exception e) { LOG.info(e); - return; + return null; } - if (content == null) return; - - TextRange range = EditorModificationUtil.pasteTransferable(editor, new Producer() { - @Nullable - @Override - public Transferable produce() { - return content; - } - }); - editor.putUserData(EditorEx.LAST_PASTED_REGION, range); } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java index 59a6cbca29a6..0efcdb1d8705 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/SimplePasteAction.java @@ -19,15 +19,10 @@ 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.Caret; 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; +import org.jetbrains.annotations.NotNull; /** * @author max @@ -47,21 +42,9 @@ public class SimplePasteAction extends EditorAction { } } - private static class Handler extends EditorWriteActionHandler { + private static class Handler extends BasePasteHandler { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { - Producer producer = PasteAction.TRANSFERABLE_PROVIDER.getData(dataContext); - if (!editor.getCaretModel().supportsMultipleCarets() && editor.isColumnMode()) { - EditorModificationUtil.pasteTransferableAsBlock(editor, producer); - } - else { - TextRange range = EditorModificationUtil.pasteTransferable(editor, producer); - editor.putUserData(EditorEx.LAST_PASTED_REGION, range); - } - } - - @Override - public boolean isEnabled(Editor editor, DataContext dataContext) { + public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { return !editor.isViewer(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java index 6f4dcb458306..783854a1dee1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorCopyPasteHelperImpl.java @@ -26,12 +26,12 @@ import com.intellij.openapi.util.text.LineTokenizer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; public class EditorCopyPasteHelperImpl extends EditorCopyPasteHelper { private static final Logger LOG = Logger.getInstance(EditorCopyPasteHelperImpl.class); @@ -72,14 +72,8 @@ public class EditorCopyPasteHelperImpl extends EditorCopyPasteHelper { @Nullable @Override public TextRange[] pasteFromClipboard(@NotNull Editor editor) { - CopyPasteManager manager = CopyPasteManager.getInstance(); - if (manager.areDataFlavorsAvailable(DataFlavor.stringFlavor)) { - Transferable clipboardContents = manager.getContents(); - if (clipboardContents != null) { - return pasteTransferable(editor, clipboardContents); - } - } - return null; + Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(null); + return transferable == null ? null : pasteTransferable(editor, transferable); } @Nullable From 48c46f3fb5cbedf4c38e49a3bf394dc13dfbdc7c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 19 Jan 2015 12:34:15 +0100 Subject: [PATCH 05/19] typo (IDEA-135291) --- .../src/messages/InspectionsBundle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index ba051086dd92..01b8c5e80e0d 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -100,7 +100,7 @@ inspection.empty.method.delete.quickfix=Delete unnecessary method(s) inspection.empty.method.problem.descriptor=Method only calls its super inspection.empty.method.problem.descriptor1=Empty method overrides empty method inspection.empty.method.problem.descriptor2=The method is empty -inspection.empty.method.problem.descriptor3=The method and all it's derivables are empty +inspection.empty.method.problem.descriptor3=The method and all its derivables are empty inspection.empty.method.problem.descriptor4=All implementations of this method are empty #redundant cast From 7463327b77fb49c97896005022bd88c595f79626 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 19 Jan 2015 12:38:41 +0100 Subject: [PATCH 06/19] register action shortcut in plugin.xml so minor IDEs won't get it in their keymaps --- platform/platform-resources/src/idea/Keymap_Default.xml | 3 --- resources/src/idea/JavaActions.xml | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/platform/platform-resources/src/idea/Keymap_Default.xml b/platform/platform-resources/src/idea/Keymap_Default.xml index baf7d20c0c52..8cd7594ebaaa 100644 --- a/platform/platform-resources/src/idea/Keymap_Default.xml +++ b/platform/platform-resources/src/idea/Keymap_Default.xml @@ -716,9 +716,6 @@ - - - diff --git a/resources/src/idea/JavaActions.xml b/resources/src/idea/JavaActions.xml index 7836da0b2add..4d4329d87e6d 100644 --- a/resources/src/idea/JavaActions.xml +++ b/resources/src/idea/JavaActions.xml @@ -70,6 +70,7 @@ + From 010f194f25a25a701d0ec2fcc6cb50c757b5dab6 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 19 Jan 2015 14:40:06 +0300 Subject: [PATCH 07/19] IDEA-134809 Resource bundle editor updates selection every 500 ms if not selected on startup --- .../properties/editor/ResourceBundleEditor.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java index d5114377c313..4941fb9ef3e3 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java @@ -106,6 +106,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit private boolean myDisposed; private VirtualFileListener myVfsListener; private Editor mySelectedEditor; + private String myPropertyToSelectWhenVisible; public ResourceBundleEditor(@NotNull ResourceBundle resourceBundle) { myProject = resourceBundle.getProject(); @@ -208,6 +209,9 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit if (newEditor == this) { if (oldEditor instanceof TextEditor) { setStructureViewSelectionFromPropertiesFile(((TextEditor)oldEditor).getEditor()); + } else if (myPropertyToSelectWhenVisible != null) { + setStructureViewSelection(myPropertyToSelectWhenVisible); + myPropertyToSelectWhenVisible = null; } } else if (newEditor instanceof TextEditor) { @@ -239,6 +243,17 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit Object root = tree.getModel().getRoot(); if (AbstractTreeUi.isLoadingChildrenFor(root)) { + boolean isEditorVisible = false; + for (FileEditor editor : FileEditorManager.getInstance(myProject).getSelectedEditors()) { + if (editor == this) { + isEditorVisible = true; + break; + } + } + if (!isEditorVisible) { + return; + } + myPropertyToSelectWhenVisible = propertyName; mySelectionChangeAlarm.cancelAllRequests(); mySelectionChangeAlarm.addRequest(new Runnable() { @Override From b6c20333fb5ca1699cedd84fff34aede791bf38e Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Mon, 19 Jan 2015 14:43:31 +0300 Subject: [PATCH 08/19] property selection when resource bundle editor is activated fixed --- .../intellij/lang/properties/editor/ResourceBundleEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java index 4941fb9ef3e3..85adb5468958 100644 --- a/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java +++ b/plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java @@ -251,9 +251,9 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit } } if (!isEditorVisible) { + myPropertyToSelectWhenVisible = propertyName; return; } - myPropertyToSelectWhenVisible = propertyName; mySelectionChangeAlarm.cancelAllRequests(); mySelectionChangeAlarm.addRequest(new Runnable() { @Override From 40da9211980f2d9db06cf524bfe43879edf7946c Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 19 Jan 2015 15:00:52 +0300 Subject: [PATCH 09/19] more diagnostics for EA-63802 - assert: PositionManagerImpl$.run --- .../src/com/intellij/debugger/engine/PositionManagerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java index 071e0a1cf909..1c50ab9c1596 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -255,7 +255,7 @@ public class PositionManagerImpl implements PositionManager { baseClassNameRef.set(parentClassName); } else { - LOG.error("The name of a parent of a local (anonymous) class is null"); + LOG.error("The name of a parent " + topLevelClass + " of a local (anonymous) class " + psiClass + " is null"); } } else { From c5c7eeae5dc8317975a2ac366f1cbbb818d6b9da Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 19 Jan 2015 13:02:24 +0100 Subject: [PATCH 10/19] add "implement methods" fix for unrelated default methods error (IDEA-135295) --- .../daemon/impl/analysis/GenericsHighlightUtil.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java index e1fdc3840f2a..6832f9d226db 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/GenericsHighlightUtil.java @@ -455,9 +455,11 @@ public class GenericsHighlightUtil { HighlightUtil.formatClass(superContainingClass), JavaHighlightUtil.formatMethod(superMethod), HighlightUtil.formatClass(superContainingClass, false)); - return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) + final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) .range(classIdentifier).descriptionAndTooltip(message) .create(); + QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createImplementMethodsFix(aClass)); + return info; } if (isDefault || !isAbstract && superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { @@ -471,9 +473,11 @@ public class GenericsHighlightUtil { HighlightUtil.formatClass(containingClass) + " and " + HighlightUtil.formatClass(superContainingClass); - return HighlightInfo + final HighlightInfo info = HighlightInfo .newHighlightInfo(HighlightInfoType.ERROR).range(classIdentifier).descriptionAndTooltip(inheritUnrelatedDefaultsMessage) .create(); + QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createImplementMethodsFix(aClass)); + return info; } } } From b507f4bdd9dac935b75e6301f35ee7e063e946f3 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 19 Jan 2015 15:23:23 +0300 Subject: [PATCH 11/19] icons integrated - DSGN-1688 Icons for Console and idea.log are identical --- platform/icons/src/debugger/console_log.png | Bin 208 -> 210 bytes platform/icons/src/debugger/console_log@2x.png | Bin 270 -> 282 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/platform/icons/src/debugger/console_log.png b/platform/icons/src/debugger/console_log.png index 3e9ae80c01d41a98fd19e8a78bcc2ac7fb960569..9b18e1e769a8cdbeae9920f5f90d1781b6b084c1 100644 GIT binary patch delta 90 zcmV-g0Hy!X0n!1GBmtR`C0|a)Y5-Iq2Z})k_@H6@E`V{cVW6!!Fq_FTfK(SSAYrmx wfMEc|E0Kx1G0Jmpz;kHQofB*mh07*qoM6N<$f=Tis@c;k- delta 88 zcmV-e0H^=b0nh=EBmtL^C0|S?+5j}{gN&gDZ u2B0axP)v*g*l-Rt4Zt3V_%NCmFfah=z;s14fMK8j0000Q0-6GlBmv=(C5>pI69Q043kOEd+>iz<`Iqr~?Mv0eI9ArJouONF+B44|)d>i$@(mozCe%I{*M) W2^P*Ik=Wz_0000Fs5TJJmxZuN32PC3lkQmiMAQ4?Zv6yNhKywF-h5#8M zz<>kOEd)j#FvJ~z#{i-XriKGZ!HJ^|pn5?>cLz{{aU{Z_;Q#>p#~2vI9z&l10000< KMNUMnLSTXhRwgF^ From 7eec28c4c154e4bf88e2497f534884cfc0c51459 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 19 Jan 2015 14:03:00 +0100 Subject: [PATCH 12/19] duplicate symbols in Search Everywhere --- .../src/com/intellij/ide/actions/SearchEverywhereAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index 4bcc12c7164f..9924625c86f5 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -1685,7 +1685,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA if (o instanceof PsiElement && !(((PsiElement)o).getParent() instanceof PsiFile)) { final PsiElement element = (PsiElement)o; final PsiFile file = element.getContainingFile(); - if (!myListModel.contains(o) && + if (!myListModel.contains(o) && !symbols.contains(o) && //some elements are non-physical like DB columns (file == null || (file.getVirtualFile() != null && (includeLibs || scope.accept(file.getVirtualFile()))))) { symbols.add(o); From a5a75b212024ca035d021871a5c1937fa1db86cd Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 19 Jan 2015 16:09:46 +0300 Subject: [PATCH 13/19] IDEA-69974 Fold regions are not properly created if 'Collapse All' is invoked right after opening editor --- .../folding/impl/FoldingUpdate.java | 7 +++++++ .../impl/UpdateFoldRegionsOperation.java | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java index 07bd92cb687a..333725920ac6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/FoldingUpdate.java @@ -281,6 +281,13 @@ public class FoldingUpdate { } public static class FoldingMap extends MultiMap{ + public FoldingMap() { + } + + public FoldingMap(FoldingMap map) { + super(map); + } + @NotNull @Override protected Map> createMap() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java index ad0992d6128f..3e0d504fddd2 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/UpdateFoldRegionsOperation.java @@ -76,11 +76,14 @@ class UpdateFoldRegionsOperation implements Runnable { FoldingModelEx foldingModel = (FoldingModelEx)myEditor.getFoldingModel(); Map rangeToExpandStatusMap = newTroveMap(); - removeInvalidRegions(info, foldingModel, rangeToExpandStatusMap); + // FoldingUpdate caches instances of our object, so they must be immutable. + FoldingUpdate.FoldingMap elementsToFold = new FoldingUpdate.FoldingMap(myElementsToFoldMap); + + removeInvalidRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap); Map shouldExpand = newTroveMap(); Map groupExpand = newTroveMap(); - List newRegions = addNewRegions(info, foldingModel, rangeToExpandStatusMap, shouldExpand, groupExpand); + List newRegions = addNewRegions(info, foldingModel, elementsToFold, rangeToExpandStatusMap, shouldExpand, groupExpand); applyExpandStatus(newRegions, shouldExpand, groupExpand); } @@ -100,14 +103,14 @@ class UpdateFoldRegionsOperation implements Runnable { private List addNewRegions(@NotNull EditorFoldingInfo info, @NotNull FoldingModelEx foldingModel, - @NotNull Map rangeToExpandStatusMap, + FoldingUpdate.FoldingMap elementsToFold, @NotNull Map rangeToExpandStatusMap, @NotNull Map shouldExpand, @NotNull Map groupExpand) { List newRegions = newArrayList(); SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject); - for (PsiElement element : myElementsToFoldMap.keySet()) { + for (PsiElement element : elementsToFold.keySet()) { ProgressManager.checkCanceled(); - final Collection descriptors = myElementsToFoldMap.get(element); + final Collection descriptors = elementsToFold.get(element); for (FoldingDescriptor descriptor : descriptors) { FoldingGroup group = descriptor.getGroup(); TextRange range = descriptor.getRange(); @@ -165,7 +168,7 @@ class UpdateFoldRegionsOperation implements Runnable { private void removeInvalidRegions(@NotNull EditorFoldingInfo info, @NotNull FoldingModelEx foldingModel, - @NotNull Map rangeToExpandStatusMap) { + FoldingUpdate.FoldingMap elementsToFold, @NotNull Map rangeToExpandStatusMap) { List toRemove = newArrayList(); InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(myProject); for (FoldRegion region : foldingModel.getAllFoldRegions()) { @@ -176,7 +179,7 @@ class UpdateFoldRegionsOperation implements Runnable { if (isInjected != myForInjected) continue; } final Collection descriptors; - if (element != null && !(descriptors = myElementsToFoldMap.get(element)).isEmpty()) { + if (element != null && !(descriptors = elementsToFold.get(element)).isEmpty()) { boolean matchingDescriptorFound = false; FoldingDescriptor[] array = descriptors.toArray(new FoldingDescriptor[descriptors.size()]); for (FoldingDescriptor descriptor : array) { @@ -194,7 +197,7 @@ class UpdateFoldRegionsOperation implements Runnable { break; } else { - myElementsToFoldMap.remove(element, descriptor); + elementsToFold.remove(element, descriptor); } } } From 74dfa8b378b4ee1ed022312163ee11336ac62b9d Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Mon, 19 Jan 2015 16:23:35 +0300 Subject: [PATCH 14/19] IDEA-135271 Delete file dialog does not position mouse cursor on default button --- .../src/com/intellij/ui/messages/SheetMessage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java b/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java index 7837b48ab3fa..e9627386eb88 100755 --- a/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java +++ b/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java @@ -25,6 +25,7 @@ import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.ui.mac.MacMainFrameDecorator; +import com.intellij.util.IJSwingUtilities; import com.intellij.util.ui.Animator; import org.jetbrains.annotations.NotNull; @@ -221,6 +222,7 @@ public class SheetMessage { staticImage = null; myWindow.setContentPane(myController.getPanel(myWindow)); + IJSwingUtilities.moveMousePointerOn(myWindow.getRootPane().getDefaultButton()); myController.requestFocus(); } else { if (restoreFullScreenButton) { From 66eba8e34d22b4b396f614dac87eeeab7f81b468 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 19 Jan 2015 14:24:48 +0100 Subject: [PATCH 15/19] can't find Kotlin top-level function in SE --- .../intellij/ide/actions/SearchEverywhereAction.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index 9924625c86f5..6ce52a5ab56e 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -1682,7 +1682,7 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myProgressIndicator, new Processor() { @Override public boolean process(Object o) { - if (o instanceof PsiElement && !(((PsiElement)o).getParent() instanceof PsiFile)) { + if (isSymbol(o)) { final PsiElement element = (PsiElement)o; final PsiFile file = element.getContainingFile(); if (!myListModel.contains(o) && !symbols.contains(o) && @@ -1698,6 +1698,16 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA return symbols; } + protected boolean isSymbol(Object o) { + if (o instanceof PsiElement) { + final PsiElement e = (PsiElement)o; + //todo[kb] need a better way to avoid mixing java classes with symbols. Same to other languages where + //todo[kb] symbol provider returns classes. We need kind of suppressor API & EP here. + return !e.getLanguage().is(Language.findLanguageByID("JAVA")) || !(e.getParent() instanceof PsiFile); + } + return false; + } + private SearchResult getClasses(String pattern, boolean includeLibs, final int max, ChooseByNamePopup chooseByNamePopup) { final SearchResult classes = new SearchResult(); if (chooseByNamePopup == null) { From 4a7928f3763a205d7dc51a05e8ed16a49e17ad2f Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 19 Jan 2015 16:45:13 +0300 Subject: [PATCH 16/19] IDEA-69974 Fold regions are not properly created if 'Collapse All' is invoked right after opening editor test case added --- ...gProcessingOnDocumentModificationTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/openapi/editor/impl/FoldingProcessingOnDocumentModificationTest.java b/java/java-tests/testSrc/com/intellij/openapi/editor/impl/FoldingProcessingOnDocumentModificationTest.java index 6da536d86d2c..ad12ef131055 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/editor/impl/FoldingProcessingOnDocumentModificationTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/editor/impl/FoldingProcessingOnDocumentModificationTest.java @@ -16,6 +16,7 @@ package com.intellij.openapi.editor.impl; import com.intellij.codeInsight.folding.CodeFoldingManager; +import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.FoldRegion; import com.intellij.testFramework.TestFileType; @@ -55,7 +56,31 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT assertFalse(foldRegion.isExpanded()); } + public void testCollapseAllHappensBeforeFirstCodeFoldingPass() throws Exception { + init("class Foo {\n" + + " void m() {\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " }\n" + + "}", TestFileType.JAVA); + + buildInitialFoldRegions(); + executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS); + runFoldingPass(true); + assertEquals(1, myEditor.getFoldingModel().getAllFoldRegions().length); + } + + private static void buildInitialFoldRegions() { + CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myEditor); + } + private static void updateFoldRegions() { CodeFoldingManager.getInstance(getProject()).updateFoldRegions(myEditor); } + + private static void runFoldingPass(boolean firstTime) { + Runnable runnable = CodeFoldingManager.getInstance(getProject()).updateFoldRegionsAsync(myEditor, firstTime); + assertNotNull(runnable); + runnable.run(); + } } From ab14fd7d1248de979b2a69b59aaadc645a05acca Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 19 Jan 2015 16:28:07 +0300 Subject: [PATCH 17/19] decompiler: fixed NPE with disabled line mapping --- .../org/jetbrains/java/decompiler/IdeaDecompiler.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java index 93650c2da4af..72e0f4f06512 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -183,8 +183,9 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { } decompiler.decompileContext(); - file.putUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY, - new ExactMatchLineNumbersMapping(saver.myMapping)); + if (saver.myMapping != null) { + file.putUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY, new ExactMatchLineNumbersMapping(saver.myMapping)); + } return saver.myResult; } @@ -344,7 +345,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { private static class ExactMatchLineNumbersMapping implements LineNumbersMapping { private int[] myMapping; - private ExactMatchLineNumbersMapping(int[] mapping) { + private ExactMatchLineNumbersMapping(@NotNull int[] mapping) { myMapping = mapping; } From 4fb1124d2dd6ead2c24ec00417438051cb3a40fe Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 19 Jan 2015 14:58:18 +0100 Subject: [PATCH 18/19] IDEA-133004 (no comment injections for binary files) --- .../plugins/intelliLang/inject/InjectorUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java index 1b4e43ec4df1..035507d22122 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectorUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -229,15 +229,17 @@ public class InjectorUtils { public static BaseInjection findCommentInjection(@NotNull PsiElement context, @NotNull String supportId, @Nullable Ref causeRef) { PsiElement target = CompletionUtil.getOriginalOrSelf(context); PsiFile file = target.getContainingFile(); + if (file == null || file.getFileType().isBinary()) return null; TreeMap map = getInjectionMap(file); - Map.Entry entry = map == null ? null : map.lowerEntry(target.getTextRange()); + if (map == null) return null; + Map.Entry entry = map.lowerEntry(target.getTextRange()); if (entry == null) return null; PsiComment psiComment = PsiTreeUtil.findElementOfClassAtOffset(file, entry.getKey().getStartOffset(), PsiComment.class, false); if (psiComment == null) return null; TextRange r0 = psiComment.getTextRange(); - // calulate topmost siblings & heights + // calculate topmost siblings & heights PsiElement commonParent = PsiTreeUtil.findCommonParent(psiComment, target); int h1 = 0, h2 = 0; PsiElement e1 = psiComment, e2 = target; @@ -269,8 +271,7 @@ public class InjectorUtils { } @Nullable - private static TreeMap getInjectionMap(@Nullable final PsiFile file) { - if (file == null) return null; // e.g. null for synthetic groovy variables + private static TreeMap getInjectionMap(@NotNull final PsiFile file) { return CachedValuesManager.getCachedValue(file, new CachedValueProvider>() { @Nullable @Override From 9cf3ef745393cdf5c72da0ddc17c65abbaf9919b Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 19 Jan 2015 17:12:52 +0300 Subject: [PATCH 19/19] IDEA-135033 Storage for activation status fixed & .gdsl files within library sources ignored --- .../groovy/dsl/DslActivationStatus.java | 20 +++++++++++++------ .../groovy/dsl/GroovyDslFileIndex.java | 7 +++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/DslActivationStatus.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/DslActivationStatus.java index de1d162148bb..267707e08207 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/DslActivationStatus.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/DslActivationStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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,6 +16,7 @@ package org.jetbrains.plugins.groovy.dsl; import com.intellij.openapi.components.*; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import gnu.trove.THashMap; @@ -49,11 +50,16 @@ public class DslActivationStatus implements PersistentStateComponent { @Nullable public synchronized String getInactivityReason(VirtualFile file) { String status = myStatus.get(file); - return status == null || status == ENABLED ? null : status; + return ENABLED.equals(status) ? null : status; } public synchronized boolean isActivated(VirtualFile file) { - return myStatus.get(file) == ENABLED; + final String status = myStatus.get(file); + if (status == null) { + myStatus.put(file, ENABLED); + return true; + } + return ENABLED.equals(status); } @Nullable @@ -66,7 +72,9 @@ public class DslActivationStatus implements PersistentStateComponent { Element element = new Element("file"); root.addContent(element); element.setAttribute("url", file.getUrl()); - element.setAttribute("status", (status == ENABLED ? "" : status)); + if (!ENABLED.equals(status)) { + element.setAttribute("status", status); + } } return root; } @@ -76,10 +84,10 @@ public class DslActivationStatus implements PersistentStateComponent { List children = state.getChildren("file"); for (Element element : children) { String url = element.getAttributeValue("url", ""); - String status = element.getAttributeValue("status", ENABLED); + String status = element.getAttributeValue("status"); VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file != null) { - myStatus.put(file, status); + myStatus.put(file, StringUtil.isNotEmpty(status) ? status : ENABLED); } } } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index e9692292588f..692aab0efc4c 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -74,7 +74,7 @@ import java.util.regex.Pattern; */ public class GroovyDslFileIndex extends ScalarIndexExtension { private static final Key> CACHED_EXECUTOR = Key.create("CachedGdslExecutor"); - private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.dsl.GroovyDslFileIndex"); + private static final Logger LOG = Logger.getInstance(GroovyDslFileIndex.class); @NonNls public static final ID NAME = ID.create("GroovyDslFileIndex"); @NonNls private static final String OUR_KEY = "ourKey"; @@ -412,7 +412,10 @@ public class GroovyDslFileIndex extends ScalarIndexExtension { if (!vfile.isValid()) { continue; } - if (!fileIndex.isInLibraryClasses(vfile) && !fileIndex.isInLibrarySource(vfile)) { + if (fileIndex.isInLibrarySource(vfile)) { + continue; + } + if (!fileIndex.isInLibraryClasses(vfile)) { if (!fileIndex.isInSourceContent(vfile) || !isActivated(vfile)) { continue; }