Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit for file templates

  • Loading branch information...
commit 7d360dc31a48a53a58407a42b29998ec28b5437e 1 parent 6d6c99e
@JPMoresmau authored
Showing with 1,334 additions and 843 deletions.
  1. +1 −0  docs/releasenotes/net.sf.eclipsefp.haskell_2.3.3.txt
  2. +1 −1  net.sf.eclipsefp.haskell-feature/feature.xml
  3. +1 −1  net.sf.eclipsefp.haskell.buildwrapper/META-INF/MANIFEST.MF
  4. +30 −0 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
  5. +25 −25 net.sf.eclipsefp.haskell.core.test/META-INF/MANIFEST.MF
  6. +1 −1  net.sf.eclipsefp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/internal/doubles/MockCodeGenerator.java
  7. +4 −3 net.sf.eclipsefp.haskell.core/META-INF/MANIFEST.MF
  8. +33 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/HaskellCorePlugin.java
  9. +16 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/ModuleCreationInfo.java
  10. +2 −1  net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/SourceFileGenerator.java
  11. +34 −8 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/code/CodeGenerator.java
  12. +44 −14 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/project/ProjectModelFilesOp.java
  13. +58 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/CorePreferenceInitializer.java
  14. +13 −0 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/ICorePreferenceNames.java
  15. +2 −2 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalConfiguration.java
  16. +104 −101 ...ipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalFoldingStructureProvider.java
  17. +78 −76 ...f.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalReconcilingStrategy.java
  18. +149 −148 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ColorProvider.java
  19. +276 −275 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScannerManager.java
  20. +23 −5 ...f.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
  21. +218 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/NewHaskellProjectPP.java
  22. +174 −164 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPreviewer.java
  23. +10 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
  24. +11 −0 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
  25. +1 −0  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/properties/ModuleInclusionPP.java
  26. +25 −18 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/wizards/NewGtkProjectWizard.java
View
1  docs/releasenotes/net.sf.eclipsefp.haskell_2.3.3.txt
@@ -15,6 +15,7 @@ Fixes:
Features:
- Evaluate GHCi expressions in debug mode even when not stopped at a breakpoint
- Can specify paths of executables in preferences for Alex, Happy and UUAGC
+ - File templates for cabal file, setup.hs, new modules... (under Preferences -> Haskell -> New Project)
Internal:
View
2  net.sf.eclipsefp.haskell-feature/feature.xml
@@ -158,7 +158,7 @@ available at http://www.eclipse.org/legal/epl-v10.html.
id="net.sf.eclipsefp.haskell.buildwrapper"
download-size="0"
install-size="0"
- version="2.3.2"
+ version="2.3.3"
unpack="false"/>
<plugin
View
2  net.sf.eclipsefp.haskell.buildwrapper/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: net.sf.eclipsefp.haskell.buildwrapper;singleton:=true
-Bundle-Version: 2.3.2
+Bundle-Version: 2.3.3
Bundle-Activator: net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin
Bundle-Vendor: %bundleVendor
Bundle-Localization: plugin
View
30 net.sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
@@ -613,6 +613,36 @@ public void registerOutline(IFile file,OutlineResult or){
return cps;
}
+ public List<TokenDef> tokenTypes(String fn){
+ //long t0=System.currentTimeMillis();
+ LinkedList<String> command=new LinkedList<String>();
+ command.add("tokentypes");
+ command.add("--file="+fn);
+ JSONArray arr=run(command,ARRAY);
+ //long t01=System.currentTimeMillis();
+ List<TokenDef> cps;
+ if (arr!=null){
+ if (arr.length()>1){
+ JSONArray notes=arr.optJSONArray(1);
+ parseNotes(notes);
+ }
+ JSONArray objs=arr.optJSONArray(0);
+ cps=new ArrayList<TokenDef>(objs.length());
+ for (int a=0;a<objs.length();a++){
+ try {
+ cps.add(new TokenDef(fn,objs.getJSONObject(a)));
+ } catch (JSONException je){
+ BuildWrapperPlugin.logError(BWText.process_parse_outline_error, je);
+ }
+ }
+ } else {
+ cps=new ArrayList<TokenDef>();
+ }
+ //long t1=System.currentTimeMillis();
+ //BuildWrapperPlugin.logInfo("tokenTypes:"+(t1-t0)+"ms, parsing:"+(t1-t01)+"ms");
+ return cps;
+ }
+
public BuildFlags getBuildFlags(IFile file){
String path=file.getProjectRelativePath().toOSString();
LinkedList<String> command=new LinkedList<String>();
View
50 net.sf.eclipsefp.haskell.core.test/META-INF/MANIFEST.MF
@@ -1,25 +1,25 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Plug-in for testing Haskell Core
-Bundle-SymbolicName: net.sf.eclipsefp.haskell.core.test
-Bundle-Version: 2.2.2
-Bundle-Vendor: eclipsefp.sourceforge.net
-Require-Bundle: org.easymock;bundle-version="[2.2.0,3.0.0)",
- org.junit4,
- org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.expressions,
- org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
- net.sf.eclipsefp.haskell.core,
- net.sf.eclipsefp.haskell.ui,
- net.sf.eclipsefp.haskell.util,
- org.eclipse.ui;bundle-version="3.5.1"
-Export-Package: net.sf.eclipsefp.haskell.core.cabalmodel,
- net.sf.eclipsefp.haskell.core.internal.doubles;x-friends:="net.sf.eclipsefp.haskell.ui.test",
- net.sf.eclipsefp.haskell.core.internal.project,
- net.sf.eclipsefp.haskell.core.internal.util,
- net.sf.eclipsefp.haskell.core.project,
- net.sf.eclipsefp.haskell.core.project.util,
- net.sf.eclipsefp.haskell.core.test
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Plug-in for testing Haskell Core
+Bundle-SymbolicName: net.sf.eclipsefp.haskell.core.test
+Bundle-Version: 2.3.3
+Bundle-Vendor: eclipsefp.sourceforge.net
+Require-Bundle: org.easymock;bundle-version="[2.2.0,3.0.0)",
+ org.junit4,
+ org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.expressions,
+ org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
+ net.sf.eclipsefp.haskell.core,
+ net.sf.eclipsefp.haskell.ui,
+ net.sf.eclipsefp.haskell.util,
+ org.eclipse.ui;bundle-version="3.5.1"
+Export-Package: net.sf.eclipsefp.haskell.core.cabalmodel,
+ net.sf.eclipsefp.haskell.core.internal.doubles;x-friends:="net.sf.eclipsefp.haskell.ui.test",
+ net.sf.eclipsefp.haskell.core.internal.project,
+ net.sf.eclipsefp.haskell.core.internal.util,
+ net.sf.eclipsefp.haskell.core.project,
+ net.sf.eclipsefp.haskell.core.project.util,
+ net.sf.eclipsefp.haskell.core.test
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
View
2  ...sf.eclipsefp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/internal/doubles/MockCodeGenerator.java
@@ -19,7 +19,7 @@ public void setOutput(final String output) {
}
@Override
- public String createModuleContent(
+ public String createModuleContent(final String projectName,
final String[] folderNames,
final String name,
final EHaskellCommentStyle style)
View
7 net.sf.eclipsefp.haskell.core/META-INF/MANIFEST.MF
@@ -10,11 +10,12 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="3.5.0",
org.eclipse.text;bundle-version="3.5.0",
- net.sf.eclipsefp.haskell.util;bundle-version="2.3.2",
- net.sf.eclipsefp.haskell.hlint;bundle-version="2.3.2",
+ net.sf.eclipsefp.haskell.util,
+ net.sf.eclipsefp.haskell.hlint,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.2",
- net.sf.eclipsefp.haskell.buildwrapper;bundle-version="2.3.2"
+ net.sf.eclipsefp.haskell.buildwrapper,
+ org.eclipse.core.variables
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
View
33 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/HaskellCorePlugin.java
@@ -6,12 +6,14 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import net.sf.eclipsefp.haskell.core.compiler.CompilerManager;
import net.sf.eclipsefp.haskell.core.expressions.HaskellPropertyTester;
import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
@@ -20,6 +22,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.IValueVariable;
+import org.eclipse.core.variables.VariablesPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -176,4 +181,32 @@ private void collectCompilerInfo() {
public static final IEclipsePreferences instanceScopedPreferences() {
return InstanceScope.INSTANCE.getNode( getPluginId() );
}
+
+ public static String populateTemplate(final String pref,final Map<String,String> extraVars){
+ IStringVariableManager mgr=VariablesPlugin.getDefault().getStringVariableManager();
+ IEclipsePreferences coreNode = instanceScopedPreferences();
+ String template=coreNode.get( pref, "" ); //$NON-NLS-1$
+
+ try {
+ IValueVariable[] vars = new IValueVariable[0];
+ if (extraVars!=null){
+ vars = new IValueVariable[extraVars.size()];
+ int a=0;
+ for (String key:extraVars.keySet()){
+ String val=extraVars.get( key );
+ vars[a++]=mgr.newValueVariable( key, "",true,val );//$NON-NLS-1$
+
+ }
+ mgr.addVariables( vars );
+ }
+ try {
+ return mgr.performStringSubstitution( template );
+ } finally {
+ mgr.removeVariables( vars );
+ }
+ } catch (CoreException ce){
+ HaskellCorePlugin.log( ce );
+ }
+ return "";//$NON-NLS-1$
+ }
}
View
16 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/ModuleCreationInfo.java
@@ -6,6 +6,7 @@
import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
@@ -30,6 +31,7 @@
*/
private boolean foldersQualify=true;
+ private IProject project;
// attribute setters and getters
////////////////////////////////
@@ -40,6 +42,7 @@ public ModuleCreationInfo() {
public ModuleCreationInfo(final IFile f) {
super();
+ this.project=f.getProject();
IContainer src=ResourceUtil.getSourceContainer( f );
setSourceContainer( src );
if (src!=null){
@@ -86,6 +89,9 @@ public IContainer getSourceContainer() {
public void setSourceContainer( final IContainer sourceContainer ) {
this.sourceContainer = sourceContainer;
+ if (this.sourceContainer!=null){
+ this.project=this.sourceContainer.getProject();
+ }
}
public EHaskellCommentStyle getCommentStyle() {
@@ -137,4 +143,14 @@ public void setEditorStanza( final PackageDescriptionStanza editorStanza ) {
}
+ public IProject getProject() {
+ return project;
+ }
+
+
+ public void setProject( final IProject project ) {
+ this.project = project;
+ }
+
+
}
View
3  net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/SourceFileGenerator.java
@@ -100,7 +100,8 @@ private IFile createFile( final ModuleCreationInfo info,
final String[] segments = getPathSegments( info );
final String moduleName = info.getModuleName();
final EHaskellCommentStyle style = info.getCommentStyle();
- String fileContent = fCodeGenerator.createModuleContent( segments,
+ String pName=info.getProject()!=null?info.getProject().getName():"";
+ String fileContent = fCodeGenerator.createModuleContent( pName,segments,
moduleName,
style );
String fileName = createFileName( style, moduleName );
View
42 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/code/CodeGenerator.java
@@ -3,7 +3,12 @@
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.core.internal.code;
+import java.util.HashMap;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.core.code.EHaskellCommentStyle;
+import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
+import net.sf.eclipsefp.haskell.core.preferences.TemplateVariables;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
@@ -13,21 +18,42 @@
*/
public class CodeGenerator {
- // TODO honor code template for generating this
- public String createModuleContent( final String[] folderNames,
+ public String createModuleContent( final String projectName,
+ final String[] folderNames,
final String name,
final EHaskellCommentStyle style ) {
StringBuilder sb = new StringBuilder();
sb.append( PlatformUtil.NL );
sb.append(getPrefixFor( style ));
- sb.append( "module " ); //$NON-NLS-1$
+ StringBuilder module=new StringBuilder();
+ StringBuilder src=new StringBuilder();
for( int i = 0; i < folderNames.length; i++ ) {
- sb.append( folderNames[ i ] );
- sb.append( "." ); //$NON-NLS-1$
+ module.append( folderNames[ i ] );
+ module.append( "." ); //$NON-NLS-1$
+ if (src.length()>0){
+ src.append("/");//$NON-NLS-1$
+ }
+ src.append(folderNames[ i ]);
}
- sb.append( name );
- sb.append( " where" ); //$NON-NLS-1$
- sb.append( PlatformUtil.NL);
+ module.append(name);
+ Map<String,String> vars=new HashMap<String, String>();
+ vars.put( TemplateVariables.MODULE_NAME, module.toString() );
+ vars.put( TemplateVariables.PROJECT_NAME, projectName );
+ vars.put( TemplateVariables.SRC, src.toString() );
+ vars.put( TemplateVariables.USER_NAME, PlatformUtil.getCurrentUser() );
+
+ String mod=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MODULE, vars );
+ sb.append(mod);
+// sb.append( "module " ); //$NON-NLS-1$
+// for( int i = 0; i < folderNames.length; i++ ) {
+// sb.append( folderNames[ i ] );
+// sb.append( "." ); //$NON-NLS-1$
+// }
+// sb.append( name );
+// sb.append( " where" ); //$NON-NLS-1$
+// sb.append( PlatformUtil.NL);
+
+
sb.append( getSuffixFor(style) );
return sb.toString();
}
View
58 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/internal/project/ProjectModelFilesOp.java
@@ -6,12 +6,15 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.core.cabalmodel.CabalContributorManager;
-import net.sf.eclipsefp.haskell.core.cabalmodel.CabalSyntax;
import net.sf.eclipsefp.haskell.core.cabalmodel.ICabalContributor;
import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescription;
-import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionStanza;
+import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionLoader;
+import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
+import net.sf.eclipsefp.haskell.core.preferences.TemplateVariables;
import net.sf.eclipsefp.haskell.core.project.HaskellProjectCreationOperation;
import net.sf.eclipsefp.haskell.util.FileUtil;
import net.sf.eclipsefp.haskell.util.PlatformUtil;
@@ -43,15 +46,20 @@ public void run( final IProject project,
// we create nothing if no component selected, probably we're getting files from source control system or something
if (isExecutable() || isLibrary()){
String name = project.getName();
+ String src=HaskellProjectCreationOperation.getSourceDir();
+ Map<String,String> vars=new HashMap<String, String>();
+ vars.put( TemplateVariables.PROJECT_NAME, name );
+ vars.put( TemplateVariables.SRC, src );
+ vars.put( TemplateVariables.USER_NAME, PlatformUtil.getCurrentUser() );
// we create a normal setup, but it could be a literate file
IFile litSetup = project.getFile( "Setup.lhs" ); //$NON-NLS-1$
// file may exist if project is created from source version control
if (!litSetup.exists()){
- createFile( project, new Path( SETUP_HS ), getSetupFileContent(), mo );
+ createFile( project, new Path( SETUP_HS ), getSetupFileContent(vars), mo );
}
- String src=HaskellProjectCreationOperation.getSourceDir();
+
if (isExecutable()){
String mainPath="Main";//$NON-NLS-1$
@@ -60,12 +68,12 @@ public void run( final IProject project,
}
IPath mainFile = new Path( mainPath ).addFileExtension( FileUtil.EXTENSION_HS );
- createFile( project, mainFile, getMainFileContent( ), mo );
+ createFile( project, mainFile, getMainFileContent(vars ), mo );
}
IPath cabalFile = new Path( name ).addFileExtension( FileUtil.EXTENSION_CABAL );
- createFile( project, cabalFile, getCabalFileContent( name,src ), mo );
+ createFile( project, cabalFile, getCabalFileContent( vars ), mo );
}
}
@@ -73,17 +81,21 @@ public void run( final IProject project,
// helping methods
//////////////////
- protected String getMainFileContent() {
- return "module Main where"+PlatformUtil.NL+PlatformUtil.NL+"main::IO()"+PlatformUtil.NL+"main = undefined"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ protected String getMainFileContent(final Map<String,String> vars ) {
+ vars.put( TemplateVariables.MODULE_NAME, "Main" );//$NON-NLS-1$
+ String mod=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MODULE, vars );
+ vars.put( TemplateVariables.MODULE, mod );
+ return HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MAIN, vars );
+ //return "module Main where"+PlatformUtil.NL+PlatformUtil.NL+"main::IO()"+PlatformUtil.NL+"main = undefined"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- private String getCabalFileContent( final String name,final String src ) {
- return getCabalFile( name ,src).dump();
+ private String getCabalFileContent( final Map<String,String> vars ) {
+ return getCabalFile( vars).dump();
}
- protected PackageDescription getCabalFile(final String name,final String src){
+ protected PackageDescription getCabalFile(final Map<String,String> vars){
/*String s=CabalSyntax.FIELD_NAME.getCabalName()+": " + name + NL //$NON-NLS-1$
+ CabalSyntax.FIELD_VERSION.getCabalName()+": 0.1 "+ NL + NL //$NON-NLS-1$
@@ -102,7 +114,7 @@ protected PackageDescription getCabalFile(final String name,final String src){
return s;*/
- PackageDescription pd=new PackageDescription( name );
+ /*PackageDescription pd=new PackageDescription( name );
pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_VERSION, "0.1" ); //$NON-NLS-1$
pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_CABAL_VERSION, ">= 1.2" ); //$NON-NLS-1$
pd.getStanzas().get( 0 ).update( CabalSyntax.FIELD_BUILD_TYPE, "Simple" ); //$NON-NLS-1$
@@ -124,7 +136,23 @@ protected PackageDescription getCabalFile(final String name,final String src){
pds.update( CabalSyntax.FIELD_MAIN_IS, "Main.hs" ); //$NON-NLS-1$
pds.update( CabalSyntax.FIELD_BUILD_DEPENDS, "base >= 4" ); //$NON-NLS-1$
pds.update( CabalSyntax.FIELD_GHC_OPTIONS, "-Wall" ); //$NON-NLS-1$
+ }*/
+
+ String library=""; //$NON-NLS-1$
+
+ if (isLibrary()){
+ library=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_CABAL_LIBRARY, vars );
}
+ vars.put( TemplateVariables.LIBRARY, library );
+
+ String exe="";//$NON-NLS-1$
+ if (isExecutable()){
+ exe=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_CABAL_EXE, vars );
+ }
+ vars.put( TemplateVariables.EXECUTABLE, exe );
+
+ String content=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_CABAL, vars);
+ PackageDescription pd=PackageDescriptionLoader.load( content );
for (ICabalContributor c:CabalContributorManager.getContributors()){
c.contributeOnNewProject( pd );
@@ -151,8 +179,10 @@ private void createFile( final IProject project,
}
}
- private String getSetupFileContent() {
- return "import Distribution.Simple"+PlatformUtil.NL+"main = defaultMain"+PlatformUtil.NL; //$NON-NLS-1$ //$NON-NLS-2$
+
+ private String getSetupFileContent(final Map<String,String> vars) {
+ //return "import Distribution.Simple"+PlatformUtil.NL+"main = defaultMain"+PlatformUtil.NL; //$NON-NLS-1$ //$NON-NLS-2$
+ return HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_CABAL_SETUP, vars );
}
View
58 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/CorePreferenceInitializer.java
@@ -2,7 +2,9 @@
package net.sf.eclipsefp.haskell.core.preferences;
import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
+import net.sf.eclipsefp.haskell.core.cabalmodel.CabalSyntax;
import net.sf.eclipsefp.haskell.util.FileUtil;
+import net.sf.eclipsefp.haskell.util.PlatformUtil;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
@@ -29,5 +31,61 @@ public void initializeDefaultPreferences() {
coreNode.putBoolean( DEBUG_BREAK_ON_EXCEPTION, false );
coreNode.putBoolean( DEBUG_PRINT_WITH_SHOW, true );
coreNode.putInt( RUN_COMMAND_HISTORY_MAX, 20 );
+
+ coreNode.put( TEMPLATE_CABAL,
+ CabalSyntax.FIELD_NAME.getCabalName()+": ${"+TemplateVariables.PROJECT_NAME+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ CabalSyntax.FIELD_VERSION.getCabalName()+": 0.1"+PlatformUtil.NL+ //$NON-NLS-1$
+ CabalSyntax.FIELD_CABAL_VERSION.getCabalName()+": >=1.2"+PlatformUtil.NL+ //$NON-NLS-1$
+ CabalSyntax.FIELD_AUTHOR.getCabalName()+": ${"+TemplateVariables.USER_NAME+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ ""+PlatformUtil.NL+ //$NON-NLS-1$
+ "${"+TemplateVariables.LIBRARY+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ "${"+TemplateVariables.EXECUTABLE+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ ""); //$NON-NLS-1$
+
+ coreNode.put( TEMPLATE_CABAL_LIBRARY,
+ CabalSyntax.SECTION_LIBRARY.getCabalName()+PlatformUtil.NL+
+ " "+CabalSyntax.FIELD_HS_SOURCE_DIRS.getCabalName()+": ${"+TemplateVariables.SRC+"}" +PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " "+CabalSyntax.FIELD_BUILD_DEPENDS.getCabalName()+": base >= 4" +PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ " "+CabalSyntax.FIELD_GHC_OPTIONS.getCabalName()+": -Wall" +PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ ""); //$NON-NLS-1$
+
+ coreNode.put( TEMPLATE_CABAL_EXE,
+ CabalSyntax.SECTION_EXECUTABLE.getCabalName()+" ${"+TemplateVariables.PROJECT_NAME+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ " "+CabalSyntax.FIELD_HS_SOURCE_DIRS+": ${"+TemplateVariables.SRC+"}" +PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " "+CabalSyntax.FIELD_MAIN_IS+": Main.hs"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ " "+CabalSyntax.FIELD_BUILD_DEPENDS+": base >= 4"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ " "+CabalSyntax.FIELD_GHC_OPTIONS+": -Wall"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ ""); //$NON-NLS-1$
+
+ coreNode.put( TEMPLATE_CABAL_SETUP,
+ "import Distribution.Simple"+PlatformUtil.NL+"main = defaultMain"+PlatformUtil.NL //$NON-NLS-1$ //$NON-NLS-2$
+ );
+
+ coreNode.put( TEMPLATE_MODULE,
+ "module ${"+TemplateVariables.MODULE_NAME+"} where"+PlatformUtil.NL //$NON-NLS-1$ //$NON-NLS-2$
+ );
+
+ coreNode.put( TEMPLATE_MAIN,
+ "${"+TemplateVariables.MODULE+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ "main::IO()"+PlatformUtil.NL+ //$NON-NLS-1$
+ "main = undefined" //$NON-NLS-1$
+ );
+
+ coreNode.put( TEMPLATE_GTK,
+ "${"+TemplateVariables.MODULE+"}"+PlatformUtil.NL+ //$NON-NLS-1$ //$NON-NLS-2$
+ "import Graphics.UI.Gtk"+PlatformUtil.NL+PlatformUtil.NL+ //$NON-NLS-1$
+ "main :: IO ()"+PlatformUtil.NL+ //$NON-NLS-1$
+ "main = do"+PlatformUtil.NL+ //$NON-NLS-1$
+ " initGUI"+PlatformUtil.NL+ //$NON-NLS-1$
+ " window <- windowNew"+PlatformUtil.NL+ //$NON-NLS-1$
+ " button <- buttonNew"+PlatformUtil.NL+ //$NON-NLS-1$
+ " set window [ containerBorderWidth := 10,"+PlatformUtil.NL+ //$NON-NLS-1$
+ " containerChild := button ]"+PlatformUtil.NL+ //$NON-NLS-1$
+ " set button [ buttonLabel := \"Hello World\" ]"+PlatformUtil.NL+ //$NON-NLS-1$
+ " onClicked button (putStrLn \"Hello World\")"+PlatformUtil.NL+ //$NON-NLS-1$
+ " onDestroy window mainQuit"+PlatformUtil.NL+ //$NON-NLS-1$
+ " widgetShowAll window"+PlatformUtil.NL+ //$NON-NLS-1$
+ " mainGUI"+PlatformUtil.NL //$NON-NLS-1$
+ );
}
}
View
13 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/ICorePreferenceNames.java
@@ -27,4 +27,17 @@
String DEBUG_PRINT_WITH_SHOW="DEBUG_PRINT_EVAL_WITH_SHOW"; //$NON-NLS-1$
String RUN_COMMAND_HISTORY_MAX="RUN_COMMAND_HISTORY_MAX"; //$NON-NLS-1$
+
+
+ String TEMPLATE_CABAL_LIBRARY="TEMPLATE_CABAL_LIBRARY"; //$NON-NLS-1$
+ String TEMPLATE_CABAL_EXE="TEMPLATE_CABAL_EXE"; //$NON-NLS-1$
+ String TEMPLATE_CABAL="TEMPLATE_CABAL"; //$NON-NLS-1$
+ String TEMPLATE_CABAL_SETUP="TEMPLATE_CABAL_SETUP"; //$NON-NLS-1$
+
+ String TEMPLATE_MODULE="TEMPLATE_MODULE"; //$NON-NLS-1$
+// String TEMPLATE_LIT="TEMPLATE_LIT"; //$NON-NLS-1$
+// String TEMPLATE_TEX="TEMPLATE_TEX"; //$NON-NLS-1$
+ String TEMPLATE_MAIN="TEMPLATE_MAIN"; //$NON-NLS-1$
+ String TEMPLATE_GTK="TEMPLATE_GTK"; //$NON-NLS-1$
+
}
View
4 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalConfiguration.java
@@ -42,14 +42,14 @@
*
* @author Leif Frenzel
*/
-class CabalConfiguration extends SourceViewerConfiguration {
+public class CabalConfiguration extends SourceViewerConfiguration {
private final CabalFormEditor editor;
private ITokenScanner defaultScanner;
private ITokenScanner commentScanner;
- CabalConfiguration( final CabalFormEditor editor ) {
+ public CabalConfiguration( final CabalFormEditor editor ) {
this.editor = editor;
}
View
205 ...efp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalFoldingStructureProvider.java
@@ -1,101 +1,104 @@
-package net.sf.eclipsefp.haskell.ui.internal.editors.cabal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescription;
-import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionStanza;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
-import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
-
-class CabalFoldingStructureProvider {
-
- private final CabalFormEditor editor;
- private IDocument document;
-
- CabalFoldingStructureProvider( final CabalFormEditor editor ) {
- this.editor = editor;
- }
-
- void setDocument( final IDocument document ) {
- this.document = document;
- }
-
- void updateFoldingRegions( final PackageDescription pd ) {
- try {
- Class<ProjectionAnnotationModel> ad = ProjectionAnnotationModel.class;
- ProjectionAnnotationModel model
- = ( ProjectionAnnotationModel )editor.getAdapter( ad );
- if( model != null ) {
- Set<Position> currentRegions = new HashSet<Position>();
- addFoldingRegions( currentRegions, pd.getStanzas() );
- updateFoldingRegions( model, currentRegions );
- }
- } catch( final BadLocationException badlox ) {
- // ignore
- }
- }
-
- private void updateFoldingRegions( final ProjectionAnnotationModel model,
- final Set<Position> currentRegions ) {
- Annotation[] deletions = diff( model, currentRegions );
- Map<ProjectionAnnotation, Position> adds
- = new HashMap<ProjectionAnnotation, Position>();
- Iterator<Position> it = currentRegions.iterator();
- while( it.hasNext() ) {
- adds.put( new ProjectionAnnotation(), it.next() );
- }
-
- if( ( deletions.length != 0 || adds.size() != 0 ) ) {
- model.modifyAnnotations( deletions, adds, new Annotation[ 0 ] );
- }
- }
-
- private Annotation[] diff( final ProjectionAnnotationModel model,
- final Set<Position> current) {
- List<ProjectionAnnotation> deletions= new ArrayList<ProjectionAnnotation>();
- Iterator<?> it = model.getAnnotationIterator();
- while( it.hasNext() ) {
- Object annotation = it.next();
- if( annotation instanceof ProjectionAnnotation ) {
- Position position = model.getPosition( ( Annotation )annotation );
- if( current.contains( position ) ) {
- current.remove( position );
- } else {
- deletions.add( ( ProjectionAnnotation )annotation );
- }
- }
- }
- return deletions.toArray( new ProjectionAnnotation[ deletions.size() ] );
- }
-
- private void addFoldingRegions( final Set<Position> regions,
- final Iterable<PackageDescriptionStanza> elements )
- throws BadLocationException {
- for( PackageDescriptionStanza element:elements) {
- int startLine = element.getStartLine();
- int endLine = element.getEndLine();
- if( startLine < endLine ) {
- int start = document.getLineOffset( startLine );
- int end = document.getLength();
- try {
- end = document.getLineOffset( endLine-1 )
- + document.getLineLength( endLine-1 );
- } catch( final BadLocationException badlox ) {
- // ignore
- }
- Position position= new Position( start, end - start );
- regions.add( position );
- addFoldingRegions( regions, element.getStanzas() );
- }
- }
- }
-}
+package net.sf.eclipsefp.haskell.ui.internal.editors.cabal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescription;
+import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionStanza;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+
+class CabalFoldingStructureProvider {
+
+ private final CabalFormEditor editor;
+ private IDocument document;
+
+ CabalFoldingStructureProvider( final CabalFormEditor editor ) {
+ this.editor = editor;
+ }
+
+ void setDocument( final IDocument document ) {
+ this.document = document;
+ }
+
+ void updateFoldingRegions( final PackageDescription pd ) {
+ if (editor==null){
+ return;
+ }
+ try {
+ Class<ProjectionAnnotationModel> ad = ProjectionAnnotationModel.class;
+ ProjectionAnnotationModel model
+ = ( ProjectionAnnotationModel )editor.getAdapter( ad );
+ if( model != null ) {
+ Set<Position> currentRegions = new HashSet<Position>();
+ addFoldingRegions( currentRegions, pd.getStanzas() );
+ updateFoldingRegions( model, currentRegions );
+ }
+ } catch( final BadLocationException badlox ) {
+ // ignore
+ }
+ }
+
+ private void updateFoldingRegions( final ProjectionAnnotationModel model,
+ final Set<Position> currentRegions ) {
+ Annotation[] deletions = diff( model, currentRegions );
+ Map<ProjectionAnnotation, Position> adds
+ = new HashMap<ProjectionAnnotation, Position>();
+ Iterator<Position> it = currentRegions.iterator();
+ while( it.hasNext() ) {
+ adds.put( new ProjectionAnnotation(), it.next() );
+ }
+
+ if( ( deletions.length != 0 || adds.size() != 0 ) ) {
+ model.modifyAnnotations( deletions, adds, new Annotation[ 0 ] );
+ }
+ }
+
+ private Annotation[] diff( final ProjectionAnnotationModel model,
+ final Set<Position> current) {
+ List<ProjectionAnnotation> deletions= new ArrayList<ProjectionAnnotation>();
+ Iterator<?> it = model.getAnnotationIterator();
+ while( it.hasNext() ) {
+ Object annotation = it.next();
+ if( annotation instanceof ProjectionAnnotation ) {
+ Position position = model.getPosition( ( Annotation )annotation );
+ if( current.contains( position ) ) {
+ current.remove( position );
+ } else {
+ deletions.add( ( ProjectionAnnotation )annotation );
+ }
+ }
+ }
+ return deletions.toArray( new ProjectionAnnotation[ deletions.size() ] );
+ }
+
+ private void addFoldingRegions( final Set<Position> regions,
+ final Iterable<PackageDescriptionStanza> elements )
+ throws BadLocationException {
+ for( PackageDescriptionStanza element:elements) {
+ int startLine = element.getStartLine();
+ int endLine = element.getEndLine();
+ if( startLine < endLine ) {
+ int start = document.getLineOffset( startLine );
+ int end = document.getLength();
+ try {
+ end = document.getLineOffset( endLine-1 )
+ + document.getLineLength( endLine-1 );
+ } catch( final BadLocationException badlox ) {
+ // ignore
+ }
+ Position position= new Position( start, end - start );
+ regions.add( position );
+ addFoldingRegions( regions, element.getStanzas() );
+ }
+ }
+ }
+}
View
154 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/CabalReconcilingStrategy.java
@@ -1,76 +1,78 @@
-// Copyright (c) 2006 by Leif Frenzel <himself@leiffrenzel.de>
-// All rights reserved.
-package net.sf.eclipsefp.haskell.ui.internal.editors.cabal;
-
-import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescription;
-import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionLoader;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
-import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
-import org.eclipse.swt.widgets.Display;
-
-class CabalReconcilingStrategy implements IReconcilingStrategy,
- IReconcilingStrategyExtension {
-
- private final CabalFormEditor editor;
- private IDocument document;
- private final CabalFoldingStructureProvider foldingStructureProvider;
-
- CabalReconcilingStrategy( final CabalFormEditor editor ) {
- this.editor = editor;
- foldingStructureProvider = new CabalFoldingStructureProvider( editor );
- }
-
-
- // interface methods of IReconcilingStrategy
- ////////////////////////////////////////////
-
- @Override
- public void reconcile( final IRegion partition ) {
- reconcile();
- }
-
- @Override
- public void reconcile( final DirtyRegion dirtyRegion, final IRegion subRegion ) {
- reconcile();
- }
-
- @Override
- public void setDocument( final IDocument document ) {
- this.document = document;
- foldingStructureProvider.setDocument( document );
- }
-
-
- // interface methods of IReconcilingStrategyExtension
- /////////////////////////////////////////////////////
-
- @Override
- public void initialReconcile() {
- reconcile();
- }
-
- @Override
- public void setProgressMonitor( final IProgressMonitor monitor ) {
- // unused
- }
-
-
- // helping methods
- //////////////////
-
- private void reconcile() {
- String content = document.get();
- final PackageDescription pd = PackageDescriptionLoader.load( content );
- Display.getDefault().asyncExec( new Runnable() {
- @Override
- public void run() {
- editor.setPackageDescription( pd );
- }
- } );
- foldingStructureProvider.updateFoldingRegions( pd );
- }
-}
+// Copyright (c) 2006 by Leif Frenzel <himself@leiffrenzel.de>
+// All rights reserved.
+package net.sf.eclipsefp.haskell.ui.internal.editors.cabal;
+
+import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescription;
+import net.sf.eclipsefp.haskell.core.cabalmodel.PackageDescriptionLoader;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
+import org.eclipse.swt.widgets.Display;
+
+class CabalReconcilingStrategy implements IReconcilingStrategy,
+ IReconcilingStrategyExtension {
+
+ private final CabalFormEditor editor;
+ private IDocument document;
+ private final CabalFoldingStructureProvider foldingStructureProvider;
+
+ CabalReconcilingStrategy( final CabalFormEditor editor ) {
+ this.editor = editor;
+ foldingStructureProvider = new CabalFoldingStructureProvider( editor );
+ }
+
+
+ // interface methods of IReconcilingStrategy
+ ////////////////////////////////////////////
+
+ @Override
+ public void reconcile( final IRegion partition ) {
+ reconcile();
+ }
+
+ @Override
+ public void reconcile( final DirtyRegion dirtyRegion, final IRegion subRegion ) {
+ reconcile();
+ }
+
+ @Override
+ public void setDocument( final IDocument document ) {
+ this.document = document;
+ foldingStructureProvider.setDocument( document );
+ }
+
+
+ // interface methods of IReconcilingStrategyExtension
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void initialReconcile() {
+ reconcile();
+ }
+
+ @Override
+ public void setProgressMonitor( final IProgressMonitor monitor ) {
+ // unused
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private void reconcile() {
+ String content = document.get();
+ final PackageDescription pd = PackageDescriptionLoader.load( content );
+ if (editor!=null){
+ Display.getDefault().asyncExec( new Runnable() {
+ @Override
+ public void run() {
+ editor.setPackageDescription( pd );
+ }
+ } );
+ foldingStructureProvider.updateFoldingRegions( pd );
+ }
+ }
+}
View
297 ...sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ColorProvider.java
@@ -1,149 +1,150 @@
-// Copyright (c) 2003-2008 by Leif Frenzel - see http://leiffrenzel.de
-// This code is made available under the terms of the Eclipse Public License,
-// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
-package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
-import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.resource.StringConverter;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-
-/** Provides colors for syntax coloring in the editor.
- *
- * This is implemented as singleton to make it accessible from
- * everywhere and also to reduce resource management to one single place.
- *
- * @author Leif Frenzel
- */
-public class ColorProvider implements IEditorPreferenceNames {
-
- public static final RGB DEFAULT_COMMENT = new RGB( 128, 128, 192 );
- public static final RGB DEFAULT_LITERATE_COMMENT = new RGB( 128, 128, 192 );
- public static final RGB DEFAULT_KEYWORD = new RGB( 0, 0, 196 );
- public static final RGB DEFAULT_FUNCTION = new RGB( 64, 192, 192 );
- public static final RGB DEFAULT_STRING = new RGB( 128, 64, 64 );
- public static final RGB DEFAULT_CHAR = new RGB( 96, 96, 96 );
- public static final RGB DEFAULT_NUMBER = new RGB( 0, 0, 0 );
- public static final RGB DEFAULT_VAR = new RGB( 0, 0, 0 );
- public static final RGB DEFAULT_CON = new RGB( 200, 0, 0 );
- public static final RGB DEFAULT_CPP = new RGB( 128, 128, 192 );
- public static final RGB DEFAULT_TH = new RGB( 0, 0, 0 );
- public static final RGB DEFAULT_SYMBOL = new RGB( 128, 128, 0 );
- public static final RGB DEFAULT_OTHER = new RGB( 0, 0, 0 );
-
- /** The internal singleton reference to ColorProvider. */
- private static class SingletonHolder {
- private static final ColorProvider theInstance = new ColorProvider();
- }
-
- private final Map<RGB, Color> colors;
- private final Map<String, RGB> rgbs;
-
- private IPreferenceStore prefStore;
-
- /** <p>constructs the singleton instance of ColorProvider. Private in order
- * to ensure the singleton pattern.</p> */
- private ColorProvider() {
- colors = new HashMap<RGB, Color>( 10 );
- rgbs = new HashMap<String, RGB>( 10 );
- initializeRgbs();
- }
-
- public static final ColorProvider getInstance() {
- return SingletonHolder.theInstance;
- }
-
- public ColorProvider(final IPreferenceStore store){
- prefStore=store;
- colors = new HashMap<RGB, Color>( 10 );
- rgbs = new HashMap<String, RGB>( 10 );
- initializeRgbs();
- }
-
- /** <p>releases all of the color resources held by this ColorProvider.</p> */
- public void dispose() {
- Iterator<Color> it = colors.values().iterator();
- while( it.hasNext() ) {
- it.next().dispose();
- }
- }
-
- public Color getColor( final String key ) {
- RGB rgb = rgbs.get( key );
- Assert.isNotNull( rgb );
- return getColor( rgb );
- }
-
- void changeColor( final String key, final Object newValue ) {
- RGB oldRgb = rgbs.get( key );
- if( oldRgb != null ) {
- RGB newRgb = getNewRgb( newValue );
- if( newRgb != null ) {
- rgbs.put( key, newRgb );
- }
- }
- }
-
-
- // helping methods
- //////////////////
-
- private RGB getNewRgb( final Object value ) {
- RGB result = null;
- if( value instanceof RGB ) {
- result = ( RGB )value;
- } else if( value instanceof String ) {
- result = StringConverter.asRGB( ( String )value );
- }
- return result;
- }
-
- private Color getColor( final RGB rgb ) {
- Color color = colors.get( rgb );
- if( color == null ) {
- color = new Color( Display.getCurrent(), rgb );
- colors.put( rgb, color );
- }
- return color;
- }
-
- private void initializeRgbs() {
- putRgb( EDITOR_COMMENT_COLOR, DEFAULT_COMMENT );
- putRgb( EDITOR_LITERATE_COMMENT_COLOR, DEFAULT_LITERATE_COMMENT );
- putRgb( EDITOR_FUNCTION_COLOR, DEFAULT_FUNCTION );
- putRgb( EDITOR_KEYWORD_COLOR, DEFAULT_KEYWORD );
- putRgb( EDITOR_DEFAULT_COLOR, DEFAULT_OTHER );
- putRgb( EDITOR_STRING_COLOR, DEFAULT_STRING );
- putRgb( EDITOR_CHAR_COLOR, DEFAULT_CHAR );
- putRgb( EDITOR_NUMBER_COLOR, DEFAULT_NUMBER );
- putRgb( EDITOR_VAR_COLOR, DEFAULT_VAR );
- putRgb( EDITOR_CON_COLOR, DEFAULT_CON );
- putRgb( EDITOR_CPP_COLOR, DEFAULT_CPP );
- putRgb( EDITOR_TH_COLOR, DEFAULT_TH );
- putRgb( EDITOR_SYMBOL_COLOR, DEFAULT_SYMBOL );
- }
-
- private void putRgb( final String key, final RGB defaultRgb ) {
- RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
- if( rgb == null ) {
- rgb = defaultRgb;
- }
- rgbs.put( key, rgb );
- }
-
- private IPreferenceStore getPreferenceStore() {
- if (prefStore!=null){
- return prefStore;
- }
- return HaskellUIPlugin.getDefault().getPreferenceStore();
- }
+// Copyright (c) 2003-2008 by Leif Frenzel - see http://leiffrenzel.de
+// This code is made available under the terms of the Eclipse Public License,
+// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.StringConverter;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+/** Provides colors for syntax coloring in the editor.
+ *
+ * This is implemented as singleton to make it accessible from
+ * everywhere and also to reduce resource management to one single place.
+ *
+ * @author Leif Frenzel
+ */
+public class ColorProvider implements IEditorPreferenceNames {
+
+ public static final RGB DEFAULT_COMMENT = new RGB( 128, 128, 192 );
+ public static final RGB DEFAULT_LITERATE_COMMENT = new RGB( 128, 128, 192 );
+ public static final RGB DEFAULT_KEYWORD = new RGB( 0, 0, 196 );
+ public static final RGB DEFAULT_FUNCTION = new RGB( 64, 192, 192 );
+ public static final RGB DEFAULT_STRING = new RGB( 128, 64, 64 );
+ public static final RGB DEFAULT_CHAR = new RGB( 96, 96, 96 );
+ public static final RGB DEFAULT_NUMBER = new RGB( 0, 0, 0 );
+ public static final RGB DEFAULT_VAR = new RGB( 0, 0, 0 );
+ public static final RGB DEFAULT_CON = new RGB( 200, 0, 0 );
+ public static final RGB DEFAULT_CPP = new RGB( 128, 128, 192 );
+ public static final RGB DEFAULT_TH = new RGB( 0, 0, 0 );
+ public static final RGB DEFAULT_SYMBOL = new RGB( 128, 128, 0 );
+ public static final RGB DEFAULT_OTHER = new RGB( 0, 0, 0 );
+
+ /** The internal singleton reference to ColorProvider. */
+ private static class SingletonHolder {
+ private static final ColorProvider theInstance = new ColorProvider();
+ }
+
+ private final Map<RGB, Color> colors;
+ private final Map<String, RGB> rgbs;
+
+ private IPreferenceStore prefStore;
+
+ /** <p>constructs the singleton instance of ColorProvider. Private in order
+ * to ensure the singleton pattern.</p> */
+ private ColorProvider() {
+ colors = new HashMap<RGB, Color>( 10 );
+ rgbs = new HashMap<String, RGB>( 10 );
+ initializeRgbs();
+ }
+
+ public static final ColorProvider getInstance() {
+ return SingletonHolder.theInstance;
+ }
+
+ public ColorProvider(final IPreferenceStore store){
+ prefStore=store;
+ colors = new HashMap<RGB, Color>( 10 );
+ rgbs = new HashMap<String, RGB>( 10 );
+ initializeRgbs();
+ }
+
+ /** <p>releases all of the color resources held by this ColorProvider.</p> */
+ public void dispose() {
+ Iterator<Color> it = colors.values().iterator();
+ while( it.hasNext() ) {
+ it.next().dispose();
+ it.remove();
+ }
+ }
+
+ public Color getColor( final String key ) {
+ RGB rgb = rgbs.get( key );
+ Assert.isNotNull( rgb );
+ return getColor( rgb );
+ }
+
+ void changeColor( final String key, final Object newValue ) {
+ RGB oldRgb = rgbs.get( key );
+ if( oldRgb != null ) {
+ RGB newRgb = getNewRgb( newValue );
+ if( newRgb != null ) {
+ rgbs.put( key, newRgb );
+ }
+ }
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private RGB getNewRgb( final Object value ) {
+ RGB result = null;
+ if( value instanceof RGB ) {
+ result = ( RGB )value;
+ } else if( value instanceof String ) {
+ result = StringConverter.asRGB( ( String )value );
+ }
+ return result;
+ }
+
+ private Color getColor( final RGB rgb ) {
+ Color color = colors.get( rgb );
+ if( color == null || color.isDisposed()) {
+ color = new Color( Display.getCurrent(), rgb );
+ colors.put( rgb, color );
+ }
+ return color;
+ }
+
+ private void initializeRgbs() {
+ putRgb( EDITOR_COMMENT_COLOR, DEFAULT_COMMENT );
+ putRgb( EDITOR_LITERATE_COMMENT_COLOR, DEFAULT_LITERATE_COMMENT );
+ putRgb( EDITOR_FUNCTION_COLOR, DEFAULT_FUNCTION );
+ putRgb( EDITOR_KEYWORD_COLOR, DEFAULT_KEYWORD );
+ putRgb( EDITOR_DEFAULT_COLOR, DEFAULT_OTHER );
+ putRgb( EDITOR_STRING_COLOR, DEFAULT_STRING );
+ putRgb( EDITOR_CHAR_COLOR, DEFAULT_CHAR );
+ putRgb( EDITOR_NUMBER_COLOR, DEFAULT_NUMBER );
+ putRgb( EDITOR_VAR_COLOR, DEFAULT_VAR );
+ putRgb( EDITOR_CON_COLOR, DEFAULT_CON );
+ putRgb( EDITOR_CPP_COLOR, DEFAULT_CPP );
+ putRgb( EDITOR_TH_COLOR, DEFAULT_TH );
+ putRgb( EDITOR_SYMBOL_COLOR, DEFAULT_SYMBOL );
+ }
+
+ private void putRgb( final String key, final RGB defaultRgb ) {
+ RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
+ if( rgb == null ) {
+ rgb = defaultRgb;
+ }
+ rgbs.put( key, rgb );
+ }
+
+ private IPreferenceStore getPreferenceStore() {
+ if (prefStore!=null){
+ return prefStore;
+ }
+ return HaskellUIPlugin.getDefault().getPreferenceStore();
+ }
}
View
551 ...f.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScannerManager.java
@@ -1,276 +1,277 @@
-// Copyright (c) 2003-2008 by Leif Frenzel - see http://leiffrenzel.de
-// This code is made available under the terms of the Eclipse Public License,
-// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
-package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
-
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
-import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-
-
-/** <p>A singleton to manage scanner utilities (like tokens etc.)</p>
- *
- * @author Leif Frenzel
- */
-public class ScannerManager implements IEditorPreferenceNames {
-
- /** The internal singleton reference to ScannerManager */
- private static class SingletonHolder {
- private static final ScannerManager theInstance = new ScannerManager();
- }
-
- @Deprecated
- private HaskellCodeScanner codeScanner;
- @Deprecated
- private HaskellCommentScanner commentScanner;
- @Deprecated
- private HaskellStringScanner stringScanner;
- @Deprecated
- private HaskellCharacterScanner charScanner;
- @Deprecated
- private HaskellCommentScanner literateCommentScanner;
-
- private final Map<String, PropertyChangeHandler> propertyChangeHandlers;
- private IPropertyChangeListener propertyChangeListener;
-
- private TextAttribute commentAttribute;
- private TextAttribute literateCommentAttribute;
-
- private final Map<String, IToken> tokens = new Hashtable<String, IToken>();
-
- private IPreferenceStore prefStore;
- private ColorProvider colorProvider;
-
- private ScannerManager() {
- // prevent instantiation
- propertyChangeHandlers = new HashMap<String, PropertyChangeHandler>();
- initializePropertyListener();
- }
-
- /** <p>returns the singleton instance of ScannerManager.</p> */
- public static final ScannerManager getInstance() {
- return SingletonHolder.theInstance;
- }
-
- public void dispose() {
- getPreferenceStore().removePropertyChangeListener( propertyChangeListener );
- if (colorProvider!=null){
- colorProvider.dispose();
- }
- }
-
- public ScannerManager(final IPreferenceStore prefStore){
- this.prefStore=prefStore;
- propertyChangeHandlers = new HashMap<String, PropertyChangeHandler>();
- initializePropertyListener();
- }
-
-
- public ColorProvider getColorProvider() {
- if (prefStore!=null){
- if (colorProvider==null){
- colorProvider=new ColorProvider( prefStore );
- }
- return colorProvider;
- }
- return ColorProvider.getInstance();
- }
-
- @Deprecated
- public HaskellCodeScanner getCodeScanner( final boolean latexLiterate ) {
- if( codeScanner == null ) {
- codeScanner = new HaskellCodeScanner( this,latexLiterate );
- }
- return codeScanner;
- }
-
- @Deprecated
- public HaskellCommentScanner getCommentScanner() {
- if( commentScanner == null ) {
- commentScanner = new HaskellCommentScanner( this,false );
- }
- return commentScanner;
- }
-
- @Deprecated
- public HaskellStringScanner getStringScanner() {
- if( stringScanner == null ) {
- stringScanner = new HaskellStringScanner(this);
- }
- return stringScanner;
- }
-
- @Deprecated
- public HaskellCharacterScanner getCharacterScanner() {
- if( charScanner == null ) {
- charScanner = new HaskellCharacterScanner(this);
- }
- return charScanner;
- }
-
- @Deprecated
- public HaskellCommentScanner getLiterateCommentScanner() {
- if( literateCommentScanner == null ) {
- literateCommentScanner = new HaskellCommentScanner( this,true );
- }
- return literateCommentScanner;
- }
-
- public IToken createToken( final String colorKey, final String boldKey ) {
- IToken result = getTokenInternal( colorKey, boldKey );
- if( result == null ) {
- result = createTokenInternal( colorKey, boldKey );
- }
- return result;
- }
-
- public TextAttribute getCommentAttribute() {
- if( commentAttribute == null ) {
- commentAttribute = createTextAttribute( EDITOR_COMMENT_COLOR,
- EDITOR_COMMENT_BOLD );
- }
- return commentAttribute;
- }
-
- public TextAttribute getLiterateCommentAttribute() {
- if( literateCommentAttribute == null ) {
- String colorKey = EDITOR_LITERATE_COMMENT_COLOR;
- String boldKey = EDITOR_LITERATE_COMMENT_BOLD;
- literateCommentAttribute = createTextAttribute( colorKey, boldKey );
- }
- return literateCommentAttribute;
- }
-
-
- // helping methods
- //////////////////
-
- private TextAttribute createTextAttribute( final String colorKey,
- final String boldKey ) {
- Color color = getColorProvider().getColor( colorKey );
- TextAttribute result;
- if( isBold( boldKey ) ) {
- result = new TextAttribute( color, null, SWT.BOLD );
- } else {
- result = new TextAttribute( color );
- }
- return result;
- }
-
- private void initializePropertyListener() {
- propertyChangeListener = new IPropertyChangeListener() {
- @Override
- public void propertyChange( final PropertyChangeEvent event ) {
- getColorProvider().changeColor( event.getProperty(),
- event.getNewValue() );
- // now notify all tokens out there
- PropertyChangeHandler handler = getHandler( event.getProperty() );
- if( handler != null ) {
- handler.handleChange( event );
- }
- }
- };
- getPreferenceStore().addPropertyChangeListener( propertyChangeListener );
- }
-
- private void putHandler( final String key,
- final PropertyChangeHandler handler ) {
- propertyChangeHandlers.put( key, handler );
- }
-
- private PropertyChangeHandler getHandler( final String propertyName ) {
- Object result = propertyChangeHandlers.get( propertyName );
- return ( PropertyChangeHandler )result;
- }
-
- private boolean isBold( final String boldKey ) {
- return getPreferenceStore().getBoolean( boldKey );
- }
-
- private IPreferenceStore getPreferenceStore() {
- if (prefStore!=null){
- return prefStore;
- }
- return HaskellUIPlugin.getDefault().getPreferenceStore();
- }
-
- private IToken getTokenInternal( final String colorKey,
- final String boldKey ) {
- return tokens.get( colorKey + boldKey );
- }
-
- private Token createTokenInternal( final String colorKey,
- final String boldKey ) {
- TextAttribute textAtt = createTextAttribute( colorKey, boldKey );
- final Token result = new Token( textAtt );
- PropertyChangeHandler colorHandler = new PropertyChangeHandler() {
- @Override
- void handleChange( final PropertyChangeEvent event ) {
- handleColorChange( result, event.getProperty() );
- }
- };
- putHandler( colorKey, colorHandler );
-
- PropertyChangeHandler boldHandler = new PropertyChangeHandler() {
- @Override
- void handleChange( final PropertyChangeEvent event ) {
- handleBoldChange( result, event );
- }
- };
- putHandler( boldKey, boldHandler );
- tokens.put( colorKey + boldKey, result );
- return result;
- }
-
- private void handleColorChange( final Token token, final String key ) {
- Object data = token.getData();
- if( data instanceof TextAttribute ) {
- TextAttribute oldAttribute = ( TextAttribute )data;
- Color bgColor = oldAttribute.getBackground();
- int style = oldAttribute.getStyle();
- Color color = getColorProvider().getColor( key );
- TextAttribute newAttribute = new TextAttribute( color, bgColor, style );
- token.setData( newAttribute );
- }
- }
-
- private void handleBoldChange( final Token token,
- final PropertyChangeEvent event ) {
- Object o=event.getNewValue();
-
- boolean bold = (o instanceof Boolean)?
- ( ( Boolean )o ).booleanValue():
- IPreferenceStore.TRUE.equals(o);
- Object data = token.getData();
- if( data instanceof TextAttribute ) {
- TextAttribute oldAttr = ( TextAttribute )data;
- boolean wasBold = ( ( oldAttr.getStyle() & SWT.BOLD ) != 0 );
- if( wasBold != bold ) {
- int newStyle = bold ? oldAttr.getStyle() | SWT.BOLD
- : oldAttr.getStyle() ^ SWT.BOLD;
- TextAttribute newAttribute = new TextAttribute( oldAttr.getForeground(),
- oldAttr.getBackground(),
- newStyle );
- token.setData( newAttribute );
- }
- }
- }
-
-
- // inner classes
- ////////////////
-
- private abstract class PropertyChangeHandler {
- abstract void handleChange( PropertyChangeEvent event );
- }
+// Copyright (c) 2003-2008 by Leif Frenzel - see http://leiffrenzel.de
+// This code is made available under the terms of the Eclipse Public License,
+// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
+package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+
+
+/** <p>A singleton to manage scanner utilities (like tokens etc.)</p>
+ *
+ * @author Leif Frenzel
+ */
+public class ScannerManager implements IEditorPreferenceNames {
+
+ /** The internal singleton reference to ScannerManager */
+ private static class SingletonHolder {
+ private static final ScannerManager theInstance = new ScannerManager();
+ }
+
+ @Deprecated
+ private HaskellCodeScanner codeScanner;
+ @Deprecated
+ private HaskellCommentScanner commentScanner;
+ @Deprecated
+ private HaskellStringScanner stringScanner;
+ @Deprecated
+ private HaskellCharacterScanner charScanner;
+ @Deprecated
+ private HaskellCommentScanner literateCommentScanner;
+
+ private final Map<String, PropertyChangeHandler> propertyChangeHandlers;
+ private IPropertyChangeListener propertyChangeListener;
+
+ private TextAttribute commentAttribute;
+ private TextAttribute literateCommentAttribute;
+
+ private final Map<String, IToken> tokens = new Hashtable<String, IToken>();
+
+ private IPreferenceStore prefStore;
+ private ColorProvider colorProvider;
+
+ private ScannerManager() {
+ // prevent instantiation
+ propertyChangeHandlers = new HashMap<String, PropertyChangeHandler>();
+ initializePropertyListener();
+ }
+
+ /** <p>returns the singleton instance of ScannerManager.</p> */
+ public static final ScannerManager getInstance() {
+ return SingletonHolder.theInstance;
+ }
+
+ public void dispose() {
+ getPreferenceStore().removePropertyChangeListener( propertyChangeListener );
+ if (colorProvider!=null){
+ colorProvider.dispose();
+ }
+ tokens.clear();
+ }
+
+ public ScannerManager(final IPreferenceStore prefStore){
+ this.prefStore=prefStore;
+ propertyChangeHandlers = new HashMap<String, PropertyChangeHandler>();
+ initializePropertyListener();
+ }
+
+
+ public ColorProvider getColorProvider() {
+ if (prefStore!=null){
+ if (colorProvider==null){
+ colorProvider=new ColorProvider( prefStore );
+ }
+ return colorProvider;
+ }
+ return ColorProvider.getInstance();
+ }
+
+ @Deprecated
+ public HaskellCodeScanner getCodeScanner( final boolean latexLiterate ) {
+ if( codeScanner == null ) {
+ codeScanner = new HaskellCodeScanner( this,latexLiterate );
+ }
+ return codeScanner;
+ }
+
+ @Deprecated
+ public HaskellCommentScanner getCommentScanner() {
+ if( commentScanner == null ) {
+ commentScanner = new HaskellCommentScanner( this,false );
+ }
+ return commentScanner;
+ }
+
+ @Deprecated
+ public HaskellStringScanner getStringScanner() {
+ if( stringScanner == null ) {
+ stringScanner = new HaskellStringScanner(this);
+ }
+ return stringScanner;
+ }
+
+ @Deprecated
+ public HaskellCharacterScanner getCharacterScanner() {
+ if( charScanner == null ) {
+ charScanner = new HaskellCharacterScanner(this);
+ }
+ return charScanner;
+ }
+
+ @Deprecated
+ public HaskellCommentScanner getLiterateCommentScanner() {
+ if( literateCommentScanner == null ) {
+ literateCommentScanner = new HaskellCommentScanner( this,true );
+ }
+ return literateCommentScanner;
+ }
+
+ public IToken createToken( final String colorKey, final String boldKey ) {
+ IToken result = getTokenInternal( colorKey, boldKey );
+ if( result == null ) {
+ result = createTokenInternal( colorKey, boldKey );
+ }
+ return result;
+ }
+
+ public TextAttribute getCommentAttribute() {
+ if( commentAttribute == null ) {
+ commentAttribute = createTextAttribute( EDITOR_COMMENT_COLOR,
+ EDITOR_COMMENT_BOLD );
+ }
+ return commentAttribute;
+ }
+
+ public TextAttribute getLiterateCommentAttribute() {
+ if( literateCommentAttribute == null ) {
+ String colorKey = EDITOR_LITERATE_COMMENT_COLOR;
+ String boldKey = EDITOR_LITERATE_COMMENT_BOLD;
+ literateCommentAttribute = createTextAttribute( colorKey, boldKey );
+ }
+ return literateCommentAttribute;
+ }
+
+
+ // helping methods
+ //////////////////
+
+ private TextAttribute createTextAttribute( final String colorKey,
+ final String boldKey ) {
+ Color color = getColorProvider().getColor( colorKey );
+ TextAttribute result;
+ if( isBold( boldKey ) ) {
+ result = new TextAttribute( color, null, SWT.BOLD );
+ } else {
+ result = new TextAttribute( color );
+ }
+ return result;
+ }
+
+ private void initializePropertyListener() {
+ propertyChangeListener = new IPropertyChangeListener() {
+ @Override
+ public void propertyChange( final PropertyChangeEvent event ) {
+ getColorProvider().changeColor( event.getProperty(),
+ event.getNewValue() );
+ // now notify all tokens out there
+ PropertyChangeHandler handler = getHandler( event.getProperty() );
+ if( handler != null ) {
+ handler.handleChange( event );
+ }
+ }
+ };
+ getPreferenceStore().addPropertyChangeListener( propertyChangeListener );
+ }
+
+ private void putHandler( final String key,
+ final PropertyChangeHandler handler ) {
+ propertyChangeHandlers.put( key, handler );
+ }
+
+ private PropertyChangeHandler getHandler( final String propertyName ) {
+ Object result = propertyChangeHandlers.get( propertyName );
+ return ( PropertyChangeHandler )result;
+ }
+
+ private boolean isBold( final String boldKey ) {
+ return getPreferenceStore().getBoolean( boldKey );
+ }
+
+ private IPreferenceStore getPreferenceStore() {
+ if (prefStore!=null){
+ return prefStore;
+ }
+ return HaskellUIPlugin.getDefault().getPreferenceStore();
+ }
+
+ private IToken getTokenInternal( final String colorKey,
+ final String boldKey ) {
+ return tokens.get( colorKey + boldKey );
+ }
+
+ private Token createTokenInternal( final String colorKey,
+ final String boldKey ) {
+ TextAttribute textAtt = createTextAttribute( colorKey, boldKey );
+ final Token result = new Token( textAtt );
+ PropertyChangeHandler colorHandler = new PropertyChangeHandler() {
+ @Override
+ void handleChange( final PropertyChangeEvent event ) {
+ handleColorChange( result, event.getProperty() );
+ }
+ };
+ putHandler( colorKey, colorHandler );
+
+ PropertyChangeHandler boldHandler = new PropertyChangeHandler() {
+ @Override
+ void handleChange( final PropertyChangeEvent event ) {
+ handleBoldChange( result, event );
+ }
+ };
+ putHandler( boldKey, boldHandler );
+ tokens.put( colorKey + boldKey, result );
+ return result;
+ }
+
+ private void handleColorChange( final Token token, final String key ) {
+ Object data = token.getData();
+ if( data instanceof TextAttribute ) {
+ TextAttribute oldAttribute = ( TextAttribute )data;
+ Color bgColor = oldAttribute.getBackground();
+ int style = oldAttribute.getStyle();
+ Color color = getColorProvider().getColor( key );
+ TextAttribute newAttribute = new TextAttribute( color, bgColor, style );
+ token.setData( newAttribute );
+ }
+ }
+
+ private void handleBoldChange( final Token token,
+ final PropertyChangeEvent event ) {
+ Object o=event.getNewValue();
+
+ boolean bold = (o instanceof Boolean)?
+ ( ( Boolean )o ).booleanValue():
+ IPreferenceStore.TRUE.equals(o);
+ Object data = token.getData();
+ if( data instanceof TextAttribute ) {
+ TextAttribute oldAttr = ( TextAttribute )data;
+ boolean wasBold = ( ( oldAttr.getStyle() & SWT.BOLD ) != 0 );
+ if( wasBold != bold ) {
+ int newStyle = bold ? oldAttr.getStyle() | SWT.BOLD
+ : oldAttr.getStyle() ^ SWT.BOLD;
+ TextAttribute newAttribute = new TextAttribute( oldAttr.getForeground(),
+ oldAttr.getBackground(),
+ newStyle );
+ token.setData( newAttribute );
+ }
+ }
+ }
+
+
+ // inner classes
+ ////////////////
+
+ private abstract class PropertyChangeHandler {
+ abstract void handleChange( PropertyChangeEvent event );
+ }
}
View
28 ...clipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
@@ -1,7 +1,10 @@
package net.sf.eclipsefp.haskell.ui.internal.editors.haskell.text;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.InputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -15,10 +18,8 @@
import net.sf.eclipsefp.haskell.buildwrapper.types.Occurrence;
import net.sf.eclipsefp.haskell.buildwrapper.types.TokenDef;
import net.sf.eclipsefp.haskell.core.codeassist.IScionTokens;
-import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.IEditorPreferenceNames;
-import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.SyntaxPreviewer;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -33,7 +34,6 @@
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.texteditor.MarkerUtilities;
-import org.json.JSONArray;
/**
* Uses Scion tokenTypesArbitrary function to get tokens for a haskell source
@@ -278,7 +278,7 @@ public void run() {
} else {
this.doc = document;
contents=doc.get();
- try {
+ /*try {
InputStream stream = SyntaxPreviewer.class.getResourceAsStream( "preview.json" );
// preview file
JSONArray result = new JSONArray( ResourceUtil.readStream( stream ) );
@@ -289,6 +289,24 @@ public void run() {
}
} catch( Exception ex ) {
HaskellUIPlugin.log( "Could not read preview file.", ex ); //$NON-NLS-1$
+ }*/
+ BWFacade f=new BWFacade();
+ f.setBwPath( BuildWrapperPlugin.getBwPath() );
+ try {
+
+ File file=File.createTempFile( "temp", ".hs" );
+ try {
+ Writer fw=new BufferedWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF8" ) );
+ fw.write( contents );
+ fw.close();
+ f.setCabalFile( new File(file.getParentFile(),"temp.cabal") .getAbsolutePath());
+ file.renameTo(new File( new File(file.getParentFile(),BWFacade.DIST_FOLDER),file.getName()));
+ lTokenDefs = f.tokenTypes( file.getName() );
+ } finally {
+ file.delete();
+ }
+ } catch( Exception ex ) {
+ HaskellUIPlugin.log( ex.getLocalizedMessage(), ex );
}
}
if( lTokenDefs != null && lTokenDefs.size() > 0 ) {
View
218 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/NewHaskellProjectPP.java
@@ -2,8 +2,16 @@
package net.sf.eclipsefp.haskell.ui.internal.preferences;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.core.preferences.ICorePreferenceNames;
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
+import net.sf.eclipsefp.haskell.ui.internal.editors.cabal.CabalConfiguration;
+import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellSourceViewerConfiguration;
+import net.sf.eclipsefp.haskell.ui.internal.preferences.editor.SyntaxPreviewer;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
import net.sf.eclipsefp.haskell.util.FileUtil;
import org.eclipse.core.resources.IProject;
@@ -17,6 +25,13 @@
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -34,6 +49,7 @@
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.model.WorkbenchViewerComparator;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.service.prefs.BackingStoreException;
@@ -61,6 +77,7 @@
private Button btnProjectAsSourceFolder;
private Button btnFoldersAsSourceFolder;
+ private final Map<String,TemplateDef[]> templateDefs=new HashMap<String,TemplateDef[]>();
public NewHaskellProjectPP() {
super( UITexts.preferences_project_title );
@@ -169,10 +186,95 @@ protected Control createContents( final Composite parent ) {
createFoldersGroup( result );
validate();
+ createTemplatesGroup(result);
+
Dialog.applyDialogFont( result );
return result;
}
+ private void createTemplatesGroup( final Composite result ) {
+ final Group templateGroup = new Group( result, SWT.NONE );
+ GridLayout templateLayout = new GridLayout();
+ templateLayout.numColumns = 1;
+ templateGroup.setLayout( templateLayout );
+ templateGroup.setText( UITexts.preferences_project_file_templates );
+
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.horizontalSpan = 2;
+ templateGroup.setLayoutData( gd );
+
+ final TreeViewer tv=new TreeViewer( templateGroup,SWT.SINGLE );
+ tv.getTree().setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH ) );
+ tv.setComparator( new WorkbenchViewerComparator() );
+ tv.setContentProvider( new TemplateDefCP() );
+
+ SourceViewerConfiguration cabalConf=new CabalConfiguration(null);
+ SourceViewerConfiguration haskellConf=new HaskellSourceViewerConfiguration( null );
+ TemplateDef[] cabals=new TemplateDef[4];
+ cabals[0]=new TemplateDef( ICorePreferenceNames.TEMPLATE_CABAL, UITexts.preferences_project_file_TEMPLATE_CABAL,cabalConf );
+ cabals[1]=new TemplateDef( ICorePreferenceNames.TEMPLATE_CABAL_EXE, UITexts.preferences_project_file_TEMPLATE_CABAL_EXE,cabalConf );
+ cabals[2]=new TemplateDef( ICorePreferenceNames.TEMPLATE_CABAL_LIBRARY, UITexts.preferences_project_file_TEMPLATE_CABAL_LIBRARY,cabalConf );
+ cabals[3]=new TemplateDef( ICorePreferenceNames.TEMPLATE_CABAL_SETUP, UITexts.preferences_project_file_TEMPLATE_CABAL_SETUP ,haskellConf);
+
+ TemplateDef[] haskells=new TemplateDef[3];
+ haskells[0]=new TemplateDef( ICorePreferenceNames.TEMPLATE_GTK, UITexts.preferences_project_file_TEMPLATE_GTK,haskellConf);
+ haskells[1]=new TemplateDef( ICorePreferenceNames.TEMPLATE_MAIN, UITexts.preferences_project_file_TEMPLATE_MAIN ,haskellConf);
+ haskells[2]=new TemplateDef( ICorePreferenceNames.TEMPLATE_MODULE, UITexts.preferences_project_file_TEMPLATE_MODULE ,haskellConf);
+
+ templateDefs.put(UITexts.preferences_project_file_templates_cabal,cabals);
+ templateDefs.put(UITexts.preferences_project_file_templates_haskell,haskells);
+
+ tv.setInput( templateDefs );
+
+ SyntaxPreviewer sv=new SyntaxPreviewer( templateGroup, HaskellUIPlugin.getDefault() .getPreferenceStore() );
+ sv.getTextWidget().setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH ) );
+ //final StyledText st=new StyledText( templateGroup, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER );
+ //st.setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH ) );
+ sv.getDocument().set( "" );
+ sv.getTextWidget().setEditable( false );
+
+ final List<SyntaxPreviewer> svs=new ArrayList<SyntaxPreviewer>();
+ svs.add(sv);
+
+ tv.addSelectionChangedListener( new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged( final SelectionChangedEvent arg0 ) {
+ Object o=((IStructuredSelection)arg0.getSelection()).getFirstElement();
+ if (svs.isEmpty()){
+ return;
+ }
+ SyntaxPreviewer sv=svs.get( 0 );
+ if (o instanceof TemplateDef){
+ TemplateDef td=(TemplateDef) o;
+ sv.getTextWidget().dispose();
+ svs.clear();
+ final SyntaxPreviewer sv2=new SyntaxPreviewer( templateGroup, HaskellUIPlugin.getDefault() .getPreferenceStore(), td.getConfiguration() , td.getContent() );
+ sv2.getTextWidget().setLayoutData( new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH ) );
+ sv2.setEditable( true );
+ sv2.getTextWidget().addModifyListener( new ModifyListener() {
+
+ @Override
+ public void modifyText( final ModifyEvent arg0 ) {
+ Object o=((IStructuredSelection)tv.getSelection()).getFirstElement();
+ if (o instanceof TemplateDef){
+ TemplateDef td=(TemplateDef) o;
+ td.setContent( sv2.getDocument().get() );
+ }
+ }
+ } );
+ svs.add(sv2);
+ templateGroup.layout( true );
+ } else {
+ sv.getDocument().set( "" );
+ sv.setEditable( false );
+ }
+ }
+ } );
+
+
+ }
+
private void createFoldersGroup( final Composite result ) {
Group folderGroup = new Group( result, SWT.NONE );
GridLayout layout = new GridLayout();
@@ -324,6 +426,11 @@ protected void performDefaults() {
String key = ( String )text.getData();
text.setText( store.getDefaultString( key ) );
}
+ for (String s:templateDefs.keySet()){
+ for (TemplateDef td:templateDefs.get( s )){
+ td.setContent( getPreferenceStore().getDefaultString( td.getPreference() ) );
+ }
+ }
validate();
super.performDefaults();
}
@@ -344,6 +451,11 @@ public boolean performOk() {
String key = ( String )text.getData();
store.setValue( key, text.getText() );
}
+ for (String s:templateDefs.keySet()){
+ for (TemplateDef td:templateDefs.get( s )){
+ store.setValue( td.getPreference(), td.getContent() );
+ }
+ }
try {
InstanceScope.INSTANCE.getNode(HaskellCorePlugin.getPluginId()).flush();
} catch( BackingStoreException ex ) {
@@ -358,5 +470,111 @@ protected IPreferenceStore doGetPreferenceStore() {
HaskellCorePlugin.getPluginId());
}
+ private class TemplateDef{
+ private String preference;
+ private String displayName;
+ private String content;
+ private final SourceViewerConfiguration configuration;
+
+ public TemplateDef( final String preference, final String displayName, final SourceViewerConfiguration config ) {
+ super();
+ this.preference = preference;
+ this.displayName = displayName;
+ this.content = getPreferenceStore().getString( preference );
+ this.configuration=config;
+ }
+
+ /**
+ * @return the configuration
+ */
+ public SourceViewerConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public String getPreference() {
+ return preference;
+ }
+
+ public void setPreference( final String preference ) {
+ this.preference = preference;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName( final String displayName ) {
+ this.displayName = displayName;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent( final String content ) {
+ this.content = content;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getDisplayName();
+ }
+ }
+
+ private class TemplateDefCP implements ITreeContentProvider {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ @Override
+ public void dispose() {
+
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @Override
+ public Object[] getChildren( final Object arg0 ) {
+ if (arg0 instanceof Map<?, ?>){
+ Set<String> ss=templateDefs.keySet();
+ return ss.toArray();
+ } else if (arg0 instanceof String){
+ return templateDefs.get( arg0 );
+ }
+ return new Object[0];
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ */
+ @Override
+ public Object[] getElements( final Object arg0 ) {
+ return getChildren(arg0);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ @Override
+ public Object getParent( final Object arg0 ) {
+ return null;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ @Override
+ public boolean hasChildren( final Object arg0 ) {
+ return arg0 instanceof String;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public void inputChanged( final Viewer arg0, final Object arg1, final Object arg2 ) {
+
+
+ }
+
+ }
}
View
338 ...sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPreviewer.java
@@ -1,165 +1,175 @@
-// Copyright (c) 2003-2008 by Leif Frenzel - see http://leiffrenzel.de
-// This code is made available under the terms of the Eclipse Public License,
-// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
-package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
-
-import java.io.InputStream;
-import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
-import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
-import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellSourceViewerConfiguration;
-import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellDocumentProvider;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-
-/** <p>A source viewer that uses the Haskell editor's presentation helpers
- * in order to display a preview of the current presentation preference
- * settings.</p>
- *
- * @author Leif Frenzel
- */
-public class SyntaxPreviewer extends SourceViewer implements IEditorPreferenceNames {
-
- private IPreferenceStore store;
- private final HaskellSourceViewerConfiguration config;
- private IPropertyChangeListener propertyChangeListener;
- private Color bgColor;
-
- SyntaxPreviewer( final Composite parent, final IPreferenceStore store ) {
- super( parent, null, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER );
- this.store = store;