下面列出了怎么用org.eclipse.ui.internal.EditorHistory的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 当删除一个文件时,刷新历史记录 --robert 2012-11-20
*/
@SuppressWarnings("restriction")
public static void refreshHistoryWhenDelete(IEditorInput input){
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench instanceof Workbench) {
EditorHistory history = ((Workbench) workbench).getEditorHistory();
for (EditorHistoryItem item : history.getItems()) {
if (item.matches(input)) {
history.remove(item);
}
}
history.refresh();
}
}
/**
* 当删除一个文件时,刷新历史记录 --robert 2012-11-20
*/
@SuppressWarnings("restriction")
public static void refreshHistoryWhenDelete(IEditorInput input){
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench instanceof Workbench) {
EditorHistory history = ((Workbench) workbench).getEditorHistory();
for (EditorHistoryItem item : history.getItems()) {
if (item.matches(input)) {
history.remove(item);
}
}
history.refresh();
}
}
@Override
public void createContent(Document dom, Element parent) {
if (!RepositoryManager.getInstance().hasActiveRepository()
|| !RepositoryManager.getInstance().getCurrentRepository().isLoaded()) {
return;
}
Element ul = dom.createElement("ul");
parent.appendChild(ul);
EditorHistory history = ((Workbench) PlatformUI.getWorkbench()).getEditorHistory();
EditorHistoryItem[] historyItems = history.getItems();
int maxElem = MAX_HISTORY_SIZE;
for (int i = 0; i < historyItems.length; i++) {
if (maxElem == 0)
break;
final EditorHistoryItem item = historyItems[i];
if (item.isRestored() || item.restoreState().isOK()) {
IEditorInput input = item.getInput();
if(input == null) {
break;
}
IResource resource = input.getAdapter(IResource.class);
if (resource != null && resource.isAccessible()) {
Element li = dom.createElement("li");
Element a = dom.createElement("a");
a.setAttribute("class", "hover:text-red-600");
a.setAttribute("title", item.getToolTipText());
try {
a.setAttribute("href",
String.format("http://org.eclipse.ui.intro/runAction?pluginId=%s&class=%s&file=%s",
Activator.PLUGIN_ID,
OpenEditorFromHistoryItemAction.class.getName(),
URLEncoder.encode(item.getName(), "UTF-8")));
} catch (DOMException | UnsupportedEncodingException e) {
BonitaStudioLog.error(e);
}
a.setTextContent(item.getName());
li.appendChild(a);
maxElem--;
ul.appendChild(li);
}
}
}
}
private Optional<EditorHistoryItem> findItem(EditorHistory history, int n, String itemName) {
return Stream.of(history.getItems())
.limit(n)
.filter(item -> Objects.equals(item.getName(), itemName))
.findFirst();
}