packages feed

sifflet-lib 1.2.1 → 1.2.2

raw patch · 3 files changed

+41/−18 lines, 3 files

Files

Sifflet/UI/LittleGtk.hs view
@@ -151,6 +151,7 @@     , widgetVisible      , Window+    , windowDeletable     , windowMove     , windowNew     , windowPresent
Sifflet/UI/Window.hs view
@@ -89,10 +89,7 @@                 ; widgetSetName window ("Sifflet-" ++ winId)                 ; vwin <- initWin vpui window                 ; let vpui' = vpuiInsertWindow vpui winId vwin-                -- when window is destroyed, remove it from the map-                ; uimgr (OnWindowDestroy window -                         (\ uiref ->-                              modifyIORef uiref (vpuiRemoveVPUIWindow winId)))+                ; uimgr (OnWindowDestroy window (onWindowDestroy winId))                 ; return (vpui', vwin, True)                 }           Just vw ->@@ -102,6 +99,16 @@   ; return (vpui', vw, isNew)   } +onWindowDestroy :: WinId -> IORef VPUI -> IO ()+onWindowDestroy winId uiref =+  if (winId == workspaceId) +  then +      readIORef uiref >>=+      checkForChanges "quit (by closing the workspace window)" True False+                          (\ vpui -> do { mainQuit; return vpui }) >>+      return ()+  else modifyIORef uiref (vpuiRemoveVPUIWindow winId)+ -- | Default "do-nothing" add-callbacks function initCBDefault :: VPUI -> WinId -> CBMgr -> IO () initCBDefault _vpui _winId _uimgr = return ()@@ -144,7 +151,9 @@             Nothing -> workspaceNewDefault style (buildMainMenu cbmgr)             Just func -> workspaceNewEditing style env func   ; set window [windowTitle := winId, containerChild := wsBox ws]-+                -- this should suppress the window close button,+                -- but doesn't, at least in Fluxbox+                -- windowDeletable := False] -- no close button   ; widgetShowAll window   ; windowPresent window @@ -388,24 +397,27 @@ -- | Quit from Sifflet  menuFileQuit :: VPUI -> IO VPUI-menuFileQuit vpui = checkForChanges vpui "quit" False vpuiQuit+menuFileQuit = checkForChanges "quit" False True vpuiQuit  -- | Open a file (load its function definitions)  menuFileOpen :: CBMgr -> VPUI -> IO VPUI-menuFileOpen cbmgr vpui =-    checkForChanges vpui "open file" True (continueFileOpen cbmgr)+menuFileOpen cbmgr =+    checkForChanges "open file" True True (continueFileOpen cbmgr)  -- | Offer to save changes, if any, and continue with the continuation. -- The continuation gets the current vpui if there are no changes -- or if the offer to save is rejected; otherwise, it gets a -- vpui which knows it has saved its last changes.+-- If offerCancel is true, there is an option to cancel the operation;+-- this won't work if the user is closing the main (workspace) window. -- The message, if any, is a confirmation that the file was -- saved and that we are going on to the next operation -- -- useful for open file, but not for quit. -checkForChanges :: VPUI -> String -> Bool -> (VPUI -> IO VPUI) -> IO VPUI-checkForChanges vpui beforeOperation acknowledge continue =+checkForChanges :: String -> Bool -> Bool -> (VPUI -> IO VPUI) +                -> VPUI -> IO VPUI+checkForChanges beforeOperation acknowledge offerCancel continue vpui =     let mAckIfSaved vpui' =              when (not (vpuiFileChanged vpui') && acknowledge)                  (@@ -416,12 +428,21 @@                  )              >>             return vpui'-        labels = ["Save them", -                  "Throw them away", -                  "Cancel " ++ beforeOperation]-        actions = [menuFileSave vpui >>= mAckIfSaved >>= continue, -- save-                   return vpui >>= continue,                 -- throw away-                   return vpui]                              -- cancel+        choices = [("Save them", +                    menuFileSave vpui >>= mAckIfSaved >>= continue),+                   ("Throw them away", +                    return vpui >>= continue)] ++ +                  if offerCancel+                  then [("Cancel " ++ beforeOperation, return vpui)]+                  else []+        labels = map fst choices+        actions = map snd choices+        -- labels = ["Save them", +        --           "Throw them away", +        --           ]+        -- actions = [menuFileSave vpui >>= mAckIfSaved >>= continue, -- save+        --            return vpui >>= continue,                 -- throw away+        --            return vpui]                              -- cancel         offerSaveAndContinue = showChoicesDialog "Save changes?"                         ("There are unsaved changes.  " ++                           "Before you " ++ beforeOperation ++
sifflet-lib.cabal view
@@ -1,5 +1,5 @@ name: sifflet-lib-version: 1.2.1+version: 1.2.2 cabal-version: >= 1.8 build-type: Simple license: BSD3@@ -16,7 +16,8 @@   tests and its exporters. description: Supporting modules for the Sifflet visual,    functional programming language (Hackage 'sifflet' package).-  Version 1.2.1: updated for compatibility with gtk-0.12.+  Version 1.2.2: Safely quits when main (workspace) window is closed.+  Version 1.2.1: Updated for compatibility with gtk-0.12. category:    Language   , Visual Programming