<source id="4vppl"><ins id="4vppl"></ins></source>
<u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
<object id="4vppl"></object>
  • <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

    <object id="4vppl"></object>
    <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

      <i id="4vppl"><thead id="4vppl"></thead></i>

      <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>

      當前位置:首頁 > 網(wǎng)站舊欄目 > 學習園地 > 設(shè)計軟件教程 > 關(guān)于多頁編輯器中不同Editor之間的Redo&Undo沖突的解決

      關(guān)于多頁編輯器中不同Editor之間的Redo&Undo沖突的解決
      2010-01-14 22:59:27  作者:  來源:
      在我們的插件工具的開發(fā)過程中碰到一個問題,就是在編輯xml文件的時候,因為采用了EMF建模,導致在使用Eclipse Forms編輯節(jié)點和屬性與編輯事件的JavaScript腳本的Editor之間二者的Redo&Undo功能有一定的沖突,EMF的Redo&Undo不可用,當把JavaScript編輯器中TextViewer的UndoManager屏蔽了之后,EMF的Redo&Undo才能正常,開始跟蹤調(diào)試代碼,始終沒有找到問題的癥結(jié)所在,經(jīng)過幾天的摸索,最終找到了答案.
      原來跟ContributorActionBar有關(guān),在插件中,對于Editor(這里的Editor是指的多頁編輯器外面的那個總的Editor不是里面每一頁中的Editor)來說,我們必須為其指定一個ContributorActionBar,在該類的初始化方法:
      void org.eclipse.ui.part.EditorActionBarContributor.init(IActionBars bars)
      中需要為IActionBars添加各種Action,比如CopyAction, DeleteAction, CutAction這里面就包括RedoAction和UndoAction,例如在
      void org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.init(IActionBars actionBars)中就是這樣來做的:
      java 代碼
       
      1. deleteAction = new DeleteAction(removeAllReferencesOnDelete());    
      2. deleteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));   
      3. actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);   

      上面的代碼將系統(tǒng)的Undo&Redo快捷鍵以及Eclipse菜單項Delete與deleteAction關(guān)聯(lián)起來了.
      如果多頁編輯器里面使用了一個另外一個TextEditor,那么在這個TextEditor中對Redo&Undo Action會調(diào)用org.eclipse.ui.texteditor.AbstractTextEditor.createUndoRedoActions()方法,其中代碼如下:

      java 代碼
       
      1. IUndoContext undoContext= getUndoContext();   
      2.         if (undoContext != null) {   
      3.             // Use actions provided by global undo/redo   
      4.                
      5.             // Create the undo action   
      6.             OperationHistoryActionHandler undoAction= new UndoActionHandler(getEditorSite(), undoContext);   
      7.             PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);   
      8.             undoAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.UNDO);   
      9.             registerUndoRedoAction(ITextEditorActionConstants.UNDO, undoAction);   
      10.             ... ...   

      在registerUndoRedoAction方法中:

      java 代碼
       
      1. private void registerUndoRedoAction(String actionId, OperationHistoryActionHandler action) {   
      2.         IAction oldAction= getAction(actionId);   
      3.         if (oldAction instanceof OperationHistoryActionHandler)   
      4.             ((OperationHistoryActionHandler)oldAction).dispose();   
      5.   
      6.         setAction(actionId, action);   
      7.            
      8.         IActionBars actionBars= getEditorSite().getActionBars();   
      9.         if (actionBars != null)   
      10.             actionBars.setGlobalActionHandler(actionId, action);   
      11.     }   

      會再一次的將指定的Action與全局ActionId關(guān)聯(lián)起來,這樣我們前面制定的Action就會被屏蔽掉,導致使用了TextEditor的UndoManager之后,EMF的模型編輯的Redo&Undo無法使用,找到了問題所在,至于解決辦法就好搞定了.

      另:

      研究Undo&Redo的入口在void org.eclipse.swt.custom.StyledText.modifyContent(Event event, boolean updateCaret)
      然后是void org.eclipse.swt.custom.StyledTextContent.replaceTextRange(int start, int replaceLength, String text)
      StyledTextContent這個類是用來鏈接TextViewer和Document之間的適配器,TextViewer默認的實現(xiàn)是DefaultDocumentAdapter,如果需要提供自己的DocumentAdapter的實現(xiàn)需要復(fù)寫 TextViewer 的 createDocumentAdapter() 方法,所有的操作會轉(zhuǎn)交給當前編輯的Document,對于UndoMananger來說,它會在每個TextViewer上所編輯的Document注冊一些監(jiān)聽器,用來監(jiān)聽Document的改變,當Document發(fā)生改變的時候,會觸發(fā)這些監(jiān)聽器,這些監(jiān)聽器,根據(jù)Document的改變生成一個一個的Command或者Operation并保存在StackCommand或者是History中,以便Undo的時候從StackCommand和History中取出來執(zhí)行


      安徽新華電腦學校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢
      相關(guān)熱詞搜索:編輯器 沖突 之間
      国产午夜福三级在线播放_亚洲精品成a人片在线观看_亚洲自慰一区二区三区_久久棈精品久久久久久噜噜
      <source id="4vppl"><ins id="4vppl"></ins></source>
      <u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
      <object id="4vppl"></object>
    1. <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

      <object id="4vppl"></object>
      <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

        <i id="4vppl"><thead id="4vppl"></thead></i>

        <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>
        亚洲产精品一区二区 | 天天躁中文字幕在线视频 | 亚洲欧美日韩综合久久久久 | 亚欧一线视频在线观看 | 亚洲国产精品激情在线观看 | 中文字幕色婷婷在线视频 |