Changeset 1150

Show
Ignore:
Timestamp:
05/01/08 22:41:05 (8 months ago)
Author:
fraserofthenight
Message:

Started on a file import UI

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.ui/plugin.xml

    r1142 r1150  
    530530         <keywordReference id="descent.ui.todo"/> 
    531531      </page> 
    532             <!-- 
    533       <page 
     532      <page 
     533            category="descent.ui.propertyPages.CompliancePreferencePage" 
    534534            class="descent.internal.ui.preferences.FileImportPropertyPage" 
    535535            id="descent.ui.propertyPages.FileImportPropertyPage" 
    536536            name="%fileImportPageName" 
    537537            objectClass="org.eclipse.core.resources.IProject"> 
    538       </page> 
    539       <page 
     538         <filter 
     539               name="nature" 
     540               value="descent.core.dnature"> 
     541         </filter> 
     542      </page> 
     543      <page 
     544            category="descent.ui.propertyPages.CompliancePreferencePage" 
    540545            class="descent.internal.ui.preferences.FileImportPropertyPage" 
    541546            id="descent.ui.propertyPages.FileImportPropertyPage" 
    542547            name="%fileImportPageName" 
    543548            objectClass="descent.core.IJavaProject"> 
    544       </page> 
    545       --> 
     549         <filter 
     550               name="nature" 
     551               value="descent.core.dnature"> 
     552         </filter> 
     553      </page> 
    546554      <!-- 
    547555      <page 
  • trunk/descent.ui/src/descent/internal/ui/preferences/FileImportBlock.java

    r622 r1150  
    11package descent.internal.ui.preferences; 
    22 
     3import java.io.File; 
     4 
    35import org.eclipse.core.resources.IProject; 
     6import org.eclipse.jface.viewers.LabelProvider; 
    47import org.eclipse.swt.SWT; 
     8import org.eclipse.swt.events.SelectionEvent; 
     9import org.eclipse.swt.events.SelectionListener; 
     10import org.eclipse.swt.graphics.Image; 
     11import org.eclipse.swt.layout.GridData; 
     12import org.eclipse.swt.layout.GridLayout; 
     13import org.eclipse.swt.widgets.Button; 
    514import org.eclipse.swt.widgets.Composite; 
    615import org.eclipse.swt.widgets.Control; 
     16import org.eclipse.swt.widgets.Group; 
    717import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 
    818 
    9 import descent.internal.ui.preferences.OptionsConfigurationBlock.Key; 
     19import descent.internal.ui.util.PixelConverter; 
     20import descent.internal.ui.util.SWTUtil; 
    1021import descent.internal.ui.wizards.IStatusChangeListener; 
    1122 
    1223public class FileImportBlock extends OptionsConfigurationBlock 
    1324{ 
    14    public static Key[] KEYS = new Key[] 
     25    public static Key[] KEYS = new Key[] 
    1526    { 
    1627        // TODO ...and then the ogre took the keys... 
    1728    }; 
    18      
     29     
     30    private static class FileImportLabelProvider extends LabelProvider 
     31    { 
     32        // TODO these images -- a folder and a folder with an X 
     33        private static Image ICON_FOLDER = null; 
     34        private static Image ICON_FOLDER_NOT_FOUND = null; 
     35         
     36        public Image getImage(Object element) 
     37        { 
     38            if(null == element || !(element instanceof File)) 
     39                throw new IllegalArgumentException("Expected a non-null java.io.File"); 
     40             
     41            File file = (File) element; 
     42            if(file.exists() && file.isDirectory()) 
     43                return ICON_FOLDER; 
     44            else 
     45                return ICON_FOLDER_NOT_FOUND; 
     46        } 
     47 
     48        public String getText(Object element) 
     49        { 
     50            if(null == element || !(element instanceof File)) 
     51                throw new IllegalArgumentException("Expected a non-null java.io.File"); 
     52             
     53            File file = (File) element; 
     54            return file.getAbsolutePath(); 
     55        } 
     56    } 
     57     
     58    private Button fNewButton; 
     59    private Button fEditButton; 
     60    private Button fRemoveButton; 
     61     
    1962    public FileImportBlock(IStatusChangeListener context, 
    2063            IProject project, 
     
    2669    @Override 
    2770    protected Control createContents(Composite parent) 
    28     { 
    29         return new Composite(parent, SWT.NONE); 
    30     } 
    31  
    32     @Override 
     71    {    
     72        setShell(parent.getShell()); 
     73         
     74        // Create the composite 
     75        Composite comp = new Composite(parent, SWT.NONE); 
     76        comp.setFont(parent.getFont()); 
     77        GridLayout layout = new GridLayout(); 
     78        layout.marginHeight= 0; 
     79        layout.marginWidth= 0; 
     80        layout.numColumns = 2; 
     81        comp.setLayout(layout); 
     82         
     83        createListControl(comp); 
     84        createButtons(comp); 
     85         
     86        return comp; 
     87    } 
     88     
     89    private void createListControl(Composite comp) 
     90    { 
     91        // TODO temp testing layout 
     92        Group tmp = new Group(comp, SWT.NONE); 
     93        GridData gd = new GridData(GridData.FILL_BOTH); 
     94        PixelConverter conv = new PixelConverter(comp); 
     95        gd.widthHint = conv.convertWidthInCharsToPixels(50); 
     96        tmp.setLayoutData(gd); 
     97    } 
     98     
     99    private void createButtons(Composite parent) 
     100    { 
     101        SelectionListener listener = new SelectionListener() 
     102        { 
     103            public void widgetDefaultSelected(SelectionEvent e) 
     104            { 
     105                widgetSelected(e); 
     106            } 
     107 
     108            public void widgetSelected(SelectionEvent e) 
     109            { 
     110                if(fNewButton == e.widget) 
     111                    performNew(); 
     112                else if(fEditButton == e.widget) 
     113                    performEdit(); 
     114                else if(fRemoveButton == e.widget) 
     115                    performRemove(); 
     116            } 
     117        }; 
     118         
     119        Composite comp = new Composite(parent, SWT.NONE); 
     120         
     121        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); 
     122        comp.setLayoutData(gd); 
     123         
     124        GridLayout layout = new GridLayout(); 
     125        layout.marginWidth = 0; 
     126        layout.marginHeight = 0; 
     127        comp.setLayout(layout); 
     128         
     129        fNewButton = createButton(comp, listener, "New..."); 
     130        fEditButton = createButton(comp, listener, "Edit..."); 
     131        fRemoveButton = createButton(comp, listener, "Remove"); 
     132         
     133        updateEnablement(); 
     134    } 
     135     
     136    private Button createButton(Composite comp, SelectionListener listener, String label) 
     137    { 
     138        Button button = new Button(comp, SWT.PUSH); 
     139        button.setFont(comp.getFont()); 
     140        button.setText(label); 
     141        button.addSelectionListener(listener); 
     142         
     143        GridData gd= new GridData(); 
     144        gd.horizontalAlignment= GridData.FILL; 
     145        gd.grabExcessHorizontalSpace= true; 
     146        gd.verticalAlignment= GridData.BEGINNING; 
     147        gd.widthHint = SWTUtil.getButtonWidthHint(button); 
     148        button.setLayoutData(gd); 
     149         
     150        return button; 
     151    } 
     152     
     153    private void updateEnablement() 
     154    { 
     155        File file = getSelectedElement(); 
     156        if(null == file) 
     157        { 
     158            fEditButton.setEnabled(false); 
     159            fRemoveButton.setEnabled(false); 
     160        } 
     161        else 
     162        { 
     163            fEditButton.setEnabled(true); 
     164            fRemoveButton.setEnabled(true); 
     165        } 
     166    } 
     167     
     168    private File getSelectedElement() 
     169    { 
     170        return null; 
     171    } 
     172     
     173    private void performNew() 
     174    { 
     175        // TODO 
     176    } 
     177     
     178    private void performEdit() 
     179    { 
     180        File file = getSelectedElement(); 
     181        if(null == file) 
     182            return; 
     183        
     184        // TODO 
     185    } 
     186     
     187    private void performRemove() 
     188    { 
     189        File file = getSelectedElement(); 
     190        if(null == file) 
     191            return; 
     192         
     193        // TODO 
     194    } 
     195 
     196    @Override 
    33197    protected String[] getFullBuildDialogStrings(boolean workspaceSettings) 
    34198    { 
  • trunk/descent.unittest/flute/src/org/dsource/descent/flute/io.d

    r1106 r1150  
    11module org.dsource.descent.flute.io; 
    22 
     3version(Tango) 
     4{ 
     5     
     6} 
     7else 
     8{ 
     9    import std.file : exists, read; 
     10    import std.stdio: writef, fflush, stdout; 
     11} 
     12 
     13private IOProvider ioProvider; 
     14 
     15public IOProvider getIOProvider() 
     16{ 
     17    if(null is ioProvider) 
     18    { 
     19        ioProvider = new PhobosStdioProvider(); 
     20    } 
     21     
     22    return ioProvider; 
     23} 
     24 
     25public interface IOProvider 
     26{ 
     27    /** 
     28     * Prints the given string to the output (either a socket or stdout). 
     29     *  
     30     * Params: 
     31     *     str = The string to print 
     32     */ 
     33    public void write(string str); 
     34     
     35    /** 
     36     * Flushes the output stream. Should be called before waiting for user input and 
     37     * before possibly lengthy operations to alert users. 
     38     */ 
     39    public void flush(); 
     40 
     41    /** 
     42     * Reads a line (terminated by a CRLF) from the socket and returns it. 
     43     *  
     44     * Returns: The next line from the input stream 
     45     */ 
     46    public string readln(); 
     47     
     48    /** 
     49     * Provides a library-independent interface for accessing a file. 
     50     * It is assumed the file is a smallish UTF-8 text file. 
     51     *  
     52     * Returns: a new handle to the file or null if the file could not be 
     53     *          found 
     54     */ 
     55    protected FileHandle getFileHandle(string filename); 
     56} 
     57 
     58/** 
     59 * Provides a library-independent interface for reading from a smallish UTF-8 
     60 * text file in a line-by-line manner. 
     61 */ 
     62private interface FileHandle 
     63{ 
     64    /** 
     65     * Iterates over the contents of a file line-by line. 
     66     */ 
     67    public int opApply(int delegate(ref string) dg); 
     68} 
     69 
     70version(Tango) 
     71{ 
     72     
     73} 
     74else 
     75{ 
     76    private abstract class PhobosIOProvider : IOProvider 
     77    { 
     78        protected final FileHandle getFileHandle(string filename) 
     79        { 
     80            if(exists(filename)) 
     81            { 
     82                return new class(filename) FileHandle 
     83                { 
     84                    private string filename; 
     85                     
     86                    public this(string filename) 
     87                    { 
     88                        this.filename = filename; 
     89                    } 
     90                     
     91                    public int opApply(int delegate(ref string) dg) 
     92                    { 
     93                        // Read the file 
     94                        char[] text = cast(char[]) read(filename); 
     95                         
     96                        // Iterate through the lines 
     97                        uint lineStart = 0; 
     98                        uint i = 0; 
     99                        for(; i < test.length; i++) 
     100                        { 
     101                            char c = text[i]; 
     102                            if (c == '\n') 
     103                            { 
     104                                uint lineEnd = i; 
     105                                 
     106                                // Handle a \r\n 
     107                                if(lineEnd && (text[lineEnd - 1] == '\r')) 
     108                                    lineEnd--; 
     109                                 
     110                                char[] line = text[lineStart .. lineEnd]; 
     111                                lineStart = i + 1; 
     112                                 
     113                                int result = dg(line); 
     114                                if(result) 
     115                                    return result; 
     116                            } 
     117                        } 
     118                         
     119                        // Slurp up the remainder of the text as the final line 
     120                        if(lineStart < text.length) 
     121                        { 
     122                            char[] line = text[lineStart .. i]; 
     123                            int result = dg(line); 
     124                            if(result) 
     125                                return result; 
     126                        } 
     127                         
     128                        return 0; 
     129                    } 
     130                }; 
     131            } 
     132            else 
     133            { 
     134                return null; 
     135            } 
     136        } 
     137    } 
     138     
     139    private final class PhobosStdioProvider : PhobosIOProvider 
     140    {    
     141        public void write(string str) 
     142        { 
     143            writef(str); 
     144        } 
     145         
     146        public void flush() 
     147        { 
     148            fflush(stdout); 
     149        } 
     150 
     151        public string readln() 
     152        { 
     153            return cinReadln(); 
     154        } 
     155    } 
     156} 
  • trunk/descent.unittest/src/descent/internal/unittest/ui/OpenModuleAction.java

    r1058 r1150  
    5757         
    5858        ICompilationUnit module; 
    59         IJavaElement javaElement = project.findBySignature(moduleSignature); 
     59        // TODO IJavaElement javaElement = project.findBySignature(moduleSignature); 
     60        IJavaElement javaElement = null; 
    6061        if(javaElement != null && javaElement instanceof ICompilationUnit 
    6162            && javaElement.exists())