Skip to content

Commit

Permalink
UI: Change natural focus of derivation panel
Browse files Browse the repository at this point in the history
So that it doesn't interfere with the changing-tab hotkeys
Previously the hist-view had focus, which would absorb arrow-based hotkeys
Changed how events were handled by the ClosableTabbedPane, focus should be more consistent
See #234
  • Loading branch information
Hector committed Aug 6, 2018
1 parent 1479aa1 commit eabfd32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 13 additions & 2 deletions scala/src/main/scala/quanto/gui/ClosableTabbedPane.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class DocumentTabs {

def focus(index: Int): Unit = {
selection.index = index
currentFocus match {
case Some(p) =>
p.document.focusOnNaturalComponent()
case None =>
}
}

def remove(page: DocumentPage): Unit = {
Expand Down Expand Up @@ -203,7 +208,7 @@ class DocumentTabs {

def focus(p: DocumentPage): Unit = {
try {
selection.index = pageIndex(p)
focus(pageIndex(p))
} catch {
case e: Exception => selection.index = -1
}
Expand All @@ -218,8 +223,14 @@ class DocumentTabs {
else Some(selection.page.content)
}

// Add this reaction to the peer, then handle changes at this level.
tabbedPane.selection.reactions += {
case SelectionChanged(`tabbedPane`) =>
publishChanged()
}

def publishChanged(): Unit = {
tabbedPane.selection.publish(SelectionChanged(tabbedPane))
currentFocus.foreach(_.document.focusOnNaturalComponent())
}

def documents: Iterable[DocumentPage] = pageIndex.keys
Expand Down
2 changes: 1 addition & 1 deletion scala/src/main/scala/quanto/gui/DerivationPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class DerivationPanel(val project: Project)
SimplifyPane.Preview.resizeViewToFit()
SimplifyPane.Preview.repaint()
case DocumentRequestingNaturalFocus(_) =>
histView.requestFocus()
LhsView.requestFocus()
}

// construct the controller last, as it depends on the panel elements already being initialised
Expand Down
5 changes: 2 additions & 3 deletions scala/src/main/scala/quanto/gui/QuantoDerive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.python.util.PythonInterpreter

import scala.io.Source
import scala.swing._
import scala.swing.event.{Key, SelectionChanged}
import scala.swing.event.{Key, KeyPressed, SelectionChanged}
import javax.swing.{JOptionPane, KeyStroke, SwingUtilities, UIManager}
import java.awt.event.KeyEvent
import java.awt.Frame
Expand Down Expand Up @@ -184,7 +184,7 @@ object QuantoDerive extends SimpleSwingApplication {
def addAndFocusPage(d : DocumentPage): Unit = {
MainDocumentTabs += d
listenTo(d.tabComponent)
MainDocumentTabs.publishChanged()
MainDocumentTabs.focus(d)
d.document.publish(DocumentChanged(d.document))
d.document.focusOnNaturalComponent()
}
Expand Down Expand Up @@ -1142,7 +1142,6 @@ object QuantoDerive extends SimpleSwingApplication {
}
}
}
MainDocumentTabs.publishChanged()
case None => error("No project open.")
}

Expand Down

0 comments on commit eabfd32

Please sign in to comment.