From ce92296c437b94b942ae8bc9bba7bd5ead5da6e5 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sat, 7 Oct 2017 19:27:33 +0200 Subject: [PATCH] implemented basic commandline for #200, implented open appdata folder command --- .../ui/commandLine/CommandLine.java | 128 +++++++++ .../ui/commandLine/CommandLineController.java | 248 ++++++++++++++++++ .../ui/commandLine/commands/Command.java | 37 +++ .../commandLine/commands/CommandBundle.java | 36 +++ .../ui/commandLine/commands/CommandClear.java | 29 ++ .../ui/commandLine/commands/CommandHelp.java | 45 ++++ .../ui/commandLine/commands/CommandList.java | 53 ++++ .../ui/commandLine/commands/CommandOpen.java | 47 ++++ .../commands/CommandShortcuts.java | 21 ++ .../ui/commandLine/commands/HistoryEntry.java | 28 ++ .../ui/commandLine/commands/HistoryType.java | 6 + .../commands/PossibleCommands.java | 15 ++ .../ui/controller/Controller.java | 23 ++ .../budgetmaster/languages/_de.properties | 1 + .../budgetmaster/languages/_en.properties | 1 + .../ui/commandLine/CommandLineGUI.fxml | 22 ++ .../ui/commandLine/_en.properties | 14 + .../budgetmaster/logic/utils/Strings.java | 1 + 18 files changed, 755 insertions(+) create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java create mode 100644 BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java create mode 100644 BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/CommandLineGUI.fxml create mode 100644 BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java new file mode 100644 index 000000000..0e642519d --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLine.java @@ -0,0 +1,128 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.ResourceBundle; + +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.CommandBundle; +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryEntry; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.stage.Modality; +import javafx.stage.Stage; + +public class CommandLine +{ + private Stage owner; + private Stage newStage; + private Image icon; + private ResourceBundle languageBundle; + public ArrayList<HistoryEntry> globalHistory = new ArrayList<>(); + public int lastShownCommand = 1; + public ArrayList<HistoryEntry> history = new ArrayList<>(); + private final String promptText = ">>>"; + private CommandBundle bundle; + + public CommandLine(Stage owner, Image icon, ResourceBundle languageBundle, CommandBundle commandBundle) + { + this.owner = owner; + this.icon = icon; + this.languageBundle = languageBundle; + this.bundle = commandBundle; + } + + public Stage getOwner() + { + return owner; + } + + public Stage getStage() + { + return newStage; + } + + public Image getIcon() + { + return icon; + } + + public int getLastShwonCommand() + { + return lastShownCommand; + } + + public String getPromptText() + { + return promptText; + } + + public ResourceBundle getLanguageBundle() + { + return languageBundle; + } + + public CommandBundle getBundle() + { + return bundle; + } + + public void showCommandLine(String title, double width, double height, double minWidth, double minHeight, double positionX, double positionY, boolean dark) throws IOException + { + if(newStage != null) + { + if(newStage.isShowing()) + { + return; + } + } + + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/de/deadlocker8/budgetmaster/ui/commandLine/CommandLineGUI.fxml")); + + Parent root = (Parent)fxmlLoader.load(); + newStage = new Stage(); + newStage.setScene(new Scene(root, width, height)); + newStage.setResizable(true); + newStage.setTitle(title); + newStage.initOwner(owner); + + newStage.setMinWidth(minWidth); + newStage.setMinHeight(minHeight); + if(positionX != -1) + { + newStage.setX(positionX); + } + if(positionY != -1) + { + newStage.setY(positionY); + } + + if(dark) + { + root.setStyle("-fx-base: rgb(50, 50, 50); -fx-background: rgb(50, 50, 50); -fx-control-inner-background: rgb(10, 10, 10);"); + } + + if(icon != null) + { + newStage.getIcons().add(icon); + } + + CommandLineController newController = fxmlLoader.getController(); + newController.init(this); + + newStage.initModality(Modality.NONE); + newStage.show(); + } + + public void closeCommandLine() + { + if(newStage != null) + { + if(newStage.isShowing()) + { + newStage.close(); + } + } + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java new file mode 100644 index 000000000..e3f15027e --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/CommandLineController.java @@ -0,0 +1,248 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine; + +import java.util.ArrayList; +import java.util.Comparator; + +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.Command; +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryEntry; +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.HistoryType; +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.PossibleCommands; +import javafx.application.Platform; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.input.KeyEvent; + +public class CommandLineController +{ + @FXML private TextArea textareaHistory; + @FXML private TextField textfieldInput; + + private CommandLine commandLine; + + public void init(CommandLine commandLine) + { + this.commandLine = commandLine; + + commandLine.getBundle().setController(this); + commandLine.getBundle().setLanguageBundle(commandLine.getLanguageBundle()); + + textareaHistory.setEditable(false); + textareaHistory.setWrapText(true); + + textfieldInput.setOnKeyPressed(new EventHandler<KeyEvent>() + { + @Override + public void handle(KeyEvent event) + { + if(event.getCode().equals(KeyCode.ENTER)) + { + parse(); + } + + if(event.getCode().equals(KeyCode.UP)) + { + showLastCommand(); + } + + if(event.getCode().equals(KeyCode.ESCAPE)) + { + clearConsole(); + } + + if(event.getCode().equals(KeyCode.TAB)) + { + autocomplete(); + event.consume(); + } + } + }); + + printPrompt(); + } + + public void printPrompt() + { + setConsoleText(); + clearConsole(); + } + + public void print(String message) + { + commandLine.history.add(new HistoryEntry(HistoryType.MESSAGE, message)); + setConsoleText(); + printPrompt(); + } + + public void clearHistoryLog() + { + textareaHistory.setText(""); + } + + public void clearHistory() + { + commandLine.history = new ArrayList<>(); + } + + public void clearConsole() + { + textfieldInput.setText(""); + textfieldInput.requestFocus(); + } + + private void setConsoleText() + { + clearHistoryLog(); + + StringBuilder sb = new StringBuilder(); + boolean printedLastEntry = false; + for(int i = 0; i < commandLine.history.size(); i++) + { + HistoryEntry currentEntry = commandLine.history.get(i); + if(currentEntry.getType().equals(HistoryType.COMMAND)) + { + if(printedLastEntry) + { + sb.append("\n"); + } + sb.append(commandLine.getPromptText()); + sb.append(" "); + sb.append(currentEntry.getText()); + printedLastEntry = true; + } + else + { + if(i != 0) + { + sb.append("\n"); + } + sb.append(currentEntry.getText()); + printedLastEntry = true; + } + } + + textareaHistory.setText(sb.toString()); + textareaHistory.positionCaret(sb.toString().length()); + } + + private boolean executeCommand(String[] command) + { + for(Command cmd : PossibleCommands.possibleCommands) + { + if(cmd.getKeyword().equals(command[0])) + { + cmd.execute(command, commandLine.getBundle()); + return true; + } + } + return false; + } + + private void parse() + { + String input = textfieldInput.getText().replace("\n", ""); + + if(input.equals("")) + { + printPrompt(); + return; + } + + commandLine.globalHistory.add(new HistoryEntry(HistoryType.COMMAND, input)); + commandLine.history.add(new HistoryEntry(HistoryType.COMMAND, input)); + commandLine.lastShownCommand = - 1; + + String[] command = input.split(" "); + if( ! executeCommand(command)) + { + print(commandLine.getLanguageBundle().getString("error.unknown.command")); + } + else + { + printPrompt(); + } + } + + private void showLastCommand() + { + if(commandLine.globalHistory.size() > 0) + { + if(commandLine.lastShownCommand <= 0) + { + textfieldInput.setText(commandLine.globalHistory.get(commandLine.globalHistory.size() - 1).getText()); + commandLine.lastShownCommand = commandLine.globalHistory.size() - 1; + } + else + { + textfieldInput.setText(commandLine.globalHistory.get(commandLine.lastShownCommand - 1).getText()); + commandLine.lastShownCommand--; + } + + Platform.runLater(()-> + { + textfieldInput.positionCaret(textfieldInput.getText().length()); + }); + } + } + + private void autocomplete() + { + String input = textfieldInput.getText().replace("\n", ""); + + if(input.equals("")) + { + return; + } + + ArrayList<Command> commands = PossibleCommands.possibleCommands; + + //filter possible commands + ArrayList<Command> filteredCommands = new ArrayList<>(); + for(Command currentCommand : commands) + { + if(currentCommand.getKeyword().startsWith(input)) + { + filteredCommands.add(currentCommand); + } + } + + //sort commands alphabetically + filteredCommands.sort(new Comparator<Command>() + { + @Override + public int compare(Command o1, Command o2) + { + return o1.keyword.compareTo(o2.keyword); + } + }); + + if(filteredCommands.size() == 1) + { + textfieldInput.setText(filteredCommands.get(0).getKeyword()); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.append(">>> Possible commands for \"" + input + "\":\n"); + for(int i = 0; i < filteredCommands.size(); i++) + { + sb.append(filteredCommands.get(i).keyword); + if(i != (filteredCommands.size()-1)) + { + sb.append("\n"); + } + } + + print(sb.toString()); + + textfieldInput.setText(input); + } + + Platform.runLater(()-> + { + textfieldInput.positionCaret(textfieldInput.getText().length()); + }); + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java new file mode 100644 index 000000000..1e3ddc4fe --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/Command.java @@ -0,0 +1,37 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +public abstract class Command +{ + public String keyword; + public int numberOfParams; + public String helptText; + + public String getKeyword() + { + return keyword; + } + + public int getNumberOfParams() + { + return numberOfParams; + } + + public String getHelpText() + { + return keyword; + } + + public boolean isValid(String[] command) + { + if((command.length - 1) < numberOfParams || (command.length -1) > numberOfParams) + { + return false; + } + else + { + return true; + } + } + + public abstract void execute(String[] command, CommandBundle bundle); +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java new file mode 100644 index 000000000..6a4f0966b --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandBundle.java @@ -0,0 +1,36 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +import java.util.ResourceBundle; + +import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandLineController; + +public class CommandBundle +{ + private CommandLineController controller; + private ResourceBundle languageBundle; + + public CommandBundle() + { + + } + + public CommandLineController getController() + { + return controller; + } + + public ResourceBundle getLanguageBundle() + { + return languageBundle; + } + + public void setController(CommandLineController controller) + { + this.controller = controller; + } + + public void setLanguageBundle(ResourceBundle languageBundle) + { + this.languageBundle = languageBundle; + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java new file mode 100644 index 000000000..69f59bbd6 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandClear.java @@ -0,0 +1,29 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +/** + * Clears the history log and console + */ +public class CommandClear extends Command +{ + public CommandClear() + { + super.keyword = "clear"; + super.numberOfParams = 0; + super.helptText = "help.clear"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + if(!isValid(command)) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments")); + return; + } + + bundle.getController().clearHistory(); + bundle.getController().clearHistoryLog(); + bundle.getController().clearConsole(); + bundle.getController().printPrompt(); + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java new file mode 100644 index 000000000..0358b33d3 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandHelp.java @@ -0,0 +1,45 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +import java.util.MissingResourceException; + +/** + * prints help for given command + */ +public class CommandHelp extends Command +{ + public CommandHelp() + { + super(); + super.keyword = "help"; + super.numberOfParams = 1; + super.helptText = "help.help"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + if(!isValid(command)) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments")); + return; + } + + for(Command cmd : PossibleCommands.possibleCommands) + { + if(cmd.getKeyword().equals(command[1])) + { + try + { + bundle.getController().print(bundle.getLanguageBundle().getString("help." + command[1])); + } + catch(MissingResourceException e) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.general")); + } + return; + } + } + + bundle.getController().print(bundle.getLanguageBundle().getString("error.no.help")); + } +} diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java new file mode 100644 index 000000000..92ba1054a --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandList.java @@ -0,0 +1,53 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +import java.util.ArrayList; +import java.util.Comparator; + +/** + * Lists all available commands + */ +public class CommandList extends Command +{ + public CommandList() + { + super(); + super.keyword = "list"; + super.numberOfParams = 0; + super.helptText = "help.list"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + if(!isValid(command)) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments")); + return; + } + + //sort possible commands alphabetically + ArrayList<Command> commands = PossibleCommands.possibleCommands; + commands.sort(new Comparator<Command>() + { + @Override + public int compare(Command o1, Command o2) + { + return o1.keyword.compareTo(o2.keyword); + } + }); + + //loop through all possible commands and print keyword + StringBuilder sb = new StringBuilder(); + sb.append("All possible commands:\n"); + for(int i = 0; i < commands.size(); i++) + { + sb.append(commands.get(i).keyword); + if(i != (commands.size()-1)) + { + sb.append("\n"); + } + } + + bundle.getController().print(sb.toString()); + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java new file mode 100644 index 000000000..d2e74e4e5 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandOpen.java @@ -0,0 +1,47 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +import de.deadlocker8.budgetmaster.logic.utils.Strings; +import tools.Localization; +import tools.PathUtils; + +public class CommandOpen extends Command +{ + public CommandOpen() + { + super.keyword = "open"; + super.numberOfParams = 1; + super.helptText = "help.open"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + if(!isValid(command)) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments")); + return; + } + + if(!command[1].equals("settings")) + { + bundle.getController().print(bundle.getLanguageBundle().getString("error.invalid.arguments")); + return; + } + + try + { + File folder = Paths.get(PathUtils.getOSindependentPath() + Localization.getString(Strings.FOLDER)).toFile(); + Desktop.getDesktop().open(folder); + bundle.getController().print(bundle.getLanguageBundle().getString("help.success") + " " + folder.getAbsolutePath()); + } + catch(IOException e) + { + bundle.getController().print(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java new file mode 100644 index 000000000..e442ac216 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/CommandShortcuts.java @@ -0,0 +1,21 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +/** + * Lists all available Shortcuts + */ +public class CommandShortcuts extends Command +{ + public CommandShortcuts() + { + super.keyword = "shortcuts"; + super.numberOfParams = 0; + super.helptText = "help.shortcuts"; + } + + @Override + public void execute(String[] command, CommandBundle bundle) + { + bundle.getController().print("Available Shortcuts:"); + bundle.getController().print(bundle.getLanguageBundle().getString("info.shortcuts")); + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java new file mode 100644 index 000000000..ff972e700 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryEntry.java @@ -0,0 +1,28 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +public class HistoryEntry +{ + private HistoryType type; + private String text; + + public HistoryEntry(HistoryType type, String text) + { + this.type = type; + this.text = text; + } + + public HistoryType getType() + { + return type; + } + + public String getText() + { + return text; + } + + public String toString() + { + return "HistoryEntry [type=" + type + ", text=" + text + "]"; + } +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java new file mode 100644 index 000000000..fe72a3bd1 --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/HistoryType.java @@ -0,0 +1,6 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +public enum HistoryType +{ + COMMAND, MESSAGE +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java new file mode 100644 index 000000000..88aff006d --- /dev/null +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/commandLine/commands/PossibleCommands.java @@ -0,0 +1,15 @@ +package de.deadlocker8.budgetmasterclient.ui.commandLine.commands; + +import java.util.ArrayList; +import java.util.Arrays; + +public class PossibleCommands +{ + public static final ArrayList<Command> possibleCommands = new ArrayList<>(Arrays.asList( + new CommandList(), + new CommandHelp(), + new CommandClear(), + new CommandShortcuts(), + new CommandOpen() + )); +} \ No newline at end of file diff --git a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java index b82de439c..bcedcde8f 100644 --- a/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java +++ b/BudgetMasterClient/src/main/java/de/deadlocker8/budgetmasterclient/ui/controller/Controller.java @@ -2,7 +2,9 @@ package de.deadlocker8.budgetmasterclient.ui.controller; import java.io.IOException; import java.util.ArrayList; +import java.util.Locale; import java.util.Optional; +import java.util.ResourceBundle; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; @@ -24,6 +26,8 @@ import de.deadlocker8.budgetmaster.logic.updater.VersionInformation; import de.deadlocker8.budgetmaster.logic.utils.Colors; import de.deadlocker8.budgetmaster.logic.utils.Helpers; import de.deadlocker8.budgetmaster.logic.utils.Strings; +import de.deadlocker8.budgetmasterclient.ui.commandLine.CommandLine; +import de.deadlocker8.budgetmasterclient.ui.commandLine.commands.CommandBundle; import de.deadlocker8.budgetmasterclient.utils.UIHelpers; import fontAwesome.FontIconType; import javafx.animation.FadeTransition; @@ -86,6 +90,7 @@ public class Controller extends BaseController private Updater updater; private Payment selectedPayment; private SearchPreferences searchPreferences; + private CommandLine cmd; private boolean alertIsShowing = false; private static DateTimeFormatter DATE_FORMAT; @@ -126,10 +131,28 @@ public class Controller extends BaseController paymentHandler = new PaymentHandler(); updater = new Updater(); + CommandBundle commandBundle = new CommandBundle(); + cmd = new CommandLine(getStage(), icon, ResourceBundle.getBundle("de/deadlocker8/budgetmaster/ui/commandLine/", Locale.ENGLISH), commandBundle); + if(settings.isAutoUpdateCheckEnabled()) { checkForUpdates(false); } + + getStage().getScene().setOnKeyReleased((event)->{ + if(event.getCode().toString().equals(Localization.getString(Strings.SHORTCUT_DEV_CONSOLE))) + { + try + { + cmd.showCommandLine("Dev Console", 400, 250, 400, 200, -1, -1, true); + } + catch(IOException e) + { + //TODO: errorhandling + Logger.error(e); + } + } + }); initUI(); } diff --git a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_de.properties b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_de.properties index 0760336d2..8c033c6f5 100644 --- a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_de.properties +++ b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_de.properties @@ -64,6 +64,7 @@ currency.placeholder=z.B. \u20AC, CHF, $ trusted.hosts.placeholder=z.B. localhost undefined=unbekannt tagfield.placeholder=Neuen Tag hier eingeben +shortcut.dev.console=F12 # REPORT report.position=Nr. diff --git a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_en.properties b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_en.properties index 778db0500..d826bea6e 100644 --- a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_en.properties +++ b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/languages/_en.properties @@ -64,6 +64,7 @@ currency.placeholder=e.g. \u20AC, CHF, $ trusted.hosts.placeholder=e.g. localhost undefined=undefined tagfield.placeholder=Enter new Tag here +shortcut.dev.console=F12 # REPORT report.position=No. diff --git a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/CommandLineGUI.fxml b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/CommandLineGUI.fxml new file mode 100644 index 000000000..539c299ed --- /dev/null +++ b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/CommandLineGUI.fxml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.TextArea?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.VBox?> + +<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.budgetmasterclient.ui.commandLine.CommandLineController"> + <children> + <VBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> + <children> + <TextArea fx:id="textareaHistory" prefHeight="508.0" prefWidth="572.0" VBox.vgrow="ALWAYS" /> + <TextField fx:id="textfieldInput" prefHeight="46.0" prefWidth="572.0"> + <VBox.margin> + <Insets top="14.0" /> + </VBox.margin> + </TextField> + </children> + </VBox> + </children> +</AnchorPane> diff --git a/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties new file mode 100644 index 000000000..b58ee7894 --- /dev/null +++ b/BudgetMasterClient/src/main/resources/de/deadlocker8/budgetmaster/ui/commandLine/_en.properties @@ -0,0 +1,14 @@ +help.list=list - lists all possible commands +help.help=help - shows help for given command\nSYNTAX: help [COMMAND] +help.clear=clear - clears the history +help.shortcuts=shortcuts - lists all available shortcuts +help.open=open - opens files and folders\nSYNTAX: open [FILE]\npossible Files: settings + +error.general=An error occurred. +error.unknown.command=Unknown command. Use \"list\" for a list of possible commands. +error.invalid.arguments=Invalid arguments. Use \"help commandname\" for help. +error.no.help=Unknown command as parameter. Can't display help. Use \"list\" for a list of possible commands. + +info.shortcuts=[ENTER] - execute command\n[UP] - scroll through recently used commands\n[ESC] - clear input\n[TAB] - autocomplete + +help.success=Successfully opened folder \ No newline at end of file diff --git a/BudgetMasterCore/src/main/java/de/deadlocker8/budgetmaster/logic/utils/Strings.java b/BudgetMasterCore/src/main/java/de/deadlocker8/budgetmaster/logic/utils/Strings.java index c4351c81c..c30d28c37 100644 --- a/BudgetMasterCore/src/main/java/de/deadlocker8/budgetmaster/logic/utils/Strings.java +++ b/BudgetMasterCore/src/main/java/de/deadlocker8/budgetmaster/logic/utils/Strings.java @@ -67,6 +67,7 @@ public class Strings public static final String VERSION = "version"; public static final String UNDEFINED = "undefined"; public static final String TAGFIELD_PLACEHOLDER = "tagfield.placeholder"; + public static final String SHORTCUT_DEV_CONSOLE = "shortcut.dev.console"; //REPORT public static final String REPORT_POSITION = "report.position"; -- GitLab