1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Bug 183291. ToggleBreakpointRulerAction should use the IToggleBreakpointTarget adapter based on editor file.

This commit is contained in:
Ken Ryall 2007-04-25 15:21:36 +00:00
parent 6405b3a368
commit 07564ddb49
4 changed files with 107 additions and 13 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 QNX Software Systems and others.
* Copyright (c) 2004, 2007 QNX Software Systems 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
@ -7,16 +7,21 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 183291
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
import org.eclipse.ui.part.IContributedContentsView;
/**
* The delegate of the "Toggle Function Breakpoint" action.
@ -71,8 +76,35 @@ public class ManageFunctionBreakpointActionDelegate extends ActionDelegate imple
return fSelection;
}
private ToggleBreakpointAdapter getBreakpointAdapter() {
return fBreakpointAdapter;
private IToggleBreakpointsTarget getBreakpointAdapter() {
IToggleBreakpointsTarget targetAdapter = null;
if (fTargetPart != null) {
IResource resource = (IResource) fTargetPart.getAdapter(IResource.class);
if (resource == null && fTargetPart instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class);
}
if (resource == null) {
// in case of outline view
IContributedContentsView contentsView = (IContributedContentsView) fTargetPart.getAdapter(IContributedContentsView.class);
if (contentsView != null) {
IWorkbenchPart contributingPart = contentsView.getContributingPart();
resource = (IResource) contributingPart.getAdapter(IResource.class);
if (resource == null && contributingPart instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)contributingPart).getEditorInput().getAdapter(IResource.class);
}
}
}
if (resource != null) {
targetAdapter = (IToggleBreakpointsTarget)resource.getAdapter(IToggleBreakpointsTarget.class);
}
if (targetAdapter == null) {
targetAdapter = (IToggleBreakpointsTarget)fTargetPart.getAdapter(IToggleBreakpointsTarget.class);
}
}
if (targetAdapter == null) {
targetAdapter = fBreakpointAdapter;
}
return targetAdapter;
}
private void setSelection( ISelection selection ) {

View file

@ -1,15 +1,17 @@
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* Copyright (c) 2000, 2007 IBM Corporation 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:
* IBM Corporation - initial API and implementation
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 183291
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
@ -19,6 +21,7 @@ import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWorkbenchPart;
@ -132,7 +135,16 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
*/
public void partActivated(IWorkbenchPart part) {
fActivePart = part;
fTargetAdapter = getAdapter(part);
IResource resource = (IResource) part.getAdapter(IResource.class);
if (resource == null && part instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)part).getEditorInput().getAdapter(IResource.class);
}
if (resource != null) {
fTargetAdapter = getAdapter(resource);
}
if (fTargetAdapter == null) {
fTargetAdapter = getAdapter(part);
}
update();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 QNX Software Systems and others.
* Copyright (c) 2004, 2007 QNX Software Systems 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
@ -7,14 +7,17 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 183291
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds;
import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.text.BadLocationException;
@ -23,6 +26,7 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
@ -38,7 +42,7 @@ public class ToggleBreakpointRulerAction extends Action {
private IVerticalRulerInfo fRuler;
private IWorkbenchPart fTargetPart;
private ToggleBreakpointAdapter fBreakpointAdapter;
private IToggleBreakpointsTarget fTargetAdapter;
private static final ISelection EMPTY_SELECTION = new EmptySelection();
/**
@ -51,7 +55,6 @@ public class ToggleBreakpointRulerAction extends Action {
super( ActionMessages.getString( "ToggleBreakpointRulerAction.Toggle_Breakpoint_1" ) ); //$NON-NLS-1$
fRuler = ruler;
setTargetPart( part );
fBreakpointAdapter = new ToggleBreakpointAdapter();
part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.TOGGLE_BREAKPOINT_ACTION );
setId( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT );
}
@ -69,7 +72,7 @@ public class ToggleBreakpointRulerAction extends Action {
*/
public void run() {
try {
fBreakpointAdapter.toggleLineBreakpoints( getTargetPart(), getTargetSelection() );
fTargetAdapter.toggleLineBreakpoints( getTargetPart(), getTargetSelection() );
}
catch( CoreException e ) {
ErrorDialog.openError( getTargetPart().getSite().getShell(),
@ -94,6 +97,21 @@ public class ToggleBreakpointRulerAction extends Action {
private void setTargetPart( IWorkbenchPart targetPart ) {
this.fTargetPart = targetPart;
if (fTargetPart != null) {
IResource resource = (IResource) fTargetPart.getAdapter(IResource.class);
if (resource == null && fTargetPart instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class);
}
if (resource != null) {
fTargetAdapter = (IToggleBreakpointsTarget)resource.getAdapter(IToggleBreakpointsTarget.class);
}
if (fTargetAdapter == null) {
fTargetAdapter = (IToggleBreakpointsTarget)fTargetPart.getAdapter(IToggleBreakpointsTarget.class);
}
}
if (fTargetAdapter == null) {
fTargetAdapter = new ToggleBreakpointAdapter();
}
}
/**

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 QNX Software Systems and others.
* Copyright (c) 2004, 2007 QNX Software Systems 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
@ -7,16 +7,21 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 183291
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
import org.eclipse.ui.part.IContributedContentsView;
/**
* The delegate of the "Toggle Watchpoint" action.
@ -74,8 +79,35 @@ public class ToggleWatchpointActionDelegate extends ActionDelegate implements IO
return fSelection;
}
private ToggleBreakpointAdapter getBreakpointAdapter() {
return fBreakpointAdapter;
private IToggleBreakpointsTarget getBreakpointAdapter() {
IToggleBreakpointsTarget targetAdapter = null;
if (fTargetPart != null) {
IResource resource = (IResource) fTargetPart.getAdapter(IResource.class);
if (resource == null && fTargetPart instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class);
}
if (resource == null) {
// in case of outline view
IContributedContentsView contentsView = (IContributedContentsView) fTargetPart.getAdapter(IContributedContentsView.class);
if (contentsView != null) {
IWorkbenchPart contributingPart = contentsView.getContributingPart();
resource = (IResource) contributingPart.getAdapter(IResource.class);
if (resource == null && contributingPart instanceof IEditorPart) {
resource = (IResource) ((IEditorPart)contributingPart).getEditorInput().getAdapter(IResource.class);
}
}
}
if (resource != null) {
targetAdapter = (IToggleBreakpointsTarget)resource.getAdapter(IToggleBreakpointsTarget.class);
}
if (targetAdapter == null) {
targetAdapter = (IToggleBreakpointsTarget)fTargetPart.getAdapter(IToggleBreakpointsTarget.class);
}
}
if (targetAdapter == null) {
targetAdapter = fBreakpointAdapter;
}
return targetAdapter;
}
private void setSelection( ISelection selection ) {