Changeset 1180

Show
Ignore:
Timestamp:
05/27/08 08:07:44 (8 months ago)
Author:
fraserofthenight
Message:

Added a couple actual options to the builder UI

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.building/src/descent/building/IDescentBuilderConstants.java

    r1175 r1180  
    8282    public static final String ATTR_OUTPUT_FILE = "descent.building.debuild.output_file"; 
    8383     
     84    // TODO comment 
     85    public static final String ATTR_ADD_UNITTESTS = "descent.building.debuild.add_unittests"; 
     86    public static final String ATTR_DISABLE_ASSERTS = "descent.building.debuild.disable_asserts"; 
     87    public static final String ATTR_ADD_DEBUG_INFO = "descent.building.debuild.add_debug_info"; 
     88    public static final String ATTR_INSTRUMENT_FOR_COVERAGE = "descent.building.debuild.instrument_for_coverage"; 
     89    public static final String ATTR_INSTRUMENT_FOR_PROFILE = "descent.building.debuild.instrument_for_profile"; 
     90     
    8491    /** 
    8592     * Constant used for {@link #ATTR_OUTPUT_TYPE} to specify the output target 
  • trunk/descent.building/src/descent/building/compiler/BooleanOption.java

    r1177 r1180  
    77     
    88    public BooleanOption(String attributeId, boolean defaultValue, 
    9             String label, String groupLabel, String onText, String offText) 
     9            String label, String groupLabel, String onText, String offText, 
     10            String helpText) 
    1011    { 
    11         super(attributeId, defaultValue ? "true" : "false", label, groupLabel); 
     12        super(attributeId, defaultValue ? "true" : "false", label, groupLabel, helpText); 
    1213        this.onText = onText; 
    1314        this.offText = offText; 
  • trunk/descent.building/src/descent/building/compiler/CompilerOption.java

    r1177 r1180  
    77    private final String label; 
    88    private final String groupLabel; 
     9    private final String helpText; 
    910     
    1011    public CompilerOption(String attributeId, String defaultValue, String label, 
    11             String groupLabel
     12            String groupLabel, String helpText
    1213    { 
    1314        this.attributeId = attributeId; 
     
    1516        this.label = label; 
    1617        this.groupLabel = groupLabel; 
     18        this.helpText = helpText; 
    1719    } 
    1820     
     
    3638        return groupLabel; 
    3739    } 
     40     
     41    public final String getHelpText() 
     42    { 
     43        return helpText; 
     44    } 
    3845} 
  • trunk/descent.building/src/descent/building/compiler/EnumOption.java

    r1177 r1180  
    99    public EnumOption(String attributeId, String defaultValue, 
    1010            String label, String groupLabel, String[] optionValues, 
    11             String[] optionEditLabels
     11            String[] optionEditLabels, String helpText
    1212    { 
    1313        this(attributeId, defaultValue, label, groupLabel,  
    14                 optionValues, optionEditLabels, null); 
     14                optionValues, optionEditLabels, null, helpText); 
    1515    } 
    1616     
    1717    public EnumOption(String attributeId, String defaultValue, 
    1818            String label, String groupLabel, String[] optionValues, 
    19             String[] optionEditLabels, String[] optionViewLabels) 
     19            String[] optionEditLabels, String[] optionViewLabels, 
     20            String helpText) 
    2021    { 
    21         super(attributeId, defaultValue, label, groupLabel); 
     22        super(attributeId, defaultValue, label, groupLabel, helpText); 
    2223        this.optionValues = optionValues; 
    2324        this.optionEditLabels = optionEditLabels; 
  • trunk/descent.building/src/descent/building/compiler/StringOption.java

    r1177 r1180  
    44{ 
    55    public StringOption(String attributeId, String defaultValue, 
    6             String label, String groupLabel
     6            String label, String groupLabel, String helpText
    77    { 
    8         super(attributeId, defaultValue, label, groupLabel); 
     8        super(attributeId, defaultValue, label, groupLabel, helpText); 
    99    } 
    1010} 
  • trunk/descent.building/src/descent/internal/building/compiler/DmdCompilerInterface.java

    r1177 r1180  
    1313import descent.building.compiler.IResponseInterpreter; 
    1414import descent.building.compiler.BuildResponse; 
     15 
     16import static descent.building.IDescentBuilderConstants.*; 
     17import static descent.internal.building.compiler.IDmdCompilerConstants.*; 
    1518 
    1619public class DmdCompilerInterface implements ICompilerInterface 
     
    260263    static 
    261264    { 
    262         final String GROUP_FEATURES; 
     265        final String GROUP_FEATURES = "Features"; 
     266        final String GROUP_WARNINGS = "Warnings"; 
     267        final String GROUP_OPTIMIZATION = "Optimization"; 
    263268         
     269        // TODO file options for header & doc generation 
    264270        uiOptions = new CompilerOption[] 
    265         { 
     271        {           
    266272            //------------------------------------------------------------------ 
    267273            // Features 
    268274             
     275            new BooleanOption( 
     276                    ATTR_ADD_DEBUG_INFO, 
     277                    true, 
     278                    "Add debugging symbols", 
     279                    GROUP_FEATURES, 
     280                    "-g", 
     281                    "", 
     282                    "Adds debugging symbols. These make the generated objects " + 
     283                    "slightly larger but is needed to use a debugger with the " + 
     284                    "program."), 
     285                     
     286            new BooleanOption( 
     287                    ATTR_DISABLE_ASSERTS, 
     288                    false, 
     289                    "Release mode (disable asserts & contracts)", 
     290                    GROUP_FEATURES, 
     291                    "-release", 
     292                    "", 
     293                    "Turns off assert() statements in the code, in {} and out {} " + 
     294                    "blocks on functions, and checking for array bounds errors. This " + 
     295                    "makes the code run faster, so is a good choice for releasing the " + 
     296                    "application, but are often useful for development."), 
     297                     
     298                     
     299            new BooleanOption( 
     300                    ATTR_ADD_UNITTESTS, 
     301                    false, 
     302                    "Add unit tests", 
     303                    GROUP_FEATURES, 
     304                    "-unittest", 
     305                    "", 
     306                    "Adds code so that unittest {} blocks in your code are run before " + 
     307                    "the program launches and enables version(unitttest) {} blocks."), 
     308                             
     309            new BooleanOption( 
     310                    ATTR_INSTRUMENT_FOR_COVERAGE, 
     311                    false, 
     312                    "Instrument for coverage analysis", 
     313                    GROUP_FEATURES, 
     314                    "-cov", 
     315                    "", 
     316                    "Adds code to the generated objects so that they will generate " + 
     317                    "a file containing code coverage information after the program " + 
     318                    "has been run. This is useful for seeing if unit tests execute " + 
     319                    "all paths in your code."), 
     320                                     
     321            new BooleanOption( 
     322                    ATTR_INSTRUMENT_FOR_PROFILE, 
     323                    false, 
     324                    "Instrument for profiling", 
     325                    GROUP_FEATURES, 
     326                    "-profile", 
     327                    "", 
     328                    "Adds code to the generated objects so they can be prodiled. " + 
     329                    "This helps find bottlenecks that could be slowing down your " + 
     330                    "application."), 
     331             
     332            //------------------------------------------------------------------ 
     333            // Warnings 
     334             
     335            new BooleanOption( 
     336                    ATTR_ALLOW_DEPRECATED, 
     337                    true, 
     338                    "Allow deprecated code", 
     339                    GROUP_WARNINGS, 
     340                    "-d", 
     341                    "", 
     342                    "Allows code marked with the \"deprecated\" tags to be included " + 
     343                    "in your program."), 
     344             
     345            new BooleanOption( 
     346                    ATTR_SHOW_WARNINGS, 
     347                    false, 
     348                    "Show warnings", 
     349                    GROUP_WARNINGS, 
     350                    "-w", 
     351                    "", 
     352                    "Adds warnings for potentially unsafe or error-prone code. In " + 
     353                    "DMD, if warnings are encountered, the program will not be " + 
     354                    "compiled."), 
     355             
     356               
     357            //------------------------------------------------------------------ 
     358            // Optimization 
     359             
     360            new BooleanOption( 
     361                    ATTR_OPTIMIZE_CODE, 
     362                    false, 
     363                    "Optimize code", 
     364                    GROUP_OPTIMIZATION, 
     365                    "-O", 
     366                    "", 
     367                    "Optimizes the generated code for best efficiency."), 
     368             
     369            new BooleanOption( 
     370                    ATTR_INLINE_CODE, 
     371                    false, 
     372                    "Inline functions", 
     373                    GROUP_OPTIMIZATION, 
     374                    "-inline", 
     375                    "", 
     376                    "Allows inlining of short functions for increased code efficiency. " + 
     377                    "This may cause issues with some debuggers."), 
     378             
     379            new BooleanOption( 
     380                    ATTR_NOFLOAT, 
     381                    false, 
     382                    "Don't generate __fltused reference", 
     383                    GROUP_OPTIMIZATION, 
     384                    "-nofloat", 
     385                    "", 
     386                    "Prevents the emission of the __fltused reference in object files, " + 
     387                    "even if floating point code is present. This is useful in library " + 
     388                    "files."), 
    269389        }; 
    270390    } 
     
    307427    public CompilerOption[] getOptions() 
    308428    { 
    309         // TODO Auto-generated method stub 
    310429        return uiOptions; 
    311430    } 
  • trunk/descent.building/src/descent/internal/building/ui/CompilerTab.java

    r1177 r1180  
    1616import org.eclipse.jface.viewers.ComboBoxCellEditor; 
    1717import org.eclipse.jface.viewers.EditingSupport; 
     18import org.eclipse.jface.viewers.ISelectionChangedListener; 
    1819import org.eclipse.jface.viewers.ITreeContentProvider; 
     20import org.eclipse.jface.viewers.ITreeSelection; 
     21import org.eclipse.jface.viewers.SelectionChangedEvent; 
    1922import org.eclipse.jface.viewers.TextCellEditor; 
     23import org.eclipse.jface.viewers.TreePath; 
    2024import org.eclipse.jface.viewers.TreeViewer; 
    2125import org.eclipse.jface.viewers.TreeViewerColumn; 
     
    3236import org.eclipse.swt.widgets.Combo; 
    3337import org.eclipse.swt.widgets.Composite; 
     38import org.eclipse.swt.widgets.Group; 
     39import org.eclipse.swt.widgets.Label; 
    3440import org.eclipse.swt.widgets.Layout; 
    3541import org.eclipse.swt.widgets.Link; 
     
    6470            comp = new Composite(comp, SWT.NONE); 
    6571            GridData gd = new GridData(GridData.FILL_HORIZONTAL); 
    66             gd.horizontalSpan = 1
     72            gd.horizontalSpan = 2
    6773            comp.setLayoutData(gd); 
    6874            GridLayout layout = new GridLayout(); 
     
    7682                    "configurations."); 
    7783            gd = new GridData(GridData.FILL_BOTH); 
    78             gd.horizontalSpan = 1
     84            gd.horizontalSpan = 2
    7985            fHelpText.setLayoutData(gd); 
    8086            fHelpText.addSelectionListener(new SelectionAdapter() 
     
    243249            public abstract void setValue(Object value); 
    244250            public abstract String getText(); 
     251            public abstract void initializeTo(String value); 
     252            public abstract void applyTo(ILaunchConfigurationWorkingCopy config); 
    245253        } 
    246254         
     
    288296                return selected ? option.getOnText() : option.getOffText(); 
    289297            } 
     298             
     299            @Override 
     300            public void initializeTo(String value) 
     301            { 
     302                selected = Boolean.valueOf(value); 
     303            } 
     304 
     305            @Override 
     306            public void applyTo(ILaunchConfigurationWorkingCopy config) 
     307            { 
     308                config.setAttribute(option.getAttributeId(), 
     309                        selected ? "true" : "false"); 
     310            } 
    290311        } 
    291312         
     
    335356            { 
    336357                return option.getOptionViewLabels()[selected]; 
     358            } 
     359             
     360            @Override 
     361            public void initializeTo(String value) 
     362            { 
     363                String[] optionValues = option.getOptionValues(); 
     364                for(int i = 0; i < optionValues.length; i++) 
     365                { 
     366                    if(optionValues[i].equals(i)) 
     367                    { 
     368                        selected = Integer.valueOf(i); 
     369                        return; 
     370                    } 
     371                } 
     372            } 
     373             
     374            @Override 
     375            public void applyTo(ILaunchConfigurationWorkingCopy config) 
     376            { 
     377                config.setAttribute(getOption().getAttributeId(), 
     378                        option.getOptionValues()[selected.intValue()]); 
    337379            } 
    338380        } 
     
    380422            { 
    381423                selected = (String) value; 
     424            } 
     425             
     426            @Override 
     427            public void initializeTo(String value) 
     428            { 
     429                selected = value; 
     430            } 
     431             
     432            @Override 
     433            public void applyTo(ILaunchConfigurationWorkingCopy config) 
     434            { 
     435                config.setAttribute(getOption().getAttributeId(), selected); 
    382436            } 
    383437        } 
     
    435489                    Object newInput) 
    436490            { 
    437                 // TODO 
     491                // This is handled externally 
    438492            } 
    439493        } 
     
    442496        private TreeViewer fViewer; 
    443497        private TreeEntry[] fEntries; 
     498        private Group fHelpGroup; 
     499        private Label fHelpText; 
    444500         
    445501        public void addToControl(Composite comp) 
    446502        { 
    447             fEntries = getTree(); 
     503            initializeTree(); 
    448504             
    449505            fViewer = new TreeViewer(comp, SWT.BORDER | SWT.FULL_SELECTION); 
     506            fViewer.setContentProvider(new OptionsContentProvider()); 
    450507            fViewer.getTree().setHeaderVisible(true); 
    451508            fViewer.getTree().setLinesVisible(true); 
     
    456513             
    457514            TreeViewerColumn column = new TreeViewerColumn(fViewer, SWT.NONE); 
    458             column.getColumn().setWidth(200); 
     515            column.getColumn().setWidth(250); 
    459516            column.getColumn().setText("Option"); 
    460517            column.setLabelProvider(new ColumnLabelProvider() 
     
    530587             
    531588            GridData gd = new GridData(GridData.FILL_BOTH); 
     589            gd.horizontalSpan = 1; 
    532590            fViewer.getControl().setLayoutData(gd); 
    533591             
    534             fViewer.setContentProvider(new OptionsContentProvider()); 
    535         } 
    536          
    537         private TreeEntry[] getTree() 
    538         { 
     592            fHelpGroup = new Group(comp, SWT.SHADOW_IN); 
     593            gd = new GridData(GridData.FILL_VERTICAL); 
     594            gd.horizontalSpan = 1; 
     595            gd.widthHint = 200; // PERHAPS use PixelConverter or something...? 
     596            fHelpGroup.setLayoutData(gd); 
     597             
     598            GridLayout groupLayout = new GridLayout(); 
     599            groupLayout.numColumns = 1; 
     600            fHelpGroup.setLayout(groupLayout); 
     601             
     602            fHelpText = new Label(fHelpGroup, SWT.LEFT | SWT.WRAP); 
     603            gd = new GridData(GridData.FILL_BOTH); 
     604            gd.horizontalSpan = 1; 
     605            fHelpText.setText(""); 
     606            fHelpText.setLayoutData(gd); 
     607             
     608            fViewer.addSelectionChangedListener(new ISelectionChangedListener() 
     609            { 
     610                public void selectionChanged(SelectionChangedEvent event) 
     611                {    
     612                    TreePath[] paths = ((ITreeSelection) fViewer.getSelection()).getPaths(); 
     613                    if(0 == paths.length) 
     614                    { 
     615                        fHelpText.setText(""); 
     616                        fHelpText.update(); 
     617                        return; 
     618                    } 
     619                     
     620                    Object selected = paths[0].getLastSegment(); 
     621                    if(!(selected instanceof CompilerUIOption)) 
     622                    { 
     623                        fHelpText.setText(""); 
     624                        fHelpText.update(); 
     625                        return; 
     626                    } 
     627                     
     628                    fHelpText.setText(((CompilerUIOption) selected).getOption(). 
     629                            getHelpText()); 
     630                    fHelpText.update(); 
     631                } 
     632            }); 
     633             
     634            fViewer.setInput(this); 
     635            fViewer.expandAll(); 
     636        } 
     637         
     638        private void initializeTree() 
     639        { 
     640            if(null != fEntries) 
     641                return; 
     642             
    539643            ICompilerInterface compilerInterface =  
    540644                getCompilerInterface(fSelectedCompiler); 
     
    545649            { 
    546650                String group = opt.getGroupLabel(); 
    547                 if(!groups.containsKey(group)); 
     651                if(!groups.containsKey(group)) 
    548652                    groups.put(group, new ArrayList<CompilerUIOption>()); 
    549653                groups.get(group).add(toUIOption(opt)); 
    550654            } 
    551655             
    552             TreeEntry[] entries = new TreeEntry[groups.size()]; 
     656            fEntries = new TreeEntry[groups.size()]; 
    553657            int i = 0; 
    554658            for(String group : groups.keySet()) 
    555659            { 
    556660                List<CompilerUIOption> list = groups.get(group); 
    557                 entries[i] = new TreeEntry(group,  
     661                fEntries[i] = new TreeEntry(group,  
    558662                        list.toArray(new CompilerUIOption[list.size()])); 
    559663                i++; 
    560664            } 
    561              
    562             return entries; 
    563665        } 
    564666         
     
    588690            fSelectedCompiler = compiler; 
    589691            if(null != fViewer && null != fSelectedCompiler) 
    590                 fViewer.setInput(fSelectedCompiler); 
     692            { 
     693                // TODO 
     694            } 
    591695        } 
    592696 
    593697        public void initializeFrom(ILaunchConfiguration config) 
    594698        { 
    595             // TODO Auto-generated method stub 
     699            initializeTree(); 
     700            for(TreeEntry group : fEntries) 
     701            { 
     702                for(CompilerUIOption uiOpt : group.children) 
     703                { 
     704                    CompilerOption opt = uiOpt.getOption(); 
     705                    String defaultValue = opt.getDefaultValue(); 
     706                    String value = defaultValue; 
     707                    try 
     708                    { 
     709                        value = config.getAttribute(opt.getAttributeId(), defaultValue); 
     710                    } 
     711                    catch(CoreException e) { } 
     712                    uiOpt.initializeTo(value); 
     713                    fViewer.update(uiOpt, null); 
     714                } 
     715            } 
    596716        } 
    597717 
    598718        public void performApply(ILaunchConfigurationWorkingCopy config) 
    599719        { 
    600             // TODO Auto-generated method stub 
     720            initializeTree(); 
     721            for(TreeEntry group : fEntries) 
     722            { 
     723                for(CompilerUIOption uiOpt : group.children) 
     724                { 
     725                    uiOpt.applyTo(config); 
     726                } 
     727            } 
    601728        } 
    602729 
    603730        public void setDefaults(ILaunchConfigurationWorkingCopy config) 
    604731        { 
    605             // TODO Auto-generated method stub 
     732            initializeTree(); 
     733            for(TreeEntry group : fEntries) 
     734            { 
     735                for(CompilerUIOption uiOpt : group.children) 
     736                { 
     737                    CompilerOption opt = uiOpt.getOption(); 
     738                    config.setAttribute(opt.getAttributeId(), opt.getDefaultValue()); 
     739                } 
     740            } 
    606741        } 
    607742 
    608743        public String validate() 
    609744        { 
    610             // TODO Auto-generated method stub 
     745            // PERHAPS should we allow options to validate themselves? 
    611746            return null; 
    612747        } 
     
    654789    { 
    655790        GridLayout layout = new GridLayout(); 
    656         layout.numColumns = 1
     791        layout.numColumns = 2
    657792        return layout; 
    658793    }