Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T6A1][F09-A4] Poh Yee Heng #842

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ Use case ends.
> 3a1. AddressBook shows an error message <br>
Use case resumes at step 2

#### Use case: Change theme

**MSS**

1. User requests to change to a new theme
2. AddressBook changes the theme
Use case ends.

**Extensions**

1a. The theme to be renamed does not exist

> 1a1. AddressBook shows an error message <br>
Use case ends


## Appendix C : Non Functional Requirements

1. Should work on any [mainstream OS](#mainstream-os) as long as it has Java 8 or higher installed.
Expand Down
11 changes: 11 additions & 0 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ Examples:
Clears all entries from the address book.<br>
Format: `clear`

## Changing a theme : `theme`
Changes the theme of the app. Irreversible.<br>
Format: `theme NEW_THEME`

> Changes the theme of the app.

Examples:
* `theme Light`<br>
Changes the theme of the app to Light theme.


## Exiting the program : `exit`
Exits the program.<br>
Format: `exit`
Expand Down
8 changes: 6 additions & 2 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ public ReadOnlyPerson getPerson() {
}

@Override
public CommandResult execute() {
public CommandResult execute() throws Exception {
try {
addressBook.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (UniquePersonList.DuplicatePersonException dpe) {
return new CommandResult(MESSAGE_DUPLICATE_PERSON);
}
}


@Override
public boolean isMutating() {
return true;
}
}
34 changes: 34 additions & 0 deletions src/seedu/addressbook/commands/ChangeThemeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.ui.Gui;

public class ChangeThemeCommand extends Command {

public static final String COMMAND_WORD = "theme";

public static String MESSAGE_USAGE = String.format(COMMAND_WORD + ":\n"
+ "Changes theme of the application.\n\t"
+ "Parameters: NEW_THEME\n\t"
+ "Themes available: %1$s\n\t"
+ "Example: " + COMMAND_WORD + " Light", AddressBook.allThemesString());

public static final String MESSAGE_SUCCESS = "Theme changed successfully";
public static final String MESSAGE_FAILED_THEME_DOES_NOT_EXIST = "Theme %1$s does not exist.\n";

private final String newThemeName;

public ChangeThemeCommand(String newThemeName) {
this.newThemeName = newThemeName;
}

@Override
public CommandResult execute() {
if (!addressBook.containsTheme(newThemeName)) {
return new CommandResult(String.format(MESSAGE_FAILED_THEME_DOES_NOT_EXIST, newThemeName));
}
Gui.changeTheme(newThemeName);
return new CommandResult(MESSAGE_SUCCESS);
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean isMutating() {
return true;
}
}
3 changes: 2 additions & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly

/**
* Executes the command and returns the result.
* @throws Exception
*/
public abstract CommandResult execute();
public abstract CommandResult execute() throws Exception;

/**
* Supplies the data the command will operate on.
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
}
}

@Override
public boolean isMutating() {
return true;
}

}
6 changes: 5 additions & 1 deletion src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class ExitCommand extends Command {
public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
}


@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String>
}
return matchedPersons;
}

@Override
public boolean isMutating() {
return false;
}

}
8 changes: 7 additions & 1 deletion src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ public class HelpCommand extends Command {
+ "\n" + ViewCommand.MESSAGE_USAGE
+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE;
+ "\n" + ExitCommand.MESSAGE_USAGE
+ "\n" + ChangeThemeCommand.MESSAGE_USAGE;

public HelpCommand() {}

@Override
public CommandResult execute() {
return new CommandResult(MESSAGE_ALL_USAGES);
}

@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public IncorrectCommand(String feedbackToUser){
public CommandResult execute() {
return new CommandResult(feedbackToUser);
}

@Override
public boolean isMutating() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}

@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}

@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}

@Override
public boolean isMutating() {
return false;
}

}
23 changes: 22 additions & 1 deletion src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AddressBook {

private final UniquePersonList allPersons;
private final UniqueTagList allTags; // can contain tags not attached to any person

private final static String[] allThemes = {"Dark", "Light", "Mocha", "Grape"};
public static AddressBook empty() {
return new AddressBook();
}
Expand Down Expand Up @@ -106,6 +106,27 @@ public boolean containsTag(Tag key) {
}

/**
* Checks if provided theme name exists
* */

public boolean containsTheme(String theme) {
for (String th : allThemes) {
if (th.equals(theme)) {
return true;
}
}
return false;
}

/**
* Returns all themes as a string, for use of help command.
* */
public static String allThemesString() {
return String.join(", ", allThemes);
}

/**

* Removes the equivalent person from the address book.
*
* @throws PersonNotFoundException if no such Person could be found.
Expand Down
5 changes: 4 additions & 1 deletion src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public CommandResult execute(String userCommandText) throws Exception {
private CommandResult execute(Command command) throws Exception {
command.setData(addressBook, lastShownList);
CommandResult result = command.execute();
storage.save(addressBook);
if (command.isMutating()) {
storage.save(addressBook);

}
return result;
}

Expand Down
Loading