diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy index 367584b3..4b0e60fe 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/AddCommentView.groovy @@ -50,8 +50,9 @@ class AddCommentView extends BasicWindow { Button saveButton = new Button("Save", { String newComment = textBox.getText() newComment = Base64.encode(DataUtil.encodei18nString(newComment)) + String encodedOldComment = sharedFile.getComment() sharedFile.setComment(newComment) - core.eventBus.publish(new UICommentEvent(sharedFile : sharedFile, oldComment : oldComment)) + core.eventBus.publish(new UICommentEvent(sharedFile : sharedFile, oldComment : encodedOldComment)) close() }) Button cancelButton = new Button("Cancel", {close()}) diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy index 21cebc6a..27216c48 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy @@ -23,6 +23,7 @@ class BrowseView extends BasicWindow { private final TextGUI textGUI private final Core core private final Table table + private final TerminalSize terminalSize private final LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER) BrowseView(BrowseModel model, TextGUI textGUI, Core core, TerminalSize terminalSize) { @@ -30,6 +31,7 @@ class BrowseView extends BasicWindow { this.model = model this.textGUI = textGUI this.core = core + this.terminalSize = terminalSize setHints([Window.Hint.EXPANDED]) @@ -102,6 +104,8 @@ class BrowseView extends BasicWindow { } private void viewComment(String infoHash) { - + UIResultEvent result = model.rootToResult[infoHash] + ViewCommentView view = new ViewCommentView(result, terminalSize) + textGUI.addWindowAndWait(view) } } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy index 2f8e3dd1..252ec12a 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy @@ -23,12 +23,14 @@ class ResultsView extends BasicWindow { private final TextGUI textGUI private final Core core private final Table table + private final TerminalSize terminalSize ResultsView(ResultsModel model, Core core, TextGUI textGUI, TerminalSize terminalSize) { super(model.results.results[0].sender.getHumanReadableName() + " Results") this.model = model this.core = core this.textGUI = textGUI + this.terminalSize = terminalSize setHints([Window.Hint.EXPANDED]) @@ -85,6 +87,8 @@ class ResultsView extends BasicWindow { } private void viewComment(String infohash) { - + UIResultEvent result = model.rootToResult[infohash] + ViewCommentView view = new ViewCommentView(result, terminalSize) + textGUI.addWindowAndWait(view) } } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy new file mode 100644 index 00000000..801411bd --- /dev/null +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy @@ -0,0 +1,39 @@ +package com.muwire.clilanterna + +import com.googlecode.lanterna.TerminalSize +import com.googlecode.lanterna.gui2.BasicWindow +import com.googlecode.lanterna.gui2.Button +import com.googlecode.lanterna.gui2.GridLayout +import com.googlecode.lanterna.gui2.GridLayout.Alignment +import com.googlecode.lanterna.gui2.LayoutData +import com.googlecode.lanterna.gui2.Panel +import com.googlecode.lanterna.gui2.TextBox +import com.googlecode.lanterna.gui2.Window +import com.muwire.core.SharedFile +import com.muwire.core.search.UIResultEvent +import com.muwire.core.util.DataUtil + +import net.i2p.data.Base64 + +class ViewCommentView extends BasicWindow { + private final TextBox textBox + private final LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER) + + ViewCommentView(UIResultEvent result, TerminalSize terminalSize) { + super("View Comments For "+result.getName()) + + setHints([Window.Hint.CENTERED]) + + Panel contentPanel = new Panel() + contentPanel.setLayoutManager(new GridLayout(1)) + + TerminalSize boxSize = new TerminalSize((terminalSize.getColumns() / 2).toInteger(), (terminalSize.getRows() / 2).toInteger()) + textBox = new TextBox(boxSize, result.comment, TextBox.Style.MULTI_LINE) + contentPanel.addComponent(textBox, layoutData) + + Button closeButton = new Button("Close", {close()}) + contentPanel.addComponent(closeButton, layoutData) + + setComponent(contentPanel) + } +}