-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCscopeFinderPlugin.java
More file actions
113 lines (90 loc) · 3.29 KB
/
Copy pathCscopeFinderPlugin.java
File metadata and controls
113 lines (90 loc) · 3.29 KB
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
113
package cscopefinder;
import org.gjt.sp.jedit.EditPlugin;
import org.gjt.sp.jedit.View;
import org.gjt.sp.util.Log;
import cscopefinder.helpers.ProjectHelper;
import cscopefinder.commands.UpdateDbCommand;
import cscopefinder.commands.GenerateFileListCommand;
import projectviewer.vpt.VPTProject;
import static cscopefinder.commands.QueryCommand.FIND_SYMBOL;
import static cscopefinder.commands.QueryCommand.FIND_DEF;
import static cscopefinder.commands.QueryCommand.FIND_CALLING;
import static cscopefinder.commands.QueryCommand.FIND_CALLED_BY;
import static cscopefinder.commands.QueryCommand.FIND_INCLUDE;
import static cscopefinder.commands.QueryCommand.createCommand;
public class CscopeFinderPlugin extends EditPlugin
{
static private CscopeRunner runner;
static private ProjectHelper projHelper;
public void start() {
Log.log(Log.DEBUG, CscopeFinderPlugin.class, "Starting...");
runner = new CscopeRunner();
projHelper = new ProjectHelper();
projHelper.startWatcher();
}
public void stop() {
runner = null;
projHelper.stopWatcher();
projHelper = null;
Log.log(Log.DEBUG, CscopeFinderPlugin.class, "Stopped.");
}
public static void findSymbol(View view) {
runQuery(view, FIND_SYMBOL);
}
public static void findCalling(View view) {
runQuery(view, FIND_CALLING);
}
public static void findDefinition(View view, boolean preview) {
runQuery(view, FIND_DEF, preview);
}
public static void findIncludedBy(View view) {
runQuery(view, FIND_INCLUDE);
}
public static void findCalledBy(View view) {
runQuery(view, FIND_CALLED_BY);
}
public static void generateDb(final View view) {
Runnable runAfter = new Runnable() {
public void run() {
updateDb(view);
}
};
runner.runCommand(new GenerateFileListCommand(view, runAfter), view);
}
public static void generateDb(final View view, final VPTProject prj) {
Runnable runAfter = new Runnable() {
public void run() {
updateDb(view);
}
};
runner.runCommand(new GenerateFileListCommand(prj, view, runAfter), view);
}
public static void updateDb(View view) {
runner.runCommand(view, new UpdateDbCommand());
}
public static void abortCurrentCommand(View view) {
runner.abortCurrentCommand();
}
private static void runQuery(View view, int type) {
runQuery(view, type, false);
}
private static void runQuery(View view, int type, boolean preview) {
String query = getQuery(view);
if (query == null || query.isEmpty()) {
Log.log(Log.WARNING, CscopeFinderPlugin.class, "Query was empty, doing nothing");
}
runner.runCommand(view, createCommand(type, query, preview));
}
private static String getQuery(View view) {
String query = view.getTextArea().getSelectedText();
if (query == null || query.isEmpty()) {
view.getTextArea().selectWord();
query = view.getTextArea().getSelectedText();
view.getTextArea().selectNone();
}
query = query.trim();
if (query.contains(" "))
query = '"' + query + '"';
return query;
}
}