1 package org.antlr.works.editor; 2 3 import org.antlr.works.ate.folding.ATEFoldingEntity; 4 import org.antlr.works.ate.folding.ATEFoldingEntityProxy; 5 import org.antlr.works.ate.folding.ATEFoldingManager; 6 import org.antlr.works.components.grammar.CEditorGrammar; 7 import org.antlr.works.prefs.AWPrefs; 8 import org.antlr.works.syntax.element.ElementAction; 9 import org.antlr.works.syntax.element.ElementRule; 10 11 import java.util.List ; 12 42 43 public class EditorFoldingManager extends ATEFoldingManager { 44 45 protected static final int TAG_RULES = 0; 46 protected static final int TAG_ACTIONS = 1; 47 48 protected CEditorGrammar editor; 49 50 public EditorFoldingManager(CEditorGrammar editor) { 51 super(editor.textEditor); 52 this.editor = editor; 53 } 54 55 public void textPaneWillFold() { 56 super.textPaneWillFold(); 57 editor.disableTextPaneUndo(); 58 } 59 60 public void textPaneDidFold() { 61 super.textPaneDidFold(); 62 editor.enableTextPaneUndo(); 63 editor.editorIdeas.hide(); 64 editor.editorTips.hide(); 65 } 66 67 public ATEFoldingEntityProxy createEntityProxy(ATEFoldingEntity entity) { 68 int tag; 69 if(entity instanceof ElementRule) 70 tag = TAG_RULES; 71 else if(entity instanceof ElementAction) 72 tag = TAG_ACTIONS; 73 else 74 return null; 75 76 return new ATEFoldingEntityProxy(this, entity.foldingEntityID(), tag); 77 } 78 79 public void provideFoldingEntities() { 80 List <ElementRule> rules = editor.parserEngine.getRules(); 81 if(rules != null) { 82 for(int index=0; index<rules.size(); index++) { 83 ElementRule rule = rules.get(index); 84 addEntity(rule); 85 } 86 } 87 88 if(AWPrefs.getFoldingEnabled() && AWPrefs.getDisplayActionsAnchorsFolding()) { 90 List <ElementAction> actions = editor.parserEngine.getActions(); 91 if(actions != null) { 92 for(int index=0; index<actions.size(); index++) { 93 ElementAction action = actions.get(index); 94 if(action.rule.isExpanded()) 95 addEntity(action); 96 } 97 } 98 } 99 } 100 101 public ATEFoldingEntity getEntityForIdentifier(List entities, String identifier) { 102 if(entities == null || entities.isEmpty()) 103 return null; 104 for(int index=0; index<entities.size(); index++) { 106 ATEFoldingEntity entity = (ATEFoldingEntity)entities.get(index); 107 if(entity.foldingEntityID().equals(identifier)) 108 return entity; 109 } 110 return null; 111 } 112 113 public ATEFoldingEntity getEntityForKey(Object key, int tag) { 114 if(tag == TAG_ACTIONS) 115 return getEntityForIdentifier(editor.parserEngine.getActions(), (String )key); 116 else if(tag == TAG_RULES) 117 return getEntityForIdentifier(editor.parserEngine.getRules(), (String )key); 118 else 119 return null; 120 } 121 122 } 123 | Popular Tags |