Skip to content

Commit

Permalink
#147: fixes broken tab selection on when loading files
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Sep 29, 2023
1 parent 4ac47c8 commit 482f448
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/app/logorrr/io/FileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object FileManager extends CanLog {
private def openFileWithDetectedEncoding(path: Path): BufferedReader = {
val encoding = FEncoding(path)
if (encoding == Unknown) {
logWarn(encoding.asString + " encoding - fallback to UTF-8")
logTrace(encoding.asString + " encoding - fallback to UTF-8")
new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile), UTF8.asString))
} else {
new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile), encoding.asString))
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/scala/app/logorrr/conf/LogoRRRGlobals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ object LogoRRRGlobals extends CanLog {
private val hostServicesProperty = new SimpleObjectProperty[HostServices]()

def persist(): Unit = {
Fs.write(FilePaths.settingsFilePath, ConfigWriter[Settings].to(LogoRRRGlobals.getSettings()).render(renderOptions))
Fs.write(FilePaths.settingsFilePath, ConfigWriter[Settings].to(LogoRRRGlobals.getSettings).render(renderOptions))
}

def getOrderedLogFileSettings: Seq[LogFileSettings] = mutSettings.getOrderedLogFileSettings()

def bindWindow(window: Window): Unit = {
window.setX(LogoRRRGlobals.getStageX())
window.setY(LogoRRRGlobals.getStageY())
window.setWidth(LogoRRRGlobals.getStageWidth())
window.setHeight(LogoRRRGlobals.getStageHeight())
window.setX(LogoRRRGlobals.getStageX)
window.setY(LogoRRRGlobals.getStageY)
window.setWidth(LogoRRRGlobals.getStageWidth)
window.setHeight(LogoRRRGlobals.getStageHeight)

mutSettings.bindWindowProperties(window)
}

def unbindWindow(): Unit = mutSettings.unbindWindow()

def getStageWidth(): Int = mutSettings.getStageWidth()
def getStageWidth: Int = mutSettings.getStageWidth()

def getStageHeight(): Int = mutSettings.getStageHeight()
def getStageHeight: Int = mutSettings.getStageHeight()

def getStageX(): Double = mutSettings.getStageX()
def getStageX: Double = mutSettings.getStageX()

def getStageY(): Double = mutSettings.getStageY()
def getStageY: Double = mutSettings.getStageY()

def setHostServices(hostServices: HostServices): Unit = hostServicesProperty.set(hostServices)

Expand All @@ -56,11 +56,11 @@ object LogoRRRGlobals extends CanLog {
setHostServices(hostServices)
}

def getSettings(): Settings = mutSettings.petrify()
def getSettings: Settings = mutSettings.petrify()

def setSomeActive(sActive: Option[String]): Unit = mutSettings.setSomeActive(sActive)

def getSomeActive(): Option[String] = mutSettings.getSomeActive()
def getSomeActive: Option[String] = mutSettings.getSomeActive()

def removeLogFile(pathAsString: String): Unit = {

Expand Down
44 changes: 31 additions & 13 deletions app/src/main/scala/app/logorrr/views/main/LogoRRRMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,42 @@ class LogoRRRMain(closeStage: => Unit)
}

private def loadLogFiles(logs: Seq[LogFileSettings]): Unit = {
Future.sequence {
val futures: Future[Seq[(String, ObservableList[LogEntry])]] = Future.sequence {
logInfo(s"Loading ${logs.length} log files: " + logs.map(_.pathAsString).mkString("['", "',`'", "']"))
logs.filter(s => !ambp.contains(s.pathAsString)).map(s => Future((s.pathAsString, s.readEntries())))
}.onComplete({
}
futures.onComplete({
case Success(lfs: Seq[(String, ObservableList[LogEntry])]) =>
lfs.foreach({
case (pathAsString, es) => JfxUtils.execOnUiThread({
logTrace(s"Loading `$pathAsString` with ${es.size()} entries.")
ambp.addLogFileTab(LogFileTab(pathAsString, es))
LogoRRRGlobals.getSomeActive() match {
case Some(value) if pathAsString == value =>
selectLog(value)
case _ =>
}
JfxUtils.execOnUiThread({
lfs.foreach({
case (pathAsString, es) =>
logTrace(s"Loading `$pathAsString` with ${es.size()} entries.")
ambp.addLogFileTab(LogFileTab(pathAsString, es))
})
// after loading everything, set active log like specified in the config file
LogoRRRGlobals.getSomeActive match {
case Some(selectedPath) =>
logTrace(s"Active Path: $selectedPath")
lfs.map(_._1).zipWithIndex.find(tpl => tpl._1 == selectedPath) match {
case Some((path, index)) =>
selectLog(path)
case None =>
logWarn("not found removing active entry")
LogoRRRGlobals.setSomeActive(None)
}
case None => logTrace("No active path entry found")
}
// only after loading all files we initialize the 'add' listener
// otherwise we would overwrite the active log everytime
ambp.logViewTabPane.initLogFileAddListener()
})
case Failure(exception) =>
logException("Could not load logfiles", exception)
})
// init listener also in error case
ambp.logViewTabPane.initLogFileAddListener()
}

)
}

/** called when 'Open File' is selected. */
Expand All @@ -65,7 +82,8 @@ class LogoRRRMain(closeStage: => Unit)
if (!ambp.contains(pathAsString)) {
ambp.addLogFile(path)
} else {
logTrace("File is already opened.")
logTrace(s"$pathAsString is already opened, selecting tab ...")
ambp.selectLog(pathAsString)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class LogoRRRMainBorderPane extends BorderPane with CanLog {
}
})

logViewTabPane.init()
}


Expand All @@ -49,7 +48,8 @@ class LogoRRRMainBorderPane extends BorderPane with CanLog {
if (!contains(pathAsString)) {
addLogFile(path)
} else {
logWarn(s"$pathAsString is already opened ...")
logTrace(s"$pathAsString is already opened, selecting tab ...")
selectLog(pathAsString)
}
} else {
logWarn(s"$pathAsString does not exist.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LogoRRRMainTabPane()
/**
* Defines what should happen when a tab is selected
* */
def init(): Unit = {
def initLogFileAddListener(): Unit = {
getSelectionModel.selectedItemProperty().addListener(JfxUtils.onNew {
t1: Tab =>
t1 match {
Expand Down Expand Up @@ -69,10 +69,10 @@ class LogoRRRMainTabPane()
def selectLog(pathAsString: String): Unit = {
getLogFileTabs.find(_.pathAsString == pathAsString) match {
case Some(value) =>
logTrace(s"Selects tab view with path ${pathAsString}.")
logTrace(s"Selects tab view with path $pathAsString.")
getSelectionModel.select(value)
case None =>
logWarn(s"Couldn't find tab with ${pathAsString}, selecting last tab ...")
logWarn(s"Couldn't find tab with $pathAsString, selecting last tab ...")
selectLastLogFile()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object LogoRRRScene {
*/
def mkSceneListener(): ChangeListener[Scene] =
JfxUtils.onNew[Scene](scene => {
val (x, y) = (LogoRRRGlobals.getStageX(), LogoRRRGlobals.getStageY())
val (x, y) = (LogoRRRGlobals.getStageX, LogoRRRGlobals.getStageY)
scene.getWindow.setX(x)
scene.getWindow.setY(y)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ case class LogoRRRStage(stage: Stage) extends CanLog {

private val logorrrMain = new LogoRRRMain(JfxUtils.closeStage(stage))

val (width, height) = (LogoRRRGlobals.getStageWidth(), LogoRRRGlobals.getStageHeight())
val (width, height) = (LogoRRRGlobals.getStageWidth, LogoRRRGlobals.getStageHeight)

val scene = new Scene(logorrrMain, width, height)

Expand Down

0 comments on commit 482f448

Please sign in to comment.