Ignore:
Timestamp:
06/28/13 14:38:46 (11 years ago)
Author:
pharms
Message:
  • improved autocompletion of console to also autocomplete to paths and objects in the global data container
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-utils/src/main/java/de/ugoe/cs/util/console/CommandExecuter.java

    r1238 r1243  
    3030import java.util.jar.JarInputStream; 
    3131import java.util.logging.Level; 
     32 
     33import de.ugoe.cs.util.StringTools; 
    3234 
    3335/** 
     
    356358        Command[] commands = getAvailableCommands(); 
    357359         
    358         List<Command> matchingCommands = new ArrayList<Command>(); 
    359         for (Command command : commands) { 
    360             String commandName = command.getClass().getSimpleName().substring(3); 
    361             if (commandName.startsWith(commandPrefix)) { 
    362                 matchingCommands.add(command); 
    363             } 
    364         } 
     360        String[] completions = new String[commands.length]; 
    365361         
    366         StringBuffer completedPrefix = new StringBuffer(commandPrefix); 
     362        for (int i = 0; i < commands.length; i++) { 
     363            completions[i] = commands[i].getClass().getSimpleName().substring(3); 
     364        } 
    367365         
    368         boolean foundCompletion = false; 
    369          
    370         while (!foundCompletion) { 
    371             char nextCompletionChar = 0; 
    372             for (Command command : matchingCommands) { 
    373                 String commandName = command.getClass().getSimpleName().substring(3); 
    374                 if (commandName.length() > completedPrefix.length()) { 
    375                     if (nextCompletionChar == 0) { 
    376                         nextCompletionChar = commandName.charAt(completedPrefix.length()); 
    377                     } 
    378                     else if (nextCompletionChar != commandName.charAt(completedPrefix.length())) { 
    379                         foundCompletion = true; 
    380                     } 
    381                 } 
    382                 else { 
    383                     foundCompletion = true; 
    384                 } 
    385             } 
    386              
    387             if (!foundCompletion && (nextCompletionChar != 0)) { 
    388                 completedPrefix.append(nextCompletionChar); 
    389             } 
    390             else { 
    391                 foundCompletion = true; 
    392             } 
    393         } 
    394          
    395         return completedPrefix.toString(); 
     366        return StringTools.autocomplete(commandPrefix, completions); 
    396367    } 
    397368} 
Note: See TracChangeset for help on using the changeset viewer.