Skip to content

Commit

Permalink
Merge pull request #196 from rladstaetter/189-context-menu-doesnt-sho…
Browse files Browse the repository at this point in the history
…w-up-if-only-one-log-file-is-opened

#189: fixes context menu for LogFileTab
  • Loading branch information
rladstaetter authored Dec 27, 2023
2 parents f7e40d1 + 269f988 commit 4dd5abc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
24 changes: 17 additions & 7 deletions app/src/main/scala/app/logorrr/views/logfiletab/LogFileTab.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ class LogFileTab(val mutLogFileSettings: MutLogFileSettings

}, s"Init '$pathAsString'")

def initContextMenu(): Unit = setContextMenu(mkContextMenu())



private def mkContextMenu(): ContextMenu = {
val openInFinderMenuItem = new OpenInFinderMenuItem(pathAsString)
val closeMenuItem = new CloseMenuItem(this)
val openInFinderMenuItem = new OpenInFinderMenuItem(pathAsString)

val closeOtherFilesMenuItem = new CloseOtherFilesMenuItem(this)
val closeAllFilesMenuItem = new CloseAllFilesMenuItem(this)

Expand All @@ -158,13 +162,19 @@ class LogFileTab(val mutLogFileSettings: MutLogFileSettings
Seq(new CloseLeftFilesMenuItem(this), new CloseRightFilesMenuItem(this))
}

val items = Seq(closeMenuItem
, closeOtherFilesMenuItem
, closeAllFilesMenuItem) ++ leftRightCloser ++ Seq(openInFinderMenuItem)

val menu = new ContextMenu()
menu.getItems.addAll(items: _*)
menu
val items = {
// special handling if there is only one tab
if (getTabPane.getTabs.size() == 1) {
Seq(closeMenuItem, openInFinderMenuItem)
} else {
Seq(closeMenuItem
, closeOtherFilesMenuItem
, closeAllFilesMenuItem) ++ leftRightCloser ++ Seq(openInFinderMenuItem)
}
}

new ContextMenu(items: _*)
}

private def addListeners(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CloseLeftFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Fil
}.toSeq
}
tabPane.getTabs.removeAll(toBeDeleted: _*)
// reinit context menu since there are no files left on the left side and thus the option should not be shown anymore
tabPane.getTabs.get(0).asInstanceOf[LogFileTab].initContextMenu()

})

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CloseOtherFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Ot
}.toSeq
}
tabPane.getTabs.removeAll(toBeDeleted: _*)
// reinit context menu since only one tab is left
tabPane.getTabs.get(0).asInstanceOf[LogFileTab].initContextMenu()
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CloseRightFilesMenuItem(fileTab: => LogFileTab) extends MenuItem("Close Fi
}.toSeq
}
tabPane.getTabs.removeAll(toBeDeleted: _*)
// reinit context menu since there are no files left on the right side and thus the option should not be shown anymore
tabPane.getTabs.get(tabPane.getTabs.size() -1).asInstanceOf[LogFileTab].initContextMenu()

})

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class MainTabPane extends TabPane with CanLog {
def addLogFileTab(tab: LogFileTab): Unit = {
tab.init()
getTabs.add(tab)
tab.initContextMenu()
}

}

0 comments on commit 4dd5abc

Please sign in to comment.