diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/LogFileTab.scala b/app/src/main/scala/app/logorrr/views/logfiletab/LogFileTab.scala index 67b04c9f..38dae498 100644 --- a/app/src/main/scala/app/logorrr/views/logfiletab/LogFileTab.scala +++ b/app/src/main/scala/app/logorrr/views/logfiletab/LogFileTab.scala @@ -7,6 +7,7 @@ import app.logorrr.model.LogEntry import app.logorrr.util._ import app.logorrr.views.LogoRRRAccelerators import app.logorrr.views.autoscroll.LogTailer +import app.logorrr.views.logfiletab.actions.{CloseAllFilesMenuItem, CloseLeftFilesMenuItem, CloseMenuItem, CloseOtherFilesMenuItem, CloseRightFilesMenuItem, OpenInFinderMenuItem} import app.logorrr.views.search.Fltr import javafx.beans.binding.Bindings import javafx.collections.{ListChangeListener, ObservableList} @@ -114,7 +115,7 @@ class LogFileTab(val mutLogFileSettings: MutLogFileSettings logFileTabContent.init() /** don't monitor file anymore if tab is closed, free listeners */ - setOnCloseRequest((_: Event) => cleanupBeforeClose()) + setOnCloseRequest((_: Event) => shutdown()) if (mutLogFileSettings.isAutoScrollActive) { startTailer() @@ -166,11 +167,6 @@ class LogFileTab(val mutLogFileSettings: MutLogFileSettings menu } - def cleanupBeforeClose(): Unit = { - shutdown() - LogoRRRGlobals.removeLogFile(pathAsString) - } - private def addListeners(): Unit = { selectedProperty().addListener(selectedListener) @@ -195,6 +191,7 @@ class LogFileTab(val mutLogFileSettings: MutLogFileSettings stopTailer() } removeListeners() + LogoRRRGlobals.removeLogFile(pathAsString) } diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/OpenInFinderMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/OpenInFinderMenuItem.scala deleted file mode 100644 index 3bf64483..00000000 --- a/app/src/main/scala/app/logorrr/views/logfiletab/OpenInFinderMenuItem.scala +++ /dev/null @@ -1,112 +0,0 @@ -package app.logorrr.views.logfiletab - -import app.logorrr.util.OsUtil -import javafx.scene.control.{MenuItem, Tab} - -import java.awt.Desktop -import java.nio.file.Paths -import scala.collection.immutable.Seq -import scala.jdk.CollectionConverters.CollectionHasAsScala - -class OpenInFinderMenuItem(pathAsString: String) extends MenuItem(if (OsUtil.isWin) { - "Show Log in Explorer" -} else if (OsUtil.isMac) { - "Show Log in Finder" -} else { - "Show Log ..." -}) { - - setOnAction(_ => Desktop.getDesktop.open(Paths.get(pathAsString).getParent.toFile)) - -} - -class CloseMenuItem(fileTab: => LogFileTab) extends MenuItem("Close") { - - setOnAction(_ => Option(fileTab.getTabPane.getSelectionModel.getSelectedItem).foreach { t => - fileTab.cleanupBeforeClose() - fileTab.getTabPane.getTabs.remove(t) - }) - -} - -class CloseOtherFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Other Files") { - val tabPane = fileTab.getTabPane - setOnAction(_ => { - val toBeDeleted: Seq[Tab] = { - tabPane.getTabs.asScala.flatMap { t => - if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { - None - } else { - t.asInstanceOf[LogFileTab].cleanupBeforeClose() - Option(t) - } - }.toSeq - } - tabPane.getTabs.removeAll(toBeDeleted: _*) - }) - -} - -class CloseAllFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close All Files") { - val tabPane = fileTab.getTabPane - setOnAction(_ => { - val toBeDeleted: Seq[Tab] = { - tabPane.getTabs.asScala.flatMap { t => - t.asInstanceOf[LogFileTab].cleanupBeforeClose() - Option(t) - }.toSeq - } - tabPane.getTabs.removeAll(toBeDeleted: _*) - }) - -} - - -class CloseLeftFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Files to the Left") { - val tabPane = fileTab.getTabPane - setOnAction(_ => { - var deletethem = true - val toBeDeleted: Seq[Tab] = { - tabPane.getTabs.asScala.flatMap { t => - if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { - deletethem = false - None - } else { - if (deletethem) { - t.asInstanceOf[LogFileTab].cleanupBeforeClose() - Option(t) - } else { - None - } - } - }.toSeq - } - tabPane.getTabs.removeAll(toBeDeleted: _*) - }) - -} - - -class CloseRightFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Files to the Right") { - val tabPane = fileTab.getTabPane - setOnAction(_ => { - var deletethem = false - val toBeDeleted: Seq[Tab] = { - tabPane.getTabs.asScala.flatMap { t => - if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { - deletethem = true - None - } else { - if (deletethem) { - t.asInstanceOf[LogFileTab].cleanupBeforeClose() - Option(t) - } else { - None - } - } - }.toSeq - } - tabPane.getTabs.removeAll(toBeDeleted: _*) - }) - -} \ No newline at end of file diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseAllFilesMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseAllFilesMenuItem.scala new file mode 100644 index 00000000..44b8743c --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseAllFilesMenuItem.scala @@ -0,0 +1,20 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.views.logfiletab.LogFileTab +import javafx.scene.control.{MenuItem, Tab} + +import scala.jdk.CollectionConverters.CollectionHasAsScala + +class CloseAllFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close All Files") { + private val tabPane = fileTab.getTabPane + setOnAction(_ => { + val toBeDeleted: Seq[Tab] = { + tabPane.getTabs.asScala.flatMap { t => + t.asInstanceOf[LogFileTab].shutdown() + Option(t) + }.toSeq + } + tabPane.getTabs.removeAll(toBeDeleted: _*) + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseLeftFilesMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseLeftFilesMenuItem.scala new file mode 100644 index 00000000..db22019b --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseLeftFilesMenuItem.scala @@ -0,0 +1,30 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.views.logfiletab.LogFileTab +import javafx.scene.control.{MenuItem, Tab} + +import scala.jdk.CollectionConverters.CollectionHasAsScala + +class CloseLeftFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Files to the Left") { + private val tabPane = fileTab.getTabPane + setOnAction(_ => { + var deletethem = true + val toBeDeleted: Seq[Tab] = { + tabPane.getTabs.asScala.flatMap { t => + if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { + deletethem = false + None + } else { + if (deletethem) { + t.asInstanceOf[LogFileTab].shutdown() + Option(t) + } else { + None + } + } + }.toSeq + } + tabPane.getTabs.removeAll(toBeDeleted: _*) + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseMenuItem.scala new file mode 100644 index 00000000..a9657e21 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseMenuItem.scala @@ -0,0 +1,13 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.views.logfiletab.LogFileTab +import javafx.scene.control.MenuItem + +class CloseMenuItem(fileTab: => LogFileTab) extends MenuItem("Close") { + + setOnAction(_ => Option(fileTab.getTabPane.getSelectionModel.getSelectedItem).foreach { t => + fileTab.shutdown() + fileTab.getTabPane.getTabs.remove(t) + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseOtherFilesMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseOtherFilesMenuItem.scala new file mode 100644 index 00000000..89bea868 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseOtherFilesMenuItem.scala @@ -0,0 +1,24 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.views.logfiletab.LogFileTab +import javafx.scene.control.{MenuItem, Tab} + +import scala.jdk.CollectionConverters.CollectionHasAsScala + +class CloseOtherFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Other Files") { + private val tabPane = fileTab.getTabPane + setOnAction(_ => { + val toBeDeleted: Seq[Tab] = { + tabPane.getTabs.asScala.flatMap { t => + if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { + None + } else { + t.asInstanceOf[LogFileTab].shutdown() + Option(t) + } + }.toSeq + } + tabPane.getTabs.removeAll(toBeDeleted: _*) + }) + +} diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseRightFilesMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseRightFilesMenuItem.scala new file mode 100644 index 00000000..53b7c127 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/CloseRightFilesMenuItem.scala @@ -0,0 +1,31 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.views.logfiletab.LogFileTab +import javafx.scene.control.{MenuItem, Tab} + +import scala.jdk.CollectionConverters.CollectionHasAsScala + + +class CloseRightFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Files to the Right") { + private val tabPane = fileTab.getTabPane + setOnAction(_ => { + var deletethem = false + val toBeDeleted: Seq[Tab] = { + tabPane.getTabs.asScala.flatMap { t => + if (t.asInstanceOf[LogFileTab].pathAsString == fileTab.pathAsString) { + deletethem = true + None + } else { + if (deletethem) { + t.asInstanceOf[LogFileTab].shutdown() + Option(t) + } else { + None + } + } + }.toSeq + } + tabPane.getTabs.removeAll(toBeDeleted: _*) + }) + +} \ No newline at end of file diff --git a/app/src/main/scala/app/logorrr/views/logfiletab/actions/OpenInFinderMenuItem.scala b/app/src/main/scala/app/logorrr/views/logfiletab/actions/OpenInFinderMenuItem.scala new file mode 100644 index 00000000..3032a224 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/logfiletab/actions/OpenInFinderMenuItem.scala @@ -0,0 +1,23 @@ +package app.logorrr.views.logfiletab.actions + +import app.logorrr.util.OsUtil +import javafx.scene.control.MenuItem + +import java.awt.Desktop +import java.nio.file.Paths + +object OpenInFinderMenuItem { + val menuItemText: String = if (OsUtil.isWin) { + "Show Log in Explorer" + } else if (OsUtil.isMac) { + "Show Log in Finder" + } else { + "Show Log ..." + } +} + +class OpenInFinderMenuItem(pathAsString: String) extends MenuItem(OpenInFinderMenuItem.menuItemText) { + + setOnAction(_ => Desktop.getDesktop.open(Paths.get(pathAsString).getParent.toFile)) + +} diff --git a/app/src/main/scala/app/logorrr/views/main/MainTabPane.scala b/app/src/main/scala/app/logorrr/views/main/MainTabPane.scala index 93887389..e4085370 100644 --- a/app/src/main/scala/app/logorrr/views/main/MainTabPane.scala +++ b/app/src/main/scala/app/logorrr/views/main/MainTabPane.scala @@ -42,7 +42,6 @@ class MainTabPane extends TabPane with CanLog { initDnD() } - /** * Defines what should happen when a tab is selected * */ @@ -62,10 +61,7 @@ class MainTabPane extends TabPane with CanLog { /** shutdown all tabs */ def shutdown(): Unit = { getSelectionModel.selectedItemProperty().removeListener(selectedTabListener) - getLogFileTabs.foreach(t => { - t.shutdown() - LogoRRRGlobals.removeLogFile(t.pathAsString) - }) + getLogFileTabs.foreach(_.shutdown()) getTabs.clear() }