Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJames Blackburn2010-03-22 10:37:18 +0000
committerJames Blackburn2010-03-22 10:37:18 +0000
commit617f0c7802b375343f574ed2a2ff70081f92626a (patch)
treede721c7dad42d60c1358b8badcb09f798f641720 /core
parent03cbd47472b2e9e639325d25b5dd3456d662a59a (diff)
downloadorg.eclipse.cdt-617f0c7802b375343f574ed2a2ff70081f92626a.tar.gz
org.eclipse.cdt-617f0c7802b375343f574ed2a2ff70081f92626a.tar.xz
org.eclipse.cdt-617f0c7802b375343f574ed2a2ff70081f92626a.zip
Bug 170590 - CDTBuildAction: save before build preference should cause dirty editors in referenced projects to be saved.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/BuildGroup.java78
1 files changed, 76 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/BuildGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/BuildGroup.java
index af5e1eca330..6b1639937cd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/BuildGroup.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/BuildGroup.java
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
@@ -25,9 +31,14 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.BuildAction;
import org.eclipse.ui.ide.IDEActionFactory;
+import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.cdt.core.CCorePlugin;
@@ -38,7 +49,12 @@ public class BuildGroup extends CViewActionGroup {
/**
* An internal class which overrides the 'shouldPerformResourcePruning'
- * method so that referenced projects aren't build twice
+ * method so that referenced projects aren't build twice . (The CDT
+ * managedbuild builds CDT reference project configuration as part of
+ * building the top-level project).
+ *
+ * Also ensure that files in referenced projects are saved automatically
+ * before build.
*/
public static class CDTBuildAction extends BuildAction {
public CDTBuildAction(IShellProvider shell, int kind) {
@@ -47,12 +63,70 @@ public class BuildGroup extends CViewActionGroup {
@Override
protected boolean shouldPerformResourcePruning() {
// If the selected resources aren't new-style CDT projects, then
- // fall-back to parent behaviour
+ // fall-back to parent behaviour.
+ // For CDT projects, we only want 'build' to be called on the top-level
+ // selected project(s)
for (Object res : getSelectedResources())
if (!(res instanceof IProject) || !CCorePlugin.getDefault().isNewStyleProject((IProject)res))
return super.shouldPerformResourcePruning();
return false;
}
+ @Override
+ @SuppressWarnings("unchecked")
+ public void run() {
+ // Ensure we correctly save files in all referenced projects before build
+ Set<IProject> prjs = new HashSet<IProject>();
+ for (IResource resource : (List<IResource>)getSelectedResources()) {
+ IProject project = resource.getProject();
+ if (project != null) {
+ prjs.add(project);
+ try {
+ prjs.addAll(Arrays.asList(project.getReferencedProjects()));
+ } catch (CoreException e) {
+ // Project not accessible or not open
+ }
+ }
+ }
+ saveEditors(prjs);
+
+ // Now delegate to the parent
+ super.run();
+ }
+
+ /**
+ * Taken from inaccessible o.e.ui.ide.BuildUtilities.java
+ *
+ * Causes all editors to save any modified resources in the provided collection
+ * of projects depending on the user's preference.
+ * @param projects The projects in which to save editors, or <code>null</code>
+ * to save editors in all projects.
+ */
+ private static void saveEditors(Collection<IProject> projects) {
+ if (!BuildAction.isSaveAllSet()) {
+ return;
+ }
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (int i = 0; i < windows.length; i++) {
+ IWorkbenchPage[] pages = windows[i].getPages();
+ for (int j = 0; j < pages.length; j++) {
+ IWorkbenchPage page = pages[j];
+ if (projects == null) {
+ page.saveAllEditors(false);
+ } else {
+ IEditorPart[] editors = page.getDirtyEditors();
+ for (int k = 0; k < editors.length; k++) {
+ IEditorPart editor = editors[k];
+ IFile inputFile = ResourceUtil.getFile(editor.getEditorInput());
+ if (inputFile != null) {
+ if (projects.contains(inputFile.getProject())) {
+ page.saveEditor(editor, false);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
private static class RebuildAction extends CDTBuildAction {

Back to the top