1 22 23 package org.gjt.sp.jedit.menu; 24 25 import javax.swing.*; 27 import java.awt.event.*; 28 import java.io.File ; 29 import java.util.Arrays ; 30 31 import org.gjt.sp.jedit.browser.*; 32 import org.gjt.sp.jedit.io.FileVFS; 33 import org.gjt.sp.jedit.*; 34 36 public class DirectoryProvider implements DynamicMenuProvider 37 { 38 public DirectoryProvider(String dir) 40 { 41 this.dir = dir; 42 } 44 public boolean updateEveryTime() 46 { 47 return true; 48 } 50 public void update(JMenu menu) 52 { 53 final View view = GUIUtilities.getView(menu); 54 55 final String path; 56 if(dir == null) 57 { 58 path = view.getBuffer().getDirectory(); 59 } 60 else 61 path = dir; 62 63 JMenuItem mi = new JMenuItem(path + ":"); 64 mi.setActionCommand(path); 65 mi.setIcon(FileCellRenderer.openDirIcon); 66 67 ActionListener fileListener = new ActionListener() 69 { 70 public void actionPerformed(ActionEvent evt) 71 { 72 jEdit.openFile(view,evt.getActionCommand()); 73 } 74 }; 75 76 ActionListener dirListener = new ActionListener() 77 { 78 public void actionPerformed(ActionEvent evt) 79 { 80 VFSBrowser.browseDirectory(view, 81 evt.getActionCommand()); 82 } 83 }; 85 mi.addActionListener(dirListener); 86 87 menu.add(mi); 88 menu.addSeparator(); 89 90 if(dir == null && !(view.getBuffer().getVFS() instanceof FileVFS)) 91 { 92 mi = new JMenuItem(jEdit.getProperty( 93 "directory.not-local")); 94 mi.setEnabled(false); 95 menu.add(mi); 96 return; 97 } 98 99 File directory = new File (path); 100 101 JMenu current = menu; 102 103 String backupPrefix = jEdit.getProperty("backup.prefix"); 105 String backupSuffix = jEdit.getProperty("backup.suffix"); 106 107 File [] list = directory.listFiles(); 108 if(list == null || list.length == 0) 109 { 110 mi = new JMenuItem(jEdit.getProperty( 111 "directory.no-files")); 112 mi.setEnabled(false); 113 menu.add(mi); 114 } 115 else 116 { 117 int maxItems = jEdit.getIntegerProperty("menu.spillover",20); 118 119 Arrays.sort(list, 120 new MiscUtilities.StringICaseCompare()); 121 for(int i = 0; i < list.length; i++) 122 { 123 File file = list[i]; 124 125 String name = file.getName(); 126 127 if(name.endsWith(".marks")) 129 continue; 130 131 if(name.startsWith("#") && name.endsWith("#")) 133 continue; 134 135 if((backupPrefix.length() != 0 137 && name.startsWith(backupPrefix)) 138 || (backupSuffix.length() != 0 139 && name.endsWith(backupSuffix))) 140 continue; 141 142 146 mi = new JMenuItem(name); 147 mi.setActionCommand(file.getPath()); 148 mi.addActionListener(file.isDirectory() 149 ? dirListener 150 : fileListener); 151 mi.setIcon(file.isDirectory() 152 ? FileCellRenderer.dirIcon 153 : FileCellRenderer.fileIcon); 154 155 if(current.getItemCount() >= maxItems && i != list.length - 1) 156 { 157 JMenu newCurrent = new JMenu( 159 jEdit.getProperty( 160 "common.more")); 161 current.add(newCurrent); 162 current = newCurrent; 163 } 164 current.add(mi); 165 } 166 } 167 } 169 private String dir; 171 } 173 | Popular Tags |