Skip to content

Commit

Permalink
update multiple undo, auto scroll and help window offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ghurabah93 committed Oct 30, 2016
1 parent 001aa85 commit b125f10
Show file tree
Hide file tree
Showing 9 changed files with 495 additions and 14 deletions.
431 changes: 431 additions & 0 deletions docs/UserGuide.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/seedu/task/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CommandResult execute(String commandText) {
//@@author A0147335E-reused
logger.info("SUCCESS");

if (!commandText.equals("undo")) {
if (!commandText.toLowerCase().startsWith("undo")) {
historyManager.getPreviousCommandList().add(commandText);
return command.execute(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/task/logic/commands/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public CommandResult execute(boolean isUndo) {
if (isUndo == false) {
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, newTask, null));
}
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, newTask));
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, newTask.getName()));
}

@Override
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/seedu/task/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,37 @@ public class UndoCommand extends Command {
public static final String MESSAGE_SUCCESS = "Undo: ";

public static final String MESSAGE_FAIL = "Cannot undo anymore!";


public final int numOfTimes;

public final boolean isMultiUndo;

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public UndoCommand() {

numOfTimes = 1;
isMultiUndo = false;
}

public UndoCommand(int numOfTimes) {
this.numOfTimes = numOfTimes;
isMultiUndo = true;

}

@Override
public CommandResult execute(boolean isUndo) {
if (history.getUndoList().size() == 0) {
return new CommandResult(MESSAGE_FAIL);
}
String outputUndoList = "";
for (int i = 0; i < numOfTimes; i++) {

if (history.getUndoList().size() != 0) {
outputUndoList = MESSAGE_SUCCESS + history.getPreviousCommandList().get(history.getPreviousCommandList().size()-1);
outputUndoList += MESSAGE_SUCCESS + history.getPreviousCommandList().get(history.getPreviousCommandList().size()-1) + "\n" ;
String[] getIndex = history.getPreviousCommandList().get(history.getPreviousCommandList().size()-1).split(" ");
String previousCommand = getIndex[0];
String[] previousCommandDetails = getIndex;
Expand Down Expand Up @@ -71,9 +87,11 @@ public CommandResult execute(boolean isUndo) {
checkCommandListSize();
}
else {
outputUndoList = MESSAGE_FAIL;
if (!isMultiUndo) {
outputUndoList = MESSAGE_FAIL;
}
}
}

return new CommandResult(outputUndoList);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/task/logic/commands/UndoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CommandResult execute(boolean isUndo) {
if (isUndo == false) {
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, newTask, null));
}
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, newTask));
return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, newTask.getName()));
}

@Override
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/seedu/task/logic/parser/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Command parseCommand(String userInput) {
return new HelpCommand();

case UndoCommand.COMMAND_WORD:
return new UndoCommand();
return prepareUndo(arguments);

//@@author A0147944U-reused
case DirectoryCommand.COMMAND_WORD:
Expand Down Expand Up @@ -624,6 +624,22 @@ private Command prepareDelete(String args) {

return new DeleteCommand(index.get());
}

/**
* Parses arguments in the context of the undo task command.
*
* @param args full command args string
* @return the undoed command
*/
private Command prepareUndo(String args) {

Optional<Integer> index = parseIndex(args);
if(!index.isPresent()){
return new UndoCommand();
}

return new UndoCommand(index.get());
}

/**
* Parses arguments in the context of the select task command.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/task/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ private class NameQualifier implements Qualifier {

@Override
public boolean run(ReadOnlyTask task) {
String name = task.getName().fullName.toLowerCase();

String name = task.getAsText().toLowerCase();

return nameKeyWords.stream()
.filter(keyword -> name.indexOf(keyword.toLowerCase())>=0)
.findAny()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/task/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class HelpWindow extends UiPart {
private static final String FXML = "HelpWindow.fxml";
private static final String TITLE = "Help";
private static final String USERGUIDE_URL =
"https://github.com/CS2103AUG2016-T17-C3/Task-Manager/blob/master/docs/UserGuide.md";
"file:///" + System.getProperty("user.dir") + "/docs/UserGuide.html";

private AnchorPane mainPane;

Expand Down
20 changes: 17 additions & 3 deletions src/main/java/seedu/task/ui/TaskListPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.task.ui;

import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
Expand Down Expand Up @@ -64,23 +65,23 @@ private void setConnections(ObservableList<ReadOnlyTask> taskList) {
taskListView.setItems(taskList);
taskListView.setCellFactory(listView -> new TaskListViewCell());
setEventHandlerForSelectionChangeEvent();

addAutoScroll(taskListView);

}

private void addToPlaceholder() {
SplitPane.setResizableWithParent(placeHolderPane, false);

placeHolderPane.getChildren().add(panel);

}

private void setEventHandlerForSelectionChangeEvent() {
taskListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
logger.fine("Selection in task list panel changed to : '" + newValue + "'");
raise(new TaskPanelSelectionChangedEvent(newValue));

}
});

Expand All @@ -92,6 +93,19 @@ public void scrollTo(int index) {
taskListView.getSelectionModel().clearAndSelect(index);
});
}
public static <S> void addAutoScroll(final ListView<S> view) {
if (view == null) {
throw new NullPointerException();
}

view.getItems().addListener((ListChangeListener<S>) (c -> {
c.next();
final int size = view.getItems().size();
if (size > 0) {
view.scrollTo(size - 1);
}
}));
}

class TaskListViewCell extends ListCell<ReadOnlyTask> {

Expand Down

0 comments on commit b125f10

Please sign in to comment.