{-| Module representing types of pop-up windows: Error Window. Confirmation Window Input window. -} module Popup where import Graphics.UI.Gtk {-| Pops an error window, that displays an error message to the user. -} errorWindow :: String -- ^ The error message to be displayed to the user. -> IO ( ) errorWindow message = do dialogWindow <- messageDialogNew Nothing [DialogModal] MessageError ButtonsOk message dialogRun dialogWindow widgetDestroy dialogWindow {-| Pops a confirmation window. The user can then either select OK or Cancel based upon the confirmation displayed. -} confirmWindow :: String -- ^ The confirmation message to be displayed. -> IO Bool -- ^ Whether or not the user selected OK. confirmWindow message = do dialogWindow <- messageDialogNew Nothing [DialogModal] MessageQuestion ButtonsYesNo message dialogRun dialogWindow >>= (\r -> widgetDestroy dialogWindow >> return ( r == ResponseYes ) ) {-| Pops up an input window, displaying a message. The user then supplies some input and that is recorded. -} inputWindow :: String -- ^ The title of the window. -> String -- ^ The message to be displayed to the user. -> IO String -- ^ The users input. inputWindow title message = do dialog <- dialogNew dialogBox <- dialogGetUpper dialog hbox <- hBoxNew False 3 set dialog [ windowTitle := title, windowDefaultWidth := 300, windowDefaultHeight := 100 ] --Create message & text box. textBox <- entryNew request <- labelNew ( Just message ) --Pack components. boxPackStart hbox request PackNatural 0 boxPackEnd hbox textBox PackGrow 0 boxPackStartDefaults dialogBox hbox --Ad OK & Cancel buttons. dialogAddButton dialog stockOk ResponseOk dialogAddButton dialog stockCancel ResponseCancel --Show window & components widgetShow textBox widgetShow request widgetShow hbox --Get the result & close pop-up. result <- dialogRun dialog widgetDestroy dialog if ( result == ResponseOk ) then do ( entryGetText textBox >>= return ) else do return ""