From 0d650e8be4933b4a6b4a676aa8d5651cd81b909e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Ladst=C3=A4tter?= Date: Tue, 26 Dec 2023 14:58:27 +0100 Subject: [PATCH] #178: fixes selection when applying context actions in textview --- .../logorrr/views/ops/TextSizeButton.scala | 4 +-- .../app/logorrr/views/search/OpsToolBar.scala | 3 +- .../app/logorrr/views/text/LogTextView.scala | 34 ++++++++----------- .../app/logorrr/views/text/LogoRRRLabel.scala | 2 +- .../contextactions/IgnoreAboveMenuItem.scala | 30 ++++++++++++++++ .../contextactions/IgnoreBelowMenuItem.scala | 23 +++++++++++++ .../DecreaseTextSizeButton.scala | 2 +- .../IncreaseTextSizeButton.scala | 2 +- 8 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreAboveMenuItem.scala create mode 100644 app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreBelowMenuItem.scala rename app/src/main/scala/app/logorrr/views/text/{ => toolbaractions}/DecreaseTextSizeButton.scala (88%) rename app/src/main/scala/app/logorrr/views/text/{ => toolbaractions}/IncreaseTextSizeButton.scala (91%) diff --git a/app/src/main/scala/app/logorrr/views/ops/TextSizeButton.scala b/app/src/main/scala/app/logorrr/views/ops/TextSizeButton.scala index df10b53b..c27d40f4 100644 --- a/app/src/main/scala/app/logorrr/views/ops/TextSizeButton.scala +++ b/app/src/main/scala/app/logorrr/views/ops/TextSizeButton.scala @@ -6,12 +6,12 @@ import javafx.scene.control.{Button, Label, Tooltip} import javafx.scene.input.{KeyCode, KeyEvent} import javafx.scene.paint.Color -abstract class TextSizeButton(size: Int, tooltipMessage: String) +abstract class TextSizeButton(fontSize: Int, tooltipMessage: String) extends Button with HasFontSizeProperty { private val label = new Label("T") - label.setStyle(LogoRRRFonts.jetBrainsMono(size)) + label.setStyle(LogoRRRFonts.jetBrainsMono(fontSize)) label.setTextFill(Color.DARKGREY) setGraphic(label) setTooltip(new Tooltip(tooltipMessage)) diff --git a/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala b/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala index 8553bb63..2194c7d8 100644 --- a/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala +++ b/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala @@ -5,8 +5,7 @@ import app.logorrr.util.OsUtil import app.logorrr.views.autoscroll.AutoScrollCheckBox import app.logorrr.views.block.HasBlockSizeProperty import app.logorrr.views.ops.{ClearLogButton, CopyLogButton, DecreaseBlockSizeButton, IncreaseBlockSizeButton} -import app.logorrr.views.settings.timer.TimerSettingsLogView -import app.logorrr.views.text.{DecreaseTextSizeButton, IncreaseTextSizeButton} +import app.logorrr.views.text.toolbaractions.{DecreaseTextSizeButton, IncreaseTextSizeButton} import javafx.beans.property.SimpleIntegerProperty import javafx.collections.ObservableList import javafx.collections.transformation.FilteredList diff --git a/app/src/main/scala/app/logorrr/views/text/LogTextView.scala b/app/src/main/scala/app/logorrr/views/text/LogTextView.scala index 9ceaf1c1..d5be3bd8 100644 --- a/app/src/main/scala/app/logorrr/views/text/LogTextView.scala +++ b/app/src/main/scala/app/logorrr/views/text/LogTextView.scala @@ -3,6 +3,7 @@ package app.logorrr.views.text import app.logorrr.conf.mut.MutLogFileSettings import app.logorrr.model.LogEntry import app.logorrr.util.{CanLog, JfxUtils} +import app.logorrr.views.text.contextactions.{IgnoreAboveMenuItem, IgnoreBelowMenuItem} import javafx.collections.transformation.FilteredList import javafx.scene.control._ @@ -61,23 +62,18 @@ class LogTextView(mutLogFileSettings: MutLogFileSettings })) } - /** 'pragmatic way' to determine width of max elems in this view */ + /** determine width of max elems in this view */ def maxLength: Int = filteredList.size().toString.length class LogEntryListCell extends ListCell[LogEntry] { styleProperty().bind(mutLogFileSettings.fontStyleBinding) setGraphic(null) - val ignoreAbove = new MenuItem("Ignore entries above") - val ignoreBelow = new MenuItem("Ignore entries below") - val cm = new ContextMenu(ignoreAbove, ignoreBelow) - override def updateItem(t: LogEntry, b: Boolean): Unit = { super.updateItem(t, b) Option(t) match { - case Some(e) => - calculateLabel(e) + case Some(e) => calculateLabel(e) case None => setGraphic(null) setContextMenu(null) @@ -90,21 +86,21 @@ class LogTextView(mutLogFileSettings: MutLogFileSettings , mutLogFileSettings.filtersProperty.get().asScala.toSeq , mutLogFileSettings.fontStyleBinding , mutLogFileSettings.fontSizeProperty) + setGraphic(entry) - ignoreAbove.setOnAction(_ => { - val currPredicate = filteredList.getPredicate - filteredList.setPredicate((entry: LogEntry) => currPredicate.test(entry) && e.lineNumber <= entry.lineNumber) - logTrace("Ignoring all entries prior to line number " + e.lineNumber) - }) - ignoreBelow.setOnAction(_ => { - val currPredicate = filteredList.getPredicate - filteredList.setPredicate((entry: LogEntry) => currPredicate.test(entry) && entry.lineNumber <= e.lineNumber) - logTrace("Ignoring all entries after line number " + e.lineNumber) - }) - - setContextMenu(cm) + + val ignoreAboveMenuItem = new IgnoreAboveMenuItem(mutLogFileSettings + , e + , filteredList + , scrollToActiveLogEntry) + val ignoreBelowMenuItem = new IgnoreBelowMenuItem(e, filteredList) + + setContextMenu(new ContextMenu(ignoreAboveMenuItem, ignoreBelowMenuItem)) } } } + + + diff --git a/app/src/main/scala/app/logorrr/views/text/LogoRRRLabel.scala b/app/src/main/scala/app/logorrr/views/text/LogoRRRLabel.scala index 7747d97f..d6f4a2ed 100644 --- a/app/src/main/scala/app/logorrr/views/text/LogoRRRLabel.scala +++ b/app/src/main/scala/app/logorrr/views/text/LogoRRRLabel.scala @@ -8,7 +8,7 @@ import javafx.scene.paint.Color object LogoRRRLabel { - def mkBg(color: Color) = new Background(new BackgroundFill(color, new CornerRadii(1.25), Insets.EMPTY)) + private def mkBg(color: Color) = new Background(new BackgroundFill(color, new CornerRadii(1.25), Insets.EMPTY)) def mkL(msg: String, color: Color): Label = { val l = new Label(msg) diff --git a/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreAboveMenuItem.scala b/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreAboveMenuItem.scala new file mode 100644 index 00000000..28675033 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreAboveMenuItem.scala @@ -0,0 +1,30 @@ +package app.logorrr.views.text.contextactions + +import app.logorrr.conf.mut.MutLogFileSettings +import app.logorrr.model.LogEntry +import app.logorrr.util.CanLog +import javafx.collections.transformation.FilteredList +import javafx.scene.control.MenuItem + +/** + * Filters out all entries before the given current log entry and updates the current position. + * + * This filter will be reset if any other filter is changed in the filters menu bar. + * + * @param mutLogFileSettings reference to global settings + * @param currentEntry current entry + * @param filteredList filtered list + * @param scrollToActiveLogEntry function to scroll to current active log entry + */ +class IgnoreAboveMenuItem(mutLogFileSettings: MutLogFileSettings + , currentEntry: LogEntry + , filteredList: FilteredList[LogEntry] + , scrollToActiveLogEntry: () => Unit) extends MenuItem("Ignore entries above") with CanLog { + setOnAction(_ => { + val currPredicate = filteredList.getPredicate + filteredList.setPredicate((entry: LogEntry) => currPredicate.test(entry) && currentEntry.lineNumber <= entry.lineNumber) + mutLogFileSettings.setSelectedLineNumber(currentEntry.lineNumber) + scrollToActiveLogEntry() + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreBelowMenuItem.scala b/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreBelowMenuItem.scala new file mode 100644 index 00000000..a0493428 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/text/contextactions/IgnoreBelowMenuItem.scala @@ -0,0 +1,23 @@ +package app.logorrr.views.text.contextactions + +import app.logorrr.model.LogEntry +import app.logorrr.util.CanLog +import javafx.collections.transformation.FilteredList +import javafx.scene.control.MenuItem + +/** + * Cuts away all entries following the current log entry. + * + * Selected log entry stays the same, also no change to current position (compare this to the IgnoreAbove action) + * + * @param currentEntry current selected log entry + * @param filteredList filtered log entry list + */ +class IgnoreBelowMenuItem(currentEntry: LogEntry, filteredList: FilteredList[LogEntry]) extends MenuItem("Ignore entries below") with CanLog { + + setOnAction(_ => { + val currPredicate = filteredList.getPredicate + filteredList.setPredicate((entry: LogEntry) => currPredicate.test(entry) && entry.lineNumber <= currentEntry.lineNumber) + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/text/DecreaseTextSizeButton.scala b/app/src/main/scala/app/logorrr/views/text/toolbaractions/DecreaseTextSizeButton.scala similarity index 88% rename from app/src/main/scala/app/logorrr/views/text/DecreaseTextSizeButton.scala rename to app/src/main/scala/app/logorrr/views/text/toolbaractions/DecreaseTextSizeButton.scala index 4eea8794..a6f4f823 100644 --- a/app/src/main/scala/app/logorrr/views/text/DecreaseTextSizeButton.scala +++ b/app/src/main/scala/app/logorrr/views/text/toolbaractions/DecreaseTextSizeButton.scala @@ -1,4 +1,4 @@ -package app.logorrr.views.text +package app.logorrr.views.text.toolbaractions import app.logorrr.views.ops.TextSizeButton import app.logorrr.views.search.OpsToolBar diff --git a/app/src/main/scala/app/logorrr/views/text/IncreaseTextSizeButton.scala b/app/src/main/scala/app/logorrr/views/text/toolbaractions/IncreaseTextSizeButton.scala similarity index 91% rename from app/src/main/scala/app/logorrr/views/text/IncreaseTextSizeButton.scala rename to app/src/main/scala/app/logorrr/views/text/toolbaractions/IncreaseTextSizeButton.scala index 6c17c00b..1bc2c923 100644 --- a/app/src/main/scala/app/logorrr/views/text/IncreaseTextSizeButton.scala +++ b/app/src/main/scala/app/logorrr/views/text/toolbaractions/IncreaseTextSizeButton.scala @@ -1,4 +1,4 @@ -package app.logorrr.views.text +package app.logorrr.views.text.toolbaractions import app.logorrr.views.ops.TextSizeButton import app.logorrr.views.search.OpsToolBar