Skip to content

Commit

Permalink
Fixed: ShowMessage dialogs may display cropped messages #31
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsacha committed Apr 4, 2024
1 parent c0fdec6 commit 3eefe11
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions scalafx-extras/src/main/scala/org/scalafx/extras/ShowMessage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,21 @@ trait ShowMessage {
* @param header header text.
* @param content main content text.
*/
def showError(title: String, header: String, content: String = ""): Unit = {
def showError(title: String, header: String, content: String = "", resizable: Boolean = false): Unit = {
messageLogger.foreach(_.error(s"<$title> $header $content"))
// Rename to avoid name clashes
val dialogTitle = title
val _title = title
val _resizable = resizable

onFXAndWait {
new Alert(AlertType.Error) {
initOwner(parentWindow.orNull)
this.title = dialogTitle
this.title = _title
headerText = header
contentText = content
this.resizable = _resizable
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
}.showAndWait()
}
}
Expand All @@ -248,18 +252,18 @@ trait ShowMessage {
def showInformation(title: String, header: String, content: String, resizable: Boolean = false): Unit = {
// messageLogger.info(s"<$title> $header $content")
// Rename to avoid name clashes
val dialogTitle = title

val _title = title
val _resizable = resizable

onFXAndWait {
new Alert(AlertType.Information) {
initOwner(parentWindow.orNull)
this.title = dialogTitle
this.title = _title
headerText = header
contentText = content
this.resizable = _resizable
dialogPane().minHeight(Region.USE_PREF_SIZE)
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
}.showAndWait()
}
}
Expand All @@ -271,17 +275,21 @@ trait ShowMessage {
* @param header header text.
* @param content main content text.
*/
def showWarning(title: String, header: String, content: String): Unit = {
def showWarning(title: String, header: String, content: String, resizable: Boolean = false): Unit = {
messageLogger.foreach(_.warn(s"<$title> $header $content"))
// Rename to avoid name clashes
val dialogTitle = title
val _title = title
val _resizable = resizable

onFXAndWait {
new Alert(AlertType.Warning) {
initOwner(parentWindow.orNull)
this.title = dialogTitle
this.title = _title
headerText = header
contentText = content
this.resizable = _resizable
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
}.showAndWait()
}
}
Expand All @@ -294,16 +302,20 @@ trait ShowMessage {
* @param content content text.
* @return `true` when user selected 'OK' and `false` when user selected `Cancel` or dismissed the dialog.
*/
def showConfirmation(title: String, header: String, content: String = ""): Boolean = {
def showConfirmation(title: String, header: String, content: String = "", resizable: Boolean = false): Boolean = {
// Rename to avoid name clashes
val dialogTitle = title
val _title = title
val _resizable = resizable

val result = onFXAndWait {
new Alert(AlertType.Confirmation) {
initOwner(parentWindow.orNull)
this.title = dialogTitle
this.title = _title
headerText = header
contentText = content
this.resizable = _resizable
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
}.showAndWait()
}
result match {
Expand All @@ -321,16 +333,25 @@ trait ShowMessage {
* @return `Some(true)` when user selected 'OK', `Some(false)` when user selected `No`,
* and `None` user selected `Cancel` or dismissed the dialog.
*/
def showConfirmationYesNoCancel(title: String, header: String, content: String = ""): Option[Boolean] = {
def showConfirmationYesNoCancel(
title: String,
header: String,
content: String = "",
resizable: Boolean = false
): Option[Boolean] = {
// Rename to avoid name clashes
val dialogTitle = title
val _title = title
val _resizable = resizable

val result = onFXAndWait {
new Alert(AlertType.Confirmation) {
initOwner(parentWindow.orNull)
this.title = dialogTitle
this.title = _title
headerText = header
contentText = content
this.resizable = _resizable
dialogPane().setMinWidth(Region.USE_PREF_SIZE)
dialogPane().setMinHeight(Region.USE_PREF_SIZE)
buttonTypes = Seq(ButtonType.OK, ButtonType.No, ButtonType.Cancel)
}.showAndWait()
}
Expand Down

0 comments on commit 3eefe11

Please sign in to comment.