Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c63e927156c0bc0f145388556e92902b05d94d64 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2007-2012 Wind River Systems, Inc. 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:
 *     Ted R Williams (Wind River Systems, Inc.) - initial implementation
 *******************************************************************************/

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

import java.util.Properties;

import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
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.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;

public class FindAction implements IViewActionDelegate {

	private static String FIND_NEXT_ID = "org.eclipse.cdt.debug.ui.memory.search.FindNextAction"; //$NON-NLS-1$

	private IMemoryRenderingSite fView;

	private static Properties fSearchDialogProperties = new Properties();

	public static Properties getProperties() {
		return fSearchDialogProperties;
	}

	@Override
	public void init(IViewPart view) {
		if (view instanceof IMemoryRenderingSite)
			fView = (IMemoryRenderingSite) view;
	}

	@Override
	public void run(IAction action) {
		ISelection selection = fView.getSite().getSelectionProvider().getSelection();

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

			// return if current selection is empty
			if (strucSel.isEmpty())
				return;

			Object obj = strucSel.getFirstElement();

			if (obj == null)
				return;

			IMemoryBlock memBlock = null;

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

			Shell shell = CDebugUIPlugin.getActiveWorkbenchShell();
			FindReplaceDialog dialog = new FindReplaceDialog(shell, (IMemoryBlockExtension) memBlock, fView,
					fSearchDialogProperties, fAction);
			if (action.getId().equals(FIND_NEXT_ID)) {
				if (Boolean.valueOf(fSearchDialogProperties.getProperty(FindReplaceDialog.SEARCH_ENABLE_FIND_NEXT,
						Boolean.FALSE.toString()))) {
					dialog.performFindNext();
				}
				return;
			} else {
				dialog.open();

				// TODO: finish feature?
				//Object results[] = dialog.getResult();
			}
		}

	}

	private static IAction fAction = null;

	@Override
	public void selectionChanged(IAction action, ISelection selection) {

		if (action.getId().equals(FIND_NEXT_ID)) {
			fAction = action;
			action.setEnabled(Boolean.valueOf(fSearchDialogProperties
					.getProperty(FindReplaceDialog.SEARCH_ENABLE_FIND_NEXT, Boolean.FALSE.toString())));
		}
	}

}

Back to the top