mirror of
https://github.com/gildur/SimplePropertiesEditor.git
synced 2026-03-30 23:07:05 +09:00
initial commit
This commit is contained in:
7
.classpath
Executable file
7
.classpath
Executable file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
28
.project
Executable file
28
.project
Executable file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SimplePropertiesEditor</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
8
.settings/org.eclipse.jdt.core.prefs
Executable file
8
.settings/org.eclipse.jdt.core.prefs
Executable file
@@ -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
|
||||
13
META-INF/MANIFEST.MF
Executable file
13
META-INF/MANIFEST.MF
Executable file
@@ -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
|
||||
6
build.properties
Executable file
6
build.properties
Executable file
@@ -0,0 +1,6 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.,\
|
||||
icons/
|
||||
BIN
icons/icon.gif
Normal file
BIN
icons/icon.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 B |
17
plugin.xml
Executable file
17
plugin.xml
Executable file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.editors">
|
||||
<editor
|
||||
name="SimplePropertiesEditor"
|
||||
extensions="properties"
|
||||
icon="icons/icon.gif"
|
||||
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
|
||||
class="org.gildur.simplepropertieseditor.editor.SimplePropertiesEditor"
|
||||
id="org.gildur.simplepropertieseditor.editor.SimplePropertiesEditor">
|
||||
</editor>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
81
src/org/gildur/simplepropertieseditor/Activator.java
Executable file
81
src/org/gildur/simplepropertieseditor/Activator.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
50
src/org/gildur/simplepropertieseditor/editor/ColorManager.java
Executable file
50
src/org/gildur/simplepropertieseditor/editor/ColorManager.java
Executable file
@@ -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<RGB, Color> colorTable = new HashMap<RGB, Color>(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;
|
||||
}
|
||||
}
|
||||
34
src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java
Executable file
34
src/org/gildur/simplepropertieseditor/editor/PropertiesColorConstants.java
Executable file
@@ -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);
|
||||
}
|
||||
80
src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java
Executable file
80
src/org/gildur/simplepropertieseditor/editor/PropertiesConfiguration.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
70
src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java
Executable file
70
src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentProvider.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
279
src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java
Executable file
279
src/org/gildur/simplepropertieseditor/editor/PropertiesDocumentWrapper.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
47
src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java
Executable file
47
src/org/gildur/simplepropertieseditor/editor/PropertiesPartitionScanner.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
43
src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java
Executable file
43
src/org/gildur/simplepropertieseditor/editor/SimplePropertiesEditor.java
Executable file
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user