author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 18 Mar 2010 11:56:59 -0700 | |
changeset 276 | f2f4a1259de8 |
parent 52 | f577ea64429e |
child 355 | 8726e95bcbba |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.core.model; |
|
6 |
||
7 |
import org.chromium.debug.core.util.ChromiumDebugPluginUtil; |
|
8 |
import org.eclipse.core.resources.IResource; |
|
9 |
import org.eclipse.core.runtime.CoreException; |
|
10 |
import org.eclipse.debug.core.DebugPlugin; |
|
11 |
import org.eclipse.debug.core.model.IBreakpoint; |
|
12 |
import org.eclipse.debug.core.model.ILineBreakpoint; |
|
13 |
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; |
|
14 |
import org.eclipse.jface.text.ITextSelection; |
|
15 |
import org.eclipse.jface.viewers.ISelection; |
|
16 |
import org.eclipse.ui.IWorkbenchPart; |
|
17 |
import org.eclipse.ui.texteditor.ITextEditor; |
|
18 |
||
19 |
/** |
|
20 |
* Adapter to create breakpoints in JS files. |
|
21 |
*/ |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
22 |
public abstract class LineBreakpointAdapter implements IToggleBreakpointsTarget { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
23 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
24 |
public static class ForVirtualProject extends LineBreakpointAdapter { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
25 |
@Override |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
26 |
protected ITextEditor getEditor(IWorkbenchPart part) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
27 |
if (part instanceof ITextEditor) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
28 |
ITextEditor editorPart = (ITextEditor) part; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
29 |
IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
30 |
if (resource != null && |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
31 |
ChromiumDebugPluginUtil.CHROMIUM_EXTENSION.equals(resource.getFileExtension())) { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
32 |
return editorPart; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
33 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
34 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
35 |
return null; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
36 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
37 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
38 |
@Override |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
39 |
protected String getDebugModelId() { |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
40 |
return VProjectWorkspaceBridge.DEBUG_MODEL_ID; |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
41 |
} |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
42 |
} |
2 | 43 |
|
44 |
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) |
|
45 |
throws CoreException { |
|
46 |
ITextEditor textEditor = getEditor(part); |
|
47 |
if (textEditor != null) { |
|
48 |
IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class); |
|
49 |
ITextSelection textSelection = (ITextSelection) selection; |
|
50 |
int lineNumber = textSelection.getStartLine(); |
|
51 |
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
52 |
getDebugModelId()); |
2 | 53 |
for (int i = 0; i < breakpoints.length; i++) { |
54 |
IBreakpoint breakpoint = breakpoints[i]; |
|
55 |
if (resource.equals(breakpoint.getMarker().getResource())) { |
|
56 |
if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber + 1) { |
|
57 |
// remove |
|
58 |
breakpoint.delete(); |
|
59 |
return; |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
// Line numbers start with 0 in V8, with 1 in Eclipse. |
|
65 |
ChromiumLineBreakpoint lineBreakpoint = new ChromiumLineBreakpoint(resource, lineNumber + 1); |
|
66 |
DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selection) { |
|
71 |
return getEditor(part) != null; |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Returns the editor being used to edit a PDA file, associated with the given |
|
76 |
* part, or <code>null</code> if none. |
|
77 |
* @param part workbench part |
|
78 |
* @return the editor being used to edit a PDA file, associated with the given |
|
79 |
* part, or <code>null</code> if none |
|
80 |
*/ |
|
52
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
81 |
protected abstract ITextEditor getEditor(IWorkbenchPart part); |
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
82 |
|
f577ea64429e
Migrated to unmodified Chromium Development Tools version
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
83 |
protected abstract String getDebugModelId(); |
2 | 84 |
|
85 |
public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) |
|
86 |
throws CoreException { |
|
87 |
// TODO(apavlov): Implement method breakpoints if feasible. |
|
88 |
} |
|
89 |
||
90 |
public boolean canToggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) { |
|
91 |
// TODO(apavlov): Implement method breakpoints if feasible. |
|
92 |
return true; |
|
93 |
} |
|
94 |
||
95 |
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection) |
|
96 |
throws CoreException { |
|
97 |
// TODO(apavlov): Implement watchpoints if feasible. |
|
98 |
} |
|
99 |
||
100 |
public boolean canToggleWatchpoints(IWorkbenchPart part, ISelection selection) { |
|
101 |
// TODO(apavlov): Implement watchpoints if feasible. |
|
102 |
return false; |
|
103 |
} |
|
104 |
} |