-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickOpenFile.java
More file actions
127 lines (108 loc) · 3.59 KB
/
Copy pathQuickOpenFile.java
File metadata and controls
127 lines (108 loc) · 3.59 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import com.intellij.ide.actions.OpenFileAction;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.tree.TreeModel;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class QuickOpenFile extends AnAction {
String userHome = System.getProperty("user.home"); //user home
String quickFindFilePath = userHome + "/IDEAConfig/quickFind.txt";
String filePrefixPath = userHome + "/IDEAConfig/filePrefix.txt";
ArrayList<String> pageList = new ArrayList();
String filePrefix = ""; // file prefix path
// read the config
private void readConfig(Project p){
pageList.clear();
readFileByLines(quickFindFilePath, p);
readFilePrefix(filePrefixPath, p);
}
/**
* @Description: add all file shortcut to list
* @Param line
* @Param p idea project (for debug )
* @Return: void
* @Exception:
* @author: alf
* @date: 2021/2/19
*/
private void addToList(String line, Project p ) {
this.pageList.add(line);
}
public void readFileByLines(String fileName, Project p ) {
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String line = null;
// read oneline per iteration
while ((line = reader.readLine()) != null) {
// if not empty and not comment starts with '#'
if( !line.trim().isEmpty() && !line.startsWith("#")) {
this.addToList(line,p);
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
/**
* @Description: read file prefix path
* @Param fileName the file which stores the configration
* @Param p the project
* @Return: void
* @Exception:
* @author: alf
* @date: 2021/2/19
*/
public void readFilePrefix(String fileName, Project p ) {
File file = new File(fileName);
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
filePrefix = reader.readLine().trim();
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
/***
* @Description: display file shortcut menu when enter the key
* @Param e
* @Return: void
* @Exception:
* @author: aplaceof
* @date: 2021/2/19
*/
@Override
public void actionPerformed(AnActionEvent e) {
Project p = e.getData(PlatformDataKeys.PROJECT);
this.readConfig(p); // load plugins config first
// String title = "" + pageList.size();
// Messages.showMessageDialog(p, title, title, Messages.getInformationIcon());
QuickOpenForm tf = new QuickOpenForm(pageList, p, filePrefix);
tf.setTableData();
}
}