Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2961fc1d20154a94ce975e518a823058f7f83ecd (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
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.cdt.ui.breakpoints;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.handlers.HandlerUtil;

/**
 * Presents a custom properties dialog to configure the attibutes of a C/C++ breakpoint.
 */
public class BreakpointScopeCategoryPropertiesHandler extends AbstractHandler {

    /**
     * Constructor for CBreakpointPropertiesAction.
     */
    public BreakpointScopeCategoryPropertiesHandler() {
        super();
    }

    public Object execute(ExecutionEvent event) throws ExecutionException {
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        final BreakpointScopeCategory category = getScopeCategory(event.getApplicationContext());

        if (part != null && category != null) {
            PreferenceDialog dlg = PreferencesUtil.createPropertyDialogOn(part.getSite().getShell(), category, null, null, null);
            if (dlg != null) {
                dlg.open();
            }
        }

        return null;
    }

    @Override
    public void setEnabled(Object evaluationContext) {
        setBaseEnabled( getScopeCategory(evaluationContext) != null );
    }

    private BreakpointScopeCategory getScopeCategory(Object evaluationContext) {
        if (evaluationContext instanceof IEvaluationContext) {
            Object s = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
            if (s instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection)s;
                if (ss.size() == 1 && ss.getFirstElement() instanceof IBreakpointContainer) {
                    IAdaptable category = ((IBreakpointContainer)ss.getFirstElement()).getCategory();
                    if (category instanceof BreakpointScopeCategory) {
                        return (BreakpointScopeCategory)category;
                    }
                }
            }
        }
        return null;
    }
}

Back to the top