use haskell-gi bugfix to improve tab reordering

This commit is contained in:
sheaf 2020-09-26 00:21:49 +02:00
parent 58ca70c1bd
commit a5ba7dcd33
3 changed files with 20 additions and 10 deletions

5
.gitignore vendored
View file

@ -3,9 +3,10 @@ cabal.project.local
assets/*.svg
assets/*/
refs/
img/examples
files/
img/examples
math/
refs/
*.txt
*.md

View file

@ -29,3 +29,9 @@ source-repository-package
type: git
location: https://github.com/sheaf/waargonaut
tag: dc835fb86d2592fa2e55753fa4eb7c59d6124699
-- haskell-gi: add fix for GValue
source-repository-package
type: git
location: https://github.com/haskell-gi/haskell-gi
tag: 6fe7fc271095b5b6115b142f72995ebc11840afb

View file

@ -18,6 +18,8 @@ import Control.Monad
( join, unless, void )
import Data.Foldable
( for_, sequenceA_ )
import Data.Functor
( (<&>) )
import Data.Traversable
( for )
@ -32,6 +34,10 @@ import qualified GI.Cairo.Render.Connector as Cairo
-- gi-gtk
import qualified GI.Gtk as GTK
-- haskell-gi-base
import qualified Data.GI.Base.GValue as GI
import qualified Data.GI.Base.GType as GI
-- stm
import qualified Control.Concurrent.STM as STM
( atomically )
@ -134,7 +140,7 @@ newFileTab
widgetAddClasses closeFileButton [ "fileBarCloseButton" ]
GTK.widgetShowAll tab
-- We've placed the new tab at the end. Now rearrange it if needed.
-- We've placed the new tab at the end. Now rearrange it if necessary.
case newTabLoc of
LastTab -> pure ()
AfterCurrentTab -> do
@ -143,13 +149,10 @@ newFileTab
for mbUnique \ docUnique -> do
Map.lookup docUnique <$> STM.readTVar fileBarTabsTVar
for_ mbActiveTab \ ( activeTab, _ ) -> do
children <- GTK.containerGetChildren fileTabsBox
for_ ( zip children [0..] ) \ ( childWidget, activeTabIndex ) -> do
mbBox <- GTK.castTo GTK.Box childWidget
for_ mbBox \ box ->
if box == activeTab
then GTK.boxReorderChild fileTabsBox tab ( activeTabIndex + 1 )
else pure ()
gValue <- GI.newGValue GI.gtypeInt
GTK.containerChildGetProperty fileTabsBox activeTab "position" gValue
( GI.get_int gValue <&> ( +1 ) ) >>= GI.set_int gValue
GTK.containerChildSetProperty fileTabsBox tab "position" gValue
-- Ensure consistency of hover/selection state between the two elements in the tab.
for_ @_ @_ @_ @() [ Exists @GTK.IsWidget pgButton, Exists @GTK.IsWidget closeFileButton ] \ ( Exists button ) -> do