From 4dc222cdae64f302b51e8e8903d4f9c5b67b8cdb Mon Sep 17 00:00:00 2001 From: Gareth Daniel Smith Date: Mon, 27 Jan 2020 20:15:40 +0000 Subject: [PATCH] Call the destroy method on windows in window hosts Reject bad states by erroring, instead of attempting to handle them. --- .../src/GI/Gtk/Declarative/WindowHost.hs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/gi-gtk-declarative/src/GI/Gtk/Declarative/WindowHost.hs b/gi-gtk-declarative/src/GI/Gtk/Declarative/WindowHost.hs index 7d37eb3..26d317e 100644 --- a/gi-gtk-declarative/src/GI/Gtk/Declarative/WindowHost.hs +++ b/gi-gtk-declarative/src/GI/Gtk/Declarative/WindowHost.hs @@ -64,20 +64,18 @@ patch' -> (Maybe (Bin Gtk.Window e2), Widget e2) -> Patch patch' windowState childState (w1, c1) (w2, c2) = case (w1, w2, windowState) of + (Just _ , _ , Nothing ) -> error "Previous window but no previous state" + (Nothing , _ , Just ws ) -> error "Previous state but no previous window" (Just w1', Just w2', Just windowState') -> patch'' windowState' w1' w2' - (Just _ , Just w2', Nothing ) -> modifyWindow $ create w2' - (Just _ , Nothing , Just ws ) -> destroyWindow ws - (Just _ , Nothing , Nothing ) -> keepWindow Nothing - (Nothing , Just w2', Just ws ) -> replaceWindow ws $ create w2' + (Just w , Nothing , Just ws ) -> destroyWindow ws w (Nothing , Just w2', Nothing ) -> modifyWindow $ create w2' - (Nothing , Nothing , Just ws ) -> destroyWindow ws (Nothing , Nothing , Nothing ) -> keepWindow Nothing where patch'' :: SomeState -> Bin Gtk.Window e1 -> Bin Gtk.Window e2 -> Patch patch'' windowState' w1' w2' = case patch windowState' w1' w2' of Keep -> keepWindow $ Just windowState' Modify wp -> modifyWindow wp - Replace wp -> replaceWindow windowState' wp + Replace wp -> modifyWindow $ destroy windowState' w1' *> wp keepWindow :: Maybe SomeState -> Patch keepWindow windowState' = case patch childState c1 c2 of @@ -91,18 +89,11 @@ patch' windowState childState (w1, c1) (w2, c2) = case (w1, w2, windowState) of Modify cs -> Modify $ wrapState <$> fmap Just windowPatch <*> cs Replace cs -> Replace $ wrapState <$> fmap Just windowPatch <*> cs - replaceWindow :: SomeState -> IO SomeState -> Patch - replaceWindow windowState' windowPatch = - modifyWindow $ destroy windowState' *> windowPatch - - destroyWindow :: SomeState -> Patch - destroyWindow windowState' = case patch childState c1 c2 of - Keep -> Modify $ wrapState Nothing childState <$ destroy windowState' - Modify cs -> Modify $ destroy windowState' *> (wrapState Nothing <$> cs) - Replace cs -> Replace $ destroy windowState' *> (wrapState Nothing <$> cs) - - destroy :: SomeState -> IO () - destroy = someStateWidget >=> Gtk.widgetDestroy + destroyWindow :: SomeState -> Bin Gtk.Window e -> Patch + destroyWindow windowState' window = case patch childState c1 c2 of + Keep -> Modify $ wrapState Nothing childState <$ destroy windowState' window + Modify cs -> Modify $ destroy windowState' window *> (wrapState Nothing <$> cs) + Replace cs -> Replace $ destroy windowState' window *> (wrapState Nothing <$> cs) -- | Wrap the child state in the window state wrapState :: Maybe SomeState -> SomeState -> SomeState