Changeset 1249


Ignore:
Timestamp:
Jul 22, 2011, 12:37:51 PM (6 years ago)
Author:
stefan
Message:

sort files suggested for completion after \includegraphics and show only those in level 1 that are relevant

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/codehelper/commands.xml

    r1246 r1249  
    311311  <command name="includegraphics" usage="\includegraphics[@opt@]{@file@}" hint="includes a graphic; requires package 'graphicx'">
    312312    <argument name="opt"/>
    313     <argument name="file" type="file|defaultExtension=png" value="" completion="true"/>
     313    <argument name="file" type="file|defaultExtension=png|extensions=eps,ps,png,pdf" value="" completion="true"/>
    314314  </command>
    315315
     
    318318
    319319  <command name="input" usage="\input{@file@}" hint="causes the indicated file to be read and processed">
    320     <argument name="file" type="file|defaultExtension=tex" value="" completion="true"/>
     320    <argument name="file" type="file|defaultExtension=tex|extensions=tex" value="" completion="true"/>
    321321  </command>
    322322
  • trunk/src/jlatexeditor/codehelper/IncludeCodeHelper.java

    r1233 r1249  
    22
    33import jlatexeditor.Doc;
     4import jlatexeditor.SCEManager;
    45import sce.codehelper.CHCommand;
     6import sce.codehelper.CHCommandArgument;
    57import sce.codehelper.PatternPair;
    68import sce.codehelper.WordWithPos;
     
    810
    911import java.io.File;
     12import java.io.FileFilter;
    1013import java.io.FilenameFilter;
    1114import java.util.ArrayList;
     15import java.util.Arrays;
     16import java.util.regex.Pattern;
    1217
    1318public class IncludeCodeHelper extends PatternHelper {
    14   protected File path;
     19  protected final Pattern defaultFilePattern = Pattern.compile(".*");
     20  protected Pattern filePattern = null;
     21  protected File path;
    1522  protected WordWithPos fileName;
    1623
     
    4552      if (!path.isDirectory()) return false;
    4653
    47       fileName = params.get(2);
     54      // determine file extensions
     55      filePattern = defaultFilePattern;
     56      try {
     57        ArrayList<CHCommandArgument> arguments = SCEManager.getLatexCommands().getCommands().get(params.get(0).word).getArguments();
     58        for (CHCommandArgument argument : arguments) {
     59          if (!argument.isOptional()) {
     60            filePattern = Pattern.compile(".*(" + argument.getType().getProperty("extensions").replaceAll(",", "|") + ")");
     61          }
     62        }
     63      } catch (Exception ignored) {}
     64
     65      fileName = params.get(2);
    4866      return true;
    4967    }
     
    5876  @Override
    5977  public Iterable<? extends CHCommand> getCompletions(int level) {
    60     return getCompletions(path, fileName.word);
     78    Pattern filePattern;
     79    switch (level) {
     80      case 1:  filePattern = this.filePattern;
     81        break;
     82      default: filePattern = defaultFilePattern;
     83    }
     84    return getCompletions(path, fileName.word, filePattern);
    6185  }
    6286
     
    6690  }
    6791
    68   public Iterable<FileCompletion> getCompletions(File path, final String fileName) {
     92  public Iterable<FileCompletion> getCompletions(File path, final String fileName, final Pattern filePattern) {
    6993    ArrayList<FileCompletion> list = new ArrayList<FileCompletion>();
    7094
     
    7397    }
    7498
    75     File[] fileList = path.listFiles(new FilenameFilter() {
    76       public boolean accept(File dir, String name) {
    77         return name.startsWith(fileName);
    78       }
     99    File[] fileList = path.listFiles(new FileFilter() {
     100      public boolean accept(File file) {
     101        String name = file.getName();
     102        return name.startsWith(fileName) && (file.isDirectory() || filePattern.matcher(name).find());
     103      }
    79104    });
     105
     106    Arrays.sort(fileList);
    80107
    81108    for (File file : fileList) {
     
    97124    String completion = null;
    98125
    99     for (CHCommand command : getCompletions(path, fileName)) {
     126    for (CHCommand command : getCompletions(path, fileName, defaultFilePattern)) {
    100127      String commandName = command.getName();
    101128      if (commandName.startsWith(fileName)) {
Note: See TracChangeset for help on using the changeset viewer.