| 1 |
{-# LANGUAGE ScopedTypeVariables #-} |
| 2 |
{-# LANGUAGE OverloadedStrings #-} |
| 3 |
import Graphics.UI.Gtk |
| 4 |
import Data.Text (Text) |
| 5 |
|
| 6 |
-- A function like this can be used to tag string literals for i18n. |
| 7 |
-- It also avoids a lot of type annotations. |
| 8 |
__ :: Text -> Text |
| 9 |
__ = id -- Replace with getText from the hgettext package in localised versions |
| 10 |
|
| 11 |
uiDef = |
| 12 |
"<ui>\ |
| 13 |
\ <menubar>\ |
| 14 |
\ <menu name=\"File\" action=\"FileAction\">\ |
| 15 |
\ <menuitem name=\"New\" action=\"NewAction\" />\ |
| 16 |
\ <menuitem name=\"Open\" action=\"OpenAction\" />\ |
| 17 |
\ <menuitem name=\"Save\" action=\"SaveAction\" />\ |
| 18 |
\ <menuitem name=\"SaveAs\" action=\"SaveAsAction\" />\ |
| 19 |
\ <separator/>\ |
| 20 |
\ <menuitem name=\"Exit\" action=\"ExitAction\"/>\ |
| 21 |
\ <placeholder name=\"FileMenuAdditions\" />\ |
| 22 |
\ </menu>\ |
| 23 |
\ <menu name=\"Edit\" action=\"EditAction\">\ |
| 24 |
\ <menuitem name=\"Cut\" action=\"CutAction\"/>\ |
| 25 |
\ <menuitem name=\"Copy\" action=\"CopyAction\"/>\ |
| 26 |
\ <menuitem name=\"Paste\" action=\"PasteAction\"/>\ |
| 27 |
\ </menu>\ |
| 28 |
\ </menubar>\ |
| 29 |
\ <toolbar>\ |
| 30 |
\ <placeholder name=\"FileToolItems\">\ |
| 31 |
\ <separator/>\ |
| 32 |
\ <toolitem name=\"New\" action=\"NewAction\"/>\ |
| 33 |
\ <toolitem name=\"Open\" action=\"OpenAction\"/>\ |
| 34 |
\ <toolitem name=\"Save\" action=\"SaveAction\"/>\ |
| 35 |
\ <separator/>\ |
| 36 |
\ </placeholder>\ |
| 37 |
\ <placeholder name=\"EditToolItems\">\ |
| 38 |
\ <separator/>\ |
| 39 |
\ <toolitem name=\"Cut\" action=\"CutAction\"/>\ |
| 40 |
\ <toolitem name=\"Copy\" action=\"CopyAction\"/>\ |
| 41 |
\ <toolitem name=\"Paste\" action=\"PasteAction\"/>\ |
| 42 |
\ <separator/>\ |
| 43 |
\ </placeholder>\ |
| 44 |
\ </toolbar>\ |
| 45 |
\</ui>" :: Text |
| 46 |
|
| 47 |
main = do |
| 48 |
initGUI |
| 49 |
|
| 50 |
-- Create the menus |
| 51 |
fileAct <- actionNew "FileAction" (__"File") Nothing Nothing |
| 52 |
editAct <- actionNew "EditAction" (__"Edit") Nothing Nothing |
| 53 |
|
| 54 |
-- Create menu items |
| 55 |
newAct <- actionNew "NewAction" (__"New") |
| 56 |
(Just (__"Clear the spreadsheet area.")) |
| 57 |
(Just stockNew) |
| 58 |
on newAct actionActivated $ putStrLn "New activated." |
| 59 |
openAct <- actionNew "OpenAction" (__"Open") |
| 60 |
(Just (__"Open an existing spreadsheet.")) |
| 61 |
(Just stockOpen) |
| 62 |
on openAct actionActivated $ putStrLn "Open activated." |
| 63 |
saveAct <- actionNew "SaveAction" (__"Save") |
| 64 |
(Just (__"Save the current spreadsheet.")) |
| 65 |
(Just stockSave) |
| 66 |
on saveAct actionActivated $ putStrLn "Save activated." |
| 67 |
saveAsAct <- actionNew "SaveAsAction" (__"SaveAs") |
| 68 |
(Just (__"Save spreadsheet under new name.")) |
| 69 |
(Just stockSaveAs) |
| 70 |
on saveAsAct actionActivated $ putStrLn "SaveAs activated." |
| 71 |
exitAct <- actionNew "ExitAction" (__"Exit") |
| 72 |
(Just (__"Exit this application.")) |
| 73 |
(Just stockSaveAs) |
| 74 |
on exitAct actionActivated $ mainQuit |
| 75 |
cutAct <- actionNew "CutAction" (__"Cut") |
| 76 |
(Just (__"Cut out the current selection.")) |
| 77 |
(Just stockCut) |
| 78 |
on cutAct actionActivated $ putStrLn "Cut activated." |
| 79 |
copyAct <- actionNew "CopyAction" (__"Copy") |
| 80 |
(Just (__"Copy the current selection.")) |
| 81 |
(Just stockCopy) |
| 82 |
on copyAct actionActivated $ putStrLn "Copy activated." |
| 83 |
pasteAct <- actionNew "PasteAction" (__"Paste") |
| 84 |
(Just (__"Paste the current selection.")) |
| 85 |
(Just stockPaste) |
| 86 |
on pasteAct actionActivated $ putStrLn "Paste activated." |
| 87 |
|
| 88 |
standardGroup <- actionGroupNew ("standard"::Text) |
| 89 |
mapM_ (actionGroupAddAction standardGroup) [fileAct, editAct] |
| 90 |
mapM_ (\act -> actionGroupAddActionWithAccel standardGroup act (Nothing::Maybe Text)) |
| 91 |
[newAct, openAct, saveAct, saveAsAct, exitAct, cutAct, copyAct, pasteAct] |
| 92 |
|
| 93 |
ui <- uiManagerNew |
| 94 |
mid <- uiManagerAddUiFromString ui uiDef |
| 95 |
uiManagerInsertActionGroup ui standardGroup 0 |
| 96 |
|
| 97 |
win <- windowNew |
| 98 |
on win objectDestroy mainQuit |
| 99 |
on win sizeRequest $ return (Requisition 200 100) |
| 100 |
(Just menuBar) <- uiManagerGetWidget ui ("/ui/menubar"::Text) |
| 101 |
(Just toolBar) <- uiManagerGetWidget ui ("/ui/toolbar"::Text) |
| 102 |
|
| 103 |
edit <- textViewNew |
| 104 |
vBox <- vBoxNew False 0 |
| 105 |
set vBox [boxHomogeneous := False] |
| 106 |
boxPackStart vBox menuBar PackNatural 0 |
| 107 |
boxPackStart vBox toolBar PackNatural 0 |
| 108 |
boxPackStart vBox edit PackGrow 0 |
| 109 |
|
| 110 |
containerAdd win vBox |
| 111 |
widgetShowAll win |
| 112 |
|
| 113 |
mainGUI |