blob: bf14de3b5c40f69da2c413a6f1b47b9c55c4ba70 (
plain)
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
105
106
107
108
109
110
111
112
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.ddms.views;
import com.android.ddmuilib.logcat.ILogCatMessageSelectionListener;
import com.android.ddmuilib.logcat.LogCatMessage;
import com.android.ddmuilib.logcat.LogCatPanel;
import com.android.ddmuilib.logcat.LogCatStackTraceParser;
import com.android.ide.eclipse.ddms.DdmsPlugin;
import com.android.ide.eclipse.ddms.JavaSourceRevealer;
import com.android.ide.eclipse.ddms.i18n.Messages;
import com.android.ide.eclipse.ddms.preferences.PreferenceInitializer;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionFactory;
public class LogCatView extends SelectionDependentViewPart {
/** LogCatView ID as defined in plugin.xml. */
public static final String ID = "com.android.ide.eclipse.ddms.views.LogCatView"; //$NON-NLS-1$
/** Switch perspective when a Java file is opened from logcat view. */
public static final boolean DEFAULT_SWITCH_PERSPECTIVE = true;
/** Target perspective to open when a Java file is opened from logcat view. */
public static final String DEFAULT_PERSPECTIVE_ID =
"org.eclipse.jdt.ui.JavaPerspective"; //$NON-NLS-1$
private LogCatPanel mLogCatPanel;
private LogCatStackTraceParser mStackTraceParser = new LogCatStackTraceParser();
private Clipboard mClipboard;
@Override
public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
IPreferenceStore prefStore = DdmsPlugin.getDefault().getPreferenceStore();
mLogCatPanel = new LogCatPanel(prefStore);
mLogCatPanel.createPanel(parent);
setSelectionDependentPanel(mLogCatPanel);
mLogCatPanel.addLogCatMessageSelectionListener(new ILogCatMessageSelectionListener() {
@Override
public void messageDoubleClicked(LogCatMessage m) {
onDoubleClick(m);
}
});
mClipboard = new Clipboard(parent.getDisplay());
IActionBars actionBars = getViewSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
new Action(Messages.LogCatView_Copy) {
@Override
public void run() {
mLogCatPanel.copySelectionToClipboard(mClipboard);
}
});
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
new Action(Messages.LogCatView_Select_All) {
@Override
public void run() {
mLogCatPanel.selectAll();
}
});
}
@Override
public void setFocus() {
}
private void onDoubleClick(LogCatMessage m) {
String msg = m.getMessage();
if (!mStackTraceParser.isValidExceptionTrace(msg)) {
return;
}
IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
String perspectiveId = null;
if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
}
String fileName = mStackTraceParser.getFileName(msg);
int lineNumber = mStackTraceParser.getLineNumber(msg);
String methodName = mStackTraceParser.getMethodName(msg);
JavaSourceRevealer.revealMethod(methodName, fileName, lineNumber, perspectiveId);
}
public void selectTransientAppFilter(String appName) {
mLogCatPanel.selectTransientAppFilter(appName);
}
}
|