在我的自定义插件中,我在新向导上创建了一些文件夹,并在项目首选项中添加了这些创建文件夹的路径。现在,在删除文件夹时,我需要从商店中删除该路径。为此,我延长了org.eclipse.ltk.core.refactoring.deleteParticipants
分机。我还创建了一个扩展Change
类的类,并在我写的下面的perform方法中,从首选项中删除键值。
public Change perform(IProgressMonitor pm) throws CoreException {
System.out.println("called");
IPath deletedFolderPath = deletedFolder.getProjectRelativePath().makeAbsolute();
IResource[] roots = {deletedFolder.getProject()};
String[] fileSearchPatterns = {"*.properties", "*.prefs"};
FileTextSearchScope searchScope = FileTextSearchScope.newSearchScope(roots, fileSearchPatterns, false);
String regex = deletedFolderPath.addTrailingSeparator().toString();
Pattern searchPattern = Pattern.compile(regex);
TextSearchRequestor requestor = new TextSearchRequestor() {
public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException {
IFile matchedFile = matchAccess.getFile();
if("prefs".equals(matchedFile.getFileExtension())){
String prefKey = "";
try {
prefKey = ProjectPreferences.getKeyForValue(regex, deletedFolder.getProject());
ProjectPreferences.removeKeyFromStore(prefKey, deletedFolder.getProject());
System.out.println("after");
}
catch (BackingStoreException e) {
throw new CoreException(null);
}
}
else if(".properties".equals(matchedFile.getFileExtension())) {
}
return true;
}
};
TextSearchEngine.create().search(searchScope, requestor, searchPattern, pm);
return null;
}
但是在删除向导上按“确定”后它会卡在线上。
ProjectPreferences.removeKeyFromStore(prefKey, deletedFolder.getProject())
或更具体地说,用removeKeyFromStore
方法
public static void removeKeyFromStore(String key, IProject project) throws BackingStoreException {
IEclipsePreferences projPref = getPreferences(project);
projPref.remove(key);
projPref.flush();
}
我在这里做错了什么或者其他更好的方法来实现相同的功能。
谢谢!