eclipse plugin: Migrate 'org.wesnoth.wml.ui' project...

...to 'org.wesnoth.ui'
This commit is contained in:
Timotei Dolean 2011-07-05 08:54:46 +00:00
parent be287286bd
commit a3613b9e11
64 changed files with 16544 additions and 0 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.wesnoth.ui</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.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,67 @@
#Sun Apr 10 14:12:17 EEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning

View file

@ -0,0 +1,22 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.wesnoth.ui
Bundle-Vendor: www.wesnoth.org
Bundle-Version: 1.0.3
Bundle-SymbolicName: org.wesnoth.ui;singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.wesnoth;visibility:=reexport,
org.eclipse.xtext.ui,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.eclipse.xtext.ui.shared,
org.eclipse.ui,
org.eclipse.xtext.builder,
org.antlr.runtime,
org.eclipse.xtext.xtext.ui;bundle-version="1.0.0",
org.eclipse.core.filesystem;bundle-version="1.3.0",
org.wesnoth;bundle-version="1.0.0"
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.wesnoth.ui.contentassist.antlr
Bundle-Activator: org.wesnoth.ui.internal.WMLActivator

View file

@ -0,0 +1,7 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
javacSource=1.6
javacTarget=1.6

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

View file

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="cfg"
icon="icons/wesnoth-icon_16.png"
id="org.wesnoth.WML"
name="WML Editor">
</editor>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclarationHandler"
commandId="org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclaration">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.handler.ValidateActionHandler"
commandId="org.wesnoth.WML.validate">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.core.expressions.definitions">
<definition id="org.wesnoth.WML.Editor.opened">
<and>
<reference definitionId="isActiveEditorAnInstanceOfXtextEditor"/>
<with variable="activeEditor">
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
value="org.wesnoth.WML"
forcePluginActivation="true"/>
</with>
</and>
</definition>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.preferences.LanguageRootPreferencePage"
id="org.wesnoth.WML"
name="Wesnoth WML">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
<page
category="org.wesnoth.WML"
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.syntaxcoloring.SyntaxColoringPreferencePage"
id="org.wesnoth.WML.coloring"
name="Syntax Coloring">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
<page
category="org.wesnoth.WML"
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.templates.XtextTemplatePreferencePage"
id="org.wesnoth.WML.templates"
name="Templates">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
</extension>
<extension
point="org.eclipse.ui.keywords">
<keyword
id="org.wesnoth.ui.keyword_WML"
label="WML"/>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Trigger expensive validation"
id="org.wesnoth.WML.validate"
name="Validate">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#TextEditorContext?after=group.edit">
<command
commandId="org.wesnoth.WML.validate"
style="push"
tooltip="Trigger expensive validation">
<visibleWhen checkEnabled="false">
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?endof=group.find">
<command commandId="org.eclipse.xtext.ui.editor.FindReferences">
<visibleWhen checkEnabled="false">
<reference definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler"
commandId="org.eclipse.xtext.ui.editor.FindReferences">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<!-- adding resource factories -->
<extension
point="org.eclipse.emf.ecore.extension_parser">
<parser
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.resource.IResourceFactory"
type="cfg">
</parser>
</extension>
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
<resourceServiceProvider
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
uriExtension="cfg">
</resourceServiceProvider>
</extension>
<!-- Quick Outline -->
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.outline.quickoutline.ShowQuickOutlineActionHandler"
commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Open the quick outline."
id="org.eclipse.xtext.ui.editor.outline.QuickOutline"
name="Quick Outline">
</command>
<command
categoryId="org.eclipse.xtext.ui.category.XtextEditor"
defaultHandler="org.wesnoth.ui.labeling.wmldoc.WMLDocHandler"
description="Shows WML Documentation for active resource"
id="org.wesnoth.wml.ui.showWMLDoc"
name="Shows WML Documentation">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#TextEditorContext?after=group.open">
<command commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline"
style="push"
tooltip="Open Quick Outline">
<visibleWhen checkEnabled="false">
<reference definitionId="org.wesnoth.WML.Editor.opened"/>
</visibleWhen>
</command>
</menuContribution>
</extension>
<!-- quickfix marker resolution generator -->
<extension
point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator">
</markerResolutionGenerator>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="org.wesnoth.wml.ui.showWMLDoc"
contextId="org.eclipse.xtext.ui.XtextEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F2">
</key>
</extension>
</plugin>

View file

@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
default="true"
extensions="cfg"
id="org.wesnoth.WML"
name="WML Editor">
</editor>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclarationHandler"
commandId="org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclaration">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.handler.ValidateActionHandler"
commandId="org.wesnoth.WML.validate">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<extension point="org.eclipse.core.expressions.definitions">
<definition id="org.wesnoth.WML.Editor.opened">
<and>
<reference definitionId="isActiveEditorAnInstanceOfXtextEditor"/>
<with variable="activeEditor">
<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
value="org.wesnoth.WML"
forcePluginActivation="true"/>
</with>
</and>
</definition>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.preferences.LanguageRootPreferencePage"
id="org.wesnoth.WML"
name="WML">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
<page
category="org.wesnoth.WML"
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.syntaxcoloring.SyntaxColoringPreferencePage"
id="org.wesnoth.WML.coloring"
name="Syntax Coloring">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
<page
category="org.wesnoth.WML"
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.templates.XtextTemplatePreferencePage"
id="org.wesnoth.WML.templates"
name="Templates">
<keywordReference id="org.wesnoth.ui.keyword_WML"/>
</page>
</extension>
<extension
point="org.eclipse.ui.keywords">
<keyword
id="org.wesnoth.ui.keyword_WML"
label="WML"/>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Trigger expensive validation"
id="org.wesnoth.WML.validate"
name="Validate">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#TextEditorContext?after=group.edit">
<command
commandId="org.wesnoth.WML.validate"
style="push"
tooltip="Trigger expensive validation">
<visibleWhen checkEnabled="false">
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?endof=group.find">
<command commandId="org.eclipse.xtext.ui.editor.FindReferences">
<visibleWhen checkEnabled="false">
<reference definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler"
commandId="org.eclipse.xtext.ui.editor.FindReferences">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<!-- adding resource factories -->
<extension
point="org.eclipse.emf.ecore.extension_parser">
<parser
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.resource.IResourceFactory"
type="cfg">
</parser>
</extension>
<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
<resourceServiceProvider
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
uriExtension="cfg">
</resourceServiceProvider>
</extension>
<!-- Quick Outline -->
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.outline.quickoutline.ShowQuickOutlineActionHandler"
commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline">
<activeWhen>
<reference
definitionId="org.wesnoth.WML.Editor.opened">
</reference>
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Open the quick outline."
id="org.eclipse.xtext.ui.editor.outline.QuickOutline"
name="Quick Outline">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:#TextEditorContext?after=group.open">
<command commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline"
style="push"
tooltip="Open Quick Outline">
<visibleWhen checkEnabled="false">
<reference definitionId="org.wesnoth.WML.Editor.opened"/>
</visibleWhen>
</command>
</menuContribution>
</extension>
<!-- quickfix marker resolution generator -->
<extension
point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="org.wesnoth.ui.WMLExecutableExtensionFactory:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator">
</markerResolutionGenerator>
</extension>
</plugin>

View file

@ -0,0 +1,127 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui;
import org.eclipse.xtext.ui.DefaultUiModule;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* Manual modifications go to {org.wesnoth.ui.WMLUiModule}
*/
@SuppressWarnings("all")
public abstract class AbstractWMLUiModule extends DefaultUiModule {
public AbstractWMLUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
// contributed by org.eclipse.xtext.ui.generator.ImplicitUiFragment
public com.google.inject.Provider<org.eclipse.xtext.resource.containers.IAllContainersState> provideIAllContainersState() {
return org.eclipse.xtext.ui.shared.Access.getJavaProjectsState();
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment
public Class<? extends org.eclipse.jface.text.rules.ITokenScanner> bindITokenScanner() {
return org.eclipse.xtext.ui.editor.syntaxcoloring.antlr.AntlrTokenScanner.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment
public Class<? extends org.eclipse.xtext.ui.editor.contentassist.IProposalConflictHelper> bindIProposalConflictHelper() {
return org.eclipse.xtext.ui.editor.contentassist.antlr.AntlrProposalConflictHelper.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment
public Class<? extends org.eclipse.xtext.ui.editor.IDamagerRepairer> bindIDamagerRepairer() {
return org.eclipse.xtext.ui.editor.FastDamagerRepairer.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment
public void configureHighlightingLexer(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.parser.antlr.Lexer.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.ui.LexerUIBindings.HIGHLIGHTING)).to(org.wesnoth.parser.antlr.internal.InternalWMLLexer.class);
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment
public void configureHighlightingTokenDefProvider(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.parser.antlr.ITokenDefProvider.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.ui.LexerUIBindings.HIGHLIGHTING)).to(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider.class);
}
// contributed by org.eclipse.xtext.generator.exporting.QualifiedNamesFragment
public Class<? extends org.eclipse.xtext.ui.editor.contentassist.PrefixMatcher> bindPrefixMatcher() {
return org.eclipse.xtext.ui.editor.contentassist.FQNPrefixMatcher.class;
}
// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
public void configureIResourceDescriptionsBuilderScope(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractGlobalScopeProvider.NAMED_BUILDER_SCOPE)).to(org.eclipse.xtext.builder.builderState.ShadowingResourceDescriptions.class);
}
// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
public Class<? extends org.eclipse.xtext.ui.editor.IXtextEditorCallback> bindIXtextEditorCallback() {
return org.eclipse.xtext.builder.nature.NatureAddingEditorCallback.class;
}
// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
public void configureIResourceDescriptionsPersisted(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.builder.impl.PersistentDataAwareDirtyResource.PERSISTED_DESCRIPTIONS)).to(org.eclipse.xtext.builder.builderState.IBuilderState.class);
}
// contributed by org.eclipse.xtext.generator.builder.BuilderIntegrationFragment
public Class<? extends org.eclipse.xtext.ui.editor.DocumentBasedDirtyResource> bindDocumentBasedDirtyResource() {
return org.eclipse.xtext.builder.impl.PersistentDataAwareDirtyResource.class;
}
// contributed by org.eclipse.xtext.ui.generator.labeling.LabelProviderFragment
public Class<? extends org.eclipse.jface.viewers.ILabelProvider> bindILabelProvider() {
return org.wesnoth.ui.labeling.WMLLabelProvider.class;
}
// contributed by org.eclipse.xtext.ui.generator.labeling.LabelProviderFragment
public void configureResourceUIServiceLabelProvider(com.google.inject.Binder binder) {
binder.bind(org.eclipse.jface.viewers.ILabelProvider.class).annotatedWith(org.eclipse.xtext.ui.resource.ResourceServiceDescriptionLabelProvider.class).to(org.wesnoth.ui.labeling.WMLDescriptionLabelProvider.class);
}
// contributed by org.eclipse.xtext.ui.generator.outline.TransformerFragment
public Class<? extends org.eclipse.xtext.ui.editor.outline.transformer.ISemanticModelTransformer> bindISemanticModelTransformer() {
return org.wesnoth.ui.outline.WMLTransformer.class;
}
// contributed by org.eclipse.xtext.ui.generator.outline.OutlineNodeAdapterFactoryFragment
public Class<? extends org.eclipse.xtext.ui.editor.outline.actions.IContentOutlineNodeAdapterFactory> bindIContentOutlineNodeAdapterFactory() {
return org.wesnoth.ui.outline.WMLOutlineNodeAdapterFactory.class;
}
// contributed by org.eclipse.xtext.ui.generator.quickfix.QuickfixProviderFragment
public Class<? extends org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider> bindIssueResolutionProvider() {
return org.wesnoth.ui.quickfix.WMLQuickfixProvider.class;
}
// contributed by org.eclipse.xtext.ui.generator.contentAssist.JavaBasedContentAssistFragment
public Class<? extends org.eclipse.xtext.ui.editor.contentassist.IContentProposalProvider> bindIContentProposalProvider() {
return org.wesnoth.ui.contentassist.WMLProposalProvider.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment
public Class<? extends org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext.Factory> bindContentAssistContext$Factory() {
return org.eclipse.xtext.ui.editor.contentassist.antlr.ParserBasedContentAssistContextFactory.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment
public Class<? extends org.eclipse.xtext.ui.editor.contentassist.antlr.IContentAssistParser> bindIContentAssistParser() {
return org.wesnoth.ui.contentassist.antlr.WMLParser.class;
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment
public void configureContentAssistLexerProvider(com.google.inject.Binder binder) {
binder.bind(org.wesnoth.ui.contentassist.antlr.internal.InternalWMLLexer.class).toProvider(org.eclipse.xtext.parser.antlr.LexerProvider.create(org.wesnoth.ui.contentassist.antlr.internal.InternalWMLLexer.class));
}
// contributed by org.eclipse.xtext.generator.parser.antlr.XtextAntlrUiGeneratorFragment
public void configureContentAssistLexer(com.google.inject.Binder binder) {
binder.bind(org.eclipse.xtext.ui.editor.contentassist.antlr.internal.Lexer.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.ui.LexerUIBindings.CONTENT_ASSIST)).to(org.wesnoth.ui.contentassist.antlr.internal.InternalWMLLexer.class);
}
}

View file

@ -0,0 +1,28 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui;
import org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory;
import org.osgi.framework.Bundle;
import com.google.inject.Injector;
/**
*@generated
*/
public class WMLExecutableExtensionFactory extends AbstractGuiceAwareExecutableExtensionFactory {
@Override
protected Bundle getBundle() {
return org.wesnoth.ui.internal.WMLActivator.getInstance().getBundle();
}
@Override
protected Injector getInjector() {
return org.wesnoth.ui.internal.WMLActivator.getInstance().getInjector("org.wesnoth.WML");
}
}

View file

@ -0,0 +1,262 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui.contentassist;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.*;
import org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
/**
* Represents a generated, default implementation of interface {@link IProposalProvider}.
* Methods are dynamically dispatched on the first parameter, i.e., you can override them
* with a more concrete subtype.
*/
@SuppressWarnings("all")
public class AbstractWMLProposalProvider extends AbstractJavaBasedContentProposalProvider {
public void completeWMLRoot_Tags(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLRoot_MacroCalls(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLRoot_MacroDefines(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLRoot_Textdomains(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLRoot_IfDefs(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_Plus(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void completeWMLTag_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_Tags(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_Keys(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_MacroCalls(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_MacroDefines(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_Textdomains(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_IfDefs(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTag_EndName(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLKey_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLKey_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLKey_Eol(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(0)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(1)), context, acceptor);
}
public void completeWMLMacroCall_Point(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void completeWMLMacroCall_Relative(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void completeWMLMacroCall_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroCall_Params(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(0)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(1)), context, acceptor);
}
public void completeWMLMacroCall_ExtraMacros(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLLuaCode_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLArrayCall_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_Tags(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_Keys(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_MacroCalls(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_MacroDefines(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_Textdomains(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_Values(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_IfDefs(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLMacroDefine_EndName(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(0)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(1)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(2)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(3)), context, acceptor);
}
public void completeWMLPreprocIF_Tags(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_Keys(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_MacroCalls(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_MacroDefines(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_Textdomains(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_Values(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_IfDefs(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_Elses(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLPreprocIF_EndName(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLTextdomain_Name(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
}
public void completeWMLValue_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(0)), context, acceptor);
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(1)), context, acceptor);
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(10)), context, acceptor);
}
public void completeMacroTokens_Val(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
// subclasses may override
}
public void complete_WMLRoot(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLTag(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLKey(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLKeyValue(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLMacroCall(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLLuaCode(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLArrayCall(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLMacroDefine(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLPreprocIF(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLTextdomain(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WMLValue(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_MacroTokens(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_LUA_CODE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_IFHAVE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_IFNHAVE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_IFDEF(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_IFNDEF(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_ELSE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_ENDIF(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_DEFINE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_ENDDEF(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_TEXTDOMAIN(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_STRING(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_EOL(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_WS(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_ANY_OTHER(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
public void complete_SL_COMMENT(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}
}

View file

@ -0,0 +1,134 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui.contentassist.antlr;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import org.antlr.runtime.RecognitionException;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.ui.editor.contentassist.antlr.AbstractContentAssistParser;
import org.eclipse.xtext.ui.editor.contentassist.antlr.FollowElement;
import org.eclipse.xtext.ui.editor.contentassist.antlr.internal.AbstractInternalContentAssistParser;
import com.google.inject.Inject;
import org.wesnoth.services.WMLGrammarAccess;
public class WMLParser extends AbstractContentAssistParser {
@Inject
private WMLGrammarAccess grammarAccess;
private Map<AbstractElement, String> nameMappings;
@Override
protected org.wesnoth.ui.contentassist.antlr.internal.InternalWMLParser createParser() {
org.wesnoth.ui.contentassist.antlr.internal.InternalWMLParser result = new org.wesnoth.ui.contentassist.antlr.internal.InternalWMLParser(null);
result.setGrammarAccess(grammarAccess);
return result;
}
@Override
protected String getRuleName(AbstractElement element) {
if (nameMappings == null) {
nameMappings = new HashMap<AbstractElement, String>() {
private static final long serialVersionUID = 1L;
{
put(grammarAccess.getWMLRootAccess().getAlternatives(), "rule__WMLRoot__Alternatives");
put(grammarAccess.getWMLTagAccess().getAlternatives_4(), "rule__WMLTag__Alternatives_4");
put(grammarAccess.getWMLKeyAccess().getEolAlternatives_4_0(), "rule__WMLKey__EolAlternatives_4_0");
put(grammarAccess.getWMLKeyValueAccess().getAlternatives(), "rule__WMLKeyValue__Alternatives");
put(grammarAccess.getWMLMacroCallAccess().getAlternatives_4(), "rule__WMLMacroCall__Alternatives_4");
put(grammarAccess.getWMLMacroCallAccess().getParamsAlternatives_4_0_0(), "rule__WMLMacroCall__ParamsAlternatives_4_0_0");
put(grammarAccess.getWMLMacroDefineAccess().getAlternatives_1(), "rule__WMLMacroDefine__Alternatives_1");
put(grammarAccess.getWMLPreprocIFAccess().getNameAlternatives_0_0(), "rule__WMLPreprocIF__NameAlternatives_0_0");
put(grammarAccess.getWMLPreprocIFAccess().getAlternatives_1(), "rule__WMLPreprocIF__Alternatives_1");
put(grammarAccess.getWMLValueAccess().getValueAlternatives_0(), "rule__WMLValue__ValueAlternatives_0");
put(grammarAccess.getMacroTokensAccess().getValAlternatives_0(), "rule__MacroTokens__ValAlternatives_0");
put(grammarAccess.getWMLTagAccess().getGroup(), "rule__WMLTag__Group__0");
put(grammarAccess.getWMLKeyAccess().getGroup(), "rule__WMLKey__Group__0");
put(grammarAccess.getWMLKeyAccess().getGroup_3(), "rule__WMLKey__Group_3__0");
put(grammarAccess.getWMLMacroCallAccess().getGroup(), "rule__WMLMacroCall__Group__0");
put(grammarAccess.getWMLArrayCallAccess().getGroup(), "rule__WMLArrayCall__Group__0");
put(grammarAccess.getWMLMacroDefineAccess().getGroup(), "rule__WMLMacroDefine__Group__0");
put(grammarAccess.getWMLPreprocIFAccess().getGroup(), "rule__WMLPreprocIF__Group__0");
put(grammarAccess.getWMLRootAccess().getTagsAssignment_0(), "rule__WMLRoot__TagsAssignment_0");
put(grammarAccess.getWMLRootAccess().getMacroCallsAssignment_1(), "rule__WMLRoot__MacroCallsAssignment_1");
put(grammarAccess.getWMLRootAccess().getMacroDefinesAssignment_2(), "rule__WMLRoot__MacroDefinesAssignment_2");
put(grammarAccess.getWMLRootAccess().getTextdomainsAssignment_3(), "rule__WMLRoot__TextdomainsAssignment_3");
put(grammarAccess.getWMLRootAccess().getIfDefsAssignment_4(), "rule__WMLRoot__IfDefsAssignment_4");
put(grammarAccess.getWMLTagAccess().getPlusAssignment_1(), "rule__WMLTag__PlusAssignment_1");
put(grammarAccess.getWMLTagAccess().getNameAssignment_2(), "rule__WMLTag__NameAssignment_2");
put(grammarAccess.getWMLTagAccess().getTagsAssignment_4_0(), "rule__WMLTag__TagsAssignment_4_0");
put(grammarAccess.getWMLTagAccess().getKeysAssignment_4_1(), "rule__WMLTag__KeysAssignment_4_1");
put(grammarAccess.getWMLTagAccess().getMacroCallsAssignment_4_2(), "rule__WMLTag__MacroCallsAssignment_4_2");
put(grammarAccess.getWMLTagAccess().getMacroDefinesAssignment_4_3(), "rule__WMLTag__MacroDefinesAssignment_4_3");
put(grammarAccess.getWMLTagAccess().getTextdomainsAssignment_4_4(), "rule__WMLTag__TextdomainsAssignment_4_4");
put(grammarAccess.getWMLTagAccess().getIfDefsAssignment_4_5(), "rule__WMLTag__IfDefsAssignment_4_5");
put(grammarAccess.getWMLTagAccess().getEndNameAssignment_6(), "rule__WMLTag__EndNameAssignment_6");
put(grammarAccess.getWMLKeyAccess().getNameAssignment_0(), "rule__WMLKey__NameAssignment_0");
put(grammarAccess.getWMLKeyAccess().getValueAssignment_2(), "rule__WMLKey__ValueAssignment_2");
put(grammarAccess.getWMLKeyAccess().getValueAssignment_3_3(), "rule__WMLKey__ValueAssignment_3_3");
put(grammarAccess.getWMLKeyAccess().getEolAssignment_4(), "rule__WMLKey__EolAssignment_4");
put(grammarAccess.getWMLMacroCallAccess().getPointAssignment_1(), "rule__WMLMacroCall__PointAssignment_1");
put(grammarAccess.getWMLMacroCallAccess().getRelativeAssignment_2(), "rule__WMLMacroCall__RelativeAssignment_2");
put(grammarAccess.getWMLMacroCallAccess().getNameAssignment_3(), "rule__WMLMacroCall__NameAssignment_3");
put(grammarAccess.getWMLMacroCallAccess().getParamsAssignment_4_0(), "rule__WMLMacroCall__ParamsAssignment_4_0");
put(grammarAccess.getWMLMacroCallAccess().getExtraMacrosAssignment_4_1(), "rule__WMLMacroCall__ExtraMacrosAssignment_4_1");
put(grammarAccess.getWMLLuaCodeAccess().getValueAssignment(), "rule__WMLLuaCode__ValueAssignment");
put(grammarAccess.getWMLArrayCallAccess().getValueAssignment_1(), "rule__WMLArrayCall__ValueAssignment_1");
put(grammarAccess.getWMLMacroDefineAccess().getNameAssignment_0(), "rule__WMLMacroDefine__NameAssignment_0");
put(grammarAccess.getWMLMacroDefineAccess().getTagsAssignment_1_0(), "rule__WMLMacroDefine__TagsAssignment_1_0");
put(grammarAccess.getWMLMacroDefineAccess().getKeysAssignment_1_1(), "rule__WMLMacroDefine__KeysAssignment_1_1");
put(grammarAccess.getWMLMacroDefineAccess().getMacroCallsAssignment_1_2(), "rule__WMLMacroDefine__MacroCallsAssignment_1_2");
put(grammarAccess.getWMLMacroDefineAccess().getMacroDefinesAssignment_1_3(), "rule__WMLMacroDefine__MacroDefinesAssignment_1_3");
put(grammarAccess.getWMLMacroDefineAccess().getTextdomainsAssignment_1_4(), "rule__WMLMacroDefine__TextdomainsAssignment_1_4");
put(grammarAccess.getWMLMacroDefineAccess().getValuesAssignment_1_5(), "rule__WMLMacroDefine__ValuesAssignment_1_5");
put(grammarAccess.getWMLMacroDefineAccess().getIfDefsAssignment_1_6(), "rule__WMLMacroDefine__IfDefsAssignment_1_6");
put(grammarAccess.getWMLMacroDefineAccess().getEndNameAssignment_2(), "rule__WMLMacroDefine__EndNameAssignment_2");
put(grammarAccess.getWMLPreprocIFAccess().getNameAssignment_0(), "rule__WMLPreprocIF__NameAssignment_0");
put(grammarAccess.getWMLPreprocIFAccess().getTagsAssignment_1_0(), "rule__WMLPreprocIF__TagsAssignment_1_0");
put(grammarAccess.getWMLPreprocIFAccess().getKeysAssignment_1_1(), "rule__WMLPreprocIF__KeysAssignment_1_1");
put(grammarAccess.getWMLPreprocIFAccess().getMacroCallsAssignment_1_2(), "rule__WMLPreprocIF__MacroCallsAssignment_1_2");
put(grammarAccess.getWMLPreprocIFAccess().getMacroDefinesAssignment_1_3(), "rule__WMLPreprocIF__MacroDefinesAssignment_1_3");
put(grammarAccess.getWMLPreprocIFAccess().getTextdomainsAssignment_1_4(), "rule__WMLPreprocIF__TextdomainsAssignment_1_4");
put(grammarAccess.getWMLPreprocIFAccess().getValuesAssignment_1_5(), "rule__WMLPreprocIF__ValuesAssignment_1_5");
put(grammarAccess.getWMLPreprocIFAccess().getIfDefsAssignment_1_6(), "rule__WMLPreprocIF__IfDefsAssignment_1_6");
put(grammarAccess.getWMLPreprocIFAccess().getElsesAssignment_1_7(), "rule__WMLPreprocIF__ElsesAssignment_1_7");
put(grammarAccess.getWMLPreprocIFAccess().getEndNameAssignment_2(), "rule__WMLPreprocIF__EndNameAssignment_2");
put(grammarAccess.getWMLTextdomainAccess().getNameAssignment(), "rule__WMLTextdomain__NameAssignment");
put(grammarAccess.getWMLValueAccess().getValueAssignment(), "rule__WMLValue__ValueAssignment");
put(grammarAccess.getMacroTokensAccess().getValAssignment(), "rule__MacroTokens__ValAssignment");
}
};
}
return nameMappings.get(element);
}
@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
try {
org.wesnoth.ui.contentassist.antlr.internal.InternalWMLParser typedParser = (org.wesnoth.ui.contentassist.antlr.internal.InternalWMLParser) parser;
typedParser.entryRuleWMLRoot();
return typedParser.getFollowElements();
} catch(RecognitionException ex) {
throw new RuntimeException(ex);
}
}
@Override
protected String[] getInitialHiddenTokens() {
return new String[] { "RULE_EOL", "RULE_WS", "RULE_SL_COMMENT" };
}
public WMLGrammarAccess getGrammarAccess() {
return this.grammarAccess;
}
public void setGrammarAccess(WMLGrammarAccess grammarAccess) {
this.grammarAccess = grammarAccess;
}
}

View file

@ -0,0 +1,31 @@
RULE_LUA_CODE=13
RULE_IFDEF=6
RULE_ID=10
RULE_ANY_OTHER=12
RULE_IFNDEF=7
RULE_EOL=4
RULE_TEXTDOMAIN=18
RULE_IFNHAVE=9
RULE_SL_COMMENT=5
RULE_STRING=11
RULE_ENDIF=17
RULE_DEFINE=14
RULE_ENDDEF=15
RULE_IFHAVE=8
RULE_WS=19
RULE_ELSE=16
'$'=24
'}'=34
'~'=21
'/'=25
'{'=33
'='=28
'('=26
'['=29
'[/'=32
'+'=31
'_'=20
'.'=22
')'=27
'./'=23
']'=30

View file

@ -0,0 +1,74 @@
lexer grammar InternalWML;
@header {
package org.wesnoth.ui.contentassist.antlr.internal;
// Hack: Use our own Lexer superclass by means of import.
// Currently there is no other way to specify the superclass for the lexer.
import org.eclipse.xtext.ui.editor.contentassist.antlr.internal.Lexer;
}
T20 : '_' ;
T21 : '~' ;
T22 : '.' ;
T23 : './' ;
T24 : '$' ;
T25 : '/' ;
T26 : '(' ;
T27 : ')' ;
T28 : '=' ;
T29 : '[' ;
T30 : ']' ;
T31 : '+' ;
T32 : '[/' ;
T33 : '{' ;
T34 : '}' ;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2634
RULE_LUA_CODE : '<<' ( options {greedy=false;} : . )*'>>';
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2636
RULE_IFHAVE : '#ifhave' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2638
RULE_IFNHAVE : '#ifnhave' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2640
RULE_IFDEF : '#ifdef' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2642
RULE_IFNDEF : '#ifndef' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2644
RULE_ELSE : '#else' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2646
RULE_ENDIF : '#endif' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2648
RULE_DEFINE : '#define' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2650
RULE_ENDDEF : '#enddef' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2652
RULE_TEXTDOMAIN : '#textdomain' ~(('\n'|'\r'))* ('\r'? '\n')?;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2654
RULE_STRING : '"' ('\\' ('b'|'t'|'n'|'f'|'r'|'"'|'\''|'\\')|~(('\\'|'"')))* '"';
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2656
RULE_ID : ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-'|',')+;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2658
RULE_EOL : ('\r'|'\n');
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2660
RULE_WS : (' '|'\t')+;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2662
RULE_ANY_OTHER : .;
// $ANTLR src "../org.wesnoth.ui/src-gen/org/wesnoth/ui/contentassist/antlr/internal/InternalWML.g" 2664
RULE_SL_COMMENT : '#' ~(('\n'|'\r'))* ('\r'? '\n')?;

View file

@ -0,0 +1,73 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui.internal;
import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;
import java.util.Map;
import java.util.HashMap;
/**
* Generated
*/
public class WMLActivator extends AbstractUIPlugin {
private Map<String,Injector> injectors = new HashMap<String,Injector>();
private static WMLActivator INSTANCE;
public Injector getInjector(String languageName) {
return injectors.get(languageName);
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
INSTANCE = this;
try {
injectors.put("org.wesnoth.WML", Guice.createInjector(
Modules.override(Modules.override(getRuntimeModule("org.wesnoth.WML")).with(getUiModule("org.wesnoth.WML"))).with(getSharedStateModule())
));
} catch (Exception e) {
Logger.getLogger(getClass()).error(e.getMessage(), e);
throw e;
}
}
public static WMLActivator getInstance() {
return INSTANCE;
}
protected Module getRuntimeModule(String grammar) {
if ("org.wesnoth.WML".equals(grammar)) {
return new org.wesnoth.WMLRuntimeModule();
}
throw new IllegalArgumentException(grammar);
}
protected Module getUiModule(String grammar) {
if ("org.wesnoth.WML".equals(grammar)) {
return new org.wesnoth.ui.WMLUiModule(this);
}
throw new IllegalArgumentException(grammar);
}
protected Module getSharedStateModule() {
return new org.eclipse.xtext.ui.shared.SharedStateModule();
}
}

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS
{
private static final String BUNDLE_NAME = "org.wesnoth.ui.messages"; //$NON-NLS-1$
public static String WMLDocMacro_0;
public static String WMLDocMacro_1;
public static String WMLDocMacro_2;
public static String WMLDocTag_0;
public static String WMLDocTag_1;
public static String WMLEditor_0;
public static String WMLEditor_1;
public static String WMLEditor_2;
public static String WMLEditor_3;
public static String WMLEditor_4;
public static String WMLEditor_5;
public static String WMLHighlightingConfiguration_10;
public static String WMLHighlightingConfiguration_11;
public static String WMLHighlightingConfiguration_12;
public static String WMLHighlightingConfiguration_13;
public static String WMLHighlightingConfiguration_7;
public static String WMLHighlightingConfiguration_8;
public static String WMLHighlightingConfiguration_9;
public static String WMLHyperlinkHelper_0;
static
{
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
private Messages()
{
}
}

View file

@ -0,0 +1,155 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.xtext.resource.ILocationInFileProvider;
import org.eclipse.xtext.resource.containers.IAllContainersState;
import org.eclipse.xtext.ui.editor.IXtextEditorCallback;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.autoedit.DefaultAutoEditStrategy;
import org.eclipse.xtext.ui.editor.bracketmatching.IBracketMatcher;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalComparator;
import org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider;
import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingHelper;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.editor.syntaxcoloring.antlr.AbstractAntlrTokenToAttributeIdMapper;
import org.wesnoth.ui.autoedit.WMLAutoEditStrategy;
import org.wesnoth.ui.contentassist.WMLContentAssistContext;
import org.wesnoth.ui.contentassist.WMLProposalComparator;
import org.wesnoth.ui.editor.WMLAbstractDirtyEditorCallback;
import org.wesnoth.ui.editor.WMLEditor;
import org.wesnoth.ui.folding.WMLFoldingRegionProvider;
import org.wesnoth.ui.labeling.WMLLabelProvider;
import org.wesnoth.ui.navigation.WMLHyperlinkHelper;
import org.wesnoth.ui.resource.WMLLocationInFileProvider;
import org.wesnoth.ui.syntax.WMLAntlrTokenToAttributeIdMapper;
import org.wesnoth.ui.syntax.WMLHighlightingConfiguration;
import org.wesnoth.ui.syntax.WMLHighlightingHelper;
import org.wesnoth.ui.syntax.WMLHighlightingReconciler;
import org.wesnoth.ui.syntax.WMLSemanticHighlightingCalculator;
import org.wesnoth.ui.syntax.bracketmatching.WMLBracketMatching;
import com.google.inject.Binder;
import com.google.inject.Provider;
/**
* Use this class to register components to be used within the IDE.
*/
@SuppressWarnings("all")
public class WMLUiModule extends org.wesnoth.ui.AbstractWMLUiModule
{
public final static boolean DEBUG = false;
public WMLUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
@Override
public void configure(Binder binder)
{
super.configure(binder);
}
public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration()
{
return WMLHighlightingConfiguration.class;
}
public Class<? extends AbstractAntlrTokenToAttributeIdMapper> bindTokenToAttributeIdMapper()
{
return WMLAntlrTokenToAttributeIdMapper.class;
}
public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator()
{
return WMLSemanticHighlightingCalculator.class;
}
public Class<? extends IBracketMatcher> bindIBracketMatcher()
{
// XtextGrammarBracketMatcher
return WMLBracketMatching.class;
}
public Class<? extends XtextEditor> bindEditor()
{
return WMLEditor.class;
}
public Class<? extends IHighlightingHelper> bindIHighlightingHelper()
{
return WMLHighlightingHelper.class;
}
public Class<? extends HighlightingReconciler> bindHighlightingReconciler()
{
return WMLHighlightingReconciler.class;
}
public Class<? extends ILocationInFileProvider> bindILocationInFileProvider()
{
return WMLLocationInFileProvider.class;
}
@Override
public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector()
{
return super.bindIHyperlinkDetector();
}
public Class<? extends HyperlinkHelper> bindHyperlinkHelper()
{
return WMLHyperlinkHelper.class;
}
public Class<? extends ContentAssistContext> bindContentAssistContext()
{
return WMLContentAssistContext.class;
}
public Class<? extends ICompletionProposalComparator> bindICompletionProposalComparator()
{
return WMLProposalComparator.class;
}
public Class<? extends DefaultAutoEditStrategy> bindAutoEditStrategy()
{
return WMLAutoEditStrategy.class;
}
@Override
public Class<? extends ILabelProvider> bindILabelProvider()
{
return WMLLabelProvider.class;
}
@Override
public Class<? extends IXtextEditorCallback> bindIXtextEditorCallback()
{
return WMLAbstractDirtyEditorCallback.class;
}
public Class<? extends DefaultFoldingRegionProvider> bindDefaultFoldingRegionProvider()
{
return WMLFoldingRegionProvider.class;
}
@Override
public Provider<IAllContainersState> provideIAllContainersState()
{
return org.eclipse.xtext.ui.shared.Access.getWorkspaceProjectsState();
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
public class WMLUtil
{
public static String debug(EObject root)
{
CompositeNode node = NodeUtil.getNode(root);
Iterable<AbstractNode> contents = NodeUtil.getAllContents(node);
StringBuffer text = new StringBuffer();
for (AbstractNode abstractNode : contents)
{
if (abstractNode instanceof LeafNode)
{
System.out.println((((LeafNode) abstractNode).getText()));
text.append(((LeafNode) abstractNode).getText());
}
}
return text.toString();
}
/**
* Gets current edited file
* @return
*/
public static IFile getActiveEditorFile()
{
if (EditorUtils.getActiveXtextEditor() == null)
return null;
return (IFile)EditorUtils.getActiveXtextEditor()
.getEditorInput().getAdapter(IFile.class);
}
}

View file

@ -0,0 +1,90 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.autoedit;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
/**
* Strategy that tries to close the nearest unclosed tag
*/
public class ClosingEndTagAutoEditStrategy implements IAutoEditStrategy
{
public void customizeDocumentCommand(final IDocument document,
final DocumentCommand command)
{
try
{
if (command.text.equals("/") && document.get(command.offset-1, 1).equals("[")) //$NON-NLS-1$ //$NON-NLS-2$
{
XtextEditor editor = EditorUtils.getActiveXtextEditor();
if (editor == null)
return;
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>(){
@Override
public void process(XtextResource state) throws Exception
{
IParseResult parseResult = state.getParseResult();
if(parseResult == null)
return;
CompositeNode rootNode = parseResult.getRootNode();
LeafNode node = (LeafNode) NodeUtil.findLeafNodeAtOffset(rootNode, command.offset);
String tagName = ""; //$NON-NLS-1$
EList<AbstractNode> children = node.getParent().getParent().getChildren();
for(int i = 0 ;i < children.size(); ++i)
{
if ((children.get(i) instanceof LeafNode) == false)
continue;
// we need one more child
if (i+1 >= children.size())
continue;
if (((LeafNode)children.get(i)).getText().equals("[")) //$NON-NLS-1$
{
if (children.get(i+1) instanceof LeafNode)
{
// in case we have [+
if (((LeafNode)children.get(i+1)).getText().equals("+")) //$NON-NLS-1$
{
if (i+2 >= children.size() ||
(children.get(i+2) instanceof LeafNode) == false)
continue;
tagName = ((LeafNode)children.get(i+2)).getText();
}
else
{
tagName = ((LeafNode)children.get(i+1)).getText();
}
}
}
}
if (tagName.isEmpty() == false)
{
command.shiftsCaret = true;
command.text = ("/" + tagName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
});
}
} catch (BadLocationException e) {
}
}
}

View file

@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.autoedit;
import org.eclipse.xtext.ui.editor.autoedit.DefaultAutoEditStrategy;
public class WMLAutoEditStrategy extends DefaultAutoEditStrategy
{
public WMLAutoEditStrategy()
{
super();
}
@Override
protected void configure(IEditStrategyAcceptor acceptor)
{
// don't super as we don't want autoeditor for [ or other stuff
configureStringLiteral(acceptor);
acceptor.accept(new ClosingEndTagAutoEditStrategy());
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.contentassist;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import com.google.inject.Inject;
public class WMLContentAssistContext extends ContentAssistContext
{
@Inject
public WMLContentAssistContext()
{
super();
}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.contentassist;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalComparator;
public class WMLProposalComparator implements ICompletionProposalComparator
{
public int compare(ICompletionProposal arg0, ICompletionProposal arg1)
{
if (arg0 instanceof ConfigurableCompletionProposal &&
arg1 instanceof ConfigurableCompletionProposal)
{
ConfigurableCompletionProposal tmp0 = (ConfigurableCompletionProposal)arg0;
ConfigurableCompletionProposal tmp1 = (ConfigurableCompletionProposal)arg1;
return tmp0.compareTo(tmp1);
}
return 0;
}
}

View file

@ -0,0 +1,389 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.contentassist;
import java.util.Map.Entry;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.preprocessor.Define;
import org.wesnoth.projects.ProjectCache;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.schema.SchemaParser;
import org.wesnoth.schema.Tag;
import org.wesnoth.schema.TagKey;
import org.wesnoth.ui.WMLUiModule;
import org.wesnoth.ui.WMLUtil;
import org.wesnoth.ui.labeling.WMLLabelProvider;
import org.wesnoth.utils.StringUtils;
import org.wesnoth.wml.WMLKey;
import org.wesnoth.wml.WMLTag;
import org.wesnoth.wml.core.ConfigFile;
import org.wesnoth.wml.impl.WmlFactoryImpl;
@SuppressWarnings("unused")
public class WMLProposalProvider extends AbstractWMLProposalProvider
{
protected SchemaParser schemaParser_;
protected ProjectCache projectCache_;
protected static final int KEY_VALUE_PRIORITY = 1700;
protected static final int KEY_NAME_PRIORITY = 1500;
protected static final int TAG_PRIORITY = 1000;
protected static final int MACRO_CALL_PRIORITY = 100;
/**
* For priorities, see:
* {@link #KEY_NAME_PRIORITY}
* {@link #KEY_VALUE_PRIORITY}
* {@link #TAG_PRIORITY}
* {@link #MACRO_CALL_PRIORITY}
*/
public WMLProposalProvider()
{
super();
}
/**
* Refreshes the current project cache/schema based
* on the file opened
*/
private void refresh()
{
if ( projectCache_ != null )
return;
IFile file = WMLUtil.getActiveEditorFile();
projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
// load the schema so we know what to suggest for autocomplete
SchemaParser.reloadSchemas( false );
schemaParser_ = SchemaParser.getInstance( WesnothInstallsUtils.getInstallNameForResource( file ) );
}
@Override
public void completeWMLKey_Name(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.completeWMLKey_Name(model, assignment, context, acceptor);
refresh( );
dbg("completing wmlkeyname"); //$NON-NLS-1$
addKeyNameProposals(model, context, acceptor);
}
@Override
public void complete_WMLKeyValue(EObject model, RuleCall ruleCall,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.complete_WMLKeyValue(model, ruleCall, context, acceptor);
refresh( );
dbg("completing wmlkeyvalue - rule"); //$NON-NLS-1$
addKeyValueProposals(model, context, acceptor);
}
@Override
public void complete_WMLTag(EObject model, RuleCall ruleCall,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.complete_WMLTag(model, ruleCall, context, acceptor);
refresh( );
dbg("completing wmltag - rule"); //$NON-NLS-1$
addTagProposals(model, true, context, acceptor);
}
@Override
public void completeWMLTag_Name(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.completeWMLTag_Name(model, assignment, context, acceptor);
refresh( );
dbg("completing wmltagname"); //$NON-NLS-1$
addTagProposals(model, false, context, acceptor);
}
@Override
public void completeWMLMacroCall_Name(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.completeWMLMacroCall_Name(model, assignment, context, acceptor);
refresh( );
dbg("completing wmlmacrocallname"); //$NON-NLS-1$
addMacroCallProposals(model, false, context, acceptor);
}
@Override
public void complete_WMLMacroCall(EObject model, RuleCall ruleCall,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
super.complete_WMLMacroCall(model, ruleCall, context, acceptor);
refresh( );
dbg("completing wmlmacrocall - rule"); //$NON-NLS-1$
addMacroCallProposals(model, true, context, acceptor);
}
private void addMacroCallProposals(EObject model, boolean ruleProposal,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
for(Entry<String, Define> define : projectCache_.getDefines().entrySet())
{
StringBuilder proposal = new StringBuilder(10);
if (ruleProposal == true)
proposal.append("{"); //$NON-NLS-1$
proposal.append(define.getKey());
for(String arg : define.getValue().getArguments())
proposal.append(" " + arg); //$NON-NLS-1$
proposal.append("}"); //$NON-NLS-1$
acceptor.accept(createCompletionProposal(proposal.toString(), define.getKey(),
WMLLabelProvider.getImageByName("macrocall.png"), context, MACRO_CALL_PRIORITY)); //$NON-NLS-1$
}
}
/**
* Adss the wml key's names proposals
* @param model
* @param context
* @param acceptor
*/
private void addKeyValueProposals(EObject model,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
if (model != null && model instanceof WMLKey)
{
dbg(model);
WMLKey key = (WMLKey)model;
// handle the next_scenario and first_scenario
if (key.getName().equals("next_scenario") || //$NON-NLS-1$
key.getName().equals("first_scenario")) //$NON-NLS-1$
{
for(ConfigFile config : projectCache_.getConfigs().values())
{
if (StringUtils.isNullOrEmpty( config.ScenarioId ))
continue;
acceptor.accept(createCompletionProposal(config.ScenarioId,
config.ScenarioId, WMLLabelProvider.getImageByName("scenario.png"), //$NON-NLS-1$
context, KEY_VALUE_PRIORITY));
}
}
else
{
if (model.eContainer() != null &&
model.eContainer() instanceof WMLTag)
{
WMLTag parent = (WMLTag) model.eContainer();
Tag tag = schemaParser_.getTags().get(parent.getName());
if (tag != null)
{
TagKey tagKey = tag.getChildKey(key.getName());
if (tagKey.isEnum())
{
String[] values = tagKey.getValue().split(","); //$NON-NLS-1$
for(String val : values)
{
acceptor.accept(createCompletionProposal(val, context, 1700));
}
}
}
}
}
}
}
/**
* Adss the wml key's names proposals
* @param model
* @param context
* @param acceptor
*/
private void addKeyNameProposals(EObject model,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
WMLTag tag = null;
if (model instanceof WMLTag)
tag = (WMLTag)model;
else if (model.eContainer() instanceof WMLTag)
tag = (WMLTag)model.eContainer();
if (tag != null)
{
Tag schemaTag = schemaParser_.getTags().get(tag.getName());
if ( schemaTag != null)
{
boolean found = false;
for(TagKey key : schemaTag.getKeyChildren())
{
// skip forbidden keys
if (key.isForbidden())
continue;
found = false;
// check only non-repeatable keys
if (key.isRepeatable() == false)
{
// don't suggest already completed keys
for(WMLKey eKey: tag.getKeys())
if (eKey.getName().equals(key.getName()))
found = true;
}
if (found == false)
acceptor.accept(createCompletionProposal(key.getName() + "=", //$NON-NLS-1$
key.getName(),
getImage(WmlFactoryImpl.eINSTANCE.getWmlPackage().getWMLKey()),
context, KEY_NAME_PRIORITY));
}
}
}
}
/**
* Adds the tag proposals
* @param model
* @param ruleProposal
* @param context
* @param acceptor
*/
private void addTagProposals(EObject model, boolean ruleProposal,
ContentAssistContext context, ICompletionProposalAcceptor acceptor)
{
WMLTag parentTag = null;
if (model instanceof WMLTag)
parentTag = (WMLTag)model;
else if (model.eContainer() instanceof WMLTag)
parentTag = (WMLTag)model.eContainer();
if (parentTag != null)
{
CompositeNode node = NodeUtil.getNode(model);
String parentIndent = ""; //$NON-NLS-1$
if (context.getCurrentNode().getOffset() > 0)
parentIndent = ((LeafNode)NodeUtil.findLeafNodeAtOffset(node.getParent(),
context.getCurrentNode().getOffset() -
// if we have a non-rule proposal, subtract 1
(ruleProposal ? 0 : 1)
)).getText();
// remove ugly new lines that break indentation
parentIndent = parentIndent.replace("\r", "").replace("\n", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Tag tagChildren = schemaParser_.getTags().get(parentTag.getName());
if (tagChildren != null)
{
boolean found = false;
for(Tag tag : tagChildren.getTagChildren())
{
// skip forbidden tags
if (tag.isForbidden())
continue;
found = false;
// check only non-repeatable tags
if (tag.isRepeatable() == false)
{
for(WMLTag wmlTag : parentTag.getTags())
if (wmlTag.getName().equals(tag.getName()))
{
found = true;
break;
}
}
if (found == false)
acceptor.accept(createTagProposal(tag, parentIndent,
ruleProposal, context));
}
}
else
dbg("!!! no tag found with that name:" + parentTag.getName()); //$NON-NLS-1$
}
else // we are at the root
{
Tag rootTag = schemaParser_.getTags().get("root"); //$NON-NLS-1$
dbg("root node. adding tags: "+ rootTag.getTagChildren().size()); //$NON-NLS-1$
for(Tag tag : rootTag.getTagChildren())
{
acceptor.accept(createTagProposal(tag, "", ruleProposal, context)); //$NON-NLS-1$
}
}
}
/**
* Returns the proposal for the specified tag, usign the specified indent
* @param tag The tag from which to construct the proposal
* @param indent The indent used to indent the tag and subsequent keys
* @param ruleProposal Whether this is a proposal for an entire rule or not
* @param context
* @return
*/
private ICompletionProposal createTagProposal(Tag tag, String indent, boolean ruleProposal,
ContentAssistContext context)
{
StringBuilder proposal = new StringBuilder();
if (ruleProposal)
proposal.append("["); //$NON-NLS-1$
proposal.append(tag.getName());
proposal.append("]\n"); //$NON-NLS-1$
for(TagKey key : tag.getKeyChildren())
{
if (key.isRequired())
proposal.append(String.format("\t%s%s=\n", //$NON-NLS-1$
indent, key.getName()));
}
proposal.append(String.format("%s[/%s]",indent, tag.getName())); //$NON-NLS-1$
return createCompletionProposal(proposal.toString(), tag.getName(),
getImage(WmlFactoryImpl.eINSTANCE.getWmlPackage().getWMLTag()),
context, TAG_PRIORITY);
}
private ICompletionProposal createCompletionProposal(String proposal,
ContentAssistContext context, int priority)
{
return createCompletionProposal(proposal, null, null, priority,
context.getPrefix(), context);
}
private ICompletionProposal createCompletionProposal(String proposal, String displayString,
ContentAssistContext context)
{
return createCompletionProposal(proposal, displayString, null, context);
}
public ICompletionProposal createCompletionProposal(String proposal, String displayString, Image image,
ContentAssistContext contentAssistContext, int priority)
{
return createCompletionProposal(proposal, new StyledString(displayString),
image, priority, contentAssistContext.getPrefix(), contentAssistContext);
}
/**
* Method for debugging the auto completion
* @param str
*/
private void dbg(Object str)
{
if (!(WMLUiModule.DEBUG))
return;
System.out.println(str.toString());
}
}

View file

@ -0,0 +1,17 @@
/**
* Copyright (c) 2010 - 2011, Cloudsmith Inc.
* The code, documentation and other materials contained herein have been
* licensed under the Eclipse Public License - v 1.0 by the copyright holder
* listed above, as the Initial Contributor under such license. The text of
* such license is available at www.eclipse.org.
*/
package org.wesnoth.ui.editor;
import org.eclipse.jface.action.IMenuManager;
public class DefaultExtXtextEditorCustomizer implements IExtXtextEditorCustomizer {
public void customizeEditorContextMenu(IMenuManager menuManager) {
// do nothing
}
}

View file

@ -0,0 +1,22 @@
/**
* Copyright (c) 2006-2009, Cloudsmith Inc.
* The code, documentation and other materials contained herein have been
* licensed under the Eclipse Public License - v 1.0 by the copyright holder
* listed above, as the Initial Contributor under such license. The text of
* such license is available at www.eclipse.org.
*/
package org.wesnoth.ui.editor;
import org.eclipse.jface.action.IMenuManager;
import com.google.inject.ImplementedBy;
/**
*
*
*/
@ImplementedBy(DefaultExtXtextEditorCustomizer.class)
public interface IExtXtextEditorCustomizer {
public void customizeEditorContextMenu(IMenuManager menuManager);
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.editor;
import java.util.Locale;
import org.eclipse.core.resources.IFile;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
/**
* We use an auxiliary class just to do a 'better' equals check
*/
public class LinkedFileEditorInput extends FileEditorInput
{
public LinkedFileEditorInput(IFile file)
{
super(file);
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
String targetUri = ""; //$NON-NLS-1$
if (!(obj instanceof IFileEditorInput))
{
if (obj instanceof FileStoreEditorInput)
{
FileStoreEditorInput other = (FileStoreEditorInput)obj;
targetUri = other.getURI().toString();
}
}
else
{
IFileEditorInput other = (IFileEditorInput) obj;
targetUri = other.getFile().getLocationURI().toString();
}
if (targetUri.isEmpty())
return false;
return getFile().getLocationURI().toString().toLowerCase(Locale.ENGLISH).
equals(targetUri.toLowerCase(Locale.ENGLISH));
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.editor;
import org.eclipse.xtext.ui.editor.AbstractDirtyStateAwareEditorCallback;
import org.eclipse.xtext.ui.editor.XtextEditor;
public class WMLAbstractDirtyEditorCallback extends AbstractDirtyStateAwareEditorCallback
{
@Override
public void afterCreatePartControl(XtextEditor editor)
{
super.afterCreatePartControl(editor);
}
}

View file

@ -0,0 +1,394 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.editor;
import java.io.File;
import org.apache.log4j.Level;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.ui.URIEditorInput;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingHelper;
import org.wesnoth.WesnothPlugin;
import org.wesnoth.Logger;
import org.wesnoth.ui.Messages;
import org.wesnoth.ui.WMLUiModule;
import org.wesnoth.ui.syntax.WMLHighlightingHelper;
import com.google.inject.Inject;
public class WMLEditor extends XtextEditor
{
protected static final String AUTOLINK_PROJECT_NAME = "_AutoLinked_CFGExternalFiles_"; //$NON-NLS-1$
protected static final String ENCODING_UTF8 = "utf-8"; //$NON-NLS-1$
protected IHighlightingHelper highlightingHelper_;
protected LeafNode currentHighlightedNode_;
@Inject
private IExtXtextEditorCustomizer editorCustomizer;
public WMLEditor()
{
super();
if (WMLUiModule.DEBUG)
org.apache.log4j.Logger.getLogger(XtextEditor.class).setLevel(Level.DEBUG);
// activate the wesnoth plugin
WesnothPlugin.getDefault();
}
@Override
public void createPartControl(Composite parent)
{
super.createPartControl(parent);
}
public StyledText getTextWidget()
{
return getSourceViewer().getTextWidget();
}
public ISourceViewer getSourceViewer_()
{
return getSourceViewer();
}
public WMLHighlightingHelper getHighlightingHelper()
{
return (WMLHighlightingHelper) highlightingHelper_;
}
public void setHighlightHelper(IHighlightingHelper helper)
{
highlightingHelper_ = helper;
}
public LeafNode getCurrentHighlightedNode()
{
return currentHighlightedNode_;
}
public void setCurrentHighlightedNode(LeafNode leaf)
{
currentHighlightedNode_ = leaf;
}
@Override
public boolean equals(Object obj)
{
if ((obj instanceof XtextEditor) == false)
return false;
if (getEditorInput() == null ||
((XtextEditor)obj).getEditorInput() == null)
return false;
java.net.URI u1 = ((IURIEditorInput)getEditorInput()).getURI();
java.net.URI u2 = ((IURIEditorInput)((XtextEditor)obj).getEditorInput()).getURI();
if (u1 == null || u2 == null)
return false;
return u1.toString().equals(u2.toString());
}
/**
* Here it comes the part that handles external files
* (from outside the workspace)
*
*/
/**
* Copyright (c) 2010, Cloudsmith Inc.
* The code, documentation and other materials contained herein have been
* licensed under the Eclipse Public License - v 1.0 by the copyright holder
* listed above, as the Initial Contributor under such license. The text of
* such license is available at www.eclipse.org.
*/
private void createLink(IProject project, IFile linkFile, java.net.URI uri) throws CoreException {
IPath path = linkFile.getFullPath();
IPath folders = path.removeLastSegments(1).removeFirstSegments(1);
IPath checkPath = Path.ROOT;
int segmentCount = folders.segmentCount();
for(int i = 0; i < segmentCount; i++) {
checkPath = checkPath.addTrailingSeparator().append(folders.segment(i));
IFolder folder = project.getFolder(checkPath);
if(!folder.exists())
folder.create(true, true, null);
}
linkFile.createLink(uri, IResource.ALLOW_MISSING_LOCAL, null);
}
@Override
public void dispose() {
// Unlink the input if it was linked
IEditorInput input = getEditorInput();
if(input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
if(file.isLinked()) {
file.getProject().getName().equals(AUTOLINK_PROJECT_NAME);
try {
// if the editor is disposed because workbench is shutting down, it is NOT a good
// idea to delete the link
if(PlatformUI.isWorkbenchRunning() && !PlatformUI.getWorkbench().isClosing())
file.delete(true, null);
}
catch(CoreException e) {
// Nothing to do really, it will be recreated/refreshed later if ever used - some garbage may stay behind...
Logger.getInstance().logException(e);
}
}
}
super.dispose();
}
/**
* Overridden to allow customization of editor context menu via injected handler
*
* @see org.eclipse.ui.editors.text.TextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
editorCustomizer.customizeEditorContextMenu(menu);
}
private IFile getWorkspaceFile(IFileStore fileStore) {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = workspaceRoot.findFilesForLocationURI(fileStore.toURI());
if(files != null && files.length == 1)
return files[0];
return null;
}
/**
* Translates an incoming IEditorInput being an FilestoreEditorInput, or IURIEditorInput
* that is not also a IFileEditorInput.
* FilestoreEditorInput is used when opening external files in an IDE environment.
* The result is that the regular XtextEditor gets an IEFSEditorInput which is also an
* IStorageEditorInput.
*/
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// THE ISSUE HERE:
// In the IDE, the File Open Dialog (and elsewhere) uses a FilestoreEditorInput class
// which is an IDE specific implementation.
// The state at this point:
// 1. When creating a file, the IEditorInput is an IURIEditorInput
// 2. The only (non IDE specific) interface implemented by FilestoreEditorInput is IURIEditorInput
// 3. The creation of a file is however also an IFileEditorInput
//
// Remedy:
if(input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
java.net.URI uri = ((IURIEditorInput) input).getURI();
String name = ((IURIEditorInput) input).getName();
// Check if this is linkable input
if(uri.getScheme().equals("file")) { //$NON-NLS-1$
IFile linkedFile = obtainLink(uri);
IFileEditorInput linkedInput = new LinkedFileEditorInput(linkedFile);
super.init(site, linkedInput);
}
else {
// use EMF URI (readonly) input - will open without validation though...
// (Could be improved, i.e. perform a download, make readonly, and keep in project,
// or stored in tmp, and processed as the other linked resources..
URIEditorInput uriInput = new URIEditorInput(URI.createURI(uri.toString()), name);
super.init(site, uriInput);
return;
}
return;
}
super.init(site, input);
}
/**
* Throws WrappedException - the URI must refer to an existing file!
*
* @param uri
* @return
*/
private IFile obtainLink(java.net.URI uri) {
try {
IWorkspace ws = ResourcesPlugin.getWorkspace();
// get, or create project if non existing
IProject project = ws.getRoot().getProject(AUTOLINK_PROJECT_NAME);
boolean newProject = false;
if(!project.exists()) {
project.create(null);
newProject = true;
}
if(!project.isOpen()) {
project.open(null);
project.setHidden(true);
}
if(newProject)
project.setDefaultCharset(ENCODING_UTF8, new NullProgressMonitor());
// path in project that is the same as the external file's path
IFile linkFile = project.getFile(uri.getPath());
System.out.println(linkFile);
if(linkFile.exists())
linkFile.refreshLocal(1, null); // don't know if needed (or should be avoided...)
else {
// create the link
createLink(project, linkFile, uri);
// linkFile.createLink(uri, IResource.ALLOW_MISSING_LOCAL, null);
}
return linkFile;
// IPath location = new Path(name);
// IFile file = project.getFile(location.lastSegment());
// file.createLink(location, IResource.NONE, null);
}
catch(CoreException e) {
throw new WrappedException(e);
}
}
// SaveAs support for linked files - saves them on local disc, not to workspace if file is in special
// hidden external file link project.
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
// Customize save as if the file is linked, and it is in the special external link project
//
if(input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked() &&
((IFileEditorInput) input).getFile().getProject().getName().equals(AUTOLINK_PROJECT_NAME)) {
final IEditorInput newInput;
IDocumentProvider provider = getDocumentProvider();
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
if(oldPath != null) {
dialog.setFileName(oldPath.lastSegment());
dialog.setFilterPath(oldPath.toOSString());
}
dialog.setFilterExtensions(new String[] { "*.b3", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
String path = dialog.open();
if(path == null) {
if(progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
// Check whether file exists and if so, confirm overwrite
final File localFile = new File(path);
if(localFile.exists()) {
MessageDialog overwriteDialog = new MessageDialog(shell, Messages.WMLEditor_0, null, path +
Messages.WMLEditor_1, MessageDialog.WARNING, new String[] {
IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
if(overwriteDialog.open() != Window.OK) {
if(progressMonitor != null) {
progressMonitor.setCanceled(true);
return;
}
}
}
IFileStore fileStore;
try {
fileStore = EFS.getStore(localFile.toURI());
}
catch(CoreException ex) {
Logger.getInstance().logException(ex);
String title = Messages.WMLEditor_2;
String msg = Messages.WMLEditor_3 + ex.getMessage();
MessageDialog.openError(shell, title, msg);
return;
}
IFile file = getWorkspaceFile(fileStore);
if(file != null)
newInput = new FileEditorInput(file);
else {
IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
java.net.URI uri = uriInput.getURI();
IFile linkedFile = obtainLink(uri);
newInput = new FileEditorInput(linkedFile);
}
if(provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
success = true;
}
catch(CoreException x) {
Logger.getInstance().logException(x);
final IStatus status = x.getStatus();
if(status == null || status.getSeverity() != IStatus.CANCEL) {
String title = Messages.WMLEditor_4;
String msg = Messages.WMLEditor_5 + x.getMessage();
MessageDialog.openError(shell, title, msg);
}
}
finally {
provider.changed(newInput);
if(success)
setInput(newInput);
}
if(progressMonitor != null)
progressMonitor.setCanceled(!success);
return;
}
super.performSaveAs(progressMonitor);
}
}

View file

@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.emf;
import java.util.HashMap;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
/**
* An adapter that provides storage for data in a hashmap
*/
public class HashMapStorageAdapter implements Adapter
{
private HashMap<String, Object> data_;
private Notifier notifier_;
public HashMapStorageAdapter()
{
data_ = new HashMap<String, Object>();
}
public void setData(String name, Object data)
{
data_.put(name, data);
}
public Object getData(String name)
{
return data_.get(name);
}
public Notifier getTarget()
{
return notifier_;
}
public boolean isAdapterForType(Object arg0)
{
return true;
}
public void notifyChanged(Notification arg0)
{
}
public void setTarget(Notifier arg0)
{
notifier_ = arg0;
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.emf;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
/**
* A simple adapter that stores an object
*/
public class ObjectStorageAdapter implements Adapter
{
private Object object_;
private Notifier notifier_;
public ObjectStorageAdapter(Object data)
{
object_ = data;
}
public Object getObject()
{
return object_;
}
public void setObject(Object obj)
{
object_ = obj;
}
public Notifier getTarget()
{
return notifier_;
}
public boolean isAdapterForType(Object arg0)
{
return true;
}
public void notifyChanged(Notification arg0)
{
}
public void setTarget(Notifier arg0)
{
notifier_ = arg0;
}
}

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.folding;
import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.Position;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.ui.editor.folding.DefaultFoldingRegionProvider;
import org.eclipse.xtext.ui.editor.folding.IFoldingRegion;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.wesnoth.wml.WMLKey;
import org.wesnoth.wml.WMLTextdomain;
public class WMLFoldingRegionProvider extends DefaultFoldingRegionProvider
{
@Override
protected void addFoldingRegions(IXtextDocument xtextDocument,
EObject eObject, List<IFoldingRegion> foldingRegions)
{
super.addFoldingRegions(xtextDocument, eObject, foldingRegions);
}
@Override
protected Position getPosition(IXtextDocument xtextDocument,
CompositeNode compositeNode)
{
Assert.isNotNull(compositeNode, "parameter 'compositeNode' must not be null"); //$NON-NLS-1$
if (compositeNode.getElement() instanceof WMLKey &&
((WMLKey)compositeNode.getElement()).getEol() != null &&
((WMLKey)compositeNode.getElement()).getEol().length() > 0)
return null;
else if (compositeNode.getElement() instanceof WMLTextdomain)
return null;
return super.getPosition(xtextDocument, compositeNode);
}
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling;
import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider;
/**
* Provides labels for a IEObjectDescriptions and IResourceDescriptions.
*
* see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
*/
public class WMLDescriptionLabelProvider extends DefaultDescriptionLabelProvider {
/*
//Labels and icons can be computed like this:
String text(IEObjectDescription ele) {
return "my "+ele.getName();
}
String image(IEObjectDescription ele) {
return ele.getEClass().getName() + ".gif";
}
*/
}

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling;
import java.util.Locale;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;
import com.google.inject.Inject;
/**
* Provides labels for a EObjects.
*
* see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
*/
public class WMLLabelProvider extends DefaultEObjectLabelProvider
{
private static WMLLabelProvider instance_;
@Inject
public WMLLabelProvider(AdapterFactoryLabelProvider delegate) {
super(delegate);
instance_ = this;
}
@Override
protected Object doGetImage(Object element)
{
if (element instanceof EClass)
{
return ((EClass)element).getName().toLowerCase(Locale.ENGLISH) + ".png"; //$NON-NLS-1$
}
else if (element instanceof String)
{
return element;
}
return super.doGetImage(element);
}
public static Image getImageByName(String fileName)
{
if (instance_ == null)
return null;
return instance_.getImage(fileName);
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling.wmldoc;
import org.eclipse.swt.custom.StyleRange;
/**
* An interface used to provide WML documentation
*/
public interface IWMLDocProvider
{
/**
* Gets the title of the wmldoc dialog
* @return
*/
public String getTitle();
/**
* Gets the text to be written in the info statusbar
* @return
*/
public String getInfoText();
/**
* Gets the contents to be written into the
* styledtext control of the wmldoc dialog
* @return
*/
public String getContents();
/**
* Gets an array of StyleRange used to style the contents
* @return
*/
public StyleRange[] getStyleRanges();
}

View file

@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling.wmldoc;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.graphics.Point;
import org.eclipse.xtext.parser.IParseResult;
import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.ParseTreeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.wesnoth.Logger;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.preprocessor.Define;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.ui.WMLUtil;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLTag;
/**
* A handler that handles pressing F2 on a resource in the editor
*/
public class WMLDocHandler extends AbstractHandler
{
public Object execute(ExecutionEvent event) throws ExecutionException
{
try
{
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
final String installName =
WesnothInstallsUtils.getInstallNameForResource( WMLUtil.getActiveEditorFile( ) );
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>()
{
private WMLDocInformationPresenter presenter_;
@Override
public void process(XtextResource resource) throws Exception
{
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
Point positionRelative = editor.getInternalSourceViewer().getTextWidget().getLocationAtOffset(selection.getOffset());
Point positionAbsolute = editor.getInternalSourceViewer().getTextWidget().toDisplay(positionRelative);
positionAbsolute.y +=20;
IParseResult parseResult = resource.getParseResult();
AbstractNode abstractNode = ParseTreeUtil.getCurrentOrPrecedingNodeByOffset(parseResult.getRootNode(), selection.getOffset());
if (abstractNode == null || abstractNode.eContainer() == null)
return;
CompositeNode container = (CompositeNode)abstractNode.eContainer();
if (container.getElement() instanceof WMLMacroCall)
{
WMLMacroCall macro = (WMLMacroCall)container.getElement();
Define define = ProjectUtils.getCacheForProject(
WMLUtil.getActiveEditorFile().getProject())
.getDefines().get(macro.getName());
if (define != null)
{
if (presenter_ == null)
{
presenter_ = new WMLDocInformationPresenter(
editor.getSite().getShell(),
new WMLDocMacro(define),
positionAbsolute);
presenter_.create();
}
presenter_.open();
}
}
else if (container.getElement() instanceof WMLTag)
{
if (presenter_ == null)
{
presenter_ = new WMLDocInformationPresenter(
editor.getSite().getShell(),
new WMLDocTag( installName, ((WMLTag)container.getElement()).getName()),
positionAbsolute);
presenter_.create();
}
presenter_.open();
}
}
});
}
catch (Exception e) {
Logger.getInstance().logException(e);
}
return null;
}
}

View file

@ -0,0 +1,130 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling.wmldoc;
import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class WMLDocInformationPresenter extends PopupDialog implements
MouseListener, SelectionListener, MouseTrackListener, MouseMoveListener
{
private Point bounds_;
private IWMLDocProvider currentDocProvider_;
private Composite panel_;
/**
* Creates a new WMLDocumentation information presenter
*/
public WMLDocInformationPresenter(Shell parent, IWMLDocProvider docProvider,
Point bounds)
{
super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, true,
false, false, "", ""); //$NON-NLS-1$ //$NON-NLS-2$
bounds_ = bounds;
currentDocProvider_ = docProvider;
}
@Override
protected Control createInfoTextArea(Composite parent)
{
//TODO: Add back& forward button
return super.createInfoTextArea(parent);
}
@Override
protected Control createDialogArea(Composite parent)
{
panel_ = new Composite(parent, SWT.None);
panel_.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
panel_.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
GridLayout grid = new GridLayout();
grid.numColumns = 5;
panel_.setLayout(grid);
StyledText text = new StyledText(panel_, SWT.NONE);
setTitleText(currentDocProvider_.getTitle());
setInfoText(currentDocProvider_.getInfoText());
text.setText(currentDocProvider_.getContents());
text.setEditable(false);
text.setStyleRanges(currentDocProvider_.getStyleRanges());
text.setLayoutData(createDefaultGridData(4));
text.addMouseListener(this);
text.addMouseTrackListener(this);
text.addMouseMoveListener(this);
return panel_;
}
private GridData createDefaultGridData(int columnspan) {
GridData gd = new GridData();
gd.horizontalSpan = columnspan;
gd.verticalAlignment = SWT.BEGINNING;
gd.verticalIndent = 0;
gd.horizontalIndent = 5;
return gd;
}
@Override
protected Point getInitialLocation(Point initialSize)
{
return bounds_;
}
public void mouseMove(MouseEvent e)
{
}
public void mouseEnter(MouseEvent e)
{
}
public void mouseExit(MouseEvent e)
{
}
public void mouseHover(MouseEvent e)
{
}
public void widgetSelected(SelectionEvent e)
{
}
public void widgetDefaultSelected(SelectionEvent e)
{
}
public void mouseDoubleClick(MouseEvent e)
{
}
public void mouseDown(MouseEvent e)
{
}
public void mouseUp(MouseEvent e)
{
}
}

View file

@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling.wmldoc;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.widgets.Display;
import org.wesnoth.preprocessor.Define;
import org.wesnoth.ui.Messages;
/**
* Provides WMLDoc info for a macro
*/
public class WMLDocMacro implements IWMLDocProvider
{
private Define macro_;
private String title_;
private String contents_;
private List<StyleRange> styleRanges_;
public WMLDocMacro(Define macro)
{
macro_ = macro;
}
/**
* A method used for lazly generating the documentation
*/
private void generateDoc()
{
if (title_ != null && contents_ != null && styleRanges_ != null)
return;
styleRanges_ = new ArrayList<StyleRange>();
title_ = Messages.WMLDocMacro_0 + macro_.getName();
StringBuilder content = new StringBuilder();
content.append(Messages.WMLDocMacro_1);
addStyleRange(0, content.length() - 1, SWT.BOLD);
content.append(macro_.getValue());
content.append('\n');
if (macro_.getArguments().isEmpty() == false)
{
int len = content.length() - 1;
content.append(Messages.WMLDocMacro_2);
addStyleRange(len, content.length() - len - 1, SWT.BOLD);
len = content.length() - 1;
for(String arg : macro_.getArguments())
{
content.append('\t' + arg + '\n');
}
addStyleRange(len, content.length() - len - 1, SWT.ITALIC);
}
contents_ = content.toString();
}
/**
* Adds a style range to current list
* @param offset
* @param length
* @param style
*/
private void addStyleRange(int offset, int length, int style)
{
styleRanges_.add(new StyleRange(offset, length,
Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND),
Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND),
style));
}
public String getTitle()
{
generateDoc();
return title_;
}
public String getContents()
{
generateDoc();
return contents_;
}
public StyleRange[] getStyleRanges()
{
generateDoc();
return styleRanges_.toArray(new StyleRange[styleRanges_.size()]);
}
/**
* Gets the associated macro
* @return
*/
public Define getMacro()
{
return macro_;
}
public String getInfoText()
{
return ""; //$NON-NLS-1$
}
}

View file

@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.labeling.wmldoc;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.widgets.Display;
import org.wesnoth.schema.SchemaParser;
import org.wesnoth.schema.Tag;
import org.wesnoth.ui.Messages;
/**
* Displays wml doc for a tag
* [tag] or [/tag]
*/
public class WMLDocTag implements IWMLDocProvider
{
private Tag tag_;
private String title_;
private String contents_;
private List<StyleRange> styleRanges_;
public WMLDocTag( String installName, String name )
{
tag_ = SchemaParser.getInstance( installName ).getTags().get(name);
}
/**
* A method used for lazly generating the documentation
*/
private void generateDoc()
{
if (title_ != null && contents_ != null && styleRanges_ != null)
return;
styleRanges_ = new ArrayList<StyleRange>();
if (tag_ == null)
return;
title_ = Messages.WMLDocTag_0 + tag_.getName() + "':"; //$NON-NLS-1$
StringBuilder content = new StringBuilder();
if (tag_.getDescription() != null)
{
content.append(Messages.WMLDocTag_1);
addStyleRange(0, content.length() - 1, SWT.BOLD);
content.append(tag_.getDescription().getChildKey("text").getValue()); //$NON-NLS-1$
}
contents_ = content.toString();
}
/** Adds a style range to current list
*
* @param offset
* @param length
* @param style
*/
private void addStyleRange(int offset, int length, int style)
{
styleRanges_.add(new StyleRange(offset, length,
Display.getDefault().getSystemColor(SWT.COLOR_INFO_FOREGROUND),
Display.getDefault().getSystemColor(SWT.COLOR_INFO_BACKGROUND),
style));
}
public String getTitle()
{
generateDoc();
return title_;
}
public String getInfoText()
{
return ""; //$NON-NLS-1$
}
public String getContents()
{
generateDoc();
return contents_;
}
public StyleRange[] getStyleRanges()
{
generateDoc();
return styleRanges_.toArray(new StyleRange[styleRanges_.size()]);
}
}

View file

@ -0,0 +1,19 @@
WMLDocMacro_0=Macro:
WMLDocMacro_1=Definition:\n
WMLDocMacro_2=Arguments:\n
WMLDocTag_0=Tag '
WMLDocTag_1=Description:\n
WMLEditor_0=Save As
WMLEditor_1=\ already exists.\nDo you want to replace it?
WMLEditor_2=Problems During Save As...
WMLEditor_3=Save could not be completed.
WMLEditor_4=Problems During Save As...
WMLEditor_5=Save could not be completed.
WMLHighlightingConfiguration_10=WML Start/End Tag Highlight
WMLHighlightingConfiguration_11=WML Macro Define
WMLHighlightingConfiguration_12=WML IF
WMLHighlightingConfiguration_13=WML Textdomain
WMLHighlightingConfiguration_7=WML Tag
WMLHighlightingConfiguration_8=WML Key
WMLHighlightingConfiguration_9=WML Macro Call
WMLHyperlinkHelper_0=FATAL\! file is null (and it shouldn't)

View file

@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.navigation;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink;
import org.wesnoth.utils.EditorUtils;
/**
* This is a hyperlink that opens a specified file
* and puts the cursor to specified location
*/
public class FileLocationOpenerHyperlink extends XtextHyperlink
{
private String filePath_;
private int linenum_;
@Override
public void open()
{
IEditorPart part = EditorUtils.openEditor(filePath_);
if (part != null)
{
ITextEditor editor = EditorUtils.getTextEditor(part);
IDocument doc = editor.getDocumentProvider().
getDocument(editor.getEditorInput());
int offset = 0;
try
{
// compute offset based on linenum_
offset = doc.getLineOffset(linenum_);
}
catch (BadLocationException e) {
//ignore
}
EditorUtils.getTextEditor(part).selectAndReveal(offset, 0);
}
}
public void setLinenumber(int linenum)
{
linenum_ = linenum;
}
public int getLinenumber()
{
return linenum_;
}
public void setFilePath(String filePath)
{
filePath_ = filePath;
}
public String getFilePath()
{
return filePath_;
}
}

View file

@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.navigation;
import java.io.File;
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink;
import org.wesnoth.utils.GameUtils;
public class MapOpenerHyperlink extends XtextHyperlink
{
private String location_;
public void setLocation(String location)
{
location_ = location;
}
public String getLocation()
{
return location_;
}
@Override
public void open()
{
if (new File(location_).exists())
{
GameUtils.startEditor(location_);
}
// else
// {
// // create a new file
// //TODO: create the map
// Logger.getInstance().log("Creating new map: " + mapLocation);
//
// }
}
}

View file

@ -0,0 +1,151 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.navigation;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.text.Region;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor;
import org.wesnoth.Logger;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.preferences.Preferences;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.preprocessor.Define;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.ui.Messages;
import org.wesnoth.ui.WMLUtil;
import org.wesnoth.ui.emf.ObjectStorageAdapter;
import org.wesnoth.wml.WMLMacroCall;
public class WMLHyperlinkHelper extends HyperlinkHelper
{
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset,
IHyperlinkAcceptor acceptor)
{
super.createHyperlinksByOffset(resource, offset, acceptor);
CompositeNode rootNode = NodeUtil.getRootNode(resource.getContents().get(0));
if (rootNode == null)
return;
LeafNode node = (LeafNode)NodeUtil.findLeafNodeAtOffset(rootNode, offset);
if (node == null)
return;
IFile file = WMLUtil.getActiveEditorFile();
if (file == null)
{
Logger.getInstance().logError(Messages.WMLHyperlinkHelper_0);
return;
}
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( file ) );
createMacroHyperlink( file, paths, node, acceptor, resource );
LeafNode prevNode = (LeafNode)NodeUtil.findLeafNodeAtOffset(rootNode,
node.getOffset() - 1);
if(prevNode == null)
return;
createMapHyperlink( paths, prevNode, node, acceptor, resource );
}
/**
* Creates a hyperlink for opening the macro definition
* @param prevNode
* @param node
* @param acceptor
* @param resource
*/
private void createMacroHyperlink( IFile file, Paths paths, LeafNode node,
IHyperlinkAcceptor acceptor, XtextResource resource)
{
if (node.eContainer() == null ||
(node.eContainer() instanceof CompositeNode) == false)
return;
CompositeNode container = (CompositeNode)node.eContainer();
if ((container.getElement() instanceof WMLMacroCall) == false)
return;
WMLMacroCall macro = (WMLMacroCall)container.getElement();
// get the define for the macro
Define define = ProjectUtils.getCacheForProject(file.getProject()).getDefines().get(macro.getName());
if (define == null)
{
//TODO: handle macro include call - open folder?
//Logger.getInstance().log("No macro with that name found.");
return;
}
if (define.getLocation().isEmpty() == true)
return;
String filePath = define.getLocation().split(" ")[0]; //$NON-NLS-1$
if (filePath.startsWith("~")) { // user addon relative location //$NON-NLS-1$
filePath = filePath.replaceFirst("~", //$NON-NLS-1$
paths.getUserDir( ).replace('\\', '/') + "/data/"); //$NON-NLS-1$
}
else if (filePath.startsWith("core")) { // data/core relative location //$NON-NLS-1$
filePath = filePath.replaceFirst("core", //$NON-NLS-1$
paths.getWorkingDir( ).replace('\\', '/') + "/data/core/"); //$NON-NLS-1$
}
FileLocationOpenerHyperlink macroTarget = new FileLocationOpenerHyperlink();
macroTarget.setHyperlinkRegion(new Region(container.getOffset(), container.getLength()));
macroTarget.setFilePath(filePath);
macroTarget.setLinenumber(define.getLineNum());
acceptor.accept(macroTarget);
}
/**
* Creates a hyperlink for opening the map.
* @param key The key (must me 'map_data' in this case)
* @param value The value of key, that is, the location of the map
*/
private void createMapHyperlink( Paths paths, LeafNode key, LeafNode value,
IHyperlinkAcceptor acceptor, XtextResource resource )
{
if (!(key.getText().equals("map_data"))) //$NON-NLS-1$
return;
// trim the " and the { (if any exist)
String mapLocation = value.getText();
if (mapLocation.startsWith("\"")) //$NON-NLS-1$
mapLocation = mapLocation.substring(1, value.getLength() - 1);
if (mapLocation.startsWith("{")) //$NON-NLS-1$
mapLocation = mapLocation.substring(1, value.getLength() - 1);
mapLocation = mapLocation.replaceFirst("~", //$NON-NLS-1$
paths.getUserDir( ).replace('\\','/') + "/data/"); //$NON-NLS-1$
ObjectStorageAdapter adapter = (ObjectStorageAdapter)EcoreUtil.getAdapter(value.eAdapters(),
ObjectStorageAdapter.class);
if (adapter == null)
{
adapter = new ObjectStorageAdapter(mapLocation);
value.eAdapters().add(adapter);
}
else
adapter.setObject(mapLocation);
MapOpenerHyperlink hyperlink = new MapOpenerHyperlink();
hyperlink.setHyperlinkRegion(new Region(value.getOffset(), value.getLength()));
hyperlink.setLocation(mapLocation);
acceptor.accept(hyperlink);
}
}

View file

@ -0,0 +1,23 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui.outline;
import org.eclipse.xtext.ui.editor.outline.actions.DefaultContentOutlineNodeAdapterFactory;
@SuppressWarnings( "deprecation" )
public class WMLOutlineNodeAdapterFactory extends DefaultContentOutlineNodeAdapterFactory {
private static final Class<?>[] types = {
// provide list of classes to adapt to, e.g.:
// Entity.class
// Service.class
};
@Override
public Class<?>[] getAdapterList() {
return types;
}
}

View file

@ -0,0 +1,14 @@
/*
* generated by Xtext
*/
package org.wesnoth.ui.outline;
import org.eclipse.xtext.ui.editor.outline.transformer.AbstractDeclarativeSemanticModelTransformer;
/**
* customization of the default outline structure
*
*/
public class WMLTransformer extends AbstractDeclarativeSemanticModelTransformer {
}

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.quickfix;
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
public class WMLQuickfixProvider extends DefaultQuickfixProvider {
// @Fix(MyJavaValidator.INVALID_NAME)
// public void capitalizeName(final Issue issue, IssueResolutionAcceptor acceptor) {
// acceptor.accept(issue, "Capitalize name", "Capitalize the name.", "upcase.png", new IModification() {
// public void apply(IModificationContext context) throws BadLocationException {
// IXtextDocument xtextDocument = context.getXtextDocument();
// String firstLetter = xtextDocument.get(issue.getOffset(), 1);
// xtextDocument.replace(issue.getOffset(), 1, firstLetter.toUpperCase());
// }
// });
// }
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.resource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.resource.DefaultLocationInFileProvider;
public class WMLLocationInFileProvider extends DefaultLocationInFileProvider
{
@Override
protected boolean useKeyword(Keyword keyword, EObject context)
{
return super.useKeyword(keyword, context);
}
@Override
protected EStructuralFeature getIdentifierFeature(EObject obj)
{
return super.getIdentifierFeature(obj);
}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import org.eclipse.xtext.ui.editor.syntaxcoloring.antlr.DefaultAntlrTokenToAttributeIdMapper;
public class WMLAntlrTokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper
{
@Override
protected String calculateId(String tokenName, int tokenType)
{
if (tokenName.equals("'['") || tokenName.equals("'[/'") || tokenName.equals("']'")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
{
return WMLHighlightingConfiguration.RULE_WML_TAG;
}
if (tokenName.equals("'{'") || tokenName.equals("'}'")) //$NON-NLS-1$ //$NON-NLS-2$
{
return WMLHighlightingConfiguration.RULE_WML_MACRO_CALL;
}
return super.calculateId(tokenName, tokenType);
}
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
import org.eclipse.xtext.ui.editor.utils.TextStyle;
import org.wesnoth.ui.Messages;
public class WMLHighlightingConfiguration extends DefaultHighlightingConfiguration
{
public static final String RULE_WML_TAG = "wmlTag"; //$NON-NLS-1$
public static final String RULE_WML_KEY = "wmlKey"; //$NON-NLS-1$
public static final String RULE_WML_MACRO_CALL = "wmlMacroCall"; //$NON-NLS-1$
public static final String RULE_WML_MACRO_DEFINE = "wmlMacroDefine"; //$NON-NLS-1$
public static final String RULE_WML_IF = "wmlIF"; //$NON-NLS-1$
public static final String RULE_WML_TEXTDOMAIN = "wmlTextdomain"; //$NON-NLS-1$
public static final String RULE_START_END_TAG = "wmlStartEnd"; //$NON-NLS-1$
@Override
public void configure(IHighlightingConfigurationAcceptor acceptor)
{
super.configure(acceptor);
acceptor.acceptDefaultHighlighting(RULE_WML_TAG, Messages.WMLHighlightingConfiguration_7, tagTextStyle());
acceptor.acceptDefaultHighlighting(RULE_WML_KEY, Messages.WMLHighlightingConfiguration_8, keyTextStyle());
acceptor.acceptDefaultHighlighting(RULE_WML_MACRO_CALL, Messages.WMLHighlightingConfiguration_9, macroTextStyle());
acceptor.acceptDefaultHighlighting(RULE_START_END_TAG,
Messages.WMLHighlightingConfiguration_10, startEndTextStyle());
// preproc
acceptor.acceptDefaultHighlighting(RULE_WML_MACRO_DEFINE, Messages.WMLHighlightingConfiguration_11, preprocTextStyle());
acceptor.acceptDefaultHighlighting(RULE_WML_IF, Messages.WMLHighlightingConfiguration_12, preprocTextStyle());
acceptor.acceptDefaultHighlighting(RULE_WML_TEXTDOMAIN, Messages.WMLHighlightingConfiguration_13, preprocTextStyle());
}
public TextStyle preprocTextStyle()
{
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(31, 209, 241));
textStyle.setStyle(SWT.BOLD);
return textStyle;
}
public TextStyle macroTextStyle()
{
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(197, 137, 23));
textStyle.setStyle(SWT.ITALIC);
return textStyle;
}
public TextStyle startEndTextStyle()
{
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(128, 128, 128));
textStyle.setBackgroundColor(new RGB(128, 0, 0));
textStyle.setStyle(SWT.BOLD | SWT.ITALIC);
return textStyle;
}
public TextStyle tagTextStyle()
{
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(128, 0, 0));
textStyle.setStyle(SWT.BOLD);
return textStyle;
}
public TextStyle keyTextStyle()
{
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(0, 128, 128));
textStyle.setStyle(SWT.BOLD);
return textStyle;
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.XtextSourceViewer;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingHelper;
import org.wesnoth.ui.editor.WMLEditor;
/**
* Highlighting helper.
* Initially copied from org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingManager
*
* @author Sebastian Zarnekow
*/
public class WMLHighlightingHelper extends HighlightingHelper
{
@Override
public void install(XtextEditor editor, XtextSourceViewer sourceViewer)
{
super.install(editor, sourceViewer);
((WMLEditor) editor).setHighlightHelper(this);
}
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.XtextSourceViewer;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingPresenter;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler;
import org.wesnoth.ui.editor.WMLEditor;
public class WMLHighlightingReconciler extends HighlightingReconciler
{
protected WMLEditor editor;
@Override
public void install(XtextEditor editor, XtextSourceViewer sourceViewer, HighlightingPresenter presenter)
{
super.install(editor, sourceViewer, presenter);
this.editor = (WMLEditor) editor;
}
public WMLEditor getEditor()
{
return editor;
}
@Override
public void modelChanged(XtextResource resource)
{
super.modelChanged(resource);
// add our own acceptor
WMLMergingHighlightedPositionAcceptor acceptor =
new WMLMergingHighlightedPositionAcceptor(getCalculator());
acceptor.provideHighlightingFor(resource, this);
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
import org.eclipse.xtext.ui.editor.syntaxcoloring.MergingHighlightedPositionAcceptor;
import com.google.inject.Inject;
public class WMLMergingHighlightedPositionAcceptor extends MergingHighlightedPositionAcceptor
{
protected HighlightingReconciler reconciler_;
@Inject
public WMLMergingHighlightedPositionAcceptor(ISemanticHighlightingCalculator delegate) {
super(delegate);
}
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor)
{
reconciler_ = (HighlightingReconciler) acceptor;
super.provideHighlightingFor(resource, acceptor);
}
public HighlightingReconciler getHighlightingReconciler()
{
return reconciler_;
}
}

View file

@ -0,0 +1,167 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax;
import java.util.Iterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeAdapter;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.xtext.ui.editor.syntaxcoloring.SemanticHighlightingCalculator;
import org.wesnoth.ui.editor.WMLEditor;
import org.wesnoth.wml.WMLKey;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLMacroDefine;
import org.wesnoth.wml.WMLPreprocIF;
import org.wesnoth.wml.WMLTag;
import org.wesnoth.wml.WMLTextdomain;
import org.wesnoth.wml.WmlPackage;
public class WMLSemanticHighlightingCalculator extends SemanticHighlightingCalculator
{
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor)
{
if (resource == null)
return;
// we skip xtext's default acceptor since we want only ours
if (!(acceptor instanceof WMLMergingHighlightedPositionAcceptor))
return;
Iterator<EObject> iter = EcoreUtil.getAllContents(resource, true);
while (iter.hasNext())
{
EObject current = iter.next();
if (skipNode(acceptor, current))
continue;
AbstractNode begin=null, end=null;
String beginId = null, endId = null;
if (current instanceof WMLTag)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_TAG__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_TAG;
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_TAG__END_NAME.getName());
endId = WMLHighlightingConfiguration.RULE_WML_TAG;
}
else if (current instanceof WMLKey)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_KEY__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_KEY;
}
else if (current instanceof WMLMacroCall)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_MACRO_CALL__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_MACRO_CALL;
}
else if (current instanceof WMLTextdomain)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_TEXTDOMAIN__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_TEXTDOMAIN;
}
else if (current instanceof WMLPreprocIF)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_PREPROC_IF__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_IF;
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_PREPROC_IF__END_NAME.getName());
endId = WMLHighlightingConfiguration.RULE_WML_IF;
}
else if (current instanceof WMLMacroDefine)
{
begin = getFirstFeatureNode(current, WmlPackage.Literals.WML_MACRO_DEFINE__NAME.getName());
beginId = WMLHighlightingConfiguration.RULE_WML_MACRO_DEFINE;
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_MACRO_DEFINE__END_NAME.getName());
endId = WMLHighlightingConfiguration.RULE_WML_MACRO_DEFINE;
}
highlightNode(begin, beginId, acceptor);
highlightNode(end, endId, acceptor);
}
}
/**
* We have this auxilliar function to know when to skip a node from being highlighted
* This is usually case of "highlighting start/end tags" and we don't want
* highlighting going over.
*
* @param acceptor
* @param node
* @return
*/
private boolean skipNode(IHighlightedPositionAcceptor acceptor, EObject node)
{
if (!(node instanceof WMLTag))
return false;
WMLTag tag = (WMLTag) node;
WMLEditor editor = ((WMLHighlightingReconciler)
((WMLMergingHighlightedPositionAcceptor) acceptor).
getHighlightingReconciler()).getEditor();
if (editor == null || editor.getCurrentHighlightedNode() == null)
return false;
return (tag.getName().equals(editor.getCurrentHighlightedNode().getText()));
}
private void highlightNode(AbstractNode node, String id, IHighlightedPositionAcceptor acceptor)
{
if (node == null || id == null)
return;
if (node instanceof LeafNode)
{
acceptor.addPosition(node.getOffset(), node.getLength(), id);
}
else
{
for (LeafNode leaf : node.getLeafNodes())
{
if (!leaf.isHidden())
{
acceptor.addPosition(leaf.getOffset(), leaf.getLength(), id);
}
}
}
}
@Override
public AbstractNode getFirstFeatureNode(EObject semantic, String feature)
{
NodeAdapter adapter = NodeUtil.getNodeAdapter(semantic);
if (adapter != null)
{
CompositeNode node = adapter.getParserNode();
if (node != null)
{
for (AbstractNode child : node.getChildren())
{
if (child instanceof LeafNode)
{
if (feature.equals(((LeafNode) child).getFeature()))
{
return child;
}
}
}
}
}
return null;
}
}

View file

@ -0,0 +1,174 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.wesnoth.ui.syntax.bracketmatching;
import java.util.List;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.parsetree.AbstractNode;
import org.eclipse.xtext.parsetree.CompositeNode;
import org.eclipse.xtext.parsetree.LeafNode;
import org.eclipse.xtext.parsetree.NodeUtil;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.bracketmatching.DefaultBracketMatcher;
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.Pair;
import org.wesnoth.services.WMLGrammarAccess;
import org.wesnoth.ui.editor.WMLEditor;
import org.wesnoth.ui.syntax.WMLHighlightingConfiguration;
import org.wesnoth.wml.WMLTag;
import com.google.inject.Inject;
public class WMLBracketMatching extends DefaultBracketMatcher
{
@Inject
private WMLGrammarAccess grammarAccess;
@Override
public void configure(IBracketPairAcceptor acceptor)
{
List<Pair<Keyword, Keyword>> pairs2 = grammarAccess.findKeywordPairs("[/", "]"); //$NON-NLS-1$ //$NON-NLS-2$
for (Pair<Keyword, Keyword> pair : pairs2)
{
acceptor.accept(pair.getFirst(), pair.getSecond());
}
super.configure(acceptor);
}
@Override
public IRegion computeMatchingRegion(XtextResource state, int offset)
{
if (state == null || state.getContents() == null || state.getContents().isEmpty())
return null;
CompositeNode rootNode = NodeUtil.getRootNode(state.getContents().get(0));
if (rootNode == null)
return null;
AbstractNode node = NodeUtil.findLeafNodeAtOffset(rootNode, offset);
if (node == null)
return null;
/* -- AbstractBracketMatcher.class -- */
AbstractElement element = findElement(node, getPairs());
boolean forwardSearch = true;
if (element == null)
{
forwardSearch = false;
element = findElement(node, getPairs().inverse());
}
if (element != null)
{
AbstractNode correspondingNode = findMatchingNode(node, element, forwardSearch);
if (correspondingNode != null)
{
return new Region(correspondingNode.getOffset(), correspondingNode.getLength());
}
}
WMLEditor editor = (WMLEditor) EditorUtils.getActiveXtextEditor();
if (editor == null || editor.getHighlightingHelper() == null)
return null;
HighlightingReconciler reconcilier = editor.getHighlightingHelper().getReconciler();
if (reconcilier == null)
return null;
editor.setCurrentHighlightedNode(null);
// clear any highlighted nodes
reconcilier.refresh();
/* -- WML Related -- */
// search for opened/closed tag
// find opened tag at this offset
LeafNode wmlNode = findWMLLeafNodeAtOffset(rootNode, offset, false);
if (wmlNode == null)
{
wmlNode = findWMLLeafNodeAtOffset(rootNode, offset, true);
}
if (wmlNode != null)
{
LeafNode tmp = null;
LeafNode correspondingTag = null;
boolean correspondingIsClosed = false;
for (int i = 0; i < wmlNode.getParent().getChildren().size(); i++)
{
if (!(wmlNode.getParent().getChildren().get(i) instanceof LeafNode))
continue;
if (i > 0 && wmlNode.getParent().getChildren().get(i-1) instanceof LeafNode)
tmp = (LeafNode)wmlNode.getParent().getChildren().get(i-1);
LeafNode tmpNode = (LeafNode)wmlNode.getParent().getChildren().get(i);
if ((tmpNode).getText().equals(wmlNode.getText()) &&
tmpNode != wmlNode && !tmpNode.isHidden())
{
correspondingTag = tmpNode;
if (tmp != null && tmp.getText().equals("[/")) //$NON-NLS-1$
correspondingIsClosed = true;
break;
}
}
if (correspondingTag != null)
{
int tagOffset = correspondingTag.getTotalOffset();
int length = correspondingTag.getLength();
tagOffset--; // we need to color the '['
length += 2;
// we need to color the auxilliary '/'
if (correspondingIsClosed)
{
tagOffset--;
length++;
}
editor.setCurrentHighlightedNode(correspondingTag);
reconcilier.addPosition(tagOffset, length,
WMLHighlightingConfiguration.RULE_START_END_TAG);
reconcilier.refresh();
}
}
return null;
}
public LeafNode findWMLLeafNodeAtOffset(CompositeNode parseTreeRootNode, int offset, boolean findClosed)
{
boolean isClosed = false;
for (AbstractNode node : parseTreeRootNode.getChildren())
{
if (node.getTotalOffset() <= offset)
{
if (node instanceof LeafNode && ((LeafNode) node).getText().equals("[/")) //$NON-NLS-1$
{
isClosed = true;
}
if (node.getTotalOffset() + node.getTotalLength() >= offset)
{
if (node instanceof LeafNode && isWMLTag(node) && (isClosed == findClosed))
return (LeafNode) node;
else if (node instanceof CompositeNode)
return findWMLLeafNodeAtOffset((CompositeNode) node, offset, findClosed);
}
}
}
return null;
}
private boolean isWMLTag(AbstractNode node)
{
return (node.eContainer() != null &&
node.eContainer() instanceof CompositeNode && ((CompositeNode) node.eContainer()).getElement() instanceof WMLTag);
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<template
id="wml.templates.author"
name="author"
description="author name"
context="WMLRoot"
enabled="true">#author ${user}</template>
</templates>