From ff848a052ad5fd5d8ed8f1a967b1b7298e1bcc43 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 15 May 2015 22:51:08 +0300 Subject: [PATCH 1/9] refactor to avoid SOE and fail to stop problems ever (IDEA-140324) --- .../DefaultNavBarExtension.java | 48 ++++++++++ .../ide/navigationToolbar/NavBarModel.java | 95 ++++++------------- 2 files changed, 76 insertions(+), 67 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/DefaultNavBarExtension.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/DefaultNavBarExtension.java index 06928197028d..8f888a825472 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/DefaultNavBarExtension.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/DefaultNavBarExtension.java @@ -29,6 +29,7 @@ import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiFileSystemItemProcessor; import com.intellij.psi.util.PsiUtilCore; +import com.intellij.util.PathUtil; import com.intellij.util.Processor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -181,4 +182,51 @@ public class DefaultNavBarExtension extends AbstractNavBarModelExtension { } }); } + + @Nullable + @Override + public PsiElement getParent(PsiElement psiElement) { + PsiFile containingFile = psiElement.getContainingFile(); + if (containingFile != null) { + PsiDirectory containingDirectory = containingFile.getContainingDirectory(); + if (containingDirectory != null) { + return containingDirectory; + } + } + else if (psiElement instanceof PsiDirectory) { + PsiDirectory psiDirectory = (PsiDirectory)psiElement; + Project project = psiElement.getProject(); + + PsiDirectory parentDirectory = psiDirectory.getParentDirectory(); + + if (parentDirectory == null) { + VirtualFile jar = PathUtil.getLocalFile(psiDirectory.getVirtualFile()); + if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(jar)) { + parentDirectory = PsiManager.getInstance(project).findDirectory(jar.getParent()); + } + } + return parentDirectory; + } + else if (psiElement instanceof PsiFileSystemItem) { + VirtualFile virtualFile = ((PsiFileSystemItem)psiElement).getVirtualFile(); + if (virtualFile == null) return null; + PsiManager psiManager = psiElement.getManager(); + PsiElement resultElement; + if (virtualFile.isDirectory()) { + resultElement = psiManager.findDirectory(virtualFile); + } + else { + resultElement = psiManager.findFile(virtualFile); + } + if (resultElement == null) return null; + VirtualFile parentVFile = virtualFile.getParent(); + if (parentVFile != null) { + PsiDirectory parentDirectory = psiManager.findDirectory(parentVFile); + if (parentDirectory != null) { + return parentDirectory; + } + } + } + return null; + } } diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java index 98cf21272902..ddaa4682e896 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarModel.java @@ -33,9 +33,9 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.CommonProcessors; import com.intellij.util.ObjectUtils; -import com.intellij.util.PathUtil; import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -174,7 +174,7 @@ public class NavBarModel { } }); - setModel(updatedModel); + setModel(ContainerUtil.reverse(updatedModel)); } void revalidate() { @@ -215,81 +215,42 @@ public class NavBarModel { } } - private void traverseToRoot(@NotNull PsiElement psiElement, Set roots, List model) { - if (!psiElement.isValid()) return; - final PsiFile containingFile = psiElement.getContainingFile(); - if (containingFile != null && containingFile.getVirtualFile() == null) return; //non physical elements - psiElement = getOriginalElement(psiElement); - PsiElement resultElement = psiElement; + private static void traverseToRoot(@NotNull PsiElement psiElement, Set roots, List model) { + if (!isValid(psiElement)) return; - resultElement = normalize(resultElement); - if (resultElement == null) return; + NavBarModelExtension[] extensions = Extensions.getExtensions(NavBarModelExtension.EP_NAME); - boolean foundByExtension = false; - for (final NavBarModelExtension modelExtension : Extensions.getExtensions(NavBarModelExtension.EP_NAME)) { - final PsiElement parent = modelExtension.getParent(resultElement); - if (parent != null) { - if (parent != resultElement) { // HACK is to return same element to stop traversing - traverseToRoot(parent, roots, model); - } - foundByExtension = true; - break; - } - } + for (PsiElement e = normalize(getOriginalElement(psiElement)), next = null; + e != null; e = normalize(getOriginalElement(next)), next = null) { + // check if we're running circles due to getParent()->normalize/adjust() + if (model.contains(e)) break; - if (!foundByExtension) { - if (containingFile != null) { - final PsiDirectory containingDirectory = containingFile.getContainingDirectory(); - if (containingDirectory != null) { - traverseToRoot(containingDirectory, roots, model); - } - } - else if (psiElement instanceof PsiDirectory) { - final PsiDirectory psiDirectory = (PsiDirectory)psiElement; + model.add(e); - if (!roots.contains(psiDirectory.getVirtualFile())) { - PsiDirectory parentDirectory = psiDirectory.getParentDirectory(); + // check if a root is reached + VirtualFile vFile = PsiUtilCore.getVirtualFile(e); + if (roots.contains(vFile)) break; - if (parentDirectory == null) { - VirtualFile jar = PathUtil.getLocalFile(psiDirectory.getVirtualFile()); - if (ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(jar)) { - parentDirectory = PsiManager.getInstance(myProject).findDirectory(jar.getParent()); - } - } - - - if (parentDirectory != null) { - traverseToRoot(parentDirectory, roots, model); - } - } - } - else if (psiElement instanceof PsiFileSystemItem) { - final VirtualFile virtualFile = ((PsiFileSystemItem)psiElement).getVirtualFile(); - if (virtualFile == null) return; - final PsiManager psiManager = PsiManager.getInstance(myProject); - if (virtualFile.isDirectory()) { - resultElement = psiManager.findDirectory(virtualFile); - } - else { - resultElement = psiManager.findFile(virtualFile); - } - if (resultElement == null) return; - final VirtualFile parentVFile = virtualFile.getParent(); - if (parentVFile != null && !roots.contains(parentVFile)) { - final PsiDirectory parentDirectory = psiManager.findDirectory(parentVFile); - if (parentDirectory != null) { - traverseToRoot(parentDirectory, roots, model); - } + for (NavBarModelExtension ext : extensions) { + PsiElement parent = ext.getParent(e); + if (parent != null && parent != e) { + //noinspection AssignmentToForLoopParameter + next = parent; + break; } } } - - model.add(resultElement); } - private static PsiElement getOriginalElement(PsiElement psiElement) { - final PsiElement originalElement = psiElement.getOriginalElement(); - return !(psiElement instanceof PsiCompiledElement) && originalElement instanceof PsiCompiledElement ? psiElement : originalElement; + @Nullable + private static PsiElement getOriginalElement(@Nullable PsiElement e) { + if (e == null || !e.isValid()) return null; + + PsiFile containingFile = e.getContainingFile(); + if (containingFile != null && containingFile.getVirtualFile() == null) return null; + + PsiElement orig = e.getOriginalElement(); + return !(e instanceof PsiCompiledElement) && orig instanceof PsiCompiledElement ? e : orig; } From 5f8f85cea03c16cb2a8d2c7189b36f70e22b3a78 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 15 May 2015 23:31:03 +0300 Subject: [PATCH 2/9] Separator fixed and glob used instead of regexp for PY-15869 TODO: add tests! --- python/helpers/pycharm/utrunner.py | 16 ++++++++++------ .../unittest/PythonUnitTestCommandLineState.java | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/python/helpers/pycharm/utrunner.py b/python/helpers/pycharm/utrunner.py index 3ae5cd20d564..d0450c242825 100644 --- a/python/helpers/pycharm/utrunner.py +++ b/python/helpers/pycharm/utrunner.py @@ -1,10 +1,11 @@ import sys import imp import os +import fnmatch helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0]) if sys.path[0] != helpers_dir: - sys.path.insert(0, helpers_dir) + sys.path.insert(0, helpers_dir) from tcunittest import TeamcityTestRunner from nose_helper import TestLoader, ContextSuite @@ -44,16 +45,19 @@ def loadSource(fileName): def walkModules(modulesAndPattern, dirname, names): modules = modulesAndPattern[0] pattern = modulesAndPattern[1] - prog_list = [re.compile(pat.strip()) for pat in pattern.split(',')] + # fnmatch converts glob to regexp + prog_list = [re.compile(fnmatch.translate(pat.strip())) for pat in pattern.split(',')] for name in names: for prog in prog_list: if name.endswith(".py") and prog.match(name): modules.append(loadSource(os.path.join(dirname, name))) -def loadModulesFromFolderRec(folder, pattern = "test.*"): +# For default pattern see https://docs.python.org/2/library/unittest.html#test-discovery +def loadModulesFromFolderRec(folder, pattern = "test*.py"): modules = [] if PYTHON_VERSION_MAJOR == 3: - prog_list = [re.compile(pat.strip()) for pat in pattern.split(',')] + # fnmatch converts glob to regexp + prog_list = [re.compile(fnmatch.translate(pat.strip())) for pat in pattern.split(',')] for root, dirs, files in os.walk(folder): for name in files: for prog in prog_list: @@ -101,7 +105,7 @@ if __name__ == "__main__": a = arg.split("::") if len(a) == 1: # From module or folder - a_splitted = a[0].split(";") + a_splitted = a[0].split("_args_separator_") # ";" can't be used with bash, so we use "_args_separator_" if len(a_splitted) != 1: # means we have pattern to match against if a_splitted[0].endswith(os.path.sep): @@ -128,7 +132,7 @@ if __name__ == "__main__": all.addTests(testLoader.loadTestsFromTestCase(getattr(module, a[1]))) else: all.addTests(testLoader.loadTestsFromTestClass(getattr(module, a[1])), - getattr(module, a[1])) + getattr(module, a[1])) else: # From method in class or from function debug("/ from method " + a[2] + " in testcase " + a[1] + " in " + a[0]) diff --git a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java index d915180d3772..90b0f5b4cdbe 100644 --- a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java @@ -67,7 +67,8 @@ public class PythonUnitTestCommandLineState extends case TEST_FOLDER: final String folderName = FileUtil.toSystemDependentName(myConfig.getFolderName() + "/"); if (!StringUtil.isEmpty(myConfig.getPattern()) && myConfig.usePattern()) { - specs.add(folderName + ";" + myConfig.getPattern()); + // ";" can't be used with bash, so we use "_args_separator_" + specs.add(folderName + "_args_separator_" + myConfig.getPattern()); } else { specs.add(folderName); From c7a756c10862cd5bc80475dfa373495deb66dbde Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 18 May 2015 19:37:03 +0300 Subject: [PATCH 3/9] wrapped actions should have same DumbAware-ness and other flags --- .../openapi/actionSystem/EmptyAction.java | 114 +++++++++++++----- 1 file changed, 85 insertions(+), 29 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java index 38499eb25394..63918ed1e9a0 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java @@ -85,38 +85,94 @@ public final class EmptyAction extends AnAction { } public static AnAction wrap(final AnAction action) { - return action instanceof ActionGroup ? new ActionGroup() { - { - setPopup(((ActionGroup)action).isPopup()); - copyFrom(action); - setShortcutSet(new CustomShortcutSet()); - } + final boolean isDumbAware = action.isDumbAware(); + final boolean isEnabledInModalContext = action.isEnabledInModalContext(); + final boolean inInjectedContext = action.isInInjectedContext(); + final boolean isTransparentUpdate = action.isTransparentUpdate(); + if (action instanceof ActionGroup) { + final ActionGroup group = ((ActionGroup)action); + final boolean isHideIfNoVisibleChildren = group.hideIfNoVisibleChildren(); + final boolean isDisableIfNoVisibleChildren = group.disableIfNoVisibleChildren(); + return new ActionGroup() { + { + setPopup(group.isPopup()); + copyFrom(group); + setShortcutSet(new CustomShortcutSet()); + setEnabledInModalContext(isEnabledInModalContext); + setInjectedContext(inInjectedContext); + } - @Override - public void update(final AnActionEvent e) { - action.update(e); - } + @Override + public void update(final AnActionEvent e) { + group.update(e); + } - @NotNull - @Override - public AnAction[] getChildren(@Nullable final AnActionEvent e) { - return ((ActionGroup)action).getChildren(e); - } - } : new AnAction() { - { - copyFrom(action); - setShortcutSet(new CustomShortcutSet()); - } + @NotNull + @Override + public AnAction[] getChildren(@Nullable final AnActionEvent e) { + return group.getChildren(e); + } - @Override - public void actionPerformed(final AnActionEvent e) { - action.actionPerformed(e); - } + @Override + public boolean canBePerformed(DataContext context) { + return group.canBePerformed(context); + } - @Override - public void update(final AnActionEvent e) { - action.update(e); - } - }; + @Override + public void actionPerformed(AnActionEvent e) { + group.actionPerformed(e); + } + + @Override + public boolean isDumbAware() { + return isDumbAware; + } + + @Override + public boolean isTransparentUpdate() { + return isTransparentUpdate; + } + + @Override + public boolean hideIfNoVisibleChildren() { + return isHideIfNoVisibleChildren; + } + + @Override + public boolean disableIfNoVisibleChildren() { + return isDisableIfNoVisibleChildren; + } + }; + } + else { + return new AnAction() { + { + copyFrom(action); + setShortcutSet(new CustomShortcutSet()); + setEnabledInModalContext(isEnabledInModalContext); + setInjectedContext(inInjectedContext); + } + + @Override + public void actionPerformed(final AnActionEvent e) { + action.actionPerformed(e); + } + + @Override + public void update(final AnActionEvent e) { + action.update(e); + } + + @Override + public boolean isDumbAware() { + return isDumbAware; + } + + @Override + public boolean isTransparentUpdate() { + return isTransparentUpdate; + } + }; + } } } From ba910472db597b4b2f41756e9bef64226f572df5 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Mon, 18 May 2015 20:21:23 +0300 Subject: [PATCH 4/9] Test added for PY-15869 --- .../env/unit/another_file_for_pattern.py | 9 +++++++++ .../testRunner/env/unit/file_for_pattern.py | 9 +++++++++ .../env/python/testing/PythonUnitTestingTest.java | 15 +++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 python/testData/testRunner/env/unit/another_file_for_pattern.py create mode 100644 python/testData/testRunner/env/unit/file_for_pattern.py diff --git a/python/testData/testRunner/env/unit/another_file_for_pattern.py b/python/testData/testRunner/env/unit/another_file_for_pattern.py new file mode 100644 index 000000000000..665c47936b50 --- /dev/null +++ b/python/testData/testRunner/env/unit/another_file_for_pattern.py @@ -0,0 +1,9 @@ +__author__ = 'Ilya.Kazakevich' +from unittest import TestCase + +class UTests(TestCase): + def testByPattern(self): + pass + + def testByPattern2(self): + pass \ No newline at end of file diff --git a/python/testData/testRunner/env/unit/file_for_pattern.py b/python/testData/testRunner/env/unit/file_for_pattern.py new file mode 100644 index 000000000000..6ae7d7e746ad --- /dev/null +++ b/python/testData/testRunner/env/unit/file_for_pattern.py @@ -0,0 +1,9 @@ +__author__ = 'Ilya.Kazakevich' +from unittest import TestCase + +class UTests(TestCase): + def testByPattern(self): + self.assertTrue(False) + + def testByPattern2(self): + self.assertTrue(False) \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java index 682eb8160285..a0de60ccc906 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java @@ -32,6 +32,21 @@ public class PythonUnitTestingTest extends PyEnvTestCase{ }); } + /** + * Ensures pattern is supported + */ + public void testUTRunnerByPattern() { + runPythonTest(new PyUnitTestTask("/testRunner/env/unit", "_args_separator_*pattern.py") { + + @Override + public void after() { + assertEquals(4, allTestsCount()); + assertEquals(2, passedTestsCount()); + assertEquals(2, failedTestsCount()); + } + }); + } + public void testClass() { runPythonTest(new PyUnitTestTask("/testRunner/env/unit", "test_file.py::GoodTest") { From edd72f64a3eb2206358f26c1d10b154a5125c749 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 6 Apr 2015 19:55:44 +0300 Subject: [PATCH 5/9] diff: extract common focus tracking logic --- .../diff/tools/binary/BinaryDiffViewer.java | 79 ++------ .../diff/tools/util/FocusTrackerSupport.java | 188 ++++++++++++++++++ .../threeside/ThreesideTextDiffViewer.java | 55 ++--- .../util/twoside/TwosideTextDiffViewer.java | 63 ++---- 4 files changed, 234 insertions(+), 151 deletions(-) create mode 100644 platform/diff-impl/src/com/intellij/diff/tools/util/FocusTrackerSupport.java diff --git a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java index 5b6fec5aaec2..eea633f3c40e 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java @@ -24,10 +24,10 @@ import com.intellij.diff.contents.FileContent; import com.intellij.diff.requests.ContentDiffRequest; import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.tools.util.DiffNotifications; +import com.intellij.diff.tools.util.FocusTrackerSupport; import com.intellij.diff.tools.util.SimpleDiffPanel; import com.intellij.diff.tools.util.StatusPanel; import com.intellij.diff.tools.util.base.ListenerDiffViewerBase; -import com.intellij.diff.util.DiffUserDataKeys; import com.intellij.diff.util.DiffUtil; import com.intellij.diff.util.Side; import com.intellij.openapi.Disposable; @@ -61,8 +61,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -79,10 +77,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { @Nullable private final FileEditorProvider myEditorProvider1; @Nullable private final FileEditorProvider myEditorProvider2; - @Nullable private final MyEditorFocusListener myEditorFocusListener1; - @Nullable private final MyEditorFocusListener myEditorFocusListener2; - - @NotNull private Side myCurrentSide = Side.LEFT; + @NotNull private final FocusTrackerSupport.TwosideFocusTrackerSupport myFocusTrackerSupport; public BinaryDiffViewer(@NotNull DiffContext context, @NotNull DiffRequest request) { super(context, (ContentDiffRequest)request); @@ -96,16 +91,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { myEditorProvider2 = editors.second.second; assert myEditor1 != null || myEditor2 != null; - if (myEditor1 != null && myEditor2 != null) { - myEditorFocusListener1 = new MyEditorFocusListener(Side.LEFT); - myEditorFocusListener2 = new MyEditorFocusListener(Side.RIGHT); - } - else { - myEditorFocusListener1 = null; - myEditorFocusListener2 = null; - } - - + myFocusTrackerSupport = new FocusTrackerSupport.TwosideFocusTrackerSupport(myEditor1, myEditor2); myContentPanel = new BinaryContentPanel(titlePanel, myEditor1, myEditor2); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -113,15 +99,10 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { myStatusPanel = new MyStatusPanel(); new MyFocusOppositePaneAction().setupAction(myPanel); - - - installEditorListeners(); } - @Override @CalledInAwt public void onDispose() { - destroyEditorListeners(); destroyEditors(); super.onDispose(); } @@ -130,25 +111,14 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { @CalledInAwt protected void processContextHints() { super.processContextHints(); - if (myEditor1 == null) { - myCurrentSide = Side.RIGHT; - } - else if (myEditor2 == null) { - myCurrentSide = Side.LEFT; - } - else { - Side side = myContext.getUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE); - if (side != null) myCurrentSide = side; - } + myFocusTrackerSupport.processContextHints(myRequest, myContext); } @Override @CalledInAwt protected void updateContextHints() { super.updateContextHints(); - if (myEditor1 != null && myEditor2 != null) { - myContext.putUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE, myCurrentSide); - } + myFocusTrackerSupport.updateContextHints(myRequest, myContext); } // @@ -222,20 +192,6 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { } } - private void installEditorListeners() { - if (myEditor1 != null && myEditor2 != null) { - myEditor1.getComponent().addFocusListener(myEditorFocusListener1); - myEditor2.getComponent().addFocusListener(myEditorFocusListener2); - } - } - - private void destroyEditorListeners() { - if (myEditor1 != null && myEditor2 != null) { - myEditor1.getComponent().removeFocusListener(myEditorFocusListener1); - myEditor2.getComponent().removeFocusListener(myEditorFocusListener2); - } - } - // // Diff // @@ -364,8 +320,12 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { } @NotNull - Side getCurrentSide() { - return myCurrentSide; + public Side getCurrentSide() { + return myFocusTrackerSupport.getCurrentSide(); + } + + public void setCurrentSide(@NotNull Side side) { + myFocusTrackerSupport.setCurrentSide(side); } @Nullable @@ -447,7 +407,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { @Override public void actionPerformed(@NotNull AnActionEvent e) { assert myEditor1 != null && myEditor2 != null; - myCurrentSide = myCurrentSide.other(); + setCurrentSide(getCurrentSide().other()); myPanel.requestFocus(); } @@ -465,7 +425,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { @Override public Object getData(@NonNls String dataId) { if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - return DiffUtil.getVirtualFile(myRequest, myCurrentSide); + return DiffUtil.getVirtualFile(myRequest, getCurrentSide()); } return super.getData(dataId); } @@ -476,17 +436,4 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { return -1; } } - - private class MyEditorFocusListener extends FocusAdapter { - @NotNull private final Side mySide; - - private MyEditorFocusListener(@NotNull Side side) { - mySide = side; - } - - public void focusGained(FocusEvent e) { - if (myEditor1 == null || myEditor2 == null) return; - myCurrentSide = mySide; - } - } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/FocusTrackerSupport.java b/platform/diff-impl/src/com/intellij/diff/tools/util/FocusTrackerSupport.java new file mode 100644 index 000000000000..49030bed6851 --- /dev/null +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/FocusTrackerSupport.java @@ -0,0 +1,188 @@ +/* + * 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.diff.tools.util; + +import com.intellij.diff.DiffContext; +import com.intellij.diff.requests.DiffRequest; +import com.intellij.diff.util.DiffUserDataKeys; +import com.intellij.diff.util.Side; +import com.intellij.diff.util.ThreeSide; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileEditor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.util.List; + +public class FocusTrackerSupport { + public static class TwosideFocusTrackerSupport { + @NotNull private Side myCurrentSide; + + private final boolean myDumbMode; + @Nullable private final MyFocusListener myListener1; + @Nullable private final MyFocusListener myListener2; + + public TwosideFocusTrackerSupport(@Nullable Editor editor1, @Nullable Editor editor2) { + this(getComponent(editor1), getComponent(editor2)); + } + + public TwosideFocusTrackerSupport(@Nullable FileEditor editor1, @Nullable FileEditor editor2) { + this(getComponent(editor1), getComponent(editor2)); + } + + public TwosideFocusTrackerSupport(@Nullable JComponent component1, @Nullable JComponent component2) { + assert component1 != null || component2 != null; + myCurrentSide = component2 != null ? Side.RIGHT : Side.LEFT; + + myDumbMode = component1 == null || component2 == null; + if (!myDumbMode) { + myListener1 = new MyFocusListener(Side.LEFT); + component1.addFocusListener(myListener1); + + myListener2 = new MyFocusListener(Side.RIGHT); + component2.addFocusListener(myListener2); + } + else { + myListener1 = null; + myListener2 = null; + } + } + + @NotNull + public Side getCurrentSide() { + return myCurrentSide; + } + + public void setCurrentSide(@NotNull Side side) { + if (myDumbMode) return; + myCurrentSide = side; + } + + public void processContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) { + Side side = context.getUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE); + if (side != null) setCurrentSide(side); + } + + public void updateContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) { + if (myDumbMode) return; + context.putUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE, myCurrentSide); + } + + private class MyFocusListener extends FocusAdapter { + @NotNull private final Side mySide; + + private MyFocusListener(@NotNull Side side) { + mySide = side; + } + + public void focusGained(FocusEvent e) { + myCurrentSide = mySide; + } + } + } + + public static class ThreesideFocusTrackerSupport { + @NotNull private ThreeSide myCurrentSide; + + private final boolean myDumbMode; + @Nullable private final MyFocusListener myListener1; + @Nullable private final MyFocusListener myListener2; + @Nullable private final MyFocusListener myListener3; + + public ThreesideFocusTrackerSupport(@NotNull List editors) { + this(editors.get(0), editors.get(1), editors.get(2)); + } + + public ThreesideFocusTrackerSupport(@Nullable Editor editor1, @Nullable Editor editor2, @Nullable Editor editor3) { + this(getComponent(editor1), getComponent(editor2), getComponent(editor3)); + } + + public ThreesideFocusTrackerSupport(@Nullable FileEditor editor1, @Nullable FileEditor editor2, @Nullable FileEditor editor3) { + this(getComponent(editor1), getComponent(editor2), getComponent(editor3)); + } + + public ThreesideFocusTrackerSupport(@Nullable JComponent component1, @Nullable JComponent component2, @Nullable JComponent component3) { + assert component1 != null || component2 != null || component3 != null; + myCurrentSide = component2 != null ? ThreeSide.BASE : component1 != null ? ThreeSide.LEFT : ThreeSide.RIGHT; + + boolean c1 = component1 != null; + boolean c2 = component2 != null; + boolean c3 = component3 != null; + myDumbMode = (!c1 && !c2) || (!c1 && !c3) || (!c2 && !c3); // only one not-null element + + if (!myDumbMode) { + myListener1 = component1 != null ? new MyFocusListener(ThreeSide.LEFT) : null; + if (component1 != null) component1.addFocusListener(myListener1); + + myListener2 = component2 != null ? new MyFocusListener(ThreeSide.BASE) : null; + if (component2 != null) component2.addFocusListener(myListener2); + + myListener3 = component3 != null ? new MyFocusListener(ThreeSide.RIGHT) : null; + if (component3 != null) component3.addFocusListener(myListener3); + } + else { + myListener1 = null; + myListener2 = null; + myListener3 = null; + } + } + + @NotNull + public ThreeSide getCurrentSide() { + return myCurrentSide; + } + + public void setCurrentSide(@NotNull ThreeSide side) { + if (myDumbMode || side.select(myListener1, myListener2, myListener3) == null) return; + myCurrentSide = side; + } + + public void processContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) { + ThreeSide side = context.getUserData(DiffUserDataKeys.PREFERRED_FOCUS_THREESIDE); + if (side != null) setCurrentSide(side); + } + + public void updateContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) { + if (myDumbMode) return; + context.putUserData(DiffUserDataKeys.PREFERRED_FOCUS_THREESIDE, myCurrentSide); + } + + private class MyFocusListener extends FocusAdapter { + @NotNull private final ThreeSide mySide; + + private MyFocusListener(@NotNull ThreeSide side) { + mySide = side; + } + + public void focusGained(FocusEvent e) { + myCurrentSide = mySide; + } + } + } + + @Nullable + private static JComponent getComponent(@Nullable Editor editor) { + return editor != null ? editor.getContentComponent() : null; + } + + @Nullable + private static JComponent getComponent(@Nullable FileEditor editor) { + return editor != null ? editor.getComponent() : null; + } +} diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java index 86eb56b42e7c..7c87c653daf8 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java @@ -24,12 +24,12 @@ import com.intellij.diff.requests.ContentDiffRequest; import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.diff.tools.util.DiffDataKeys; +import com.intellij.diff.tools.util.FocusTrackerSupport.ThreesideFocusTrackerSupport; import com.intellij.diff.tools.util.SimpleDiffPanel; import com.intellij.diff.tools.util.SyncScrollSupport; import com.intellij.diff.tools.util.SyncScrollSupport.ThreesideSyncScrollSupport; import com.intellij.diff.tools.util.base.InitialScrollPositionSupport; import com.intellij.diff.tools.util.base.TextDiffViewerBase; -import com.intellij.diff.util.DiffUserDataKeys; import com.intellij.diff.util.DiffUtil; import com.intellij.diff.util.Side; import com.intellij.diff.util.ThreeSide; @@ -55,8 +55,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; import java.util.ArrayList; import java.util.List; @@ -72,18 +70,14 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull protected final List myActualContents; - @NotNull private final List myEditorFocusListeners = - ContainerUtil.newArrayList(new MyEditorFocusListener(ThreeSide.LEFT), - new MyEditorFocusListener(ThreeSide.BASE), - new MyEditorFocusListener(ThreeSide.RIGHT)); @NotNull private final MyVisibleAreaListener myVisibleAreaListener1 = new MyVisibleAreaListener(Side.LEFT); @NotNull private final MyVisibleAreaListener myVisibleAreaListener2 = new MyVisibleAreaListener(Side.RIGHT); @NotNull protected final MySetEditorSettingsAction myEditorSettingsAction; - @Nullable private ThreesideSyncScrollSupport mySyncScrollListener; + @NotNull private final ThreesideFocusTrackerSupport myFocusTrackerSupport; - @NotNull private ThreeSide myCurrentSide; + @Nullable private ThreesideSyncScrollSupport mySyncScrollListener; public ThreesideTextDiffViewer(@NotNull DiffContext context, @NotNull ContentDiffRequest request) { super(context, request); @@ -97,8 +91,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { myEditors = createEditors(); List titlePanel = DiffUtil.createTextTitles(myRequest, myEditors); - myCurrentSide = ThreeSide.BASE; - + myFocusTrackerSupport = new ThreesideFocusTrackerSupport(myEditors); myContentPanel = new ThreesideTextContentPanel(myEditors, titlePanel); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -121,15 +114,14 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @CalledInAwt protected void processContextHints() { super.processContextHints(); - ThreeSide side = myContext.getUserData(DiffUserDataKeys.PREFERRED_FOCUS_THREESIDE); - if (side != null) myCurrentSide = side; + myFocusTrackerSupport.processContextHints(myRequest, myContext); } @Override @CalledInAwt protected void updateContextHints() { super.updateContextHints(); - myContext.putUserData(DiffUserDataKeys.PREFERRED_FOCUS_THREESIDE, myCurrentSide); + myFocusTrackerSupport.updateContextHints(myRequest, myContext); } @NotNull @@ -168,9 +160,6 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @Override protected void installEditorListeners() { super.installEditorListeners(); - for (int i = 0; i < 3; i++) { - myEditors.get(i).getContentComponent().addFocusListener(myEditorFocusListeners.get(i)); - } myEditors.get(0).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); myEditors.get(1).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); @@ -190,10 +179,6 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { public void destroyEditorListeners() { super.destroyEditorListeners(); - for (int i = 0; i < 3; i++) { - myEditors.get(i).getContentComponent().removeFocusListener(myEditorFocusListeners.get(i)); - } - myEditors.get(0).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); myEditors.get(1).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); @@ -238,12 +223,12 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull public EditorEx getCurrentEditor() { - return myCurrentSide.select(myEditors); + return getCurrentSide().select(myEditors); } @NotNull public DocumentContent getCurrentContent() { - return myCurrentSide.select(myActualContents); + return getCurrentSide().select(myActualContents); } @NotNull @@ -254,7 +239,11 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull public ThreeSide getCurrentSide() { - return myCurrentSide; + return myFocusTrackerSupport.getCurrentSide(); + } + + public void setCurrentSide(@NotNull ThreeSide side) { + myFocusTrackerSupport.setCurrentSide(side); } // @@ -265,7 +254,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { protected void scrollToLine(@NotNull ThreeSide side, int line) { Editor editor = side.select(myEditors); DiffUtil.scrollEditor(editor, line, false); - myCurrentSide = side; + setCurrentSide(side); } @Nullable @@ -365,26 +354,14 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { return getCurrentEditor(); } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - return DiffUtil.getVirtualFile(myRequest, myCurrentSide); + return DiffUtil.getVirtualFile(myRequest, getCurrentSide()); } else if (DiffDataKeys.CURRENT_CONTENT.is(dataId)) { return getCurrentContent(); } return super.getData(dataId); } - - private class MyEditorFocusListener extends FocusAdapter { - @NotNull private final ThreeSide mySide; - - private MyEditorFocusListener(@NotNull ThreeSide side) { - mySide = side; - } - - public void focusGained(FocusEvent e) { - myCurrentSide = mySide; - } - } - + private class MyVisibleAreaListener implements VisibleAreaListener { @NotNull Side mySide; diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java index c7109814f010..2c0058b9975f 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java @@ -24,12 +24,12 @@ import com.intellij.diff.contents.EmptyContent; import com.intellij.diff.requests.ContentDiffRequest; import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.tools.util.DiffDataKeys; +import com.intellij.diff.tools.util.FocusTrackerSupport.TwosideFocusTrackerSupport; import com.intellij.diff.tools.util.SimpleDiffPanel; import com.intellij.diff.tools.util.SyncScrollSupport; import com.intellij.diff.tools.util.SyncScrollSupport.TwosideSyncScrollSupport; import com.intellij.diff.tools.util.base.InitialScrollPositionSupport; import com.intellij.diff.tools.util.base.TextDiffViewerBase; -import com.intellij.diff.util.DiffUserDataKeys; import com.intellij.diff.util.DiffUtil; import com.intellij.diff.util.Side; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -52,8 +52,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; import java.util.Collections; import java.util.List; @@ -73,13 +71,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @NotNull protected final MySetEditorSettingsAction myEditorSettingsAction; - @NotNull private final MyEditorFocusListener myEditorFocusListener1 = new MyEditorFocusListener(Side.LEFT); - @NotNull private final MyEditorFocusListener myEditorFocusListener2 = new MyEditorFocusListener(Side.RIGHT); @NotNull private final MyVisibleAreaListener myVisibleAreaListener = new MyVisibleAreaListener(); - @Nullable protected TwosideSyncScrollSupport mySyncScrollSupport; + @NotNull private final TwosideFocusTrackerSupport myFocusTrackerSupport; - @NotNull private Side myCurrentSide; + @Nullable protected TwosideSyncScrollSupport mySyncScrollSupport; public TwosideTextDiffViewer(@NotNull DiffContext context, @NotNull ContentDiffRequest request) { super(context, request); @@ -97,8 +93,7 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { myEditor2 = editors.get(1); assert myEditor1 != null || myEditor2 != null; - myCurrentSide = myEditor1 == null ? Side.RIGHT : Side.LEFT; - + myFocusTrackerSupport = new TwosideFocusTrackerSupport(myEditor1, myEditor2); myContentPanel = new TwosideTextContentPanel(titlePanel, myEditor1, myEditor2); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -124,25 +119,14 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @CalledInAwt protected void processContextHints() { super.processContextHints(); - if (myEditor1 == null) { - myCurrentSide = Side.RIGHT; - } - else if (myEditor2 == null) { - myCurrentSide = Side.LEFT; - } - else { - Side side = myContext.getUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE); - if (side != null) myCurrentSide = side; - } + myFocusTrackerSupport.processContextHints(myRequest, myContext); } @Override @CalledInAwt protected void updateContextHints() { super.updateContextHints(); - if (myEditor1 != null && myEditor2 != null) { - myContext.putUserData(DiffUserDataKeys.PREFERRED_FOCUS_SIDE, myCurrentSide); - } + myFocusTrackerSupport.updateContextHints(myRequest, myContext); } @NotNull @@ -195,11 +179,9 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { protected void installEditorListeners() { super.installEditorListeners(); if (myEditor1 != null) { - myEditor1.getContentComponent().addFocusListener(myEditorFocusListener1); myEditor1.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); } if (myEditor2 != null) { - myEditor2.getContentComponent().addFocusListener(myEditorFocusListener2); myEditor2.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); } if (myEditor1 != null && myEditor2 != null) { @@ -215,11 +197,9 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { protected void destroyEditorListeners() { super.destroyEditorListeners(); if (myEditor1 != null) { - myEditor1.getContentComponent().removeFocusListener(myEditorFocusListener1); myEditor1.getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); } if (myEditor2 != null) { - myEditor2.getContentComponent().removeFocusListener(myEditorFocusListener2); myEditor2.getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); } mySyncScrollSupport = null; @@ -264,7 +244,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @NotNull public Side getCurrentSide() { - return myCurrentSide; + return myFocusTrackerSupport.getCurrentSide(); + } + + public void setCurrentSide(@NotNull Side side) { + myFocusTrackerSupport.setCurrentSide(side); } @NotNull @@ -306,7 +290,7 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { Editor editor = side.select(myEditor1, myEditor2); if (editor == null) return; DiffUtil.scrollEditor(editor, line, false); - myCurrentSide = side; + setCurrentSide(side); } @Nullable @@ -365,13 +349,13 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { if (myEditor1 == null || myEditor2 == null) return; if (myScrollToPosition) { - EditorEx currentEditor = myCurrentSide.select(myEditor1, myEditor2); - EditorEx targetEditor = myCurrentSide.other().select(myEditor1, myEditor2); - LogicalPosition position = transferPosition(myCurrentSide, currentEditor.getCaretModel().getLogicalPosition()); + EditorEx currentEditor = getCurrentSide().select(myEditor1, myEditor2); + EditorEx targetEditor = getCurrentSide().other().select(myEditor1, myEditor2); + LogicalPosition position = transferPosition(getCurrentSide(), currentEditor.getCaretModel().getLogicalPosition()); targetEditor.getCaretModel().moveToLogicalPosition(position); } - myCurrentSide = myCurrentSide.other(); + setCurrentSide(getCurrentSide().other()); myPanel.requestFocus(); getCurrentEditor().getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); } @@ -406,25 +390,12 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { return getCurrentContent(); } else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - return DiffUtil.getVirtualFile(myRequest, myCurrentSide); + return DiffUtil.getVirtualFile(myRequest, getCurrentSide()); } return super.getData(dataId); } - private class MyEditorFocusListener extends FocusAdapter { - @NotNull private final Side mySide; - - private MyEditorFocusListener(@NotNull Side side) { - mySide = side; - } - - public void focusGained(FocusEvent e) { - if (myEditor1 == null || myEditor2 == null) return; - myCurrentSide = mySide; - } - } - private class MyVisibleAreaListener implements VisibleAreaListener { @Override public void visibleAreaChanged(VisibleAreaEvent e) { From cdc1c4eaf2a79c12bf3bd6ba88e0a9d66fc6de56 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 13 May 2015 19:07:33 +0300 Subject: [PATCH 6/9] diff: use getters --- .../diff/tools/binary/BinaryDiffViewer.java | 18 ++-- .../diff/tools/simple/SimpleDiffViewer.java | 90 +++++++++---------- .../simple/SimpleThreesideDiffChange.java | 12 +-- .../simple/SimpleThreesideDiffViewer.java | 28 +++--- .../threeside/ThreesideTextDiffViewer.java | 61 +++++++------ .../util/twoside/TwosideTextDiffViewer.java | 88 ++++++++++-------- .../properties/SvnPropertiesDiffViewer.java | 34 +++---- 7 files changed, 175 insertions(+), 156 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java index eea633f3c40e..4e36785f9268 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/binary/BinaryDiffViewer.java @@ -91,8 +91,8 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { myEditorProvider2 = editors.second.second; assert myEditor1 != null || myEditor2 != null; - myFocusTrackerSupport = new FocusTrackerSupport.TwosideFocusTrackerSupport(myEditor1, myEditor2); - myContentPanel = new BinaryContentPanel(titlePanel, myEditor1, myEditor2); + myFocusTrackerSupport = new FocusTrackerSupport.TwosideFocusTrackerSupport(getEditor1(), getEditor2()); + myContentPanel = new BinaryContentPanel(titlePanel, getEditor1(), getEditor2()); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -182,13 +182,13 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { private void destroyEditors() { - if (myEditor1 != null) { + if (getEditor1() != null) { assert myEditorProvider1 != null; - myEditorProvider1.disposeEditor(myEditor1); + myEditorProvider1.disposeEditor(getEditor1()); } - if (myEditor2 != null) { + if (getEditor2() != null) { assert myEditorProvider2 != null; - myEditorProvider2.disposeEditor(myEditor2); + myEditorProvider2.disposeEditor(getEditor2()); } } @@ -341,7 +341,7 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { @NotNull FileEditor getCurrentEditor() { //noinspection ConstantConditions - return getCurrentSide().select(myEditor1, myEditor2); + return getCurrentSide().select(getEditor1(), getEditor2()); } @NotNull @@ -406,14 +406,14 @@ public class BinaryDiffViewer extends ListenerDiffViewerBase { private class MyFocusOppositePaneAction extends FocusOppositePaneAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; setCurrentSide(getCurrentSide().other()); myPanel.requestFocus(); } @Override public void update(@NotNull AnActionEvent e) { - e.getPresentation().setEnabled(myEditor1 != null && myEditor2 != null); + e.getPresentation().setEnabled(getEditor1() != null && getEditor2() != null); } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java index 4072c5bf5200..3e1a7786d1bf 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffViewer.java @@ -86,7 +86,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { mySyncScrollable = new MySyncScrollable(); myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable(); myStatusPanel = new MyStatusPanel(); - myFoldingModel = createFoldingModel(myEditor1, myEditor2); + myFoldingModel = createFoldingModel(getEditor1(), getEditor2()); myModifierProvider = new ModifierProvider(); } @@ -192,10 +192,10 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { try { indicator.checkCanceled(); - assert myActualContent1 != null || myActualContent2 != null; + assert getActualContent1() != null || getActualContent2() != null; - if (myActualContent1 == null) { - final DocumentContent content = myActualContent2; + if (getActualContent1() == null) { + final DocumentContent content = getActualContent2(); final Document document = content.getDocument(); CompareData data = ApplicationManager.getApplication().runReadAction(new Computable() { @@ -210,8 +210,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { return apply(data); } - if (myActualContent2 == null) { - final DocumentContent content = myActualContent1; + if (getActualContent2() == null) { + final DocumentContent content = getActualContent1(); final Document document = content.getDocument(); CompareData data = ApplicationManager.getApplication().runReadAction(new Computable() { @@ -226,8 +226,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { return apply(data); } - final DocumentContent content1 = myActualContent1; - final DocumentContent content2 = myActualContent2; + final DocumentContent content1 = getActualContent1(); + final DocumentContent content2 = getActualContent2(); final Document document1 = content1.getDocument(); final Document document2 = content2.getDocument(); @@ -284,8 +284,8 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { return new Runnable() { @Override public void run() { - if (myEditor1 != null && myEditor1.getDocument().getModificationStamp() != data.getStamp1()) return; - if (myEditor2 != null && myEditor2.getDocument().getModificationStamp() != data.getStamp2()) return; + if (getEditor1() != null && getEditor1().getDocument().getModificationStamp() != data.getStamp1()) return; + if (getEditor2() != null && getEditor2().getDocument().getModificationStamp() != data.getStamp2()) return; if (myFoldingModel != null) myFoldingModel.updateContext(myRequest, getFoldingModelSettings()); clearDiffPresentation(); @@ -294,7 +294,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { if (data.getFragments() != null) { for (LineFragment fragment : data.getFragments()) { - myDiffChanges.add(new SimpleDiffChange(SimpleDiffViewer.this, fragment, myEditor1, myEditor2, + myDiffChanges.add(new SimpleDiffChange(SimpleDiffViewer.this, fragment, getEditor1(), getEditor2(), getHighlightPolicy().isFineFragments())); } } @@ -353,13 +353,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { protected void onBeforeDocumentChange(@NotNull DocumentEvent e) { super.onBeforeDocumentChange(e); if (myDiffChanges.isEmpty()) return; - if (myEditor1 == null || myEditor2 == null) return; + if (getEditor1() == null || getEditor2() == null) return; Side side; - if (e.getDocument() == myEditor1.getDocument()) { + if (e.getDocument() == getEditor1().getDocument()) { side = Side.LEFT; } - else if (e.getDocument() == myEditor2.getDocument()) { + else if (e.getDocument() == getEditor2().getDocument()) { side = Side.RIGHT; } else { @@ -401,7 +401,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @CalledInAwt protected boolean doScrollToChange(@NotNull ScrollToPolicy scrollToPolicy) { if (myDiffChanges.isEmpty()) return false; - if (myEditor1 == null || myEditor2 == null) return true; + if (getEditor1() == null || getEditor2() == null) return true; SimpleDiffChange targetChange; switch (scrollToPolicy) { @@ -421,7 +421,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { } private void doScrollToChange(@NotNull SimpleDiffChange change, final boolean animated) { - if (myEditor1 == null || myEditor2 == null) return; + if (getEditor1() == null || getEditor2() == null) return; assert mySyncScrollSupport != null; final int line1 = change.getStartLine(Side.LEFT); @@ -429,14 +429,14 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { final int endLine1 = change.getEndLine(Side.LEFT); final int endLine2 = change.getEndLine(Side.RIGHT); - DiffUtil.moveCaret(myEditor1, line1); - DiffUtil.moveCaret(myEditor2, line2); + DiffUtil.moveCaret(getEditor1(), line1); + DiffUtil.moveCaret(getEditor2(), line2); mySyncScrollSupport.makeVisible(getCurrentSide(), line1, endLine1, line2, endLine2, animated); } protected boolean doScrollToContext(@NotNull DiffNavigationContext context) { - if (myEditor2 == null) return false; + if (getEditor2() == null) return false; ChangedLinesIterator changedLinesIterator = new ChangedLinesIterator(Side.RIGHT); NavigationContextChecker checker = new NavigationContextChecker(changedLinesIterator, context); @@ -492,7 +492,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @NotNull @CalledInAwt private List getSelectedChanges(@NotNull Side side) { - EditorEx editor = side.select(myEditor1, myEditor2); + EditorEx editor = side.select(getEditor1(), getEditor2()); if (editor == null) return Collections.emptyList(); final BitSet lines = DiffUtil.getSelectedLines(editor); @@ -512,7 +512,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @Nullable @CalledInAwt private SimpleDiffChange getSelectedChange(@NotNull Side side) { - EditorEx editor = side.select(myEditor1, myEditor2); + EditorEx editor = side.select(getEditor1(), getEditor2()); if (editor == null) return null; int caretLine = editor.getCaretModel().getLogicalPosition().line; @@ -629,19 +629,19 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @Override public void update(@NotNull AnActionEvent e) { Editor editor = e.getData(CommonDataKeys.EDITOR); - Side side = Side.fromLeft(editor == myEditor1); + Side side = Side.fromLeft(editor == getEditor1()); - if (myEditor1 == null || myEditor2 == null) { + if (getEditor1() == null || getEditor2() == null) { e.getPresentation().setEnabledAndVisible(false); return; } - if (editor != myEditor1 && editor != myEditor2) { + if (editor != getEditor1() && editor != getEditor2()) { e.getPresentation().setEnabledAndVisible(false); return; } - Editor modifiedEditor = side.other(myModifyOpposite).select(myEditor1, myEditor2); + Editor modifiedEditor = side.other(myModifyOpposite).select(getEditor1(), getEditor2()); if (!DiffUtil.isEditable(modifiedEditor)) { e.getPresentation().setEnabledAndVisible(false); return; @@ -653,13 +653,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @Override public void actionPerformed(@NotNull final AnActionEvent e) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); - final Side side = Side.fromLeft(editor == myEditor1); + final Side side = Side.fromLeft(editor == getEditor1()); final List selectedChanges = getSelectedChanges(side); - Editor modifiedEditor = side.other(myModifyOpposite).select(myEditor1, myEditor2); + Editor modifiedEditor = side.other(myModifyOpposite).select(getEditor1(), getEditor2()); String title = e.getPresentation().getText() + " selected changes"; DiffUtil.executeWriteCommand(modifiedEditor.getDocument(), e.getProject(), title, new Runnable() { @Override @@ -672,7 +672,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { protected boolean isSomeChangeSelected(@NotNull Side side) { if (myDiffChanges.isEmpty()) return false; - Editor editor = side.select(myEditor1, myEditor2); + Editor editor = side.select(getEditor1(), getEditor2()); if (editor == null) return false; List carets = editor.getCaretModel().getAllCarets(); @@ -753,12 +753,12 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @CalledWithWriteLock public void replaceChange(@NotNull SimpleDiffChange change, @NotNull final Side sourceSide) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; if (!change.isValid()) return; - final Document document1 = myEditor1.getDocument(); - final Document document2 = myEditor2.getDocument(); + final Document document1 = getEditor1().getDocument(); + final Document document2 = getEditor2().getDocument(); DiffUtil.applyModification(sourceSide.other().select(document1, document2), change.getStartLine(sourceSide.other()), change.getEndLine(sourceSide.other()), @@ -771,13 +771,13 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @CalledWithWriteLock public void appendChange(@NotNull SimpleDiffChange change, @NotNull final Side sourceSide) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; if (!change.isValid()) return; if (change.getStartLine(sourceSide) == change.getEndLine(sourceSide)) return; - final Document document1 = myEditor1.getDocument(); - final Document document2 = myEditor2.getDocument(); + final Document document1 = getEditor1().getDocument(); + final Document document2 = getEditor2().getDocument(); DiffUtil.applyModification(sourceSide.other().select(document1, document2), change.getEndLine(sourceSide.other()), change.getEndLine(sourceSide.other()), @@ -807,7 +807,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { private AllLinesIterator(@NotNull Side side) { mySide = side; - Editor editor = mySide.select(myEditor1, myEditor2); + Editor editor = mySide.select(getEditor1(), getEditor2()); assert editor != null; myDocument = editor.getDocument(); } @@ -858,7 +858,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { int line1 = change.getStartLine(mySide); int line2 = change.getEndLine(mySide); - Editor editor = mySide.select(myEditor1, myEditor2); + Editor editor = mySide.select(getEditor1(), getEditor2()); assert editor != null; Document document = editor.getDocument(); @@ -907,28 +907,28 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { @Override protected void processHelper(@NotNull ScrollHelper helper) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; if (!helper.process(0, 0)) return; for (SimpleDiffChange diffChange : myDiffChanges) { if (!helper.process(diffChange.getStartLine(Side.LEFT), diffChange.getStartLine(Side.RIGHT))) return; if (!helper.process(diffChange.getEndLine(Side.LEFT), diffChange.getEndLine(Side.RIGHT))) return; } - helper.process(myEditor1.getDocument().getLineCount(), myEditor2.getDocument().getLineCount()); + helper.process(getEditor1().getDocument().getLineCount(), getEditor2().getDocument().getLineCount()); } } private class MyDividerPainter implements DiffSplitter.Painter, DiffDividerDrawUtil.DividerPaintable { @Override public void paint(@NotNull Graphics g, @NotNull JComponent divider) { - if (myEditor1 == null || myEditor2 == null) return; - Graphics2D gg = DiffDividerDrawUtil.getDividerGraphics(g, divider, myEditor1.getComponent()); + if (getEditor1() == null || getEditor2() == null) return; + Graphics2D gg = DiffDividerDrawUtil.getDividerGraphics(g, divider, getEditor1().getComponent()); - gg.setColor(DiffDrawUtil.getDividerColor(myEditor1)); + gg.setColor(DiffDrawUtil.getDividerColor(getEditor1())); gg.fill(gg.getClipBounds()); - //DividerPolygonUtil.paintSimplePolygons(gg, divider.getWidth(), myEditor1, myEditor2, this); - DiffDividerDrawUtil.paintPolygons(gg, divider.getWidth(), myEditor1, myEditor2, this); + //DividerPolygonUtil.paintSimplePolygons(gg, divider.getWidth(), getEditor1(), getEditor2(), this); + DiffDividerDrawUtil.paintPolygons(gg, divider.getWidth(), getEditor1(), getEditor2(), this); if (myFoldingModel != null) myFoldingModel.paintOnDivider(gg, divider); @@ -940,7 +940,7 @@ public class SimpleDiffViewer extends TwosideTextDiffViewer { for (SimpleDiffChange diffChange : myDiffChanges) { if (!handler.process(diffChange.getStartLine(Side.LEFT), diffChange.getEndLine(Side.LEFT), diffChange.getStartLine(Side.RIGHT), diffChange.getEndLine(Side.RIGHT), - diffChange.getDiffType().getColor(myEditor1))) { + diffChange.getDiffType().getColor(getEditor1()))) { return; } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java index d38b158b1dc6..c98f6bce7ebb 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java @@ -34,7 +34,7 @@ import java.util.List; public class SimpleThreesideDiffChange { @NotNull private final MergeLineFragment myFragment; - @NotNull private final List myEditors; + @NotNull private final List myEditors; @NotNull private ConflictType myType; @@ -44,7 +44,7 @@ public class SimpleThreesideDiffChange { private int[] myLineEndShifts = new int[3]; public SimpleThreesideDiffChange(@NotNull MergeLineFragment fragment, - @NotNull List editors, + @NotNull List editors, @NotNull ComparisonPolicy policy) { myFragment = fragment; myEditors = editors; @@ -154,7 +154,7 @@ public class SimpleThreesideDiffChange { @NotNull private static ConflictType calcType(@NotNull MergeLineFragment fragment, - @NotNull List editors, + @NotNull List editors, @NotNull ComparisonPolicy policy) { boolean isLeftEmpty = isIntervalEmpty(fragment, ThreeSide.LEFT); boolean isBaseEmpty = isIntervalEmpty(fragment, ThreeSide.BASE); @@ -192,7 +192,7 @@ public class SimpleThreesideDiffChange { } private static boolean compareLeftAndRight(@NotNull MergeLineFragment fragment, - @NotNull List editors, + @NotNull List editors, @NotNull ComparisonPolicy policy) { CharSequence content1 = getRangeContent(fragment, editors, ThreeSide.LEFT); CharSequence content2 = getRangeContent(fragment, editors, ThreeSide.RIGHT); @@ -209,7 +209,7 @@ public class SimpleThreesideDiffChange { } private static boolean compareWithBase(@NotNull MergeLineFragment fragment, - @NotNull List editors, + @NotNull List editors, @NotNull ThreeSide side) { CharSequence content1 = getRangeContent(fragment, editors, ThreeSide.BASE); CharSequence content2 = getRangeContent(fragment, editors, side); @@ -219,7 +219,7 @@ public class SimpleThreesideDiffChange { @Nullable private static CharSequence getRangeContent(@NotNull MergeLineFragment fragment, - @NotNull List editors, + @NotNull List editors, @NotNull ThreeSide side) { DocumentEx document = side.select(editors).getDocument(); int line1 = fragment.getStartLine(side); diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffViewer.java index 2e23d720f70a..342052fd48b5 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffViewer.java @@ -82,7 +82,7 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { mySyncScrollable2 = new MySyncScrollable(Side.RIGHT); myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable(); myStatusPanel = new MyStatusPanel(); - myFoldingModel = new MyFoldingModel(myEditors.toArray(new EditorEx[3]), this); + myFoldingModel = new MyFoldingModel(getEditors().toArray(new EditorEx[3]), this); } @Override @@ -233,7 +233,7 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { clearDiffPresentation(); for (MergeLineFragment fragment : fragments) { - myDiffChanges.add(new SimpleThreesideDiffChange(fragment, myEditors, comparisonPolicy)); + myDiffChanges.add(new SimpleThreesideDiffChange(fragment, getEditors(), comparisonPolicy)); } myFoldingModel.install(fragments, myRequest, getFoldingModelSettings()); @@ -280,13 +280,13 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { if (myDiffChanges.isEmpty()) return; ThreeSide side; - if (e.getDocument() == myEditors.get(0).getDocument()) { + if (e.getDocument() == getEditor(0).getDocument()) { side = ThreeSide.LEFT; } - else if (e.getDocument() == myEditors.get(1).getDocument()) { + else if (e.getDocument() == getEditor(1).getDocument()) { side = ThreeSide.BASE; } - else if (e.getDocument() == myEditors.get(2).getDocument()) { + else if (e.getDocument() == getEditor(2).getDocument()) { side = ThreeSide.RIGHT; } else { @@ -396,7 +396,7 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { @Nullable @CalledInAwt private SimpleThreesideDiffChange getSelectedChange(@NotNull ThreeSide side) { - EditorEx editor = side.select(myEditors); + EditorEx editor = side.select(getEditors()); int caretLine = editor.getCaretModel().getLogicalPosition().line; @@ -554,7 +554,7 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { if (!helper.process(diffChange.getStartLine(left), diffChange.getStartLine(right))) return; if (!helper.process(diffChange.getEndLine(left), diffChange.getEndLine(right))) return; } - helper.process(left.select(myEditors).getDocument().getLineCount(), right.select(myEditors).getDocument().getLineCount()); + helper.process(left.select(getEditors()).getDocument().getLineCount(), right.select(getEditors()).getDocument().getLineCount()); } } @@ -574,7 +574,7 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { if (!diffChange.getType().isChange(mySide)) continue; if (!handler.process(diffChange.getStartLine(left), diffChange.getEndLine(left), diffChange.getStartLine(right), diffChange.getEndLine(right), - diffChange.getDiffType().getColor(myEditors.get(0)))) { + diffChange.getDiffType().getColor(getEditor(0)))) { return; } } @@ -592,13 +592,13 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { @Override public void paint(@NotNull Graphics g, @NotNull JComponent divider) { - Graphics2D gg = DiffDividerDrawUtil.getDividerGraphics(g, divider, myEditors.get(0).getComponent()); + Graphics2D gg = DiffDividerDrawUtil.getDividerGraphics(g, divider, getEditor(0).getComponent()); - gg.setColor(DiffDrawUtil.getDividerColor(myEditors.get(0))); + gg.setColor(DiffDrawUtil.getDividerColor(getEditor(0))); gg.fill(gg.getClipBounds()); - Editor editor1 = mySide.select(myEditors.get(0), myEditors.get(1)); - Editor editor2 = mySide.select(myEditors.get(1), myEditors.get(2)); + Editor editor1 = mySide.select(getEditor(0), getEditor(1)); + Editor editor2 = mySide.select(getEditor(1), getEditor(2)); //DividerPolygonUtil.paintSimplePolygons(gg, divider.getWidth(), editor1, editor2, myPaintable); DiffDividerDrawUtil.paintPolygons(gg, divider.getWidth(), editor1, editor2, myPaintable); @@ -614,8 +614,8 @@ public class SimpleThreesideDiffViewer extends ThreesideTextDiffViewer { @Override public void call(Graphics g) { - EditorEx editor1 = myEditors.get(1); - EditorEx editor2 = myEditors.get(2); + EditorEx editor1 = getEditor(1); + EditorEx editor2 = getEditor(2); int width = editor1.getScrollPane().getVerticalScrollBar().getWidth(); DiffDividerDrawUtil.paintPolygonsOnScrollbar((Graphics2D)g, width, editor1, editor2, myPaintable); diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java index 7c87c653daf8..086d396889c0 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/threeside/ThreesideTextDiffViewer.java @@ -66,9 +66,8 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull protected final SimpleDiffPanel myPanel; @NotNull protected final ThreesideTextContentPanel myContentPanel; - @NotNull protected final List myEditors; - - @NotNull protected final List myActualContents; + @NotNull private final List myEditors; + @NotNull private final List myActualContents; @NotNull private final MyVisibleAreaListener myVisibleAreaListener1 = new MyVisibleAreaListener(Side.LEFT); @NotNull private final MyVisibleAreaListener myVisibleAreaListener2 = new MyVisibleAreaListener(Side.RIGHT); @@ -77,7 +76,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull private final ThreesideFocusTrackerSupport myFocusTrackerSupport; - @Nullable private ThreesideSyncScrollSupport mySyncScrollListener; + @Nullable private ThreesideSyncScrollSupport mySyncScrollSupport; public ThreesideTextDiffViewer(@NotNull DiffContext context, @NotNull ContentDiffRequest request) { super(context, request); @@ -89,10 +88,10 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { myEditors = createEditors(); - List titlePanel = DiffUtil.createTextTitles(myRequest, myEditors); + List titlePanel = DiffUtil.createTextTitles(myRequest, getEditors()); - myFocusTrackerSupport = new ThreesideFocusTrackerSupport(myEditors); - myContentPanel = new ThreesideTextContentPanel(myEditors, titlePanel); + myFocusTrackerSupport = new ThreesideFocusTrackerSupport(getEditors()); + myContentPanel = new ThreesideTextContentPanel(getEditors(), titlePanel); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -129,8 +128,8 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { boolean[] forceReadOnly = checkForceReadOnly(); List editors = new ArrayList(3); - for (int i = 0; i < myActualContents.size(); i++) { - DocumentContent content = myActualContents.get(i); + for (int i = 0; i < getActualContents().size(); i++) { + DocumentContent content = getActualContents().get(i); EditorEx editor = DiffUtil.createEditor(content.getDocument(), myProject, forceReadOnly[i], true); DiffUtil.configureEditor(editor, content, myProject); editors.add(editor); @@ -147,7 +146,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { } private void destroyEditors() { - for (EditorEx editor : myEditors) { + for (EditorEx editor : getEditors()) { myEditorFactory.releaseEditor(editor); } } @@ -161,16 +160,16 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { protected void installEditorListeners() { super.installEditorListeners(); - myEditors.get(0).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); - myEditors.get(1).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); + getEditor(0).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); + getEditor(1).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener1); - myEditors.get(1).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener2); - myEditors.get(2).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener2); + getEditor(1).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener2); + getEditor(2).getScrollingModel().addVisibleAreaListener(myVisibleAreaListener2); SyncScrollSupport.SyncScrollable scrollable1 = getSyncScrollable(Side.LEFT); SyncScrollSupport.SyncScrollable scrollable2 = getSyncScrollable(Side.RIGHT); if (scrollable1 != null && scrollable2 != null) { - mySyncScrollListener = new ThreesideSyncScrollSupport(myEditors, scrollable1, scrollable2); + mySyncScrollSupport = new ThreesideSyncScrollSupport(getEditors(), scrollable1, scrollable2); } } @@ -179,18 +178,18 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { public void destroyEditorListeners() { super.destroyEditorListeners(); - myEditors.get(0).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); - myEditors.get(1).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); + getEditor(0).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); + getEditor(1).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener1); - myEditors.get(1).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener2); - myEditors.get(2).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener2); + getEditor(1).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener2); + getEditor(2).getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener2); - mySyncScrollListener = null; + mySyncScrollSupport = null; } protected void disableSyncScrollSupport(boolean disable) { - if (mySyncScrollListener != null) { - mySyncScrollListener.setDisabled(disable); + if (mySyncScrollSupport != null) { + mySyncScrollSupport.setDisabled(disable); } } @@ -223,12 +222,12 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @NotNull public EditorEx getCurrentEditor() { - return getCurrentSide().select(myEditors); + return getCurrentSide().select(getEditors()); } @NotNull public DocumentContent getCurrentContent() { - return getCurrentSide().select(myActualContents); + return getCurrentSide().select(getActualContents()); } @NotNull @@ -237,6 +236,16 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { return myEditors; } + @NotNull + protected EditorEx getEditor(int index) { + return myEditors.get(index); + } + + @NotNull + public List getActualContents() { + return myActualContents; + } + @NotNull public ThreeSide getCurrentSide() { return myFocusTrackerSupport.getCurrentSide(); @@ -252,7 +261,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @CalledInAwt protected void scrollToLine(@NotNull ThreeSide side, int line) { - Editor editor = side.select(myEditors); + Editor editor = side.select(getEditors()); DiffUtil.scrollEditor(editor, line, false); setCurrentSide(side); } @@ -371,7 +380,7 @@ public abstract class ThreesideTextDiffViewer extends TextDiffViewerBase { @Override public void visibleAreaChanged(VisibleAreaEvent e) { - if (mySyncScrollListener != null) mySyncScrollListener.visibleAreaChanged(e); + if (mySyncScrollSupport != null) mySyncScrollSupport.visibleAreaChanged(e); if (Registry.is("diff.divider.repainting.fix")) { myContentPanel.repaint(); } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java index 2c0058b9975f..6039b702d24d 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/twoside/TwosideTextDiffViewer.java @@ -63,11 +63,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @NotNull protected final SimpleDiffPanel myPanel; @NotNull protected final TwosideTextContentPanel myContentPanel; - @Nullable protected final EditorEx myEditor1; - @Nullable protected final EditorEx myEditor2; + @Nullable private final EditorEx myEditor1; + @Nullable private final EditorEx myEditor2; - @Nullable protected final DocumentContent myActualContent1; - @Nullable protected final DocumentContent myActualContent2; + @Nullable private final DocumentContent myActualContent1; + @Nullable private final DocumentContent myActualContent2; @NotNull protected final MySetEditorSettingsAction myEditorSettingsAction; @@ -93,8 +93,8 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { myEditor2 = editors.get(1); assert myEditor1 != null || myEditor2 != null; - myFocusTrackerSupport = new TwosideFocusTrackerSupport(myEditor1, myEditor2); - myContentPanel = new TwosideTextContentPanel(titlePanel, myEditor1, myEditor2); + myFocusTrackerSupport = new TwosideFocusTrackerSupport(getEditor1(), getEditor2()); + myContentPanel = new TwosideTextContentPanel(titlePanel, getEditor1(), getEditor2()); myPanel = new SimpleDiffPanel(myContentPanel, this, context); @@ -136,13 +136,13 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { // TODO: we may want to set editor highlighter in init() to speedup editor initialization EditorEx editor1 = null; EditorEx editor2 = null; - if (myActualContent1 != null) { - editor1 = DiffUtil.createEditor(myActualContent1.getDocument(), myProject, forceReadOnly[0], true); - DiffUtil.configureEditor(editor1, myActualContent1, myProject); + if (getActualContent1() != null) { + editor1 = DiffUtil.createEditor(getActualContent1().getDocument(), myProject, forceReadOnly[0], true); + DiffUtil.configureEditor(editor1, getActualContent1(), myProject); } - if (myActualContent2 != null) { - editor2 = DiffUtil.createEditor(myActualContent2.getDocument(), myProject, forceReadOnly[1], true); - DiffUtil.configureEditor(editor2, myActualContent2, myProject); + if (getActualContent2() != null) { + editor2 = DiffUtil.createEditor(getActualContent2().getDocument(), myProject, forceReadOnly[1], true); + DiffUtil.configureEditor(editor2, getActualContent2(), myProject); } if (editor1 != null && editor2 != null) { editor1.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT); @@ -170,24 +170,24 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { // private void destroyEditors() { - if (myEditor1 != null) myEditorFactory.releaseEditor(myEditor1); - if (myEditor2 != null) myEditorFactory.releaseEditor(myEditor2); + if (getEditor1() != null) myEditorFactory.releaseEditor(getEditor1()); + if (getEditor2() != null) myEditorFactory.releaseEditor(getEditor2()); } @CalledInAwt @Override protected void installEditorListeners() { super.installEditorListeners(); - if (myEditor1 != null) { - myEditor1.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); + if (getEditor1() != null) { + getEditor1().getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); } - if (myEditor2 != null) { - myEditor2.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); + if (getEditor2() != null) { + getEditor2().getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); } - if (myEditor1 != null && myEditor2 != null) { + if (getEditor1() != null && getEditor2() != null) { SyncScrollSupport.SyncScrollable scrollable = getSyncScrollable(); if (scrollable != null) { - mySyncScrollSupport = new TwosideSyncScrollSupport(myEditor1, myEditor2, scrollable); + mySyncScrollSupport = new TwosideSyncScrollSupport(getEditor1(), getEditor2(), scrollable); } } } @@ -196,11 +196,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @Override protected void destroyEditorListeners() { super.destroyEditorListeners(); - if (myEditor1 != null) { - myEditor1.getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); + if (getEditor1() != null) { + getEditor1().getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); } - if (myEditor2 != null) { - myEditor2.getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); + if (getEditor2() != null) { + getEditor2().getScrollingModel().removeVisibleAreaListener(myVisibleAreaListener); } mySyncScrollSupport = null; } @@ -218,14 +218,14 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @NotNull @Override protected List getEditors() { - if (myEditor1 != null && myEditor2 != null) { - return ContainerUtil.list(myEditor1, myEditor2); + if (getEditor1() != null && getEditor2() != null) { + return ContainerUtil.list(getEditor1(), getEditor2()); } - if (myEditor1 != null) { - return Collections.singletonList(myEditor1); + if (getEditor1() != null) { + return Collections.singletonList(getEditor1()); } - if (myEditor2 != null) { - return Collections.singletonList(myEditor2); + if (getEditor2() != null) { + return Collections.singletonList(getEditor2()); } return Collections.emptyList(); } @@ -254,13 +254,13 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @NotNull public EditorEx getCurrentEditor() { //noinspection ConstantConditions - return getCurrentSide().select(myEditor1, myEditor2); + return getCurrentSide().select(getEditor1(), getEditor2()); } @NotNull public DocumentContent getCurrentContent() { //noinspection ConstantConditions - return getCurrentSide().select(myActualContent1, myActualContent2); + return getCurrentSide().select(getActualContent1(), getActualContent2()); } @Nullable @@ -273,6 +273,16 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { return myEditor2; } + @Nullable + public DocumentContent getActualContent1() { + return myActualContent1; + } + + @Nullable + public DocumentContent getActualContent2() { + return myActualContent2; + } + // // Abstract // @@ -287,7 +297,7 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @CalledInAwt protected void scrollToLine(@NotNull Side side, int line) { - Editor editor = side.select(myEditor1, myEditor2); + Editor editor = side.select(getEditor1(), getEditor2()); if (editor == null) return; DiffUtil.scrollEditor(editor, line, false); setCurrentSide(side); @@ -346,11 +356,11 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { @Override public void actionPerformed(@NotNull AnActionEvent e) { - if (myEditor1 == null || myEditor2 == null) return; + if (getEditor1() == null || getEditor2() == null) return; if (myScrollToPosition) { - EditorEx currentEditor = getCurrentSide().select(myEditor1, myEditor2); - EditorEx targetEditor = getCurrentSide().other().select(myEditor1, myEditor2); + EditorEx currentEditor = getCurrentSide().select(getEditor1(), getEditor2()); + EditorEx targetEditor = getCurrentSide().other().select(getEditor1(), getEditor2()); LogicalPosition position = transferPosition(getCurrentSide(), currentEditor.getCaretModel().getLogicalPosition()); targetEditor.getCaretModel().moveToLogicalPosition(position); } @@ -364,10 +374,10 @@ public abstract class TwosideTextDiffViewer extends TextDiffViewerBase { private class MyOpenInEditorWithMouseAction extends OpenInEditorWithMouseAction { @Override protected OpenFileDescriptor getDescriptor(@NotNull Editor editor, int line) { - if (editor != myEditor1 && editor != myEditor2) return null; - Side side = Side.fromLeft(editor == myEditor1); + if (editor != getEditor1() && editor != getEditor2()) return null; + Side side = Side.fromLeft(editor == getEditor1()); - DocumentContent content = side.select(myActualContent1, myActualContent2); + DocumentContent content = side.select(getActualContent1(), getActualContent2()); if (content == null) return null; int offset = editor.logicalPositionToOffset(new LogicalPosition(line, 0)); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/properties/SvnPropertiesDiffViewer.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/properties/SvnPropertiesDiffViewer.java index eb5ed3e0f8b0..03a989a2279a 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/properties/SvnPropertiesDiffViewer.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/properties/SvnPropertiesDiffViewer.java @@ -69,7 +69,7 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { myWrapperRequest = request; myDiffChanges = diffChanges; - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; for (EditorEx editor : getEditors()) { EditorSettings settings = editor.getSettings(); @@ -90,8 +90,8 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { } for (DiffChange change : myDiffChanges) { - DiffDrawUtil.createBorderLineMarker(myEditor1, change.myEndLine1, SeparatorPlacement.TOP); - DiffDrawUtil.createBorderLineMarker(myEditor2, change.myEndLine2, SeparatorPlacement.TOP); + DiffDrawUtil.createBorderLineMarker(getEditor1(), change.myEndLine1, SeparatorPlacement.TOP); + DiffDrawUtil.createBorderLineMarker(getEditor2(), change.myEndLine2, SeparatorPlacement.TOP); } DiffSplitter splitter = myContentPanel.getSplitter(); @@ -146,10 +146,10 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { return new Runnable() { @Override public void run() { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; for (DiffChange change : myDiffChanges) { - setupHighlighting(myEditor1, change, Side.LEFT); - setupHighlighting(myEditor2, change, Side.RIGHT); + setupHighlighting(getEditor1(), change, Side.LEFT); + setupHighlighting(getEditor2(), change, Side.RIGHT); } } }; @@ -205,7 +205,7 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { @Override public void paint(@NotNull Graphics g, @NotNull JComponent divider) { - assert myEditor1 != null && myEditor2 != null; + assert getEditor1() != null && getEditor2() != null; Graphics2D gg = DiffDividerDrawUtil.getDividerGraphics(g, divider, getEditor1().getComponent()); Rectangle clip = gg.getClipBounds(); if (clip == null) return; @@ -213,23 +213,23 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { gg.setColor(DiffDrawUtil.getDividerColor()); gg.fill(clip); - JComponent header1 = myEditor1.getHeaderComponent(); - JComponent header2 = myEditor2.getHeaderComponent(); + JComponent header1 = getEditor1().getHeaderComponent(); + JComponent header2 = getEditor2().getHeaderComponent(); int headerOffset1 = header1 == null ? 0 : header1.getHeight(); int headerOffset2 = header2 == null ? 0 : header2.getHeight(); // TODO: painting is ugly if shift1 != shift2 (ex: search field is opened for one of editors) - int shift1 = myEditor1.getScrollingModel().getVerticalScrollOffset() - headerOffset1; - int shift2 = myEditor2.getScrollingModel().getVerticalScrollOffset() - headerOffset2; + int shift1 = getEditor1().getScrollingModel().getVerticalScrollOffset() - headerOffset1; + int shift2 = getEditor2().getScrollingModel().getVerticalScrollOffset() - headerOffset2; double rotate = shift1 == shift2 ? 0 : Math.atan2(shift2 - shift1, clip.width); - DiffDividerDrawUtil.paintPolygons(gg, divider.getWidth(), false, rotate == 0, myEditor1, myEditor2, this); + DiffDividerDrawUtil.paintPolygons(gg, divider.getWidth(), false, rotate == 0, getEditor1(), getEditor2(), this); for (DiffChange change : myDiffChanges) { - int y1 = myEditor1.logicalPositionToXY(new LogicalPosition(change.getStartLine(Side.LEFT), 0)).y - shift1; - int y2 = myEditor2.logicalPositionToXY(new LogicalPosition(change.getStartLine(Side.RIGHT), 0)).y - shift2; - int endY1 = myEditor1.logicalPositionToXY(new LogicalPosition(change.getEndLine(Side.LEFT), 0)).y - shift1; - int endY2 = myEditor2.logicalPositionToXY(new LogicalPosition(change.getEndLine(Side.RIGHT), 0)).y - shift2; + int y1 = getEditor1().logicalPositionToXY(new LogicalPosition(change.getStartLine(Side.LEFT), 0)).y - shift1; + int y2 = getEditor2().logicalPositionToXY(new LogicalPosition(change.getStartLine(Side.RIGHT), 0)).y - shift2; + int endY1 = getEditor1().logicalPositionToXY(new LogicalPosition(change.getEndLine(Side.LEFT), 0)).y - shift1; + int endY2 = getEditor2().logicalPositionToXY(new LogicalPosition(change.getEndLine(Side.RIGHT), 0)).y - shift2; AffineTransform oldTransform = gg.getTransform(); gg.translate(0, y1); @@ -261,7 +261,7 @@ public class SvnPropertiesDiffViewer extends TwosideTextDiffViewer { for (LineFragment fragment : diffChange.getFragments()) { if (!handler.process(Side.LEFT.getStartLine(fragment) + shift1, Side.LEFT.getEndLine(fragment) + shift1, Side.RIGHT.getStartLine(fragment) + shift2, Side.RIGHT.getEndLine(fragment) + shift2, - DiffUtil.getLineDiffType(fragment).getColor(myEditor1))) { + DiffUtil.getLineDiffType(fragment).getColor(getEditor1()))) { return; } } From c1da764748ce2eaf5e68cbfd055a4b808e13f70e Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 18 May 2015 19:30:45 +0200 Subject: [PATCH 7/9] fix combobox painting under IntelliJ LaF (bottom gap) --- .../intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java index ec05f531f5bd..e92e7ffdde6a 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaComboBoxUI.java @@ -224,7 +224,6 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { protected Rectangle rectangleForCurrentValue() { final Rectangle r = super.rectangleForCurrentValue(); r.x-= JBUI.scale(2); - r.y-= isTableCellEditor(myComboBox) ? 0 : 0;//JBUI.scale(1); return r; } @@ -336,7 +335,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { final Graphics2D g = (Graphics2D)g2; final Rectangle arrowButtonBounds = arrowButton.getBounds(); final int xxx = arrowButtonBounds.x - JBUI.scale(5); - final int H = height - JBUI.scale(4); + final int H = height - JBUI.scale(2); final int W = width - JBUI.scale(2); final GraphicsConfig config = new GraphicsConfig(g); @@ -369,7 +368,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border { paintCurrentValue(g, r, false); if (hasFocus) { - DarculaUIUtil.paintFocusRing(g, JBUI.scale(2), JBUI.scale(2), width - JBUI.scale(4), height - JBUI.scale(5)); + DarculaUIUtil.paintFocusRing(g, JBUI.scale(2), JBUI.scale(2), width - JBUI.scale(4), height - JBUI.scale(4)); } else { g.setColor(borderColor); From 2115e10f6e7a4e5336a61e8cc2935baff323a710 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 18 May 2015 20:45:00 +0300 Subject: [PATCH 8/9] Fix top hit provider for Editor Tabs --- .../ide/ui/EditorOptionsTopHitProvider.java | 26 +++++++++++++++++++ .../src/messages/ApplicationBundle.properties | 3 +++ 2 files changed, 29 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/EditorOptionsTopHitProvider.java b/platform/platform-impl/src/com/intellij/ide/ui/EditorOptionsTopHitProvider.java index e1faa3473cff..6ffe2489fb52 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/EditorOptionsTopHitProvider.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/EditorOptionsTopHitProvider.java @@ -17,6 +17,7 @@ package com.intellij.ide.ui; import com.intellij.ide.ui.search.BooleanOptionDescription; import com.intellij.openapi.editor.ex.EditorSettingsExternalizable; +import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfo; import com.intellij.util.containers.ContainerUtil; @@ -38,6 +39,31 @@ public class EditorOptionsTopHitProvider extends OptionsTopHitProvider { ? "checkbox.enable.ctrl.mousewheel.changes.font.size.macos" : "checkbox.enable.ctrl.mousewheel.changes.font.size"), "IS_WHEEL_FONTCHANGE_ENABLED"), editor("Mouse: " + messageApp("checkbox.enable.drag.n.drop.functionality.in.editor"), "IS_DND_ENABLED"), + new EditorOptionDescription(null, messageApp("checkbox.use.soft.wraps.at.editor.action.text"), "preferences.editor") { + @Override + public boolean isOptionEnabled() { + return EditorSettingsExternalizable.getInstance().isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR); + } + + @Override + public void setOptionState(boolean enabled) { + EditorSettingsExternalizable.getInstance().setUseSoftWraps(enabled, SoftWrapAppliancePlaces.MAIN_EDITOR); + fireUpdated(); + } + }, + new EditorOptionDescription(null, messageApp("checkbox.use.soft.wraps.at.console.action.text"), "preferences.editor") { + @Override + public boolean isOptionEnabled() { + return EditorSettingsExternalizable.getInstance().isUseSoftWraps(SoftWrapAppliancePlaces.CONSOLE); + } + + @Override + public void setOptionState(boolean enabled) { + EditorSettingsExternalizable.getInstance().setUseSoftWraps(enabled, SoftWrapAppliancePlaces.CONSOLE); + fireUpdated(); + } + }, + editor(messageApp("checkbox.use.custom.soft.wraps.indent.action.text"), "USE_CUSTOM_SOFT_WRAP_INDENT"), new EditorOptionDescription(null, messageApp("checkbox.show.softwraps.only.for.caret.line.action.text"), "preferences.editor") { @Override public boolean isOptionEnabled() { diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 42de805294e4..5853d7ce92e3 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -394,8 +394,11 @@ radio.close.non.modified.files.first=Close non-modified files first label.when.number.of.opened.editors.exceeds.tab.limit=When number of opened editors exceeds tab limit: group.soft.wraps=Soft Wraps checkbox.use.soft.wraps.at.editor=Use soft wraps in editor +checkbox.use.soft.wraps.at.editor.action.text=Soft Wraps: Use in editor checkbox.use.soft.wraps.at.console=Use soft wraps in console +checkbox.use.soft.wraps.at.console.action.text=Soft Wraps: Use in console checkbox.use.custom.soft.wraps.indent=Use original line's indent for wrapped parts. Additional shift: +checkbox.use.custom.soft.wraps.indent.action.text=Soft Wraps: Use original line's indent for wrapped parts checkbox.show.softwraps.only.for.caret.line=Show soft wraps for current line only checkbox.show.softwraps.only.for.caret.line.action.text=Soft Wraps: Show for current line only group.virtual.space=Virtual Space From 8b7218e5f489c5c11167d58d7a09e20941acdd9b Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 18 May 2015 21:09:08 +0300 Subject: [PATCH 9/9] EA-68476 - assert: DataManagerImpl$MyDataContext.getData --- .../handlers/XDebuggerEvaluateActionHandler.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java index fc274d686245..2f4a1fa95ddd 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerEvaluateActionHandler.java @@ -71,6 +71,8 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { text = getExpressionText(evaluator, CommonDataKeys.PROJECT.getData(dataContext), editor); } + final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); + if (text == null) { XValue value = XDebuggerTreeActionBase.getSelectedValue(dataContext); if (value != null) { @@ -81,7 +83,7 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { AppUIUtil.invokeOnEdt(new Runnable() { @Override public void run() { - showDialog(session, dataContext, editorsProvider, stackFrame, evaluator, evalMode, text); + showDialog(session, file, editorsProvider, stackFrame, evaluator, evalMode, text); } }); } @@ -90,11 +92,11 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { } } - showDialog(session, dataContext, editorsProvider, stackFrame, evaluator, mode, text); + showDialog(session, file, editorsProvider, stackFrame, evaluator, mode, text); } private static void showDialog(@NotNull XDebugSession session, - DataContext dataContext, + VirtualFile file, XDebuggerEditorsProvider editorsProvider, XStackFrame stackFrame, XDebuggerEvaluator evaluator, EvaluationMode mode, String text) { Language language = null; @@ -104,11 +106,8 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler { language = XDebuggerEditorBase.getFileTypeLanguage(position.getFile().getFileType()); } } - if (language == null) { - VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext); - if (file != null) { - language = XDebuggerEditorBase.getFileTypeLanguage(file.getFileType()); - } + if (language == null && file != null) { + language = XDebuggerEditorBase.getFileTypeLanguage(file.getFileType()); } XExpression expression = new XExpressionImpl(StringUtil.notNullize(text), language, null, mode); new XDebuggerEvaluationDialog(session, editorsProvider, evaluator, expression, stackFrame == null ? null : stackFrame.getSourcePosition()).show();