Skip to content

Commit

Permalink
Merge pull request #191 from rladstaetter/178-textview-loses-selectio…
Browse files Browse the repository at this point in the history
…n-when-ignore-entries-abovebelow-is-applied

#178: fixes selection when applying context actions in textview
  • Loading branch information
rladstaetter authored Dec 26, 2023
2 parents 841af98 + 0d650e8 commit 0b74c1f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/src/main/scala/app/logorrr/views/ops/TextSizeButton.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 15 additions & 19 deletions app/src/main/scala/app/logorrr/views/text/LogTextView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -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)
Expand All @@ -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))
}
}
}





Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
})

}
Original file line number Diff line number Diff line change
@@ -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)
})

}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0b74c1f

Please sign in to comment.