Skip to content

Commit

Permalink
#112: introduces a dedicated button to clear the log file
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Nov 6, 2022
1 parent 186ec2a commit 395be60
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
package app.logorrr.views.autoscroll

import app.logorrr.conf.LogoRRRGlobals
import app.logorrr.model.{LogEntry, LogIdAware}
import app.logorrr.util.JfxUtils
import javafx.collections.ObservableList
import javafx.scene.control.{CheckBox, ContextMenu, MenuItem, Tooltip}
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import org.kordamp.ikonli.javafx.FontIcon
import app.logorrr.model.LogIdAware
import javafx.scene.control.{CheckBox, Tooltip}

class ClearLogMenuItem(logEntries: ObservableList[LogEntry]) extends MenuItem("clear log") {
setOnAction(_ => {
logEntries.clear()
})
setGraphic(new FontIcon(FontAwesomeSolid.TRASH))
}

class AutoScrollCheckBox(val pathAsString: String
, logEntries: ObservableList[LogEntry]) extends CheckBox with LogIdAware {
class AutoScrollCheckBox(val pathAsString: String) extends CheckBox with LogIdAware {
setTooltip(new Tooltip("autoscroll"))
val cm = new ContextMenu(new ClearLogMenuItem(logEntries))
selectedProperty().bindBidirectional(LogoRRRGlobals.getLogFileSettings(pathAsString).autoScrollProperty)

selectedProperty().addListener(JfxUtils.onNew[java.lang.Boolean]({
selected =>
if (selected) {
if (Option(getContextMenu).isEmpty) {
setContextMenu(cm)
}
} else {
setContextMenu(null)
}
}))

}
16 changes: 16 additions & 0 deletions app/src/main/scala/app/logorrr/views/ops/ClearLogButton.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.logorrr.views.ops

import app.logorrr.model.LogEntry
import javafx.collections.ObservableList
import javafx.scene.control.{Button, Tooltip}
import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
import org.kordamp.ikonli.javafx.FontIcon

class ClearLogButton(logEntries: ObservableList[LogEntry]) extends Button {
private val icon = new FontIcon(FontAwesomeSolid.TRASH)
setGraphic(icon)
setTooltip(new Tooltip("clear log file"))
setOnAction(_ => {
logEntries.clear()
})
}
10 changes: 6 additions & 4 deletions app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.logorrr.model.LogEntry
import app.logorrr.util.OsUtil
import app.logorrr.views.autoscroll.AutoScrollCheckBox
import app.logorrr.views.block.HasBlockSizeProperty
import app.logorrr.views.ops.{DecreaseBlockSizeButton, IncreaseBlockSizeButton}
import app.logorrr.views.ops.{ClearLogButton, DecreaseBlockSizeButton, IncreaseBlockSizeButton}
import app.logorrr.views.text.{DecreaseTextSizeButton, IncreaseTextSizeButton}
import javafx.beans.property.SimpleIntegerProperty
import javafx.collections.ObservableList
Expand Down Expand Up @@ -44,7 +44,7 @@ class OpsToolBar(pathAsString: String
//setStyle(SearchToolBar.BackgroundSelectedStyle)
setStyle("""-fx-padding: 0px 0px 0px 4px;""")

val width = OsUtil.osFun(562, 560, 562) // different layouts (may be dependent on font size renderings?)
val width = OsUtil.osFun(602, 600, 602) // different layouts (may be dependent on font size renderings?)
setMaxWidth(width)
setMinWidth(width)

Expand All @@ -61,7 +61,9 @@ class OpsToolBar(pathAsString: String

private val searchButton = new SearchButton(searchTextField, regexToggleButton, colorPicker, addFilterFn)

val autoScrollCheckBox = new AutoScrollCheckBox(pathAsString, logEntries)
val autoScrollCheckBox = new AutoScrollCheckBox(pathAsString)

val clearLogButton = new ClearLogButton(logEntries)

val timerButton = new TimerButton(pathAsString, logEntries)

Expand All @@ -86,7 +88,7 @@ class OpsToolBar(pathAsString: String
}

val otherItems: Seq[Control] = {
Seq(autoScrollCheckBox, timerButton)
Seq(autoScrollCheckBox, clearLogButton, timerButton)
}

getItems.addAll(searchItems ++ sizeItems ++ otherItems: _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javafx.stage.{Modality, Stage}
import org.kordamp.ikonli.fontawesome5.FontAwesomeRegular
import org.kordamp.ikonli.javafx.FontIcon

case class TimerButton(pathAsString: String, logEntries: ObservableList[LogEntry])
class TimerButton(pathAsString: String, logEntries: ObservableList[LogEntry])
extends Button
with CanLog {
setGraphic(new FontIcon(FontAwesomeRegular.CLOCK))
Expand Down

0 comments on commit 395be60

Please sign in to comment.