forked from nus-cs2103-AY2324S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 2 new commands, rebind and unbind
Added the ability to rebind commands to a custom string (must not contain whitespaces), and use them as shorthand. The binds can also be removed.
- Loading branch information
Showing
5 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package command; | ||
|
||
import duke.TaskList; | ||
import duke.UserInterface; | ||
|
||
/** | ||
* Represents an executable that either binds or unbinds a | ||
*/ | ||
public class BindingExecutable implements Executable { | ||
private final boolean successState; | ||
private final boolean boundState; | ||
private final String sourceBinding; | ||
private final String customBinding; | ||
|
||
/** | ||
* Creates a new binding executable instance. | ||
* @param wasSuccessful whether the binding was successful. | ||
* @param wasBound whether an unbinding or rebinding was called. | ||
* @param sourceBinding The original binding command string. | ||
* @param customBinding THe custom binding command string. | ||
*/ | ||
public BindingExecutable(boolean wasSuccessful, boolean wasBound, String sourceBinding, String customBinding) { | ||
this.successState = wasSuccessful; | ||
this.boundState = wasBound; | ||
this.sourceBinding = sourceBinding; | ||
this.customBinding = customBinding; | ||
} | ||
|
||
/** | ||
* Executes and prints out to the ui the result of the bind command. | ||
* @param list the list associated with the bot (unnecessary.) | ||
* @param ui the ui to output to. | ||
* @return false, since the bot does not shut down. | ||
*/ | ||
@Override | ||
public boolean execute(TaskList list, UserInterface ui) { | ||
StringBuilder outputBuilder = new StringBuilder(); | ||
if (boundState) { | ||
outputBuilder.append("Adding of custom binding "); | ||
} else { | ||
outputBuilder.append("Removal of custom binding "); | ||
} | ||
outputBuilder.append("\"").append(customBinding).append("\""); | ||
outputBuilder.append(" to the source binding "); | ||
outputBuilder.append("\"").append(sourceBinding).append("\" was "); | ||
if (successState) { | ||
outputBuilder.append("successful."); | ||
} else { | ||
outputBuilder.append("unsuccessful."); | ||
} | ||
ui.output(outputBuilder.toString()); | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters