Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
13 docs/file-templates.txt
@@ -0,0 +1,13 @@
+- have templates in preferences for the content of files we create automatically
+
+Cabal
+ - library section
+ - executable section
+ - main cabal file referencing library and executable
+ - setup file
+
+Haskell
+ - module
+ - Literate module
+ - Tex module
+ - Main file referencing module
View
13 docs/test-wizard.txt
@@ -0,0 +1,13 @@
+- add test suite with test-framework
+ checkboxes: hunit, quickcheck
+ only references necessary packages
+ choose source folder
+ warning if already present
+ create test modules for
+ list existing modules
+ if inside library, reference library in build-depends of test suite
+ otherwise other-modules
+ hunit: each module defines one empty test failing on "not implemented" and a test list
+ quickcheck 2: define an always failing property
+ Main references all modules as groups
+
View
10 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/HaskellCorePlugin.java
@@ -182,13 +182,21 @@ public static final IEclipsePreferences instanceScopedPreferences() {
return InstanceScope.INSTANCE.getNode( getPluginId() );
}
+ /**
+ * populate a template with variables
+ * @param pref the preference to use to get the template
+ * @param extraVars the extra variables
+ * @return
+ */
public static String populateTemplate(final String pref,final Map<String,String> extraVars){
IStringVariableManager mgr=VariablesPlugin.getDefault().getStringVariableManager();
IEclipsePreferences coreNode = instanceScopedPreferences();
+ // get template
String template=coreNode.get( pref, "" ); //$NON-NLS-1$
try {
IValueVariable[] vars = new IValueVariable[0];
+ // add extra vars
if (extraVars!=null){
vars = new IValueVariable[extraVars.size()];
int a=0;
@@ -200,8 +208,10 @@ public static String populateTemplate(final String pref,final Map<String,String>
mgr.addVariables( vars );
}
try {
+ // perform the substitution
return mgr.performStringSubstitution( template );
} finally {
+ // remove variables because otherwise we can't reset them
mgr.removeVariables( vars );
}
} catch (CoreException ce){
View
5 ....haskell.core/src/net/sf/eclipsefp/haskell/core/internal/project/ProjectModelFilesOp.java
@@ -48,6 +48,9 @@ public void run( final IProject project,
String name = project.getName();
String src=HaskellProjectCreationOperation.getSourceDir();
Map<String,String> vars=new HashMap<String, String>();
+ /**
+ * put vars
+ */
vars.put( TemplateVariables.PROJECT_NAME, name );
vars.put( TemplateVariables.SRC, src );
vars.put( TemplateVariables.USER_NAME, PlatformUtil.getCurrentUser() );
@@ -82,8 +85,10 @@ public void run( final IProject project,
//////////////////
protected String getMainFileContent(final Map<String,String> vars ) {
+ /** get module header **/
vars.put( TemplateVariables.MODULE_NAME, "Main" );//$NON-NLS-1$
String mod=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MODULE, vars );
+ /** get content **/
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$
View
3  ...haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/CorePreferenceInitializer.java
@@ -32,6 +32,9 @@ public void initializeDefaultPreferences() {
coreNode.putBoolean( DEBUG_PRINT_WITH_SHOW, true );
coreNode.putInt( RUN_COMMAND_HISTORY_MAX, 20 );
+ /**
+ * default code templates
+ */
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$
View
23 ...lipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/preferences/TemplateVariables.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2012 by JP Moresmau
+ * 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.core.preferences;
+
+/**
+ * Variables we define in the code templates
+ *
+ * @author JP Moresmau
+ *
+ */
+public interface TemplateVariables {
+
+ public static final String PROJECT_NAME="project_name"; //$NON-NLS-1$
+ public static final String USER_NAME="user_name"; //$NON-NLS-1$
+ public static final String SRC="src"; //$NON-NLS-1$
+ public static final String LIBRARY="library"; //$NON-NLS-1$
+ public static final String EXECUTABLE="executable"; //$NON-NLS-1$
+ public static final String MODULE="module"; //$NON-NLS-1$
+ public static final String MODULE_NAME="module_name"; //$NON-NLS-1$
+}
View
34 ...l.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/text/ScionTokenScanner.java
@@ -290,23 +290,27 @@ 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" );
+ if (contents.length()>0){
+ BWFacade f=new BWFacade();
+ f.setBwPath( BuildWrapperPlugin.getBwPath() );
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();
+
+ 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 );
}
- } catch( Exception ex ) {
- HaskellUIPlugin.log( ex.getLocalizedMessage(), ex );
+ } else {
+ lTokenDefs=new ArrayList<TokenDef>();
}
}
if( lTokenDefs != null && lTokenDefs.size() > 0 ) {
View
55 ....haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/NewHaskellProjectPP.java
@@ -38,13 +38,17 @@
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.IWorkbench;
@@ -203,8 +207,11 @@ private void createTemplatesGroup( final Composite result ) {
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 ) );
+ final GridData dataTv= new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH ) ;
+ tv.getTree().setLayoutData(dataTv);
tv.setComparator( new WorkbenchViewerComparator() );
tv.setContentProvider( new TemplateDefCP() );
@@ -226,8 +233,33 @@ private void createTemplatesGroup( final Composite result ) {
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 Sash sash = new Sash(templateGroup, SWT.HORIZONTAL);
+ final GridData dataS= new GridData( GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL );
+ //dataS.heightHint=6;
+ sash.setLayoutData( dataS);
+
+
+ final GridData dataSv= new GridData( GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH );
+
+ sash.addListener( SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent( final Event event ) {
+ Rectangle clientArea = templateGroup.getClientArea();
+ int newHeight = event.y;
+ //clientArea.height - event.y - sash.getSize().y;
+ if (newHeight != dataTv.heightHint) {
+ dataTv.heightHint = newHeight- sash.getBounds().height;
+ dataSv.heightHint = clientArea.height - event.y + 20;
+ templateGroup.layout();
+ }
+
+ }
+ });
+
+
+ SyntaxPreviewer sv=new SyntaxPreviewer( templateGroup, HaskellUIPlugin.getDefault() .getPreferenceStore(), new HaskellSourceViewerConfiguration( null ),"" );
+ sv.getTextWidget().setLayoutData(dataSv );
//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( "" );
@@ -250,7 +282,7 @@ public void selectionChanged( final SelectionChangedEvent arg0 ) {
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.getTextWidget().setLayoutData(dataSv);
sv2.setEditable( true );
sv2.getTextWidget().addModifyListener( new ModifyListener() {
@@ -471,8 +503,8 @@ protected IPreferenceStore doGetPreferenceStore() {
}
private class TemplateDef{
- private String preference;
- private String displayName;
+ private final String preference;
+ private final String displayName;
private String content;
private final SourceViewerConfiguration configuration;
@@ -496,17 +528,10 @@ 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;
@@ -531,7 +556,7 @@ public String toString() {
*/
@Override
public void dispose() {
-
+ // NOOP
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
@@ -572,7 +597,7 @@ public boolean hasChildren( final Object arg0 ) {
*/
@Override
public void inputChanged( final Viewer arg0, final Object arg1, final Object arg2 ) {
-
+ // NOOP
}
View
14 ...skell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxPreviewer.java
@@ -39,10 +39,22 @@
private IPropertyChangeListener propertyChangeListener;
private Color bgColor;
- public SyntaxPreviewer( final Composite parent, final IPreferenceStore store ) {
+ /**
+ * show the preview content
+ * @param parent the UI parent
+ * @param store the preferences store to get color preferences from
+ */
+ SyntaxPreviewer( final Composite parent, final IPreferenceStore store ) {
this(parent,store,new HaskellSourceViewerConfiguration( null ), loadTextFromResource( "preview.hs" ));
}
+ /**
+ * show arbitrary content
+ * @param parent the UI parent
+ * @param store the preferences store to get color preferences from
+ * @param config the source viewer configuration
+ * @param content the document contents
+ */
public SyntaxPreviewer( final Composite parent, final IPreferenceStore store,final SourceViewerConfiguration config,final String content ) {
super( parent, null, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER );
this.store = store;
View
2  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/wizards/NewGtkProjectWizard.java
@@ -100,8 +100,10 @@ protected PackageDescription getCabalFile( final Map<String,String> vars) {
*/
@Override
protected String getMainFileContent(final Map<String,String> vars) {
+ /** get module header **/
vars.put( TemplateVariables.MODULE_NAME, "Main" );//$NON-NLS-1$
String mod=HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_MODULE, vars );
+ /** get content **/
vars.put( TemplateVariables.MODULE, mod );
return HaskellCorePlugin.populateTemplate( ICorePreferenceNames.TEMPLATE_GTK, vars );
// return "module Main where"+PlatformUtil.NL+PlatformUtil.NL+

No commit comments for this range

Something went wrong with that request. Please try again.