Changeset 1233


Ignore:
Timestamp:
Jul 21, 2011, 12:02:27 AM (6 years ago)
Author:
stefan
Message:

multi-level completion for environments

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/bib/BibCodeHelper.java

    r1139 r1233  
    7575  }
    7676
    77   public Iterable<? extends CHCommand> getCompletions() {
     77  public Iterable<? extends CHCommand> getCompletions(int level) {
    7878    return getCompletions(name.word);
    7979  }
  • trunk/src/jlatexeditor/codehelper/BeamerCodeHelper.java

    r1231 r1233  
    4040
    4141  @Override
    42   public Iterable<? extends CHCommand> getCompletions() {
     42  public Iterable<? extends CHCommand> getCompletions(int level) {
    4343    return getCompletions(word.word);
    4444  }
  • trunk/src/jlatexeditor/codehelper/CiteHelper.java

    r872 r1233  
    2929
    3030  @Override
    31   public Iterable<? extends CHCommand> getCompletions() {
     31  public Iterable<? extends CHCommand> getCompletions(int level) {
    3232    return getCompletions(word.word);
    3333  }
  • trunk/src/jlatexeditor/codehelper/CommandsCodeHelper.java

    r1232 r1233  
    1313import util.TrieSet;
    1414
    15 import java.lang.reflect.Array;
    16 import java.util.ArrayList;
    1715import java.util.Arrays;
    1816import java.util.List;
     
    5755
    5856  @Override
    59   public Iterable<? extends CHCommand> getCompletions() {
     57  public Iterable<? extends CHCommand> getCompletions(int level) {
    6058    return getCompletions(word.word);
    6159  }
  • trunk/src/jlatexeditor/codehelper/DocumentClassCodeHelper.java

    r1231 r1233  
    3838
    3939  @Override
    40   public Iterable<? extends CHCommand> getCompletions() {
     40  public Iterable<? extends CHCommand> getCompletions(int level) {
    4141    return getCompletions(word.word);
    4242  }
  • trunk/src/jlatexeditor/codehelper/EnvironmentCodeHelper.java

    r1231 r1233  
    5050
    5151  @Override
    52   public Iterable<? extends CHCommand> getCompletions() {
    53     return getCompletions(word.word);
     52  public Iterable<? extends CHCommand> getCompletions(int level) {
     53    int minUsageCount = 0;
     54    switch (level) {
     55      case 1:  minUsageCount = 0; break;
     56      default: minUsageCount = 0; break;
     57    }
     58    return getCompletions(word.word, minUsage(minUsageCount));
    5459  }
    5560
     
    5964  }
    6065
    61   public Iterable<CHCommand> getCompletions(String search) {
     66  public Iterable<CHCommand> getCompletions(String search, Function1 filterFunc) {
    6267    ExtIterable<String> userIter = SCEManager.getBackgroundParser().getEnvironments().getObjectsIterable(search).map(ENVIRONMENT_2_STRING_FUNCTION);
    63     int minUsageCount = 0;
    64     ExtIterable<String> packEnvIter = PackagesExtractor.getPackageParser().getEnvironments().getTrieSetIterator(search).filter(minUsage(minUsageCount)).map(TRIE_SET_2_STRING_FUNCTION);
    65     ExtIterable<String> dcEnvIter = PackagesExtractor.getDocClassesParser().getEnvironments().getTrieSetIterator(search).filter(minUsage(minUsageCount)).map(TRIE_SET_2_STRING_FUNCTION);
     68    ExtIterable<String> packEnvIter = PackagesExtractor.getPackageParser().getEnvironments().getTrieSetIterator(search).filter(filterFunc).map(TRIE_SET_2_STRING_FUNCTION);
     69    ExtIterable<String> dcEnvIter = PackagesExtractor.getDocClassesParser().getEnvironments().getTrieSetIterator(search).filter(filterFunc).map(TRIE_SET_2_STRING_FUNCTION);
    6670
    6771    ExtIterable<CHCommand> mergedIter = new MergeSortIterable<String>(STRING_COMPARATOR, userIter, packEnvIter, dcEnvIter).map(STRING_2_CHCOMMAND);
  • trunk/src/jlatexeditor/codehelper/GenericCodeHelper.java

    r1154 r1233  
    3131  }
    3232
    33   public Iterable<? extends CHCommand> getCompletions() {
     33  public Iterable<? extends CHCommand> getCompletions(int level) {
    3434    AbstractTrie<?> trie = getCompletionTrie.apply();
    3535
  • trunk/src/jlatexeditor/codehelper/IncludeCodeHelper.java

    r856 r1233  
    5757
    5858  @Override
    59   public Iterable<? extends CHCommand> getCompletions() {
     59  public Iterable<? extends CHCommand> getCompletions(int level) {
    6060    return getCompletions(path, fileName.word);
    6161  }
  • trunk/src/jlatexeditor/codehelper/UsePackageCodeHelper.java

    r1231 r1233  
    22
    33import de.endrullis.utils.collections.CollectionUtils;
     4import de.endrullis.utils.collections.ExtIterable;
    45import jlatexeditor.PackagesExtractor;
    56import sce.codehelper.CHCommand;
     
    78import sce.codehelper.WordWithPos;
    89import util.Function1;
     10import util.Trie;
     11import util.TrieSet;
    912
    1013import java.util.ArrayList;
     
    1821public class UsePackageCodeHelper extends PatternHelper {
    1922  protected WordWithPos word;
     23  private static final Function1<PackagesExtractor.Package,CHCommand> PACKAGE_2_CHCOMMAND = new Function1<PackagesExtractor.Package, CHCommand>() {
     24    @Override
     25    public CHCommand apply(PackagesExtractor.Package a1) {
     26      return new ValueCompletion(a1.getName());
     27    }
     28  };
    2029
    2130  public UsePackageCodeHelper() {
     
    3847
    3948  @Override
    40   public Iterable<? extends CHCommand> getCompletions() {
    41     return getCompletions(word.word);
     49  public Iterable<? extends CHCommand> getCompletions(int level) {
     50    int minUsageCount = 0;
     51    switch (level) {
     52      case 1:  minUsageCount = 50; break;
     53      case 2:  minUsageCount = 1; break;
     54      default: minUsageCount = 0; break;
     55    }
     56    return getCompletions(word.word, minUsage(minUsageCount));
    4257  }
    4358
     
    4762  }
    4863
    49   public Iterable<CHCommand> getCompletions(String search) {
    50     List<String> packageNames = PackagesExtractor.getPackageParser().getPackages().getStrings(search, 20);
    51     if (packageNames == null) packageNames = new ArrayList<String>();
     64  public Iterable<CHCommand> getCompletions(String search, Function1<PackagesExtractor.Package, Boolean> filterFunc) {
     65    ExtIterable<PackagesExtractor.Package> packIter = PackagesExtractor.getPackageParser().getPackages().getObjectsIterable(search);
     66    if (packIter == null) return new ArrayList<CHCommand>();
    5267
    53     return CollectionUtils.map(packageNames, new Function1<String, CHCommand>() {
    54       public CHCommand apply(String packageName) {
    55         return new ValueCompletion(packageName);
     68    return packIter.filter(filterFunc).map(PACKAGE_2_CHCOMMAND).toList(20);
     69  }
     70
     71  protected Function1<PackagesExtractor.Package, Boolean> minUsage(final int minUsageCount) {
     72    return new Function1<PackagesExtractor.Package, Boolean>() {
     73      @Override
     74      public Boolean apply(PackagesExtractor.Package pack) {
     75        return pack.getUsageCount() >= minUsageCount;
    5676      }
    57     });
     77    };
    5878  }
    5979
  • trunk/src/jlatexeditor/codehelper/WordCompletion.java

    r996 r1233  
    3535
    3636  @Override
    37   public Iterable<? extends CHCommand> getCompletions() {
     37  public Iterable<? extends CHCommand> getCompletions(int level) {
    3838    ArrayList<CHCommand> commands = new ArrayList<CHCommand>();
    3939    List<String> strings = backgroundParser.getWords().getStrings(word.word, 100);
  • trunk/src/jlatexeditor/gproperties/GPropertiesCodeHelper.java

    r1220 r1233  
    5454
    5555  @Override
    56   public Iterable<? extends CHCommand> getCompletions() {
     56  public Iterable<? extends CHCommand> getCompletions(int level) {
    5757    return getCompletions(key, value.word);
    5858  }
  • trunk/src/sce/codehelper/CodeHelper.java

    r757 r1233  
    4444   *
    4545   * @return list of completion suggestions.
     46   * @param level completion level
    4647   */
    47   public abstract Iterable<? extends CHCommand> getCompletions();
     48  public abstract Iterable<? extends CHCommand> getCompletions(int level);
    4849
    4950  /**
  • trunk/src/sce/codehelper/CodeHelperPane.java

    r1232 r1233  
    1010import java.awt.event.MouseEvent;
    1111import java.awt.event.MouseListener;
    12 import java.awt.font.TextAttribute;
    1312import java.util.ArrayList;
    14 import java.util.Map;
    1513import java.util.regex.Matcher;
    1614import java.util.regex.Pattern;
     
    4341  // the position of the code helper
    4442  private WordWithPos wordPos = null;
     43  private int level = 1;
    4544  // the prefix
    4645
     
    9796    popup.setVisible(visible);
    9897    if (!visible) {
     98      level = 1;
    9999      wordPos = null;
    100100    }
     
    140140
    141141    dimension.width = Math.min(480, dimension.width + 30);
    142     dimension.height = Math.min(320, dimension.height + 5);
     142    dimension.height = Math.min(320, dimension.height + 20);
    143143
    144144    return dimension;
     
    166166  /**
    167167   * Updates the search prefix for the code helper.
     168   * @param level completion level
    168169   */
    169   private void updatePrefix() {
     170  private void updatePrefix(int level) {
    170171    if (wordPos == null || codeHelper == null) return;
     172
     173    status.setText("Level " + level);
    171174
    172175    // get selection
     
    178181
    179182    if (codeHelper.documentChanged()) {
    180       for (CHCommand command : codeHelper.getCompletions()) model.addElement(command);
     183      for (CHCommand command : codeHelper.getCompletions(level)) model.addElement(command);
    181184      wordPos = codeHelper.getWordToReplace();
    182185
     
    266269        WordWithPos wordToReplace = tabCompletion.getWordToReplace();
    267270
    268         for (CHCommand command : tabCompletion.getCompletions()) {
     271        for (CHCommand command : tabCompletion.getCompletions(level)) {
    269272          if (wordToReplace.word.equals(command.getName())) {
    270273            SCECaret caret = pane.getCaret();
     
    378381    if (codeHelper.matches()) {
    379382      wordPos = codeHelper.getWordToReplace();
    380       updatePrefix();
     383      updatePrefix(level);
    381384      String replacement = codeHelper.getMaxCommonPrefix();
    382385
    383386      if (replacement != null) {
    384         replace(wordPos, replacement);
     387        if (wordPos.word.equals(replacement)) {
     388          level = Math.min(level + 1, 3);
     389        } else {
     390          replace(wordPos, replacement);
     391        }
    385392
    386393        if (!popup.isVisible()) {
     
    396403    if (codeHelper.matches()) {
    397404      wordPos = codeHelper.getWordToReplace();
    398       updatePrefix();
     405      updatePrefix(level);
    399406
    400407      String replacement = codeHelper.getMaxCommonPrefix();
     
    437444    }
    438445
    439     if (isVisible()) updatePrefix();
     446    if (isVisible()) updatePrefix(level);
    440447    else {
    441448      if (idleThread != null) {
  • trunk/src/sce/codehelper/CombinedCodeHelper.java

    r757 r1233  
    4040
    4141  @Override
    42   public Iterable<? extends CHCommand> getCompletions() {
    43     return currentPatternHelper.getCompletions();
     42  public Iterable<? extends CHCommand> getCompletions(int level) {
     43    return currentPatternHelper.getCompletions(level);
    4444  }
    4545
  • trunk/src/sce/codehelper/StaticCommandsCodeHelper.java

    r996 r1233  
    4545
    4646  @Override
    47   public Iterable<? extends CHCommand> getCompletions() {
     47  public Iterable<? extends CHCommand> getCompletions(int level) {
    4848    return getCompletions(command.word);
    4949  }
Note: See TracChangeset for help on using the changeset viewer.