import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.*;
-
/**
* Simple command implementation
+ *
* @author Ilya.Kazakevich
*/
public class CommandAdapter implements Command {
@NotNull
private final String myName;
- @NotNull
- private final List<Argument> myArguments = new ArrayList<Argument>();
@Nullable
private final String myHelp;
+ @NotNull
+ private final ArgumentsInfo myArgumentsInfo;
/**
- * @param help help text
- * @param name command name
- * @param arguments command arguments
- */
- public CommandAdapter(@NotNull final String name, @Nullable final String help, @NotNull final Argument... arguments) {
- this(name, help, Arrays.asList(arguments));
- }
-
- /**
- * @param help help text
- * @param name command name
- * @param arguments command arguments
+ * @param help help text
+ * @param name command name
+ * @param argumentsInfo arguments info
*/
- public CommandAdapter(@NotNull final String name, @Nullable final String help, @NotNull final Collection<Argument> arguments) {
+ public CommandAdapter(@NotNull final String name, @Nullable final String help, @NotNull ArgumentsInfo argumentsInfo) {
myName = name;
- myArguments.addAll(arguments);
myHelp = help;
+ myArgumentsInfo = argumentsInfo;
}
/**
@NotNull
@Override
public final ArgumentsInfo getArgumentsInfo() {
- return NoArgumentsInfo.INSTANCE;
+ return myArgumentsInfo;
}
}
* currenly used strategy (see interface for more info)
*/
private Strategy myStrategy;
- /**
- * When user asks for completion, last word should be removed if it is tied to suggestion
- */
- private boolean myLastSuggestionTiedToWord;
/**
@Override
public void textChanged(final boolean inForcedTextMode) {
- myLastSuggestionTiedToWord = false;
configureStrategy();
myView.setSubText(myStrategy.getSubText());
final Pair<SpecialErrorPlace, List<WordWithPosition>> errorInfo = myStrategy.getErrorInfo();
final String lastPart = getLastPart();
if ((lastPart != null) && myStrategy.isUnknownTextExists()) {
//Filter to starts from
- myLastSuggestionTiedToWord = true;
final Iterator<String> iterator = suggestions.iterator();
while (iterator.hasNext()) {
final String textToCheck = iterator.next();
*/
@NotNull
private SuggestionsBuilder getBuilderWithHistory() {
- final SuggestionsBuilder suggestionsBuilder = new SuggestionsBuilder();
+ return new SuggestionsBuilder();
+
+ // TODO: Uncomment when history would be fixed
+ /*final SuggestionsBuilder suggestionsBuilder = new SuggestionsBuilder();
final List<CommandExecutionInfo> history = getHistory();
final Collection<String> historyCommands = new LinkedHashSet<String>();
for (final CommandExecutionInfo info : history) {
suggestionsBuilder.changeGroup(true);
}
- return suggestionsBuilder;
+ return suggestionsBuilder;*/
}
/**
if (suggestionInfo.getSuggestions().contains(valueFromSuggestionList)) {
final ParsedCommandLine commandLine = getParsedCommandLine();
final List<String> words = commandLine != null ? commandLine.getAsWords() : new ArrayList<String>();
- if (!words.isEmpty() && myLastSuggestionTiedToWord) {
+ if (!words.isEmpty() && myView.isCaretOnWord()) {
words.remove(words.size() - 1);
}
words.add(valueFromSuggestionList);
@Override
public void suggestionRequested() {
- myLastSuggestionTiedToWord = false;
-
final SuggestionInfo suggestionInfo = myStrategy.getSuggestionInfo();
final List<String> suggestions = suggestionInfo.getSuggestions();
if (!suggestions.isEmpty()) {
- // TODO: Uncomment when history would be fixed
- final SuggestionsBuilder suggestionsBuilder = new SuggestionsBuilder();/*getBuilderWithHistory();*/
+ final SuggestionsBuilder suggestionsBuilder = getBuilderWithHistory();
suggestionsBuilder.add(suggestions);
myView.displaySuggestions(suggestionsBuilder, suggestionInfo.myAbsolute, null);
}