+ * If the {@link ICBreakpoint#SOURCE_HANDLE} resolves to the same file on
+ * the filesystem as the preferred resource the preferred resource is used.
+ *
+ * @param preferred
+ * resource to use if it matches the SOURCE_HANDLE
+ * @return Resource to install marker on, or null
for not
+ * available.
+ */
+ private IResource getResource(IResource preferred) {
+ IResource resolved = null;
+ String source = getString(ICBreakpoint.SOURCE_HANDLE);
+ if (!"".equals(source)) { //$NON-NLS-1$
+ IPath rawLocation = preferred.getRawLocation();
+ if (rawLocation != null) {
+ File file = rawLocation.toFile();
+ File sourceFile = new File(source);
+ if (file.getAbsoluteFile().equals(sourceFile.getAbsoluteFile())) {
+ resolved = preferred;
+ }
+ }
+
+ if (resolved == null) {
+ IPath path = Path.fromOSString(source);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IFile file = root.getFileForLocation(path);
+ if (file == null) {
+ resolved = root;
+ } else {
+ resolved = file;
+ }
+ }
+ }
+ if (resolved == null) {
+ resolved = preferred;
+ }
+ return resolved;
}
private void saveToExistingMarker(final ICBreakpoint breakpoint, final IMarker marker) throws IOException {
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
index 5b282c20817..245a165ed06 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2012 QNX Software Systems and others.
+ * Copyright (c) 2004, 2015 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
@@ -10,6 +10,7 @@
* Nokia - https://bugs.eclipse.org/bugs/show_bug.cgi?id=145606
* QNX Software Systems - Catchpoints support https://bugs.eclipse.org/bugs/show_bug.cgi?id=226689
* Scott Tepavich (WindRiver) - Fixed bad reference to messages.properties string (Bug 393178)
+ * Jonah Graham (Kichwa Coders) - Create "Add Line Breakpoint (C/C++)" action (Bug 464917)
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.breakpoints;
@@ -34,11 +35,15 @@ import org.eclipse.cdt.debug.ui.breakpoints.CBreakpointUIContributionFactory;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointContext;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointsUIContribution;
import org.eclipse.cdt.debug.ui.preferences.ReadOnlyFieldEditor;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugModelProvider;
@@ -54,18 +59,22 @@ import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
import org.eclipse.ui.model.IWorkbenchAdapter;
/**
@@ -196,6 +205,78 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
}
}
+ class BreakpointFileNameFieldEditor extends BreakpointStringFieldEditor {
+
+ private Composite composite;
+
+ public BreakpointFileNameFieldEditor(String name, String labelText, Composite parent) {
+ super(name, labelText, parent);
+ }
+
+ @Override
+ protected void adjustForNumColumns(int numColumns) {
+ super.adjustForNumColumns(numColumns);
+ ((GridData) composite.getLayoutData()).horizontalSpan = numColumns;
+ }
+
+ @Override
+ protected void doFillIntoGrid(Composite parent, int numColumns) {
+ super.doFillIntoGrid(parent, numColumns);
+
+ composite = new Composite(parent, SWT.NONE);
+ composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(getNumberOfControls(), 1).align(SWT.END, SWT.FILL).create());
+ composite.setLayout(new FillLayout());
+ Button browseWorkspace = new Button(composite, SWT.PUSH);
+ browseWorkspace.setText(BreakpointsMessages.getString("CBreakpointPropertyPage.workspace_button")); //$NON-NLS-1$
+ browseWorkspace.setFont(parent.getFont());
+ browseWorkspace.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent evt) {
+ FilteredResourcesSelectionDialog dialog = new FilteredResourcesSelectionDialog(getShell(), false, ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE);
+ String text = getTextControl().getText();
+ IPath path = Path.fromOSString(text);
+ String filename;
+ if (path.segmentCount() > 0) {
+ filename = path.segment(path.segmentCount() - 1);
+ } else {
+ filename = "*.c"; //$NON-NLS-1$
+ }
+ dialog.setInitialPattern(filename);
+ if (dialog.open() == Window.OK) {
+ Object[] result = dialog.getResult();
+ if (result.length == 0)
+ return;
+ if (result[0] instanceof IFile) {
+ IFile file = (IFile) result[0];
+ IPath location = file.getRawLocation();
+ if (location != null) {
+ String newValue = location.makeAbsolute().toOSString();
+ setStringValue(newValue);
+ }
+ }
+ }
+ }
+ });
+
+
+ Button browseFileSystem = new Button(composite, SWT.PUSH);
+ browseFileSystem.setText(BreakpointsMessages.getString("CBreakpointPropertyPage.file_system_button")); //$NON-NLS-1$
+ browseFileSystem.setFont(parent.getFont());
+ browseFileSystem.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent evt) {
+ FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET);
+ dialog.setFileName(getTextControl().getText());
+ String newValue = dialog.open();
+ if (newValue != null) {
+ setStringValue(newValue);
+ }
+ }
+ });
+ }
+
+ }
+
class WatchpointRangeFieldEditor extends IntegerFieldEditor {
private static final String DISABLED_VALUE = "0"; //$NON-NLS-1$
@@ -542,15 +623,7 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
}
else if ( breakpoint instanceof ILineBreakpoint ) {
- String fileName = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
- if ( fileName != null ) {
- addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.sourceHandle_label" ), fileName ) ); //$NON-NLS-1$
- }
- int lNumber = getPreferenceStore().getInt(IMarker.LINE_NUMBER);
- if (lNumber > 0) {
- getPreferenceStore().setValue( IMarker.LINE_NUMBER, lNumber);
- createLineNumberEditor(getFieldEditorParent());
- }
+ createFileLineNumberEditor(getFieldEditorParent());
}
else if ( breakpoint instanceof CEventBreakpoint ) {
createEventBreakpointEditor( breakpoint, ICBreakpointsUIContribution.BREAKPOINT_LABELS);
@@ -596,13 +669,44 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
function = BreakpointsMessages.getString( "CBreakpointPropertyPage.function_valueNotAvailable_label" ); //$NON-NLS-1$
}
addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.function_label" ), function ) ); //$NON-NLS-1$
- }
- }
+ }
+ }
+
+ protected void createFileLineNumberEditor( Composite parent ) {
+ String title = BreakpointsMessages.getString( "CBreakpointPropertyPage.sourceHandle_label" ); //$NON-NLS-1$
+ ICBreakpoint breakpoint = getBreakpoint();
+
+ boolean isNewBreakpoint = breakpoint == null || breakpoint.getMarker() == null;
+ String fileName = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
+ boolean isFilenameEditable = fileName != null && fileName.isEmpty();
+
+ if (isNewBreakpoint && isFilenameEditable) {
+ BreakpointFileNameFieldEditor fileNameEditor = new BreakpointFileNameFieldEditor(
+ ICLineBreakpoint.SOURCE_HANDLE, title, parent);
+ fileNameEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.fileName_errorMessage")); //$NON-NLS-1$
+ fileNameEditor.setEmptyStringAllowed(false);
+ addField(fileNameEditor);
+ } else {
+ if (fileName != null) {
+ addField(createLabelEditor(parent, title, fileName));
+ }
+ }
+
+ int lNumber = getPreferenceStore().getInt(IMarker.LINE_NUMBER);
+ if (lNumber > 0 || isNewBreakpoint) {
+ if (lNumber < 1) {
+ lNumber = 1;
+ }
+ getPreferenceStore().setValue(IMarker.LINE_NUMBER, lNumber);
+ createLineNumberEditor(parent);
+ }
+ }
protected void createLineNumberEditor( Composite parent ) {
String title = BreakpointsMessages.getString( "CBreakpointPropertyPage.lineNumber_label" ); //$NON-NLS-1$
BreakpointIntegerFieldEditor labelFieldEditor =new BreakpointIntegerFieldEditor( IMarker.LINE_NUMBER ,title, parent);
labelFieldEditor.setValidRange( 1, Integer.MAX_VALUE );
+ labelFieldEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.lineNumber_errorMessage")); //$NON-NLS-1$
addField( labelFieldEditor );
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java
index b87ef7854cd..fc97308fbfa 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 Mentor Graphics and others.
+ * Copyright (c) 2011, 2015 Mentor Graphics 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
@@ -9,6 +9,7 @@
* Mentor Graphics - Initial API and implementation
* Marc Khouzam (Ericsson) - Don't allow to set two bps at same line (bug 432503)
* Teodor Madan (Freescale) - Do not create multiple watchpoints /method breakpoints at same location ( 445375 )
+ * Jonah Graham (Kichwa Coders) - Create "Add Line Breakpoint (C/C++)" action (Bug 464917)
*******************************************************************************/
package org.eclipse.cdt.debug.ui.breakpoints;
@@ -364,6 +365,9 @@ abstract public class AbstractToggleBreakpointAdapter
}
}
}
+ } else if (interactive && !toggle) {
+ createLineBreakpoint(true, part, null, ResourcesPlugin.getWorkspace().getRoot(), -1);
+ return;
} else {
errorMessage = ActionMessages.getString("RunToLineAdapter.Operation_is_not_supported_1"); //$NON-NLS-1$
}