Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for PR 71089: C/C++ make project page bug

This is a patch for PR 71089: C/C++ make project page bug; for 2.0.1 
branch only.

I am not sure if there is work being done on C/C++ Make Project property 
page for 2.1, but I would like to see this problem addressed better. The 
problem is the property page behavior when one or all CDT builders are 
disabled. I guess it is a valid workflow to have internal CDT builders 
disabled while providing custom external builders. Maybe corresponding 
property page tabs should be invisible if a builder is disabled.

Thanks,
Vmir

Index: src/org/eclipse/cdt/make/internal/ui/ErrorParserBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/ErrorParserBlock.java,v
retrieving revision 1.2
diff -u -r1.2 ErrorParserBlock.java
--- src/org/eclipse/cdt/make/internal/ui/ErrorParserBlock.java	4 Sep 2003 20:26:22 -0000	1.2
+++ src/org/eclipse/cdt/make/internal/ui/ErrorParserBlock.java	30 Jul 2004 19:58:11 -0000
@@ -13,25 +13,49 @@
 import org.eclipse.cdt.make.core.IMakeBuilderInfo;
 import org.eclipse.cdt.make.core.MakeBuilder;
 import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.cdt.make.ui.dialogs.DiscoveryOptionsBlock.ProjectManifestChangeNotification;
 import org.eclipse.cdt.ui.dialogs.AbstractErrorParserBlock;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.Preferences;
+import org.eclipse.swt.widgets.Composite;
 
 public class ErrorParserBlock extends AbstractErrorParserBlock {
-
+	// make builder enabled
+	private boolean fInitialized = false;
+	private ProjectManifestChangeNotification fNotification;
+	
 	public ErrorParserBlock(Preferences prefs) {
 		super(prefs);
 	}
 
 	/* (non-Javadoc)
+	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+	 */
+	public void createControl(Composite parent) {
+		super.createControl(parent);
+		// recieve notifications when .project file is changed
+		fNotification = new ProjectManifestChangeNotification(getContainer().getProject()) {
+			protected void dotProjectFileChanged() {
+				try {
+					MakeCorePlugin.createBuildInfo(getContainer().getProject(), MakeBuilder.BUILDER_ID);
+				} catch (CoreException e) {
+					fInitialized = false;
+				}
+			}
+		};
+	}
+
+	/* (non-Javadoc)
 	 * @see org.eclipse.cdt.ui.dialogs.ErrorParserBlock#getErrorParserIDs(org.eclipse.core.resources.IProject)
 	 */
 	protected String[] getErrorParserIDs(IProject project) {
 		IMakeBuilderInfo info;
 		try {
 			info = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
+			fInitialized = true;
 		} catch (CoreException e) {
+			fInitialized = false;
 			return new String[0];
 		}
 		return info.getErrorParsers();
@@ -41,8 +65,10 @@
 	 * @see org.eclipse.cdt.ui.dialogs.ErrorParserBlock#saveErrorParsers(org.eclipse.core.resources.IProject, java.lang.String[])
 	 */
 	public void saveErrorParsers(IProject project, String[] parserIDs) throws CoreException {
-		IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
-		info.setErrorParsers(parserIDs);
+		if (fInitialized) {
+			IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
+			info.setErrorParsers(parserIDs);
+		}
 	}
 
 }
Index: src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java,v
retrieving revision 1.10
diff -u -r1.10 DiscoveryOptionsBlock.java
--- src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java	26 Jun 2004 20:08:13 -0000	1.10
+++ src/org/eclipse/cdt/make/ui/dialogs/DiscoveryOptionsBlock.java	30 Jul 2004 19:58:11 -0000
@@ -32,9 +32,16 @@
 import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
 import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
 import org.eclipse.cdt.utils.ui.controls.ControlFactory;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtension;
@@ -107,6 +114,8 @@
 	private Map providerParsers = new HashMap();
 	private String initialProviderParserId = null;
 	private boolean fCreatePathContainer = false;
+	
+	private ProjectManifestChangeNotification fNotification;
 
 	public DiscoveryOptionsBlock() {
 		super(MakeUIPlugin.getResourceString(DIALOG_TITLE));
@@ -139,6 +148,18 @@
 		retrieveSIConsoleParsers();
 		initialBuilderParserId = fBuildInfo.getMakeBuilderConsoleParserId(); //$NON-NLS-1$
 		initialProviderParserId = fBuildInfo.getESIProviderConsoleParserId(); //$NON-NLS-1$
+		
+		if (project != null) {
+			fNotification = new ProjectManifestChangeNotification(project) {
+				protected void dotProjectFileChanged() {
+					try {
+						MakeCorePlugin.createScannerConfigBuildInfo(getContainer().getProject(), ScannerConfigBuilder.BUILDER_ID);
+					} catch(CoreException e) {
+						fInitialized = false;
+					}
+				}
+			};
+		}
 	}
 
 	/*
@@ -147,6 +168,10 @@
 	 * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	public void performApply(IProgressMonitor monitor) throws CoreException {
+		// Missing builder info
+		if (!fInitialized) {
+			return;
+		}
 		if (monitor == null) {
 			monitor = new NullProgressMonitor();
 		}
@@ -223,6 +248,10 @@
 	 * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
 	 */
 	public void performDefaults() {
+		// Missing builder info
+		if (!fInitialized) {
+			return;
+		}
 		IScannerConfigBuilderInfo info;
 		// Populate with the default values
 		if (getContainer().getProject() != null) {
@@ -267,7 +296,7 @@
 	 */
 	public void createControl(Composite parent) {
 		// Create the composite control for the tab
-		int tabColumns = 2;
+		int tabColumns = 1;
 		Font font = parent.getFont();
 		Composite composite = ControlFactory.createComposite(parent, tabColumns);
 		((GridLayout)composite.getLayout()).makeColumnsEqualWidth = false;
@@ -302,17 +331,18 @@
 			showMissingBuilder = true;
 		}
 
+		if (showMissingBuilder || (!needsSCNature && !fInitialized)) {
+			ControlFactory.createEmptySpace(parent);
+			ControlFactory.createLabel(parent, MakeUIPlugin.getResourceString(MISSING_BUILDER_MSG));
+			return false;
+		}
+
 		Group scGroup = ControlFactory.createGroup(parent, MakeUIPlugin.getResourceString(SC_GROUP_LABEL), numColumns);
 		scGroup.setFont(parent.getFont());
 		((GridData)scGroup.getLayoutData()).grabExcessHorizontalSpace = true;
 		((GridData)scGroup.getLayoutData()).horizontalSpan = numColumns;
 		((GridData)scGroup.getLayoutData()).horizontalAlignment = GridData.FILL;
 
-		if (showMissingBuilder || (!needsSCNature && !fInitialized)) {
-			ControlFactory.createLabel(scGroup, MakeUIPlugin.getResourceString(MISSING_BUILDER_MSG));
-			return false;
-		}
-
 		// Add checkbox
 		scEnabledButton = ControlFactory.createCheckBox(scGroup, MakeUIPlugin.getResourceString(SC_ENABLED_LABEL));
 		scEnabledButton.setFont(parent.getFont());
@@ -506,6 +536,7 @@
 		esiProviderCommand.setEnabled(isScannerConfigDiscoveryEnabled() && isProviderCommandEnabled()
 				&& !useDefaultESIProviderCmd());
 		esiProviderParserComboBox.setEnabled(isScannerConfigDiscoveryEnabled() && isProviderCommandEnabled());
+		enableProblemGenerationButton.setEnabled(isScannerConfigDiscoveryEnabled());
 	}
 
 	private boolean useDefaultESIProviderCmd() {
@@ -580,7 +611,7 @@
 	 * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#isValid()
 	 */
 	public boolean isValid() {
-		if (isProviderCommandEnabled() == true && useDefaultESIProviderCmd() == false) {
+		if (fInitialized && isProviderCommandEnabled() && !useDefaultESIProviderCmd()) {
 			String cmd = getSIProviderCommandLine();
 			if (cmd == null || cmd.length() == 0) {
 				return false;
@@ -598,5 +629,68 @@
 			return MakeUIPlugin.getResourceString(SI_PROVIDER_CMD_ERROR_MESSAGE);
 		}
 		return null;
+	}
+
+	/**
+	 * A utility class to notify when .project file is changed
+	 * 
+	 * @author vhirsl
+	 */
+	public static abstract class ProjectManifestChangeNotification implements IResourceChangeListener {
+		private IProject fProject;
+
+		public ProjectManifestChangeNotification(IProject project) {
+			fProject = project;
+			// register for change events
+			ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+		}
+
+		/* (non-Javadoc)
+		 * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+		 */
+		public void resourceChanged(IResourceChangeEvent event) {
+			// look for unexpected changes of .project file (like in case of disabling the builder)
+			if (event.getSource() instanceof IWorkspace) {
+				IResourceDelta delta = event.getDelta();
+				IResource resource = event.getResource();
+
+				if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
+					try {
+						delta.accept(new IResourceDeltaVisitor() {
+							/* (non-Javadoc)
+							 * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+							 */
+							public boolean visit(IResourceDelta delta) throws CoreException {
+								IResource resource = delta.getResource();
+								if (resource instanceof IFile) {
+									if (resource.getName().equals(".project")) {//$NON-NLS-1$
+										// .project file changed
+										dotProjectFileChanged();
+									}
+								}
+								else if (resource instanceof IProject) {
+									if (resource == fProject) {
+										return true;
+									}
+								}
+								return resource.getType() == IResource.ROOT;
+							}
+						}, IResourceDelta.CHANGED);
+					} catch (CoreException e) {
+						MakeCorePlugin.log(e.getStatus());
+					}
+				}
+			}
+		}
+		
+		protected abstract void dotProjectFileChanged();
+		
+		/* (non-Javadoc)
+		 * @see java.lang.Object#finalize()
+		 */
+		protected void finalize() throws Throwable {
+			ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+			super.finalize();
+		}
 	}
 }
Index: src/org/eclipse/cdt/make/ui/dialogs/SettingsBlock.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/ui/dialogs/SettingsBlock.java,v
retrieving revision 1.13
diff -u -r1.13 SettingsBlock.java
--- src/org/eclipse/cdt/make/ui/dialogs/SettingsBlock.java	25 Jun 2004 14:49:37 -0000	1.13
+++ src/org/eclipse/cdt/make/ui/dialogs/SettingsBlock.java	30 Jul 2004 19:58:11 -0000
@@ -15,6 +15,7 @@
 import org.eclipse.cdt.make.core.MakeCorePlugin;
 import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
 import org.eclipse.cdt.make.ui.IMakeHelpContextIds;
+import org.eclipse.cdt.make.ui.dialogs.DiscoveryOptionsBlock.ProjectManifestChangeNotification;
 import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage;
 import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
 import org.eclipse.cdt.utils.ui.controls.ControlFactory;
@@ -100,6 +101,7 @@
 	IMakeBuilderInfo fBuildInfo;
 	Preferences fPrefs;
 	String fBuilderID;
+	ProjectManifestChangeNotification fNotification;
 
 	public SettingsBlock(Preferences prefs, String builderID) {
 		super(MakeUIPlugin.getResourceString(MAKE_LABEL));
@@ -349,6 +351,17 @@
 
 		if (getContainer().getProject() != null) {
 			createBuilderWorkingDirControls(composite);
+			
+			// recieve notifications when .project file is changed
+			fNotification = new ProjectManifestChangeNotification(getContainer().getProject()) {
+				protected void dotProjectFileChanged() {
+					try {
+						fBuildInfo = MakeCorePlugin.createBuildInfo(getContainer().getProject(), fBuilderID);
+					} catch (CoreException e) {
+						fBuildInfo = null;
+					}
+				}
+			};
 		}
 	}
 
@@ -363,6 +376,10 @@
 	}
 
 	public void performApply(IProgressMonitor monitor) throws CoreException {
+		// Missing builder info
+		if (fBuildInfo == null) {
+			return;
+		}
 		if (monitor == null) {
 			monitor = new NullProgressMonitor();
 		}
@@ -423,6 +440,10 @@
 	}
 
 	public void performDefaults() {
+		// Missing builder info
+		if (fBuildInfo == null) {
+			return;
+		}
 		IMakeBuilderInfo info;
 		if (getContainer().getProject() != null) {
 			info = MakeCorePlugin.createBuildInfo(fPrefs, fBuilderID, false);

Back to the top