Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f4b2e59a9bd71228f58d852e32948b61d6a5dda0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*******************************************************************************
 * Copyright (c) 2010, 2012 Wind River Systems and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.debug.ui.memory.search;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

public class FindReplaceHandler extends AbstractHandler implements IHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
		if (part instanceof IMemoryRenderingSite) {
			IMemoryRenderingSite fView = (IMemoryRenderingSite) part;
			ISelection selection = fView.getSite().getSelectionProvider().getSelection();

			if (selection instanceof IStructuredSelection) {
				IStructuredSelection strucSel = (IStructuredSelection) selection;

				if (!strucSel.isEmpty()) {
					IMemoryBlock memBlock = null;
					Object obj = strucSel.getFirstElement();

					if (obj instanceof IMemoryRendering) {
						memBlock = ((IMemoryRendering) obj).getMemoryBlock();
					} else if (obj instanceof IMemoryBlock) {
						memBlock = (IMemoryBlock) obj;
					}

					if (memBlock instanceof IMemoryBlockExtension) {
						FindReplaceDialog dialog = new FindReplaceDialog(
								PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
								(IMemoryBlockExtension) memBlock, fView, FindAction.getProperties(), null);
						dialog.open();
					}
				}
			}
		}

		return null;
	}
}

Back to the top