From a5ba7dcd338177c2d91a95c3aee209ade2aa9dce Mon Sep 17 00:00:00 2001 From: sheaf Date: Sat, 26 Sep 2020 00:21:49 +0200 Subject: [PATCH] use haskell-gi bugfix to improve tab reordering --- .gitignore | 5 +++-- cabal.project | 6 ++++++ src/app/MetaBrush/UI/FileBar.hs | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 8b33153..19a8f47 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,10 @@ cabal.project.local assets/*.svg assets/*/ -refs/ -img/examples files/ +img/examples +math/ +refs/ *.txt *.md diff --git a/cabal.project b/cabal.project index 2745e04..25f67a7 100644 --- a/cabal.project +++ b/cabal.project @@ -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 diff --git a/src/app/MetaBrush/UI/FileBar.hs b/src/app/MetaBrush/UI/FileBar.hs index 9c85322..890225e 100644 --- a/src/app/MetaBrush/UI/FileBar.hs +++ b/src/app/MetaBrush/UI/FileBar.hs @@ -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