Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Allow editing a Make View tag (core patch)

This core patch updates the MakeUtil.java class which is responsible for
maintaining the
mapping between make targets/tags and the resources on which they are being
applied.
The update adds a new method so that you can do an inline replacement of a
given
target tag with another target tag, principally to support editing in the
UI.

Incidentally,  just like realloc can be both a malloc and a free, so can the
replacement
method.   See the JavaDoc on the method for further details.

For the ChangeLog:
- Update the core MakeUtil class with a method to support inline replacement
of a
   make target with a different make target.


Index: src/org/eclipse/cdt/core/resources/MakeUtil.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/MakeUtil.java,v
retrieving revision 1.2
diff -u -r1.2 MakeUtil.java
--- src/org/eclipse/cdt/core/resources/MakeUtil.java	21 Apr 2003 17:08:55 -0000	1.2
+++ src/org/eclipse/cdt/core/resources/MakeUtil.java	8 Jul 2003 13:19:37 -0000
@@ -141,6 +141,36 @@
 		MakeUtil.setPersistentTargets (resource, newTargets);
     }
 
+	/**
+	 * Replace a tag on a resource. Functionally equivalent to
+	 *  removePersistantTag(resource, oldtarget)
+	 *  addPersistantTag(resource, newtarget)
+	 * If the oldtarget doesn't exist, the newtarget is added. 
+	 * If the newtarget is null, the oldtarget is removed.
+	 * @param resource The resource the tag applies to
+	 * @param oldtarget The oldtarget tag
+	 * @param newtarget The newtarget tag to replace the old target tag or null. If
+	 * newtarget is null then this call is the same as removePersistantTarget(resource, oldtarget)
+	 */
+	public static void replacePersistentTarget (IResource resource, String oldtarget, String newtarget) {
+		if(newtarget == null) {
+			removePersistentTarget(resource, oldtarget);
+			return;
+		}
+		
+		String[] targets = MakeUtil.getPersistentTargets (resource);
+		for (int i = 0; i < targets.length; i++) {
+			if (targets[i].equals (oldtarget)) {
+				targets[i] = newtarget;
+				MakeUtil.setPersistentTargets (resource, targets);
+				return;
+			}
+		}
+		
+		//The target wasn't found, create a new one
+		addPersistentTarget(resource, newtarget);
+	}
+
     private MakeUtil() {
     }
 

Back to the top