Permalink
Browse files

Merge pull request #19 from clanehin/master

Tweaks to outline view.
  • Loading branch information...
2 parents bbe20df + 20b8650 commit e2772f7a54926a02cadcf6c1de0790c67d948bc2 @JPMoresmau committed May 13, 2011
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import net.sf.eclipsefp.haskell.scion.types.OutlineDef;
+import net.sf.eclipsefp.haskell.scion.types.OutlineDef.OutlineDefType;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
@@ -17,8 +18,35 @@
public class OutlineCP implements ITreeContentProvider{
private Map<String,List<OutlineDef>> input;
+ /**
+ * For elements that expand into an identically-named single element with an obvious
+ * type, we could just expand directly into that child element's children.
+ */
+ public boolean hasSingularChild( final Object o ){
+ if( ((OutlineDef)o).getType() != OutlineDefType.DATA ) {
+ return false;
+ }
+
+ Object[] children = getRawChildren( o );
+
+ if( children.length != 1 ) {
+ return false;
+ }
+
+ return ((OutlineDef)children[0]).getType() == OutlineDefType.CONSTRUCTOR &&
+ ((OutlineDef)children[0]).getName().equals( ((OutlineDef)o).getName() );
+ }
+
public Object[] getChildren( final Object parentElement ) {
- //return input.toArray();
+ Object[] result = getRawChildren( parentElement );
+ if( hasSingularChild( parentElement ) ) {
+ return getChildren( result[0] );
+ } else {
+ return result;
+ }
+ }
+
+ public Object[] getRawChildren( final Object parentElement ) {
List<OutlineDef> l=input.get(((OutlineDef )parentElement).getID());
if (l!=null){
return l.toArray();
@@ -25,7 +25,7 @@
imageKeysByType.put(OutlineDef.OutlineDefType.SYN,IImageNames.TYPE_DECL);
imageKeysByType.put(OutlineDef.OutlineDefType.INSTANCE,IImageNames.INSTANCE_DECL);
imageKeysByType.put(OutlineDef.OutlineDefType.FIELD,IImageNames.FIELD_DECL);
- imageKeysByType.put(OutlineDef.OutlineDefType.CONSTRUCTOR,IImageNames.DATA_DECL);
+ imageKeysByType.put(OutlineDef.OutlineDefType.CONSTRUCTOR,IImageNames.CONSTRUCTOR_DECL);
}
@@ -91,6 +91,7 @@ private static void declareImages() {
declare( FUNCTION_BINDING, OBJECT + "functionbinding.gif" ); //$NON-NLS-1$
declare( PATTERN_BINDING, OBJECT + "patternbinding.gif" ); //$NON-NLS-1$
declare( DATA_DECL, OBJECT + "datadecl.gif" ); //$NON-NLS-1$
+ declare( CONSTRUCTOR_DECL, OBJECT + "constructordecl.gif" ); //$NON-NLS-1$
declare( TYPE_DECL, OBJECT + "typedecl.gif" ); //$NON-NLS-1$
declare( NEWTYPE_DECL, OBJECT + "typedecl.gif" ); //$NON-NLS-1$
declare( TYPE_SIGNATURE, OBJECT + "typesig.gif" ); //$NON-NLS-1$
@@ -48,6 +48,7 @@
String FUNCTION_BINDING = ID + ".FUNCTION_BINDING"; //$NON-NLS-1$
String PATTERN_BINDING = ID + ".PATTERN_BINDING"; //$NON-NLS-1$
String DATA_DECL = ID + ".DATA_DECL"; //$NON-NLS-1$
+ String CONSTRUCTOR_DECL = ID + ".CONSTRUCTOR_DECL"; //$NON-NLS-1$
String TYPE_SIGNATURE = ID + ".TYPE_SIGNATURE"; //$NON-NLS-1$
String TYPE_DECL = ID + ".TYPE_DECL"; //$NON-NLS-1$
String NEWTYPE_DECL = ID + ".NEWTYPE_DECL"; //$NON-NLS-1$

0 comments on commit e2772f7

Please sign in to comment.