View | Details | Raw Unified | Return to bug 277879 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+12 lines)
Lines 230-233 Link Here
230
   	id="sourceViewerConfig"
230
   	id="sourceViewerConfig"
231
   	name="Source Viewer Configuration"
231
   	name="Source Viewer Configuration"
232
   	schema="schema/sourceViewerConfig.exsd"/>
232
   	schema="schema/sourceViewerConfig.exsd"/>
233
   	
234
   <!--=============================================-->
235
   <!-- Image Associated with Photran Projects      -->
236
   <!--=============================================-->
237
   <extension
238
         point="org.eclipse.ui.ide.projectNatureImages">
239
      <image
240
            icon="icons/full/obj16/f_ovr.gif"
241
            natureId="org.eclipse.photran.core.fnature"
242
            id="org.eclipse.photran.ui.fProjectNatureImage">
243
      </image>
244
   </extension> 
233
</plugin>
245
</plugin>
(-)plugin.xml (+14 lines)
Lines 129-132 Link Here
129
		  priority="high"/>
129
		  priority="high"/>
130
  </extension>
130
  </extension>
131
131
132
<!-- =================================================================================== -->
133
<!-- Photran Nature for Fortran Projects                                                 -->
134
<!-- =================================================================================== -->
135
   <extension
136
         id="fnature"
137
         name="%fnature.name"
138
         point="org.eclipse.core.resources.natures">
139
      <runtime>
140
         <run
141
               class="org.eclipse.photran.core.FProjectNature">
142
         </run>
143
      </runtime>
144
   </extension>
145
132
</plugin>
146
</plugin>
(-)src/org/eclipse/photran/core/FProjectNature.java (+122 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     QNX Software Systems - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.photran.core;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProjectDescription;
20
import org.eclipse.core.resources.IProjectNature;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
24
/**
25
 * This file copied (mostly) from org.eclipse.cdt.core.CProjectNature.
26
 * 
27
 * @author Matt Scarpino
28
 */
29
public class FProjectNature implements IProjectNature {
30
31
    public static final String F_NATURE_ID = "org.eclipse.photran.core.fnature"; //$NON-NLS-1$
32
33
    private IProject fProject;
34
35
    public FProjectNature() {
36
    }
37
38
    public FProjectNature(IProject project) {
39
        setProject(project);
40
    }
41
42
    public static void addFNature(IProject project, IProgressMonitor mon) throws CoreException {
43
        addNature(project, F_NATURE_ID, mon);
44
    }
45
46
    public static void removeFNature(IProject project, IProgressMonitor mon) throws CoreException {
47
        removeNature(project, F_NATURE_ID, mon);
48
    }
49
50
    /**
51
     * Utility method for adding a nature to a project.
52
     * 
53
     * @param project
54
     *            the project to add the nature
55
     * @param natureId
56
     *            the id of the nature to assign to the project
57
     * @param monitor
58
     *            a progress monitor to indicate the duration of the operation,
59
     *            or <code>null</code> if progress reporting is not required.
60
     *  
61
     */
62
    public static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
63
        IProjectDescription description = project.getDescription();
64
        String[] prevNatures = description.getNatureIds();
65
        for(int i=0; i<prevNatures.length; i++) {
66
            if (natureId.equals(prevNatures[i]))
67
                return;
68
        }
69
        String[] newNatures = new String[prevNatures.length + 1];
70
        System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length);
71
        newNatures[0] = natureId;
72
        description.setNatureIds(newNatures);
73
        project.setDescription(description, monitor);
74
    }
75
76
    /**
77
     * Utility method for removing a project nature from a project.
78
     * 
79
     * @param project
80
     *            the project to remove the nature from
81
     * @param natureId
82
     *            the nature id to remove
83
     * @param monitor
84
     *            a progress monitor to indicate the duration of the operation,
85
     *            or <code>null</code> if progress reporting is not required.
86
     */
87
    public static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
88
        IProjectDescription description = project.getDescription();
89
        String[] prevNatures = description.getNatureIds();
90
        List newNatures = new ArrayList(Arrays.asList(prevNatures));
91
        newNatures.remove(natureId);
92
        description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()]));
93
        project.setDescription(description, monitor);
94
    }
95
96
    /**
97
     * @see IProjectNature#configure
98
     */
99
    public void configure() throws CoreException {
100
    }
101
102
    /**
103
     * @see IProjectNature#deconfigure
104
     */
105
    public void deconfigure() throws CoreException {
106
    }
107
108
    /**
109
     * @see IProjectNature#getProject
110
     */
111
    public IProject getProject() {
112
        return fProject;
113
    }
114
115
    /**
116
     * @see IProjectNature#setProject
117
     */
118
    public void setProject(IProject project) {
119
        fProject = project;
120
    }
121
}
122
(-)src/org/eclipse/photran/cdtinterface/ui/FortranProjectWizard.java (-3 / +99 lines)
Lines 10-24 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.photran.cdtinterface.ui;
11
package org.eclipse.photran.cdtinterface.ui;
12
12
13
import java.io.ByteArrayInputStream;
14
import java.io.FileNotFoundException;
15
import java.io.IOException;
16
import java.io.RandomAccessFile;
17
import java.util.ArrayList;
18
import java.util.Iterator;
19
13
import org.eclipse.cdt.core.CProjectNature;
20
import org.eclipse.cdt.core.CProjectNature;
21
import org.eclipse.cdt.core.model.CoreModel;
22
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
23
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
14
import org.eclipse.cdt.ui.newui.UIMessages;
24
import org.eclipse.cdt.ui.newui.UIMessages;
15
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
25
import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard;
26
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IProject;
27
import org.eclipse.core.resources.IProject;
28
import org.eclipse.core.resources.IProjectDescription;
17
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.NullProgressMonitor;
30
import org.eclipse.core.runtime.NullProgressMonitor;
31
import org.eclipse.photran.core.FProjectNature;
19
32
20
/**
33
/**
21
 * @author ???
34
 * @author ???
35
 * @author Matt Scarpino - 7/20/2009 - Updated to include Fortran nature in project  
22
 */
36
 */
23
public class FortranProjectWizard extends CDTCommonProjectWizard
37
public class FortranProjectWizard extends CDTCommonProjectWizard
24
{
38
{
Lines 31-48 Link Here
31
45
32
	public String[] getNatures()
46
	public String[] getNatures()
33
	{
47
	{
34
		return new String[] { CProjectNature.C_NATURE_ID };
48
		return new String[] { FProjectNature.F_NATURE_ID, CProjectNature.C_NATURE_ID };
35
	}
49
	}
36
50
51
	/**
52
	 * This method is called immediately after the createIProject() method in
53
	 * the CDTCommonProjectWizard class
54
	 */
37
	protected IProject continueCreation(IProject prj)
55
	protected IProject continueCreation(IProject prj)
38
	{
56
	{
39
		try
57
		try
40
		{
58
		{
41
			CProjectNature.addCNature(prj, new NullProgressMonitor());
59
            // Add C nature to the project
60
            CProjectNature.addCNature(prj, new NullProgressMonitor());
61
            
62
            // Add Fortran nature to the project
63
            FProjectNature.addFNature(prj, new NullProgressMonitor());
42
		}
64
		}
43
		catch (CoreException e) {}
65
		catch (CoreException e) {}
44
		
66
		
45
		return prj;
67
		return prj;
46
	}
68
	}	
69
	
70
    /**
71
     * This method is called within the performFinish() method of the
72
     * CDTCommonProjectWizard class. Among other things, it sets the Photran
73
     * nature first in the project's nature list. This ensures that the project
74
     * will be displayed as a Fortran project in the Photran navigator. 
75
     */	
76
    protected boolean setCreated() throws CoreException 
77
    {
78
        ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
79
        
80
        ICProjectDescription des = mngr.getProjectDescription(newProject, false);
81
        if(des.isCdtProjectCreating())
82
        {
83
            des = mngr.getProjectDescription(newProject, true);
84
            des.setCdtProjectCreated();
85
            mngr.setProjectDescription(newProject, des, false, null);
86
            return true;
87
        }
88
        
89
        // Access the .project file in the recently-created project
90
        final IFile projFile = (IFile)newProject.findMember(IProjectDescription.DESCRIPTION_FILE_NAME);
91
        if(projFile.exists()) 
92
        {
93
            try 
94
            {
95
                // Create a list of lines in .project file
96
                RandomAccessFile raFile = new RandomAccessFile(projFile.getLocation().toOSString(), "rws");
97
                ArrayList lineList = new ArrayList();
98
                String line;
99
                while((line = raFile.readLine()) != null) 
100
                    lineList.add(line);
101
                raFile.close();
102
                
103
                // Find the natures in the list
104
                Iterator itr = lineList.iterator();
105
                int first_index = 0, phot_index = 0;
106
                while (itr.hasNext()) 
107
                {
108
                    line = (String)itr.next();
109
                    if(line.trim().equals("<natures>"))
110
                        first_index = lineList.indexOf(line) + 1;
111
                    else if(line.contains("photran"))
112
                        phot_index = lineList.indexOf(line);
113
                }
114
                
115
                // Swap the photran nature with the first nature
116
                String temp = (String)lineList.get(first_index);
117
                lineList.set(first_index, lineList.get(phot_index));
118
                lineList.set(phot_index, temp);
119
                
120
                // Write the new lines to the .project file
121
                itr = lineList.iterator();
122
                StringBuffer content = new StringBuffer("");
123
                while (itr.hasNext()) 
124
                {
125
                    content.append((String)itr.next() + "\n");
126
                }
127
                projFile.setContents(new ByteArrayInputStream(content.toString().getBytes()), IFile.FORCE, null);
47
128
129
                // Deallocate
130
                lineList.clear();
131
            }
132
            catch (FileNotFoundException e) {
133
                e.printStackTrace();
134
            }
135
            catch (IOException e) {
136
                e.printStackTrace();
137
            }
138
            catch (CoreException e) {
139
                e.printStackTrace();
140
            }            
141
        }       
142
        return false;
143
    }	
48
}
144
}
(-)src/org/eclipse/photran/cdtinterface/ui/FortranView.java (-1 / +10 lines)
Lines 11-23 Link Here
11
package org.eclipse.photran.cdtinterface.ui;
11
package org.eclipse.photran.cdtinterface.ui;
12
12
13
import org.eclipse.cdt.internal.ui.cview.CView;
13
import org.eclipse.cdt.internal.ui.cview.CView;
14
import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider;
15
import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
16
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
17
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
14
18
15
/**
19
/**
16
 * The Fortran Projects View is just the C/C++ Projects View with a different name.
20
 * The Fortran Projects View is just the C/C++ Projects View with a different name.
17
 * 
21
 * 
18
 * @author Jeff Overbey
22
 * @author Jeff Overbey
23
 * @author Matt Scarpino - 7/20/2009 - Updated to access Fortran-specific label provider.
19
 */
24
 */
20
public class FortranView extends CView
25
public class FortranView extends CView
21
{
26
{
22
    public static final String FORTRAN_VIEW_ID = "org.eclipse.photran.ui.FortranView";
27
    public static final String FORTRAN_VIEW_ID = "org.eclipse.photran.ui.FortranView";
23
}
28
    
29
    protected CUILabelProvider createLabelProvider() {
30
        return new FViewLabelProvider(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | CElementImageProvider.SMALL_ICONS);
31
    }
32
}
(-)src/org/eclipse/photran/cdtinterface/ui/FViewLabelProvider.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Matthew Scarpino, Eclipse Engineering LLC
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *******************************************************************************/
9
package org.eclipse.photran.cdtinterface.ui;
10
11
import org.eclipse.cdt.internal.core.model.TranslationUnit;
12
import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider;
13
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.content.IContentType;
15
import org.eclipse.jface.resource.ImageDescriptor;
16
import org.eclipse.photran.cdtinterface.CDTInterfacePlugin;
17
import org.eclipse.swt.graphics.Image;
18
19
/**
20
 * This class provides images to the FortranView. Specifically, it checks for the contentType
21
 * of source files in the view and returns the Photran icon for files with Fortran-based content.
22
 * 
23
 * @author Matt Scarpino
24
 */
25
public class FViewLabelProvider extends CViewLabelProvider
26
{
27
    public static final String FIXED_FORM_CONTENT_TYPE = "org.eclipse.photran.core.fixedFormFortranSource";
28
    public static final String FREE_FORM_CONTENT_TYPE = "org.eclipse.photran.core.freeFormFortranSource";
29
 
30
    Image fortranFileImage;
31
    
32
    public FViewLabelProvider(int textFlags, int imageFlags)
33
    {
34
        super(textFlags, imageFlags);
35
    }
36
37
    // This is something of a hack. Originally I tried using AdapterFactory objects and WorkspaceAdapters,
38
    // but they never seemed to work. This works, but it's not particularly elegant and the image only
39
    // shows up in the Fortran navigator.
40
    public Image getImage(Object element) 
41
    {
42
        if (element instanceof TranslationUnit) 
43
        {
44
            String fileName = ((TranslationUnit)element).getFile().getName();
45
            IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(fileName);
46
            if(contentType.getId().equals(FIXED_FORM_CONTENT_TYPE) || contentType.getId().equals(FREE_FORM_CONTENT_TYPE))          
47
            {
48
                if(fortranFileImage == null) {
49
                    fortranFileImage = CDTInterfacePlugin.getImageDescriptor("icons/obj16/f_file_obj.gif").createImage();
50
                }
51
                return fortranFileImage;
52
            }
53
        }
54
        return super.getImage(element);
55
    }
56
    
57
    public void dispose() {
58
        if(fortranFileImage != null)
59
            fortranFileImage.dispose();
60
        super.dispose();
61
    }
62
}

Return to bug 277879