createGlobalMenu :: GInfo -> LibFunc -> IORef [String]
                 -> IO [GlobalMenu]
createGlobalMenu gi showLib _ = do
 ost <- readIORef $ intState gi
 case i_state ost of
  Nothing -> return []
  Just _ -> do
   let ln = libName gi
       opts = hetcatsOpts gi
       ral = runAndLock gi
       performProofMenuAction cmd =
           ral . proofMenu gi cmd
       mkGlobProofButton cmd =
         Button (menuTextGlobCmd cmd) . performProofMenuAction (GlobCmd cmd)
   return
    [GlobalMenu (Menu Nothing
     [ Button "Undo" $ ral $ undo gi True
     , Button "Redo" $ ral $ undo gi False
     , Menu (Just "Hide/Show names/nodes/edges")
        [ Button "Hide/Show internal node names"
                 $ ral $ toggleHideNames gi
        , Button "Hide/Show unnamed nodes without open proofs"
                 $ ral $ toggleHideNodes gi
        , Button "Hide/Show newly added proven edges"
                 $ ral $ toggleHideEdges gi
      ]
     , Button "Focus node" $ ral $ focusNode gi
#ifdef GTKGLADE
     , Button "Consistency checker"
         (performProofMenuAction (GlobCmd CheckConsistencyCurrent)
           $ showConsistencyChecker Nothing gi)
     , Button "Automatic proofs"
         (performProofMenuAction (CommentCmd "generated by \"automatic proofs\"")
           $ showAutomaticProofs gi)
#endif
     , Menu (Just "Proofs") $ map (\ (cmd, act) ->
        mkGlobProofButton cmd $ return . return . act ln) globLibAct
        ++ map (\ (cmd, act) -> mkGlobProofButton cmd $ return . act ln)
           globLibResultAct
        ++ [ Menu (Just "Flattening") $ map ( \ (cmd, act) ->
           mkGlobProofButton cmd $ return . act) globResultAct ]
     , Button "Dump Development Graph" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> print . pretty . lookupDGraph (i_ln ist2)
              $ i_libEnv ist2
     , Button "Dump Cons Inclusions" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> dumpConsInclusions (hetcatsOpts gi)
                          $ lookupDGraph (i_ln ist2) $ i_libEnv ist2
     , Button "Show Library Graph" $ ral $ showLibGraph gi showLib
     , Button "Show RefinementTree" $ ral $ showLibGraph gi showRefTree
     , Button "Save Graph for uDrawGraph" $ ral
              $ saveUDGraph gi (mapNodeTypes opts) $ mapEdgeTypes opts
     , Button "Save proof-script" $ ral
              $ askSaveProofScript (graphInfo gi) $ intState gi
     ])
    ]

-- | A list of all Node Types
createGlobalMenu :: GInfo -> LibFunc -> IORef [String]
                 -> IO [GlobalMenu]
createGlobalMenu gi showLib _ = do
 ost <- readIORef $ intState gi
 case i_state ost of
  Nothing -> return []
  Just _ -> do
   let ln = libName gi
       opts = hetcatsOpts gi
       ral = runAndLock gi
       performProofMenuAction cmd =
           ral . proofMenu gi cmd
       mkGlobProofButton cmd =
         Button (menuTextGlobCmd cmd) . performProofMenuAction (GlobCmd cmd)
   return
    [GlobalMenu (Menu Nothing
     [ Button "Undo" $ ral $ undo gi True
     , Button "Redo" $ ral $ undo gi False
     , Menu (Just "Hide/Show names/nodes/edges")
        [ Button "Hide/Show internal node names"
                 $ ral $ toggleHideNames gi
        , Button "Hide/Show unnamed nodes without open proofs"
                 $ ral $ toggleHideNodes gi
        , Button "Hide/Show newly added proven edges"
                 $ ral $ toggleHideEdges gi
      ]
     , Button "Focus node" $ ral $ focusNode gi
#ifdef GTKGLADE
     , Button "Consistency checker"
         (performProofMenuAction (GlobCmd CheckConsistencyCurrent)
           $ showConsistencyChecker Nothing gi)
     , Button "Automatic proofs"
         (performProofMenuAction (CommentCmd "generated by \"automatic proofs\"")
           $ showAutomaticProofs gi)
#endif
     , Menu (Just "Proofs") $ map (\ (cmd, act) ->
        mkGlobProofButton cmd $ return . return . act ln) globLibAct
        ++ map (\ (cmd, act) -> mkGlobProofButton cmd $ return . act ln)
           globLibResultAct
        ++ [ Menu (Just "Flattening") $ map ( \ (cmd, act) ->
           mkGlobProofButton cmd $ return . act) globResultAct ]
     , Button "Dump Development Graph" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> print . pretty . lookupDGraph (i_ln ist2)
              $ i_libEnv ist2
     , Button "Dump Cons Inclusions" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> dumpConsInclusions (hetcatsOpts gi)
                          $ lookupDGraph (i_ln ist2) $ i_libEnv ist2
     , Button "Show Library Graph" $ ral $ showLibGraph gi showLib
     , Button "Show RefinementTree" $ ral $ showLibGraph gi showRefTree
     , Button "Save Graph for uDrawGraph" $ ral
              $ saveUDGraph gi (mapNodeTypes opts) $ mapEdgeTypes opts
     , Button "Save proof-script" $ ral
              $ askSaveProofScript (graphInfo gi) $ intState gi
     ])
    ]

-- | A list of all Node Types
createGlobalMenu gi showLib _ = do
 ost <- readIORef $ intState gi
 case i_state ost of
  Nothing -> return []
  Just _ -> do
   let ln = libName gi
       opts = hetcatsOpts gi
       ral = runAndLock gi
       performProofMenuAction cmd =
           ral . proofMenu gi cmd
       mkGlobProofButton cmd =
         Button (menuTextGlobCmd cmd) . performProofMenuAction (GlobCmd cmd)
   return
    [GlobalMenu (Menu Nothing
     [ Button "Undo" $ ral $ undo gi True
     , Button "Redo" $ ral $ undo gi False
     , Menu (Just "Hide/Show names/nodes/edges")
        [ Button "Hide/Show internal node names"
                 $ ral $ toggleHideNames gi
        , Button "Hide/Show unnamed nodes without open proofs"
                 $ ral $ toggleHideNodes gi
        , Button "Hide/Show newly added proven edges"
                 $ ral $ toggleHideEdges gi
      ]
     , Button "Focus node" $ ral $ focusNode gi
#ifdef GTKGLADE
     , Button "Consistency checker"
         (performProofMenuAction (GlobCmd CheckConsistencyCurrent)
           $ showConsistencyChecker Nothing gi)
     , Button "Automatic proofs"
         (performProofMenuAction (CommentCmd "generated by \"automatic proofs\"")
           $ showAutomaticProofs gi)
#endif
     , Menu (Just "Proofs") $ map (\ (cmd, act) ->
        mkGlobProofButton cmd $ return . return . act ln) globLibAct
        ++ map (\ (cmd, act) -> mkGlobProofButton cmd $ return . act ln)
           globLibResultAct
        ++ [ Menu (Just "Flattening") $ map ( \ (cmd, act) ->
           mkGlobProofButton cmd $ return . act) globResultAct ]
     , Button "Dump Development Graph" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> print . pretty . lookupDGraph (i_ln ist2)
              $ i_libEnv ist2
     , Button "Dump Cons Inclusions" $ do
          ost2 <- readIORef $ intState gi
          case i_state ost2 of
            Nothing -> putStrLn "no lib"
            Just ist2 -> dumpConsInclusions (hetcatsOpts gi)
                          $ lookupDGraph (i_ln ist2) $ i_libEnv ist2
     , Button "Show Library Graph" $ ral $ showLibGraph gi showLib
     , Button "Show RefinementTree" $ ral $ showLibGraph gi showRefTree
     , Button "Save Graph for uDrawGraph" $ ral
              $ saveUDGraph gi (mapNodeTypes opts) $ mapEdgeTypes opts
     , Button "Save proof-script" $ ral
              $ askSaveProofScript (graphInfo gi) $ intState gi
     ])
    ]

-- | A list of all Node Types