From eb1a9e8b2a77366d027340b4b6149153a5e571dd Mon Sep 17 00:00:00 2001 From: Piotr Wolny Date: Wed, 3 Feb 2010 23:20:07 +0100 Subject: [PATCH] initial commit --- .classpath | 7 + .project | 28 ++ .settings/org.eclipse.jdt.core.prefs | 8 + META-INF/MANIFEST.MF | 13 + build.properties | 6 + icons/icon.gif | Bin 0 -> 178 bytes plugin.xml | 17 ++ .../simplepropertieseditor/Activator.java | 81 +++++ .../editor/ColorManager.java | 50 ++++ .../editor/PropertiesColorConstants.java | 34 +++ .../editor/PropertiesConfiguration.java | 80 +++++ .../editor/PropertiesDocumentProvider.java | 70 +++++ .../editor/PropertiesDocumentWrapper.java | 279 ++++++++++++++++++ .../editor/PropertiesPartitionScanner.java | 47 +++ .../editor/SimplePropertiesEditor.java | 43 +++ 15 files changed, 763 insertions(+) create mode 100755 .classpath create mode 100755 .project create mode 100755 .settings/org.eclipse.jdt.core.prefs create mode 100755 META-INF/MANIFEST.MF create mode 100755 build.properties create mode 100644 icons/icon.gif create mode 100755 plugin.xml create mode 100755 src/org/gildur/simplepropertieseditor/Activator.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/ColorManager.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java create mode 100755 src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..8a8f166 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.project b/.project new file mode 100755 index 0000000..d809437 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + SimplePropertiesEditor + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..a056047 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Tue Feb 02 21:30:31 CET 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100755 index 0000000..ac5c3c8 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SimplePropertiesEditor +Bundle-SymbolicName: SimplePropertiesEditor; singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.gildur.simplepropertieseditor.Activator +Bundle-Vendor: Piotr Wolny +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.ui.editors, + org.eclipse.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy diff --git a/build.properties b/build.properties new file mode 100755 index 0000000..4b8162a --- /dev/null +++ b/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/icons/icon.gif b/icons/icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..6c2c944907000dc65bfaf6fdeeac9da33c0781bc GIT binary patch literal 178 zcmZ?wbhEHb6krfwXpv?B0wyLV78VvZHa2#4b}lY1US3{)etrP~0SO5SNl8gLIXMLd z1!H4l6B83FD=P;Fhv?|&^z`)1%*^8A;`;jfhK7dD&dyo0W}Q8I_V3@n|51VBPZmZl z26+Y@kWC;v8CdlnsQ0C0&dXR8=ibEdik-pRVD)yM<&}Nkc3;YM + + + + + + + + + diff --git a/src/org/gildur/simplepropertieseditor/Activator.java b/src/org/gildur/simplepropertieseditor/Activator.java new file mode 100755 index 0000000..779511a --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/Activator.java @@ -0,0 +1,81 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle. + * + * @author Piotr Wolny + */ +public class Activator extends AbstractUIPlugin { + /** + * The plug-in ID. + */ + public static final String PLUGIN_ID = "SimplePropertiesEditor"; + + /** + * The shared instance. + */ + private static Activator plugin; + + /** + * Default constructor. + */ + public Activator() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance. + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given plug-in relative path. + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/src/org/gildur/simplepropertieseditor/editor/ColorManager.java b/src/org/gildur/simplepropertieseditor/editor/ColorManager.java new file mode 100755 index 0000000..2d13622 --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/ColorManager.java @@ -0,0 +1,50 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +public class ColorManager { + + protected Map colorTable = new HashMap(10); + + public void dispose() { + for (Color c : colorTable.values()) { + c.dispose(); + } + } + + public Color getColor(RGB rgb) { + Color color = colorTable.get(rgb); + if (color == null) { + color = new Color(Display.getCurrent(), rgb); + colorTable.put(rgb, color); + } + return color; + } +} diff --git a/src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java b/src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java new file mode 100755 index 0000000..6c7f7f2 --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java @@ -0,0 +1,34 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import org.eclipse.swt.graphics.RGB; + +public interface PropertiesColorConstants { + + RGB DEFAULT = new RGB(0, 0, 0); + + RGB COMMENT = new RGB(0, 255, 0); + + RGB ENTRY = new RGB(0, 0, 255); +} diff --git a/src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java b/src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java new file mode 100755 index 0000000..8baefa3 --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java @@ -0,0 +1,80 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; + +public class PropertiesConfiguration extends SourceViewerConfiguration { + + private ColorManager colorManager; + + public PropertiesConfiguration(ColorManager colorManager) { + this.colorManager = colorManager; + } + + @Override + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PropertiesPartitionScanner.PROPERTIES_COMMENT, + PropertiesPartitionScanner.PROPERTIES_ENTRY }; + } + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + + SimpleDamagerRepaierer dr = new SimpleDamagerRepaierer(new TextAttribute(colorManager + .getColor(PropertiesColorConstants.ENTRY))); + reconciler.setDamager(dr, PropertiesPartitionScanner.PROPERTIES_ENTRY); + reconciler.setRepairer(dr, PropertiesPartitionScanner.PROPERTIES_ENTRY); + + SimpleDamagerRepaierer ndr = new SimpleDamagerRepaierer(new TextAttribute(colorManager + .getColor(PropertiesColorConstants.COMMENT))); + reconciler.setDamager(ndr, PropertiesPartitionScanner.PROPERTIES_COMMENT); + reconciler.setRepairer(ndr, PropertiesPartitionScanner.PROPERTIES_COMMENT); + + return reconciler; + } + + private static class SimpleDamagerRepaierer extends DefaultDamagerRepairer { + + private TextAttribute textAttribute; + + public SimpleDamagerRepaierer(TextAttribute textAttribute) { + super(new RuleBasedScanner()); + this.textAttribute = textAttribute; + } + + @Override + protected TextAttribute getTokenTextAttribute(IToken token) { + return textAttribute; + } + } +} \ No newline at end of file diff --git a/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java b/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java new file mode 100755 index 0000000..4ebda5b --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java @@ -0,0 +1,70 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.FastPartitioner; +import org.eclipse.ui.editors.text.FileDocumentProvider; + +public class PropertiesDocumentProvider extends FileDocumentProvider { + + @Override + protected IDocument createDocument(Object element) throws CoreException { + IDocument document = super.createDocument(element); + if (document != null) { + IDocumentPartitioner partitioner = new FastPartitioner(new PropertiesPartitionScanner(), + new String[] { PropertiesPartitionScanner.PROPERTIES_ENTRY, + PropertiesPartitionScanner.PROPERTIES_COMMENT }); + partitioner.connect(document); + document.setDocumentPartitioner(partitioner); + } + + String content = document.get(); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < content.length(); i++) { + char c = content.charAt(i); + if (c == '\\') { + c = content.charAt(i + 1); + if (c == 'u') { + int code = Integer.parseInt(content.substring(i + 2, i + 6), 16); + buffer.append((char) code); + i += 5; + } + } else { + buffer.append(c); + } + } + document.set(buffer.toString()); + + return document; + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, Object element, final IDocument document, boolean overwrite) + throws CoreException { + super.doSaveDocument(monitor, element, new PropertiesDocumentWrapper(document), overwrite); + } +} diff --git a/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java b/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java new file mode 100755 index 0000000..eed610d --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java @@ -0,0 +1,279 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.BadPositionCategoryException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.IDocumentPartitioningListener; +import org.eclipse.jface.text.IPositionUpdater; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.Position; + +public class PropertiesDocumentWrapper implements IDocument { + + private IDocument document; + + public PropertiesDocumentWrapper(IDocument document) { + this.document = document; + } + + @Override + public void addDocumentListener(IDocumentListener arg0) { + document.addDocumentListener(arg0); + } + + @Override + public void addDocumentPartitioningListener(IDocumentPartitioningListener arg0) { + document.addDocumentPartitioningListener(arg0); + } + + @Override + public void addPosition(Position arg0) throws BadLocationException { + document.addPosition(arg0); + } + + @Override + public void addPosition(String arg0, Position arg1) throws BadLocationException, BadPositionCategoryException { + document.addPosition(arg0, arg1); + } + + @Override + public void addPositionCategory(String arg0) { + document.addPositionCategory(arg0); + } + + @Override + public void addPositionUpdater(IPositionUpdater arg0) { + document.addPositionUpdater(arg0); + } + + @Override + public void addPrenotifiedDocumentListener(IDocumentListener arg0) { + document.addPrenotifiedDocumentListener(arg0); + } + + @Override + public int computeIndexInCategory(String arg0, int arg1) throws BadLocationException, BadPositionCategoryException { + return document.computeIndexInCategory(arg0, arg1); + } + + @Override + public int computeNumberOfLines(String arg0) { + return document.computeNumberOfLines(arg0); + } + + @Override + public ITypedRegion[] computePartitioning(int arg0, int arg1) throws BadLocationException { + return document.computePartitioning(arg0, arg1); + } + + @Override + public boolean containsPosition(String arg0, int arg1, int arg2) { + return document.containsPosition(arg0, arg1, arg2); + } + + @Override + public boolean containsPositionCategory(String arg0) { + return document.containsPositionCategory(arg0); + } + + @Override + public String get() { + String content = document.get(); + StringBuffer buffer = new StringBuffer(); + Charset latinCharset = Charset.forName("ISO-8859-1"); + ByteBuffer encodedUnknown = latinCharset.encode("?"); + for (int i = 0; i < content.length(); i++) { + char c = content.charAt(i); + if (latinCharset.encode(String.valueOf(c)).equals(encodedUnknown)) { + buffer.append(String.format("\\u%04x", (int) c)); + } else { + buffer.append(c); + } + } + return buffer.toString(); + } + + @Override + public String get(int arg0, int arg1) throws BadLocationException { + return document.get(arg0, arg1); + } + + @Override + public char getChar(int arg0) throws BadLocationException { + return document.getChar(arg0); + } + + @Override + public String getContentType(int arg0) throws BadLocationException { + return document.getContentType(arg0); + } + + @Override + public IDocumentPartitioner getDocumentPartitioner() { + return document.getDocumentPartitioner(); + } + + @Override + public String[] getLegalContentTypes() { + return document.getLegalContentTypes(); + } + + @Override + public String[] getLegalLineDelimiters() { + return document.getLegalLineDelimiters(); + } + + @Override + public int getLength() { + return document.getLength(); + } + + @Override + public String getLineDelimiter(int arg0) throws BadLocationException { + return document.getLineDelimiter(arg0); + } + + @Override + public IRegion getLineInformation(int arg0) throws BadLocationException { + return document.getLineInformation(arg0); + } + + @Override + public IRegion getLineInformationOfOffset(int arg0) throws BadLocationException { + return document.getLineInformationOfOffset(arg0); + } + + @Override + public int getLineLength(int arg0) throws BadLocationException { + return document.getLineLength(arg0); + } + + @Override + public int getLineOfOffset(int arg0) throws BadLocationException { + return document.getLineOfOffset(arg0); + } + + @Override + public int getLineOffset(int arg0) throws BadLocationException { + return document.getLineOffset(arg0); + } + + @Override + public int getNumberOfLines() { + return document.getNumberOfLines(); + } + + @Override + public int getNumberOfLines(int arg0, int arg1) throws BadLocationException { + return document.getNumberOfLines(arg0, arg1); + } + + @Override + public ITypedRegion getPartition(int arg0) throws BadLocationException { + return document.getPartition(arg0); + } + + @Override + public String[] getPositionCategories() { + return document.getPositionCategories(); + } + + @Override + public IPositionUpdater[] getPositionUpdaters() { + return document.getPositionUpdaters(); + } + + @Override + public Position[] getPositions(String arg0) throws BadPositionCategoryException { + return document.getPositions(arg0); + } + + @Override + public void insertPositionUpdater(IPositionUpdater arg0, int arg1) { + document.insertPositionUpdater(arg0, arg1); + } + + @Override + public void removeDocumentListener(IDocumentListener arg0) { + document.removeDocumentListener(arg0); + } + + @Override + public void removeDocumentPartitioningListener(IDocumentPartitioningListener arg0) { + document.removeDocumentPartitioningListener(arg0); + } + + @Override + public void removePosition(Position arg0) { + document.removePosition(arg0); + } + + @Override + public void removePosition(String arg0, Position arg1) throws BadPositionCategoryException { + document.removePosition(arg0, arg1); + } + + @Override + public void removePositionCategory(String arg0) throws BadPositionCategoryException { + document.removePositionCategory(arg0); + } + + @Override + public void removePositionUpdater(IPositionUpdater arg0) { + document.removePositionUpdater(arg0); + } + + @Override + public void removePrenotifiedDocumentListener(IDocumentListener arg0) { + document.removePrenotifiedDocumentListener(arg0); + } + + @Override + public void replace(int arg0, int arg1, String arg2) throws BadLocationException { + document.replace(arg0, arg1, arg2); + } + + @Override + @SuppressWarnings("deprecation") + public int search(int arg0, String arg1, boolean arg2, boolean arg3, boolean arg4) throws BadLocationException { + return document.search(arg0, arg1, arg2, arg3, arg4); + } + + @Override + public void set(String arg0) { + document.set(arg0); + } + + @Override + public void setDocumentPartitioner(IDocumentPartitioner arg0) { + document.setDocumentPartitioner(arg0); + } +} diff --git a/src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java b/src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java new file mode 100755 index 0000000..a5e255e --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java @@ -0,0 +1,47 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import org.eclipse.jface.text.rules.*; + +public class PropertiesPartitionScanner extends RuleBasedPartitionScanner { + + public final static String PROPERTIES_COMMENT = "__properties_comment"; + + public final static String PROPERTIES_ENTRY = "__properties_entry"; + + public PropertiesPartitionScanner() { + + IToken comment = new Token(PROPERTIES_COMMENT); + IToken entry = new Token(PROPERTIES_ENTRY); + + IPredicateRule[] rules = new IPredicateRule[2]; + + SingleLineRule commentRule = new SingleLineRule("#", null, comment, (char) 0, true); + commentRule.setColumnConstraint(0); + rules[0] = commentRule; + rules[1] = new SingleLineRule("=", null, entry, (char) 0, true); + + setPredicateRules(rules); + } +} diff --git a/src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java b/src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java new file mode 100755 index 0000000..0a19046 --- /dev/null +++ b/src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java @@ -0,0 +1,43 @@ +// Copyright (c) 2010 Piotr Wolny +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +package org.gildur.simplepropertieseditor.editor; + +import org.eclipse.ui.editors.text.TextEditor; + +public class SimplePropertiesEditor extends TextEditor { + + private ColorManager colorManager; + + public SimplePropertiesEditor() { + super(); + colorManager = new ColorManager(); + setSourceViewerConfiguration(new PropertiesConfiguration(colorManager)); + setDocumentProvider(new PropertiesDocumentProvider()); + } + + @Override + public void dispose() { + colorManager.dispose(); + super.dispose(); + } +}