diff options
author | Mickael Istria | 2015-12-10 22:03:14 +0000 |
---|---|---|
committer | Dani Megert | 2016-01-20 13:39:54 +0000 |
commit | b6ea8c0e0e548eae232032eea6b5591dff189ee5 (patch) | |
tree | 61ab2b47ce9c1fa637a5dd0b07cc7821b8e8cec7 | |
parent | 23c9d0a7c36fa11ae3658b26158a8337fbe3293d (diff) | |
download | eclipse.platform.text-b6ea8c0e0e548eae232032eea6b5591dff189ee5.tar.gz eclipse.platform.text-b6ea8c0e0e548eae232032eea6b5591dff189ee5.tar.xz eclipse.platform.text-b6ea8c0e0e548eae232032eea6b5591dff189ee5.zip |
Bug 484157: Fix computation of fonts to propage zoom action
Change-Id: I058fff5a7bf3df89b646a15696b8ab79f8eb632d
Signed-off-by: Mickael Istria <mistria@redhat.com>
4 files changed, 136 insertions, 5 deletions
diff --git a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF index 2b03bcd5007..c576df312bf 100644 --- a/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.ui.editors.tests/META-INF/MANIFEST.MF @@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)", org.eclipse.core.filebuffers.tests;bundle-version="[3.4.100,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", - org.eclipse.text.tests;bundle-version="[3.5.0,4.0.0)" + org.eclipse.text.tests;bundle-version="[3.5.0,4.0.0)", + org.eclipse.test.performance;bundle-version="[3.12.0,4.0.0) Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Eclipse-BundleShape: dir Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java index 2c4a13a8733..b2efda56e9c 100644 --- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/EditorsTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Mickael Istria (Red Hat Inc.) - [484157] Add zoom test *******************************************************************************/ package org.eclipse.ui.editors.tests; @@ -28,6 +29,7 @@ public class EditorsTestSuite extends TestSuite { suite.addTest(GotoLineTest.suite()); suite.addTest(SegmentedModeTest.suite()); suite.addTest(MarkerAnnotationOrderTest.suite()); + suite.addTest(ZoomTest.suite()); //$JUnit-END$ return suite; } diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ZoomTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ZoomTest.java new file mode 100644 index 00000000000..5104e0b865b --- /dev/null +++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/ZoomTest.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat Inc. and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael Istria (Red Hat Inc.) + *******************************************************************************/ +package org.eclipse.ui.editors.tests; + +import java.io.ByteArrayInputStream; +import java.util.Collections; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.eclipse.test.OrderedTestSuite; + +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.widgets.Control; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; + +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; + +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.intro.IIntroPart; +import org.eclipse.ui.part.FileEditorInput; + +import org.eclipse.ui.texteditor.AbstractTextEditor; + +import junit.extensions.TestSetup; +import junit.framework.TestCase; + +/** + * @since 3.11 + * + */ +public class ZoomTest extends TestCase { + + private static IProject project; + private static IFile file; + private StyledText text; + private AbstractTextEditor editor; + private int initialFontSize; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + project = ResourcesPlugin.getWorkspace().getRoot().getProject("test"); + project.create(new NullProgressMonitor()); + project.open(new NullProgressMonitor()); + file = project.getFile("foo.txt"); + file.create(new ByteArrayInputStream("bar".getBytes()), true, new NullProgressMonitor()); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + file.delete(true, new NullProgressMonitor()); + project.delete(true, new NullProgressMonitor()); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro(); + if (intro != null) { + PlatformUI.getWorkbench().getIntroManager().closeIntro(intro); + } + + IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); + editor = (AbstractTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage().openEditor(new FileEditorInput(file), desc.getId()); + editor.setFocus(); + text = (StyledText) editor.getAdapter(Control.class); + // make sure we start from a clean state + initialFontSize = text.getFont().getFontData()[0].getHeight(); + } + + @Test + public void testZoomCommand() throws Exception { + int times = 6; + { + Command zoomInCommand = PlatformUI.getWorkbench().getService(ICommandService.class) + .getCommand("org.eclipse.ui.edit.text.zoomIn"); + for (int i = 0; i < times; i++) { + zoomInCommand.executeWithChecks(new ExecutionEvent(zoomInCommand, Collections.EMPTY_MAP, null, null)); + } + Assert.assertEquals(this.initialFontSize + 12, text.getFont().getFontData()[0].getHeight()); + } + { + Command zoomOutCommand = PlatformUI.getWorkbench().getService(ICommandService.class) + .getCommand("org.eclipse.ui.edit.text.zoomOut"); + for (int i = 0; i < times; i++) { + zoomOutCommand.executeWithChecks(new ExecutionEvent(zoomOutCommand, Collections.EMPTY_MAP, null, null)); + } + Assert.assertEquals(this.initialFontSize, text.getFont().getFontData()[0].getHeight()); + } + } + + public static junit.framework.Test suite() { + return new TestSetup(new OrderedTestSuite(ZoomTest.class)) { + protected void setUp() throws Exception { + ZoomTest.setUpBeforeClass(); + } + protected void tearDown() throws Exception { + ZoomTest.tearDownAfterClass(); + } + }; + } + +} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextZoomHandler.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextZoomHandler.java index 405525b9ea3..f334a471fe2 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextZoomHandler.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextZoomHandler.java @@ -149,12 +149,16 @@ abstract class AbstractTextZoomHandler extends AbstractHandler { res.add(referenceFontName); } String currentFontName= referenceFontName; + String rootFontName= referenceFontName; // identify "root" font to change - while (fgFontToDefault.get(currentFontName) != null && Arrays.equals(referenceFontData, fontRegistry.getFontData(currentFontName))) { + do { currentFontName= fgFontToDefault.get(currentFontName); - } + if (currentFontName != null && Arrays.equals(referenceFontData, fontRegistry.getFontData(currentFontName))) { + rootFontName= currentFontName; + } + } while (currentFontName != null); LinkedList<String> fontsToProcess= new LinkedList<>(); - fontsToProcess.add(currentFontName); + fontsToProcess.add(rootFontName); // propage to "children" fonts Set<String> alreadyProcessed= new HashSet<>(); while (!fontsToProcess.isEmpty()) { |