我正在 Eclipse 中編寫一個自定義編輯器,并且只是集成了自定義錯誤識別?,F(xiàn)在我面臨一個奇怪的問題:我可以將標(biāo)記添加到我的編輯器中,這些標(biāo)記可以很好地顯示,我也可以在編輯器運行時刪除它們。什么不起作用:當(dāng)我關(guān)閉我的編輯器時,我希望標(biāo)記消失/被刪除。我現(xiàn)在正在做的是使用像這樣設(shè)置的瞬態(tài)屬性創(chuàng)建標(biāo)記:marker.setAttribute(IMarker.TRANSIENT, true);但這似乎并沒有改變?nèi)魏螙|西。試圖通過源查看器 annotation-model刪除所有注釋。這不起作用,因為當(dāng)我嘗試掛鉤到我的 editorsdispose()方法或?qū)?a 添加DisposeListener到我的sourceviewers textwidget時, sourceviewer 已經(jīng)被處理并getSourceViewer().getAnnotationModel();返回null。我的deleteMarkers方法:private void deleteMarkers() { IAnnotationModel anmod = getSourceViewer().getAnnotationModel(); Iterator<Annotation> it = anmod.getAnnotationIterator(); while (it.hasNext()) { SimpleMarkerAnnotation a = (SimpleMarkerAnnotation) it.next(); anmod.removeAnnotation(a); try { a.getMarker().delete(); } catch (CoreException e) { e.printStackTrace(); } } }任何幫助表示贊賞^^
1 回答

MMTTMM
TA貢獻(xiàn)1869條經(jīng)驗 獲得超4個贊
掛鉤到您的編輯器關(guān)閉事件,獲取對編輯器 IResource 的引用(我相信您可以在 IEditorInput 上獲得該引用)并在相關(guān)資源上調(diào)用 IResource#deleteMarkers(),這將在您關(guān)閉編輯器時刪除它們。按照設(shè)計,當(dāng)編輯器關(guān)閉時,eclipse 不會刪除標(biāo)記。
添加回答
舉報
0/150
提交
取消