Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Termonad/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import GI.Gtk
, notebookGetNthPage
, notebookGetNPages
)
import qualified GI.Gtk as Gtk
import Data.GI.Base.GObject
import GI.Pango (FontDescription)
import GI.Vte (Terminal, CursorBlinkMode(..))
import Text.Pretty.Simple (pPrint)
Expand Down Expand Up @@ -530,6 +532,23 @@ data TMStateInvariantErr
| TabsDoNotMatch TabsDoNotMatch
deriving Show

printWidgetTree :: Gtk.IsWidget a => a -> IO ()
printWidgetTree widget_ = do
widget <- Gtk.toWidget widget_
go "" widget
where
go :: Text -> Gtk.Widget -> IO ()
go indent w = do
type_ <- gtypeFromInstance w
name <- Gtk.gtypeName type_
let ptr = Gtk.managedForeignPtr . Gtk.toManagedPtr $ w
putStrLn $ indent <> pack name <> " " <> pack (show ptr)
maybeContainer <- Gtk.castTo Gtk.Container w
for_ maybeContainer $ \container -> do
children <- Gtk.containerGetChildren container
for_ children $ \child -> do
go (" " <> indent) child

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this function in order to help me debug my implementation, but the now-debugged code is not using it anywhere, so I should probably remove it.

@cdepillabout cdepillabout Jan 16, 2022

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice. I've wanted something like this before, so I opened an issue on haskell-gi to see if it could potentially be included in gi-gtk: haskell-gi/haskell-gi#374

I don't think it makes sense to only have this in the Termonad codebase, since it seems widely helpful.

Although, if this type of function is not accepted upstream, let's move it to the Termonad.Gtk module, since there are already a few other helper functions in there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now moved printWidgetTree to Termonad.Gtk, let's remove when/if it is accepted upstream.


-- | Gather up the invariants for 'TMState' and return them as a list.
--
-- If no invariants have been violated, then this function should return an
Expand Down