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

Collapse All | Expand All

(-)src/org/eclipse/core/commands/operations/TriggeredOperations.java (-1 / +40 lines)
Lines 37-43 Link Here
37
 * @since 3.1
37
 * @since 3.1
38
 */
38
 */
39
public final class TriggeredOperations extends AbstractOperation implements
39
public final class TriggeredOperations extends AbstractOperation implements
40
		ICompositeOperation, IAdvancedUndoableOperation {
40
		ICompositeOperation, IAdvancedUndoableOperation, IContextReplacingOperation {
41
41
42
	private IUndoableOperation triggeringOperation;
42
	private IUndoableOperation triggeringOperation;
43
43
Lines 374-378 Link Here
374
		return Status.OK_STATUS;
374
		return Status.OK_STATUS;
375
375
376
	}
376
	}
377
	
378
	/**
379
	 * Replace the undo context of the receiver with the provided replacement
380
	 * undo context.  In the case of triggered operations, all contained operations
381
	 * are checked and any occurrence of the original context is replaced with the
382
	 * new undo context.
383
	 * <p>
384
	 * This message has no effect if the original undo context is not present in
385
	 * the receiver.
386
	 * 
387
	 * @param original the undo context which is to be replaced
388
	 * @param replacement the undo context which is replacing the original
389
	 * 
390
	 */
391
	public void replaceContext(IUndoContext original, IUndoContext replacement) {
392
		
393
		// first check the triggering operation
394
		if (triggeringOperation != null && triggeringOperation.hasContext(original)) {
395
			if (triggeringOperation instanceof IContextReplacingOperation) {
396
				((IContextReplacingOperation)triggeringOperation).replaceContext(original, replacement);
397
			} else {
398
				triggeringOperation.removeContext(original);
399
				triggeringOperation.addContext(replacement);
400
			}
401
		}
402
		// Now check all the children
403
		for (int i = 0; i < children.size(); i++) {
404
			IUndoableOperation child = (IUndoableOperation) children.get(i);
405
			if (child.hasContext(original)) {
406
				if (child instanceof IContextReplacingOperation) {
407
					((IContextReplacingOperation)child).replaceContext(original, replacement);
408
				} else {
409
					child.removeContext(original);
410
					child.addContext(replacement);
411
				}
412
			}
413
		}		
414
		recomputeContexts();
415
	}
377
416
378
}
417
}
(-)src/org/eclipse/core/commands/operations/IContextReplacingOperation.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.commands.operations;
12
13
/**
14
 * IContextReplacingOperation defines an interface for undoable operations that
15
 * can replace one undo context with another undo context. It is used by
16
 * operations, such as composite operations, where removing and adding an undo
17
 * context would not have the same semantic as replacing one undo context with
18
 * another.
19
 * 
20
 * @since 3.2
21
 * 
22
 */
23
public interface IContextReplacingOperation {
24
25
	/**
26
	 * Replace the undo context of the receiver with the provided replacement
27
	 * undo context.
28
	 * <p>
29
	 * This message has no effect if the original undo context is not present in
30
	 * the receiver.
31
	 * 
32
	 * @param original the undo context which is to be replaced
33
	 * @param replacement the undo context which is replacing the original
34
	 * 
35
	 */
36
	void replaceContext(IUndoContext original, IUndoContext replacement);
37
}

Return to bug 93955