Skip to content

Commit

Permalink
Add export and copy result buttons (#3193)
Browse files Browse the repository at this point in the history
* Bring back export result button

* Add export and copy result buttons
  • Loading branch information
benthecarman committed May 29, 2021
1 parent 46b33ec commit 5580771
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPane.scala
Expand Up @@ -5,6 +5,14 @@ import org.bitcoins.gui.TaskRunner
import scalafx.geometry.{Insets, Pos}
import scalafx.scene.control._
import scalafx.scene.layout._
import scalafx.stage.FileChooser
import scalafx.stage.FileChooser.ExtensionFilter

import java.awt.Toolkit.getDefaultToolkit
import java.awt.datatransfer.StringSelection
import java.io.File
import java.nio.file.Files
import scala.util.Properties

class DLCPane(glassPane: VBox) {

Expand Down Expand Up @@ -103,10 +111,38 @@ class DLCPane(glassPane: VBox) {
spacing = 10
}

val exportResultButton: Button = new Button("Export Result") {
onAction = _ => {
val txtExtensionFilter = new ExtensionFilter("Text Files", "*.txt")
val allExtensionFilter = new ExtensionFilter("All Files", "*")
val fileChooser = new FileChooser() {
extensionFilters.addAll(txtExtensionFilter, allExtensionFilter)
selectedExtensionFilter = txtExtensionFilter
initialDirectory = new File(Properties.userHome)
}
val chosenFile = fileChooser.showSaveDialog(null)
Files.write(chosenFile.toPath, resultTextArea.text.value.getBytes)
()
}
}

val copyResultButton: Button = new Button("Copy Result") {
onAction = _ => {
val clipboard = getDefaultToolkit.getSystemClipboard
val sel = new StringSelection(resultTextArea.text.value)
clipboard.setContents(sel, sel)
}
}

val resultButtonHBox: HBox = new HBox() {
spacing = 10
children = Vector(exportResultButton, copyResultButton)
}

private val tableView = new DLCTableView(model).tableView

private val textAreasAndTableViewVBox = new VBox {
children = Seq(textAreaHBox, tableView)
children = Seq(textAreaHBox, resultButtonHBox, tableView)
spacing = 10
}

Expand Down

0 comments on commit 5580771

Please sign in to comment.