[英]How to properly set the content of an IFile in Eclipse plugin when the editor is opened
[英]How to set seperate global action handler for multiple instance of eclipse form based plugin editor
我正在基於Eclipse表單的編輯器上工作。 我已經為編輯器提供了對撤消重做和臟標志的處理支持,這兩個功能對於單個插件實例都可以正常工作。 當我用2個或更多文件(2個或更多eclipse插件實例)打開它時,問題就來了。 現在,撤消重做開始變得很奇怪。 它們僅適用於最后打開的實例。
例如:假設我的編輯器支持'.xeb'文件。 如果我用我的編輯器一個一個地打開test1.xeb和test2.xeb文件。 然后撤消重做僅適用於為test2.xeb文件打開的實例。 如果我切換回其他實例,則會出現第一個實例的撤消重做。
我在編輯器的plugin.xml中有以下條目:
<plugin><extension
point="org.eclipse.ui.editors">
<editor
class="Testeditor"
default="true"
extensions="xeb"
icon="icons/sample.gif"
id="testeditor"
name="editor">
</editor>
</plugin>
我調試了代碼,發現這種奇怪的行為是由於以錯誤的方式處理全局動作而發生的。我使用下面的代碼來設置全局動作處理程序:
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.updateActionBars();
}
我瀏覽了一些與此問題有關的鏈接。 但無法理解實現此行為的概念。
http://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F
任何人都可以調查這個問題。 提前致謝。
僅在編輯器類中重寫MultiPageEditorPart的setFocus()方法,並調用設置全局操作處理程序的適當方法,如下所示:
@Override
public void setFocus() {
switch (getActivePage()) {
case 0:
pageOne.setUndoRedoActionHandlers();
break;
case 1:
pageTwo.setUndoRedoActionHandlers();
break;
}
super.setFocus();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.