Skip to content

Commit

Permalink
UI: Title updates with project change
Browse files Browse the repository at this point in the history
Cannot get the icon to update yet, however
Tested on Windows
See #235
  • Loading branch information
Hector committed Aug 7, 2018
1 parent eabfd32 commit 0ac59e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Binary file not shown.
38 changes: 29 additions & 9 deletions scala/src/main/scala/quanto/gui/QuantoDerive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ExecutionContext.Implicits.global
import java.awt.{Color, Desktop, Window}
import java.lang.NullPointerException

import javax.imageio.ImageIO
import javax.swing.filechooser.FileNameExtensionFilter
import quanto.gui.QuantoDerive.FileMenu.mnemonic
import quanto.util._
Expand Down Expand Up @@ -132,7 +133,7 @@ object QuantoDerive extends SimpleSwingApplication {
unloadProject()
None
} finally {
refreshAllMenus()
refreshAllMenusAndTitle()
}
}

Expand Down Expand Up @@ -555,7 +556,7 @@ object QuantoDerive extends SimpleSwingApplication {
Project.toJson(proj).writeTo(projectFile)
loadProject(projectFile.getAbsolutePath)
//core ! SetMLWorkingDir(rootFolder)
refreshAllMenus()
refreshAllMenusAndTitle()
}
case None =>
}
Expand Down Expand Up @@ -584,7 +585,7 @@ object QuantoDerive extends SimpleSwingApplication {
error("Unexpected error when opening project")
e.printStackTrace()
} finally {
refreshAllMenus()
refreshAllMenusAndTitle()
}
} else {
error(s"Folder does not contain a Quantomatic project: $projectFile")
Expand All @@ -601,7 +602,7 @@ object QuantoDerive extends SimpleSwingApplication {
if (closeAllOrListOfDocuments()) {
ProjectFileTree.root = None
CurrentProject = None
refreshAllMenus()
refreshAllMenusAndTitle()
}
}
}
Expand Down Expand Up @@ -1154,7 +1155,12 @@ object QuantoDerive extends SimpleSwingApplication {
// Swing.onEDT { CoreStatus.text = "OK"; CoreStatus.foreground = new Color(0,150,0) }
// }

private def refreshAllMenus() = {
private def refreshAllMenusAndTitle(): Unit = {
refreshAllMenus()
refreshTitle()
}

private def refreshAllMenus(): Unit = {
try {
FileMenu.SaveAction.enabled = false
FileMenu.SaveAsAction.enabled = false
Expand Down Expand Up @@ -1259,16 +1265,20 @@ object QuantoDerive extends SimpleSwingApplication {


val _mainframe = new MainFrame {
override def title : String = {
if (CurrentProject.isEmpty) {"Quantomatic"} else {

def refreshTitle() : Unit = {
// Setting the iconImage here isn't working on Windows
// iconImage = ImageIO.read(getClass.getResource("quantoderive.ico"))
title = if (CurrentProject.isEmpty) {"Quantomatic"} else {
CurrentProject.get.name match {
case "" => "Quantomatic"
case s => "Quantomatic - $s"
case s => s"Quantomatic - $s"
}
}
}
contents = Main


if (prefs.getBoolean("fullscreen",false)) {
peer.setExtendedState(peer.getExtendedState() | Frame.MAXIMIZED_BOTH)
}
Expand All @@ -1292,5 +1302,15 @@ object QuantoDerive extends SimpleSwingApplication {
}

def top = _mainframe
refreshAllMenus()

def refreshTitle(): Unit = {
try {
top.refreshTitle()
} catch {
case _: NullPointerException =>
// Null Pointer Exception thrown when accessing GUI too early
}
}

refreshAllMenusAndTitle()
}

0 comments on commit 0ac59e2

Please sign in to comment.