Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

delvis fixat bracketinserter

  • Loading branch information...
commit 0278bcdb34d1d6a551b0482a676aaba4e4620b72 1 parent dd3c32d
@jakobc jakobc authored
View
429 org.erlide.core.tests/src/org/erlide/core/ErlProjectTest.java
@@ -1,6 +1,8 @@
package org.erlide.core;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -31,229 +33,230 @@
public class ErlProjectTest {
- private static IErlProject[] projects;
+ private static IErlProject[] projects;
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- ErlideTestUtils.initProjects();
- // We set up projects here, it's quite costly
- final String name1 = "testproject1";
- final IErlProject erlProject1 = ErlideTestUtils.createProject(
- ErlideTestUtils.getTmpPath(name1), name1);
- final String name2 = "testproject2";
- final IErlProject erlProject2 = ErlideTestUtils.createProject(
- ErlideTestUtils.getTmpPath(name2), name2);
- projects = new IErlProject[] { erlProject1, erlProject2 };
- }
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ ErlideTestUtils.initProjects();
+ // We set up projects here, it's quite costly
+ final String name1 = "testproject1";
+ final IErlProject erlProject1 = ErlideTestUtils.createProject(
+ ErlideTestUtils.getTmpPath(name1), name1);
+ final String name2 = "testproject2";
+ final IErlProject erlProject2 = ErlideTestUtils.createProject(
+ ErlideTestUtils.getTmpPath(name2), name2);
+ projects = new IErlProject[] { erlProject1, erlProject2 };
+ }
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- ErlideTestUtils.deleteProjects();
- }
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ ErlideTestUtils.deleteProjects();
+ }
- @Before
- public void setUp() throws Exception {
- ErlideTestUtils.initModulesAndIncludes();
- }
+ @Before
+ public void setUp() throws Exception {
+ ErlideTestUtils.initModulesAndIncludes();
+ }
- @After
- public void tearDown() throws Exception {
- ErlideTestUtils.deleteModules();
- }
+ @After
+ public void tearDown() throws Exception {
+ ErlideTestUtils.deleteModules();
+ }
- @Test
- public void findIncludeFile() throws Exception {
- // given
- // a project with a module and an include including file.hrl
- final IErlProject project = projects[0];
- final String includeName = "a.hrl";
- final IErlModule include = ErlideTestUtils
- .createModule(
- project,
- includeName,
- "-include_lib(\"kernel/include/file.hrl\").\n-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
- include.open(null);
- final IErlModule module = ErlideTestUtils
- .createModule(
- project,
- "f.erl",
- "-module(f).\n-include(\"a.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n"
- + "f() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
- module.open(null);
- final IErlElementLocator model = ErlModelManager.getErlangModel();
- // when
- // looking for the include
- final IErlModule include1 = model.findIncludeFromModule(module,
- includeName, null, IErlElementLocator.Scope.PROJECT_ONLY);
- final IErlModule include2 = model.findIncludeFromProject(project,
- "file.hrl", null, IErlElementLocator.Scope.PROJECT_ONLY);
- // then
- // it should be found
- assertEquals(include, include1);
- assertNotNull(include2);
- }
+ @Test
+ public void findIncludeFile() throws Exception {
+ // given
+ // a project with a module and an include including file.hrl
+ final IErlProject project = projects[0];
+ final String includeName = "a.hrl";
+ final IErlModule include = ErlideTestUtils
+ .createModule(
+ project,
+ includeName,
+ "-include_lib(\"kernel/include/file.hrl\").\n-record(rec1, {field, another=def}).\n-define(MACRO(A), lists:reverse(A)).\n");
+ include.open(null);
+ final IErlModule module = ErlideTestUtils
+ .createModule(
+ project,
+ "f.erl",
+ "-module(f).\n-include(\"a.hrl\").\n-export([f/0]).\n-record(rec2, {a, b}).\n"
+ + "f() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
+ module.open(null);
+ final IErlElementLocator model = ErlModelManager.getErlangModel();
+ // when
+ // looking for the include
+ final IErlModule include1 = model.findIncludeFromModule(module,
+ includeName, null, IErlElementLocator.Scope.PROJECT_ONLY);
+ final IErlModule include2 = model.findIncludeFromProject(project,
+ "file.hrl", null, IErlElementLocator.Scope.PROJECT_ONLY);
+ // then
+ // it should be found
+ assertEquals(include, include1);
+ assertNotNull(include2);
+ }
- @Test
- public void findExternalIncludeFileOnIncludePath() throws Exception {
- File externalInclude = null;
- IErlProject project = null;
- // given
- // a project with an include dir outside the model
- try {
- final String projectName = "testprojectx";
- project = ErlideTestUtils.createProject(
- ErlideTestUtils.getTmpPath(projectName), projectName);
- final String includeName = "x.hrl";
- externalInclude = ErlideTestUtils.createTmpFile(includeName,
- "-record(rec2, {field, another=def}.");
- final String includePath = externalInclude.getAbsolutePath();
- final IPath p = new Path(includePath).removeLastSegments(1);
- project.setIncludeDirs(Lists.newArrayList(p));
- // when
- // looking for the include file
- // String includeFile = ModelUtils.findIncludeFile(erlProject,
- // "x.hrl", "");
- project.open(null);
- final IErlElementLocator model = ErlModelManager.getErlangModel();
- final IErlModule module = model.findIncludeFromProject(project,
- null, includePath,
- IErlElementLocator.Scope.REFERENCED_PROJECTS);
- final IErlModule module2 = model.findModuleFromProject(project,
- includeName, null,
- IErlElementLocator.Scope.REFERENCED_PROJECTS);
- // then
- // it should be found in the model
- assertNotNull(module);
- assertEquals(module, module2);
- } finally {
- if (project != null) {
- ErlideTestUtils.deleteProject(project);
- }
- if (externalInclude != null && externalInclude.exists()) {
- externalInclude.delete();
- }
- }
- }
+ @Test
+ public void findExternalIncludeFileOnIncludePath() throws Exception {
+ File externalInclude = null;
+ IErlProject project = null;
+ // given
+ // a project with an include dir outside the model
+ try {
+ final String projectName = "testprojectx";
+ project = ErlideTestUtils.createProject(
+ ErlideTestUtils.getTmpPath(projectName), projectName);
+ final String includeName = "x.hrl";
+ externalInclude = ErlideTestUtils.createTmpFile(includeName,
+ "-record(rec2, {field, another=def}.");
+ final String includePath = externalInclude.getAbsolutePath();
+ final IPath p = new Path(includePath).removeLastSegments(1);
+ project.setIncludeDirs(Lists.newArrayList(p));
+ // when
+ // looking for the include file
+ // String includeFile = ModelUtils.findIncludeFile(erlProject,
+ // "x.hrl", "");
+ project.open(null);
+ final IErlElementLocator model = ErlModelManager.getErlangModel();
+ final IErlModule module = model.findIncludeFromProject(project,
+ null, includePath,
+ IErlElementLocator.Scope.REFERENCED_PROJECTS);
+ final IErlModule module2 = model.findModuleFromProject(project,
+ includeName, null,
+ IErlElementLocator.Scope.REFERENCED_PROJECTS);
+ // then
+ // it should be found in the model
+ assertNotNull(module);
+ assertEquals(module, module2);
+ } finally {
+ if (project != null) {
+ ErlideTestUtils.deleteProject(project);
+ }
+ if (externalInclude != null && externalInclude.exists()) {
+ externalInclude.delete();
+ }
+ }
+ }
- @Test
- public void findIncludeFileOnIncludePathInOtherProject() throws Exception {
- // http://www.assembla.com/spaces/erlide/tickets/756-navigation--external-include-files-are-not-found
- IErlModule externalInclude = null;
- IErlProject project = null, project2 = null;
- // given
- // a project with an include dir outside the model
- try {
- final String projectName = "testprojectx";
- project = ErlideTestUtils.createProject(
- ErlideTestUtils.getTmpPath(projectName), projectName);
- final String projectName2 = "testprojecty";
- project2 = ErlideTestUtils.createProject(
- ErlideTestUtils.getTmpPath(projectName2), projectName2);
+ @Test
+ public void findIncludeFileOnIncludePathInOtherProject() throws Exception {
+ // http://www.assembla.com/spaces/erlide/tickets/756-navigation--external-include-files-are-not-found
+ IErlModule externalInclude = null;
+ IErlProject project = null, project2 = null;
+ // given
+ // a project with an include dir outside the model
+ try {
+ final String projectName = "testprojectx";
+ project = ErlideTestUtils.createProject(
+ ErlideTestUtils.getTmpPath(projectName), projectName);
+ final String projectName2 = "testprojecty";
+ project2 = ErlideTestUtils.createProject(
+ ErlideTestUtils.getTmpPath(projectName2), projectName2);
- final String includeName = "x.hrl";
- externalInclude = ErlideTestUtils.createInclude(project2, "x.hrl",
- "-record(rec2, {field, another=def}.");
- final String includePath = externalInclude.getFilePath();
- final IPath p = new Path(includePath).removeLastSegments(1);
- project.setIncludeDirs(Lists.newArrayList(p));
- // when
- // looking for the include file
- project.open(null);
- final IErlElementLocator model = ErlModelManager.getErlangModel();
- final IErlModule module = model.findIncludeFromProject(project,
- includeName, null, IErlElementLocator.Scope.ALL_PROJECTS);
- // then
- // it should be found in the project defining it
- assertNotNull(module);
- assertEquals(project2, ModelUtils.getProject(module));
- } finally {
- if (project != null) {
- ErlideTestUtils.deleteProject(project);
- }
- if (project2 != null) {
- ErlideTestUtils.deleteProject(project2);
- }
- }
- }
+ final String includeName = "x.hrl";
+ externalInclude = ErlideTestUtils.createInclude(project2, "x.hrl",
+ "-record(rec2, {field, another=def}.");
+ final String includePath = externalInclude.getFilePath();
+ final IPath p = new Path(includePath).removeLastSegments(1);
+ project.setIncludeDirs(Lists.newArrayList(p));
+ // when
+ // looking for the include file
+ project.open(null);
+ final IErlElementLocator model = ErlModelManager.getErlangModel();
+ final IErlModule module = model.findIncludeFromProject(project,
+ includeName, null, IErlElementLocator.Scope.ALL_PROJECTS);
+ // then
+ // it should be found in the project defining it
+ assertNotNull(module);
+ assertEquals(project2, ModelUtils.getProject(module));
+ } finally {
+ if (project != null) {
+ ErlideTestUtils.deleteProject(project);
+ }
+ if (project2 != null) {
+ ErlideTestUtils.deleteProject(project2);
+ }
+ }
+ }
- @Test
- public void findFunctionInExternalFilesTest() throws Exception {
- // given
- // a module with calls to the lists module
- final IErlProject project = projects[0];
- final IErlModule moduleE = ErlideTestUtils
- .createModule(
- project,
- "e.erl",
- "-module(e).\n-export([f/0]).\nf() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
- final IErlScanner scanner = moduleE.getScanner();
- try {
- moduleE.open(null);
- // when
- // looking for lists:reverse/2 and lists:reverse/1
- final IRpcSite backend = BackendCore.getBackendManager()
- .getIdeBackend().getRpcSite();
- final IErlModel model = ErlModelManager.getErlangModel();
- final OpenResult res = ErlideOpen.open(backend, moduleE, 49,
- ModelUtils.getImportsAsList(moduleE),
- project.getExternalModulesString(), model.getPathVars());
- final IErlFunction function = ModelUtils.findFunction(model,
- res.getName(), res.getFunction(), res.getPath(), project,
- IErlElementLocator.Scope.PROJECT_ONLY, moduleE);
- assertNotNull(function);
+ @Test
+ public void findFunctionInExternalFilesTest() throws Exception {
+ // given
+ // a module with calls to the lists module
+ final IErlProject project = projects[0];
+ final IErlModule moduleE = ErlideTestUtils
+ .createModule(
+ project,
+ "e.erl",
+ "-module(e).\n-export([f/0]).\nf() ->\n lists:reverse([1, 0]),\n lists:reverse([1, 0], [2]).\n");
+ final IErlScanner scanner = moduleE.getScanner();
+ try {
+ moduleE.open(null);
+ // when
+ // looking for lists:reverse/2 and lists:reverse/1
+ final IRpcSite backend = BackendCore.getBackendManager()
+ .getIdeBackend().getRpcSite();
+ final IErlModel model = ErlModelManager.getErlangModel();
+ final OpenResult res = ErlideOpen.open(backend,
+ moduleE.getScannerName(), 49,
+ ModelUtils.getImportsAsList(moduleE),
+ project.getExternalModulesString(), model.getPathVars());
+ final IErlFunction function = ModelUtils.findFunction(model,
+ res.getName(), res.getFunction(), res.getPath(), project,
+ IErlElementLocator.Scope.PROJECT_ONLY, moduleE);
+ assertNotNull(function);
- final IErlElement module = model.findModuleFromProject(project,
- function.getModuleName(), res.getPath(),
- IErlElementLocator.Scope.PROJECT_ONLY);
- // then
- // the function should be returned and the module, in External Files
- assertNotNull(module);
- assertEquals(function.getParent(), module);
- assertEquals(ModelUtils.getProject(function), project);
- } finally {
- scanner.dispose();
- }
- }
+ final IErlElement module = model.findModuleFromProject(project,
+ function.getModuleName(), res.getPath(),
+ IErlElementLocator.Scope.PROJECT_ONLY);
+ // then
+ // the function should be returned and the module, in External Files
+ assertNotNull(module);
+ assertEquals(function.getParent(), module);
+ assertEquals(ModelUtils.getProject(function), project);
+ } finally {
+ scanner.dispose();
+ }
+ }
- @Test
- public void findExternalModule() throws Exception {
- File externalFile = null;
- IErlProject project = null;
- try {
- // given
- // an erlang project with an external file
- final String projectName = "testproject";
- project = ErlideTestUtils.createTmpErlProject(projectName);
- final String externalFileName = "external.erl";
- externalFile = ErlideTestUtils
- .createTmpFile(externalFileName,
- "-module(external).\nf([_ | _]=L ->\n atom_to_list(L).\n");
- final String absolutePath = externalFile.getAbsolutePath();
- final String externalsFileName = "x.erlidex";
- final File externalsFile = ErlideTestUtils.createTmpFile(
- externalsFileName, absolutePath);
- project.setExternalModulesFile(externalsFile.getAbsolutePath());
- project.open(null);
- final IErlElementLocator model = ErlModelManager.getErlangModel();
- // when
- // looking for it
- final IErlModule externalModule = model.findModuleFromProject(
- project, externalFileName, null,
- IErlElementLocator.Scope.PROJECT_ONLY);
- // then
- // we should find it
- assertNotNull(externalModule);
- assertTrue(FilePathUtils.equalFilePaths(absolutePath,
- externalModule.getFilePath()));
- } finally {
- if (externalFile != null && externalFile.exists()) {
- externalFile.delete();
- }
- if (project != null) {
- ErlideTestUtils.deleteProject(project);
- }
- }
+ @Test
+ public void findExternalModule() throws Exception {
+ File externalFile = null;
+ IErlProject project = null;
+ try {
+ // given
+ // an erlang project with an external file
+ final String projectName = "testproject";
+ project = ErlideTestUtils.createTmpErlProject(projectName);
+ final String externalFileName = "external.erl";
+ externalFile = ErlideTestUtils
+ .createTmpFile(externalFileName,
+ "-module(external).\nf([_ | _]=L ->\n atom_to_list(L).\n");
+ final String absolutePath = externalFile.getAbsolutePath();
+ final String externalsFileName = "x.erlidex";
+ final File externalsFile = ErlideTestUtils.createTmpFile(
+ externalsFileName, absolutePath);
+ project.setExternalModulesFile(externalsFile.getAbsolutePath());
+ project.open(null);
+ final IErlElementLocator model = ErlModelManager.getErlangModel();
+ // when
+ // looking for it
+ final IErlModule externalModule = model.findModuleFromProject(
+ project, externalFileName, null,
+ IErlElementLocator.Scope.PROJECT_ONLY);
+ // then
+ // we should find it
+ assertNotNull(externalModule);
+ assertTrue(FilePathUtils.equalFilePaths(absolutePath,
+ externalModule.getFilePath()));
+ } finally {
+ if (externalFile != null && externalFile.exists()) {
+ externalFile.delete();
+ }
+ if (project != null) {
+ ErlideTestUtils.deleteProject(project);
+ }
+ }
- }
+ }
}
View
47 org.erlide.ui/src/org/erlide/ui/editors/erl/AbstractErlangEditor.java
@@ -1,19 +1,19 @@
package org.erlide.ui.editors.erl;
-import java.util.List;
-
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.ITextEditorExtension3;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import org.erlide.model.erlang.ErlToken;
import org.erlide.model.erlang.IErlModule;
import org.erlide.model.erlang.IErlScanner;
import org.erlide.model.root.IErlElement;
import org.erlide.model.root.IErlProject;
-import org.erlide.ui.editors.erl.autoedit.SmartTypingPreferencePage;
import org.erlide.ui.prefs.PreferenceConstants;
public abstract class AbstractErlangEditor extends TextEditor {
@@ -65,8 +65,6 @@ protected ErlangViewerBracketInserter getBracketInserter() {
public abstract String getScannerName();
protected void setupBracketInserter() {
- readBracketInserterPrefs(getBracketInserter());
-
final ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer instanceof ITextViewerExtension) {
((ITextViewerExtension) sourceViewer)
@@ -74,22 +72,29 @@ protected void setupBracketInserter() {
}
}
- public static void readBracketInserterPrefs(
- final ErlangViewerBracketInserter bracketInserter) {
- final List<Boolean> prefs = SmartTypingPreferencePage
- .getBracketInserterPreferences();
- bracketInserter.setCloseAtomsEnabled(prefs
- .get(SmartTypingPreferencePage.ATOMS));
- bracketInserter.setCloseBracketsEnabled(prefs
- .get(SmartTypingPreferencePage.BRACKETS));
- bracketInserter.setCloseStringsEnabled(prefs
- .get(SmartTypingPreferencePage.STRINGS));
- bracketInserter.setCloseBracesEnabled(prefs
- .get(SmartTypingPreferencePage.BRACES));
- bracketInserter.setCloseParensEnabled(prefs
- .get(SmartTypingPreferencePage.PARENS));
- bracketInserter.setEmbraceSelectionEnabled(prefs
- .get(SmartTypingPreferencePage.EMBRACE_SELECTION));
+ @Override
+ protected ISourceViewer createSourceViewer(final Composite parent,
+ final IVerticalRuler ruler, final int styles) {
+ final ISourceViewer viewer = new ErlangSourceViewer(parent, ruler,
+ getOverviewRuler(), true, styles,
+ new IBracketInserterValidator() {
+ @Override
+ public boolean earlyCancelCheck() {
+ return getInsertMode() != ITextEditorExtension3.SMART_INSERT;
+ }
+
+ @Override
+ public boolean validInput() {
+ return validateEditorInputState();
+ }
+ });
+ getSourceViewerDecorationSupport(viewer);
+
+ addFoldingSupport(viewer);
+
+ return viewer;
}
+ protected abstract void addFoldingSupport(final ISourceViewer viewer);
+
}
View
110 org.erlide.ui/src/org/erlide/ui/editors/erl/ErlangEditor.java
@@ -48,7 +48,6 @@
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -88,7 +87,6 @@
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
-import org.eclipse.ui.texteditor.ITextEditorExtension3;
import org.eclipse.ui.texteditor.ResourceAction;
import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.ui.texteditor.TextOperationAction;
@@ -118,7 +116,6 @@
import org.erlide.ui.editors.erl.actions.SendToConsoleAction;
import org.erlide.ui.editors.erl.actions.ShowOutlineAction;
import org.erlide.ui.editors.erl.actions.ToggleCommentAction;
-import org.erlide.ui.editors.erl.autoedit.SmartTypingPreferencePage;
import org.erlide.ui.editors.erl.folding.IErlangFoldingStructureProvider;
import org.erlide.ui.editors.erl.folding.IErlangFoldingStructureProviderExtension;
import org.erlide.ui.editors.erl.hover.ErlangAnnotationIterator;
@@ -154,8 +151,8 @@
private ColorManager colorManager;
private ErlangOutlinePage myOutlinePage;
private IPropertySource myPropertySource;
- private ProjectionSupport fProjectionSupport;
- private IErlangFoldingStructureProvider fProjectionModelUpdater;
+ ProjectionSupport fProjectionSupport;
+ IErlangFoldingStructureProvider fProjectionModelUpdater;
private OpenAction openAction;
private IndentAction indentAction;
private ToggleCommentAction toggleCommentAction;
@@ -279,12 +276,7 @@ protected void initializeKeyBindingScopes() {
@Override
public void preferenceChange(final PreferenceChangeEvent event) {
final String key = event.getKey();
- // ErlLogger.debug("event:: " + key);
- if (key.indexOf('/') != -1
- && key.split("/")[0]
- .equals(SmartTypingPreferencePage.SMART_TYPING_KEY)) {
- readBracketInserterPrefs(getBracketInserter());
- } else if ("markingOccurences".equals(key)) {
+ if ("markingOccurences".equals(key)) {
final boolean newBooleanValue = event.getNewValue().equals(
"true");
if (newBooleanValue != markOccurencesHandler.fMarkOccurrenceAnnotations) {
@@ -517,63 +509,6 @@ public Object getAdapter(@SuppressWarnings("rawtypes") final Class required) {
return super.getAdapter(required);
}
- @Override
- protected ISourceViewer createSourceViewer(final Composite parent,
- final IVerticalRuler ruler, final int styles) {
- final ISourceViewer viewer = new ErlangSourceViewer(parent, ruler,
- getOverviewRuler(), true, styles,
- new IBracketInserterValidator() {
- @Override
- public boolean earlyCancelCheck() {
- return getInsertMode() != ITextEditorExtension3.SMART_INSERT;
- }
-
- @Override
- public boolean validInput() {
- return validateEditorInputState();
- }
- });
- getSourceViewerDecorationSupport(viewer);
-
- /*
- * This is a performance optimization to reduce the computation of the
- * text presentation triggered by {@link #setVisibleDocument(IDocument)}
- */
- // if (javaSourceViewer != null && isFoldingEnabled() && (store == null
- // ||
- // !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS)))
- // javaSourceViewer.prepareDelayedProjection();
- if (isFoldingEnabled()) {
- final ProjectionViewer projectionViewer = (ProjectionViewer) viewer;
- fProjectionSupport = new ProjectionSupport(projectionViewer,
- getAnnotationAccess(), getSharedColors());
- fProjectionSupport
- .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
- fProjectionSupport
- .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
- // TODO fProjectionSupport.setHoverControlCreator(new
- // IInformationControlCreator()
- // {
- // public IInformationControl createInformationControl(Shell shell)
- // {
- // return new CustomSourceInformationControl(shell,
- // IDocument.DEFAULT_CONTENT_TYPE);
- // }
- // });
-
- fProjectionSupport.install();
-
- fProjectionModelUpdater = ErlideUIPlugin.getDefault()
- .getFoldingStructureProviderRegistry()
- .getCurrentFoldingProvider();
- if (fProjectionModelUpdater != null) {
- fProjectionModelUpdater.install(this, projectionViewer);
- }
- }
-
- return viewer;
- }
-
/**
* Jumps to the matching bracket.
*/
@@ -785,6 +720,45 @@ public IErlModule getModule() {
return fModule;
}
+ @Override
+ protected void addFoldingSupport(final ISourceViewer viewer) {
+ /*
+ * This is a performance optimization to reduce the computation of the
+ * text presentation triggered by {@link #setVisibleDocument(IDocument)}
+ */
+ // if (javaSourceViewer != null && isFoldingEnabled() && (store == null
+ // ||
+ // !store.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS)))
+ // javaSourceViewer.prepareDelayedProjection();
+ if (isFoldingEnabled()) {
+ final ProjectionViewer projectionViewer = (ProjectionViewer) viewer;
+ fProjectionSupport = new ProjectionSupport(projectionViewer,
+ getAnnotationAccess(), getSharedColors());
+ fProjectionSupport
+ .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); //$NON-NLS-1$
+ fProjectionSupport
+ .addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); //$NON-NLS-1$
+ // TODO fProjectionSupport.setHoverControlCreator(new
+ // IInformationControlCreator()
+ // {
+ // public IInformationControl createInformationControl(Shell shell)
+ // {
+ // return new CustomSourceInformationControl(shell,
+ // IDocument.DEFAULT_CONTENT_TYPE);
+ // }
+ // });
+
+ fProjectionSupport.install();
+
+ fProjectionModelUpdater = ErlideUIPlugin.getDefault()
+ .getFoldingStructureProviderRegistry()
+ .getCurrentFoldingProvider();
+ if (fProjectionModelUpdater != null) {
+ fProjectionModelUpdater.install(this, projectionViewer);
+ }
+ }
+ }
+
/**
* Returns the most narrow element including the given offset. If
* <code>reconcile</code> is <code>true</code> the editor's input element is
View
45 org.erlide.ui/src/org/erlide/ui/editors/erl/ErlangSourceViewer.java
@@ -1,20 +1,14 @@
package org.erlide.ui.editors.erl;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.ITextInputListener;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.swt.widgets.Composite;
-import org.erlide.utils.ErlLogger;
import org.erlide.utils.IDisposable;
public class ErlangSourceViewer extends ProjectionViewer implements IDisposable {
- private final IDocumentListener documentListener;
private ErlangViewerBracketInserter fBracketInserter = null;
public ErlangSourceViewer(final Composite parent,
@@ -26,45 +20,6 @@ public ErlangSourceViewer(final Composite parent,
if (validator != null) {
fBracketInserter.setValidator(validator);
}
-
- documentListener = new IDocumentListener() {
- @Override
- public void documentAboutToBeChanged(final DocumentEvent event) {
- updateTextBuffer(event);
- }
-
- @Override
- public void documentChanged(final DocumentEvent event) {
- }
- };
- addTextInputListener(new ITextInputListener() {
- @Override
- public void inputDocumentChanged(final IDocument oldInput,
- final IDocument newInput) {
- if (newInput != null) {
- newInput.addDocumentListener(documentListener);
- final String text = newInput.get();
-
- // TODO we need to be able to override this, for editors we
- // can just send the file path initially
- ErlLogger.debug("INITIAL");
- updateTextBuffer(new DocumentEvent(newInput, 0, 0, text));
- }
- }
-
- @Override
- public void inputDocumentAboutToBeChanged(final IDocument oldInput,
- final IDocument newInput) {
- if (oldInput != null) {
- oldInput.removeDocumentListener(documentListener);
- }
- }
- });
-
- }
-
- private void updateTextBuffer(final DocumentEvent event) {
- // ErlLogger.debug("UPDATE BUFFER " + event);
}
@Override
View
128 org.erlide.ui/src/org/erlide/ui/editors/erl/ErlangViewerBracketInserter.java
@@ -179,81 +179,83 @@ public void verifyKey(final VerifyEvent event) {
// early pruning to slow down normal typing as little as possible
if (!event.doit || validator.earlyCancelCheck()) {
- switch (event.character) {
- case '(':
- case '{':
- case '[':
- case '\'':
- case '\"':
- break;
- default:
- return;
- }
+ return;
+ }
+ switch (event.character) {
+ case '(':
+ case '{':
+ case '[':
+ case '\'':
+ case '\"':
+ break;
+ default:
+ return;
+ }
- final IDocument document = sourceViewer.getDocument();
+ final IDocument document = sourceViewer.getDocument();
- final Point selection = sourceViewer.getSelectedRange();
- final int offset = selection.x;
- final int length = selection.y;
- try {
- final String selStr = fEmbraceSelection ? document.get(offset,
- length) : "";
- if (selStr.length() == 0) {
- final int kind = getKindOfBracket(document, offset, length);
- // if (isStopper(kind)) {
- // return;
- // }
- if (kind == '(' || kind == '{' || kind == '[') {
+ final Point selection = sourceViewer.getSelectedRange();
+ final int offset = selection.x;
+ final int length = selection.y;
+ try {
+ final String selStr = fEmbraceSelection ? document.get(offset,
+ length) : "";
+ if (selStr.length() == 0) {
+ final int kind = getKindOfBracket(document, offset, length);
+ // if (isStopper(kind)) {
+ // return;
+ // }
+ if (kind == '(' || kind == '{' || kind == '[') {
+ return;
+ }
+
+ switch (event.character) {
+ case '(':
+ if (!fCloseParens || kind == ')') {
return;
}
+ break;
- switch (event.character) {
- case '(':
- if (!fCloseParens || kind == ')') {
- return;
- }
- break;
-
- case '[':
- if (!fCloseBrackets || kind == ']') {
- return;
- }
- break;
- case '{':
- if (!fCloseBraces || kind == '}') {
- return;
- }
- break;
- case '\'':
- if (!fCloseAtoms || kind == '\'') {
- return;
- }
- break;
- case '"':
- if (!fCloseStrings || kind == '"') {
- return;
- }
- break;
-
- default:
+ case '[':
+ if (!fCloseBrackets || kind == ']') {
return;
}
-
- if (!validator.validInput()) {
+ break;
+ case '{':
+ if (!fCloseBraces || kind == '}') {
+ return;
+ }
+ break;
+ case '\'':
+ if (!fCloseAtoms || kind == '\'') {
return;
}
+ break;
+ case '"':
+ if (!fCloseStrings || kind == '"') {
+ return;
+ }
+ break;
+
+ default:
+ return;
}
- final char character = event.character;
- final char closingCharacter = getPeerCharacter(character);
- updateDocument(document, offset, length, selStr, character,
- closingCharacter);
- event.doit = false;
- } catch (final BadLocationException e) {
- ErlLogger.error(e);
- } catch (final BadPositionCategoryException e) {
- ErlLogger.error(e);
+ if (!validator.validInput()) {
+ return;
+ }
}
+ final char character = event.character;
+ final char closingCharacter = getPeerCharacter(character);
+ updateDocument(document, offset, length, selStr, character,
+ closingCharacter);
+
+ event.doit = false;
+
+ } catch (final BadLocationException e) {
+ ErlLogger.error(e);
+ } catch (final BadPositionCategoryException e) {
+ ErlLogger.error(e);
}
}
View
29 org.erlide.ui/src/org/erlide/ui/editors/scratchpad/ErlangScratchPad.java
@@ -6,9 +6,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -69,7 +66,6 @@
import org.erlide.ui.editors.erl.actions.IndentAction;
import org.erlide.ui.editors.erl.actions.SendToConsoleAction;
import org.erlide.ui.editors.erl.actions.ToggleCommentAction;
-import org.erlide.ui.editors.erl.autoedit.SmartTypingPreferencePage;
import org.erlide.ui.editors.erl.folding.IErlangFoldingStructureProvider;
import org.erlide.ui.editors.erl.scanner.IErlangPartitions;
import org.erlide.ui.internal.ErlideUIPlugin;
@@ -80,7 +76,6 @@
ISaveablePart2 {
private ColorManager colorManager;
- private final IPreferenceChangeListener fPreferenceChangeListener = new PreferenceChangeListener();
private InformationPresenter fInformationPresenter;
private ProjectionSupport fProjectionSupport;
private IErlangFoldingStructureProvider fProjectionModelUpdater;
@@ -101,19 +96,6 @@ public ErlangScratchPad() {
registerListeners();
}
- // FIXME copied from ErlangEditor
- class PreferenceChangeListener implements IPreferenceChangeListener {
- @Override
- public void preferenceChange(final PreferenceChangeEvent event) {
- final String key = event.getKey();
- if (key.indexOf('/') != -1
- && key.split("/")[0]
- .equals(SmartTypingPreferencePage.SMART_TYPING_KEY)) {
- ErlangEditor.readBracketInserterPrefs(getBracketInserter());
- }
- }
- }
-
private void registerListeners() {
}
@@ -134,9 +116,6 @@ public void dispose() {
((ITextViewerExtension) sourceViewer)
.removeVerifyKeyListener(getBracketInserter());
}
- final IEclipsePreferences node = ErlideUIPlugin.getPrefsNode();
- node.removePreferenceChangeListener(fPreferenceChangeListener);
-
if (fActionGroups != null) {
fActionGroups.dispose();
fActionGroups = null;
@@ -190,9 +169,6 @@ public void createPartControl(final Composite parent) {
final ProjectionViewer v = (ProjectionViewer) getSourceViewer();
v.doOperation(ProjectionViewer.TOGGLE);
- final IEclipsePreferences node = ErlideUIPlugin.getPrefsNode();
- node.addPreferenceChangeListener(fPreferenceChangeListener);
-
final IInformationControlCreator informationControlCreator = getSourceViewerConfiguration()
.getInformationControlCreator(getSourceViewer());
@@ -646,4 +622,9 @@ public String getScannerName() {
return null;
}
+ @Override
+ protected void addFoldingSupport(final ISourceViewer viewer) {
+ // TODO Not yet
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.