1 19 20 package org.netbeans.modules.languages.features; 21 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import javax.swing.JMenu ; 29 import javax.swing.text.JTextComponent ; 30 import org.netbeans.api.languages.LanguagesManager; 31 import org.netbeans.api.languages.ParseException; 32 import org.netbeans.modules.editor.NbEditorKit.GenerateFoldPopupAction; 33 import org.netbeans.modules.languages.Feature; 34 import org.netbeans.modules.languages.Language; 35 import org.netbeans.modules.languages.LanguagesManagerImpl; 36 37 38 42 public class LanguagesGenerateFoldPopupAction extends GenerateFoldPopupAction { 43 44 protected void addAdditionalItems (JTextComponent target, JMenu menu) { 45 try { 46 String mimeType = (java.lang.String ) target.getDocument ().getProperty ("mimeType"); 47 Language l = ((LanguagesManagerImpl) LanguagesManager.getDefault ()).getLanguage (mimeType); 48 Set expands = new HashSet (); 49 addFoldTypes (target, menu, l, expands); 50 Iterator <Language> it = l.getImportedLanguages ().iterator (); 51 while (it.hasNext ()) 52 addFoldTypes (target, menu, it.next (), expands); 53 } catch (ParseException ex) { 54 } 55 } 56 57 private void addFoldTypes (JTextComponent target, JMenu menu, Language l, Set expands) { 58 List <Feature> features = l.getFeatures (Language.FOLD); 59 Iterator <Feature> it = features.iterator (); 60 while (it.hasNext ()) { 61 Feature fold = it.next (); 62 String expand = (String ) fold.getValue ("expand_type_action_name"); 63 if (expand == null) continue; 64 if (expands.contains (expand)) 65 continue; 66 expands.add (expand); 67 String collapse = (String ) fold.getValue ("collapse_type_action_name"); 68 if (collapse == null) continue; 69 addAction (target, menu, expand); 70 addAction (target, menu, collapse); 71 setAddSeparatorBeforeNextAction (true); 72 } 73 } 74 } 75 | Popular Tags |