Exemple #1
0
 public String previewCommand(String userCommand) {
   lastPreviewedCommand = Parser.parse(userCommand);
   lastPreviewedCommand.setPreview(true);
   return runCommand(lastPreviewedCommand);
 }
Exemple #2
0
 private String execute(Command command) {
   return command.run(ui, taskEngine);
 }
Exemple #3
0
  // @@author A0124321Y
  private String runCommand(Command command) {
    String feedback = null;

    switch (command.getType()) {
      case ADD_DREAM:
      case ADD_DEADLINE:
      case ADD_EVENT:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView(ViewType.SHOW_OUTSTANDING);
        }
        break;

      case EDIT:
      case EDIT_TO_DREAM:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView();
        }
        break;

      case EDIT_PARTIAL:
        feedback = execute(command);
        break;

      case DELETE:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView();
        }
        break;

      case DONE:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView();
        }
        break;

      case UNDO:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView();
        }
        break;

      case SEARCH:
      case SEARCH_ON:
      case SEARCH_DUE:
      case SEARCH_RANGE:
        feedback = execute(command);
        if (!command.isPreview()) {
          searchString = command.getSearchStr();
          searchTerm = command.getSearchTerm();
          searchStartDate = command.getSearchStartDate();
          searchEndDate = command.getSearchEndDate();
          searchShowDone = command.getSearchShowDone();

          updateView(ViewType.SHOW_SEARCH_RESULTS);
        }
        break;

      case SET_PATH:
        feedback = execute(command);
        break;

      case SHOW_OUTSTANDING:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView(ViewType.SHOW_OUTSTANDING);
        }
        break;

      case SHOW_DONE:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView(ViewType.SHOW_DONE);
        }
        break;

      case SHOW_ALL:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView(ViewType.SHOW_ALL);
        }
        break;

      case SHOW_SUMMARY:
        feedback = execute(command);
        if (!command.isPreview()) {
          updateView(ViewType.SHOW_SUMMARY);
        }
        break;

      case HELP:
        feedback = execute(command);
        break;

      case INVALID:
        feedback = execute(command);
        break;

      case EXIT:
        if (!command.isPreview() && !exit()) {
          feedback = Feedback.FEEDBACK_TRY_AGAIN;
        } else {
          feedback = FeedbackExit.EXIT;
        }
        break;

      default:
        break;
    }
    return feedback;
  }
Exemple #4
0
  // Process key press events
  private EventHandler<KeyEvent> createKeyPressHandler() {
    return (keyEvent) -> {

      // Remove initial splash overlay
      ui.hideSplashOverlay();

      switch (keyEvent.getCode()) {

          // Main command execution flow
        case ENTER:
          {

            // Whitespace command
            if (ui.getInput().trim().isEmpty()) {
              ui.clearInput();
              ui.hideHelpOverlay();
              return;
            }

            // Hide help unless it's a help or exit command
            if (!lastPreviewedCommand.getType().equals(CommandType.HELP)
                && !lastPreviewedCommand.getType().equals(CommandType.EXIT)) {
              ui.hideHelpOverlay();
            }

            // All the work happens here!
            String feedback = executeLastPreviewedCommand();

            // Clear input box and display feedback
            // ClearInput must come before setStatus as user input listener
            // resets status when input is cleared
            ui.clearInput();
            ui.setExecuteStatus(feedback);

            return;
          }

          // Edit description autocompletion
        case TAB:
          {
            if (!hasLastPreviewedCommand()) {
              return;
            }

            Command command = lastPreviewedCommand;
            if (command.getType() != CommandType.EDIT_PARTIAL) {
              return;
            }

            int lineNumber = lastPreviewedCommand.getLineNumber();

            if (!isValidLineNumber(lineNumber)) {
              return;
            }

            ui.setInput(
                ui.getInput().trim() + " " + getTaskFromLineNumber(lineNumber).getDescription());
            return;
          }

          // Scrolling
        case UP:
          {
            ui.scrollUpScreen();
            return;
          }
        case DOWN:
          {
            ui.scrollDownScreen();
            return;
          }

          // Show help
        case F1:
          {
            ui.showHelpOverlay();
            if (ui.getInput().isEmpty()) {
              ui.setPreviewStatus(FeedbackHelp.HELP);
            }
            return;
          }

          // Activate next help page using left/right keys
          // (but only when the input box is empty)
        case LEFT:
        case RIGHT:
          {
            if (ui.getInput().isEmpty()) {
              ui.nextHelpPage();
            }
            return;
          }

          // Hide help
        case ESCAPE:
          {
            ui.hideHelpOverlay();
            if (ui.getInput().trim().isEmpty()) {
              ui.setPreviewStatus(FEEDBACK_READY);
            }
            return;
          }

        default:
          break;
      }
    };
  }
Exemple #5
0
 public String executeLastPreviewedCommand() {
   assert (lastPreviewedCommand != null);
   lastPreviewedCommand.setPreview(false);
   return runCommand(lastPreviewedCommand);
 }