blob: a5c97d056535068b75a36a632e93b8ceb8afd741 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
{-# LANGUAGE OverloadedStrings #-}
{-
- Copyright 2018 Raymond Hogenson
-
- This file is part of HSC.
- HSC is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- HSC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with HSC. If not, see <http://www.gnu.org/licenses/>.
-}
import Graphics.UI.Gtk
import qualified Control.Monad.IO.Class as Cl
import qualified RealCalc
main :: IO ()
main = do _ <- initGUI
w <- windowNew
set w [ windowDecorated := False, windowResizable := False ]
grid <- gridNew
input <- entryNew
output <- entryNew
set output [ entryEditable := False ]
clip <- Cl.liftIO $ clipboardGet selectionPrimary
gridAttach grid input 0 0 1 1
gridAttach grid output 0 1 1 1
containerAdd w grid
_ <- w `on` deleteEvent $ do
Cl.liftIO mainQuit
return True
_ <- input `on` keyReleaseEvent $ do
k <- eventKeyName
let quit = Cl.liftIO mainQuit
case k of
"Escape" -> quit
"Return" -> quit
"bracketleft" -> do
m <- eventModifier
if Control `elem` m
then quit
else return ()
_ -> return ()
s <- Cl.liftIO $ entryGetText input
case RealCalc.calculate s of
Nothing -> return ()
Just r -> do Cl.liftIO $ clipboardSetText clip r
Cl.liftIO $ set output [ entryText := r ]
return True
widgetShowAll w
mainGUI
|