-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathUtils.hs
221 lines (189 loc) · 6.45 KB
/
Utils.hs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
{-# LANGUAGE CPP #-}
{- |
Module : $Header$
Description : cpp choice between "GUI.HTkUtils" and "GUI.ConsoleUtils"
Copyright : (c) C. Maeder, Uni Bremen 2002-2005
License : GPLv2 or higher, see LICENSE.txt
Maintainer : Christian.Maeder@dfki.de
Stability : provisional
Portability : non-portable (cpp)
Utilities on top of HTk or System.IO
-}
module GUI.Utils
( listBox
, createTextSaveDisplay
, askFileNameAndSave
#if defined GTKGLADE || defined UNI_PACKAGE
, createTextDisplay
, infoDialog
, errorDialog
, warningDialog
, questionDialog
, fileOpenDialog
, fileSaveDialog
, displayTheoryWithWarning
, progressBar
, pulseBar
#endif
) where
#ifdef GTKGLADE
import GUI.GtkUtils
( infoDialogExt
, errorDialogExt
, warningDialogExt
, questionDialogExt
, fileSaveDialogExt
, fileOpenDialogExt
, listChoiceExt
, textViewExt
, displayTheoryWithWarningExt
, progressBarExt
, pulseBarExt
)
import Static.GTheory (G_theory)
-- | create a window which displays a given text
infoDialog :: String -- ^ Title
-> String -- ^ Message
-> IO ()
infoDialog = infoDialogExt
-- | create a window which displays a given error
errorDialog :: String -- ^ Title
-> String -- ^ Message
-> IO ()
errorDialog = errorDialogExt
-- | create a window which displays a given warning and ask for continue
warningDialog :: String -- ^ Title
-> String -- ^ Message
-> IO Bool
warningDialog = warningDialogExt
-- | create a window which displays a given question
questionDialog :: String -- ^ Title
-> String -- ^ Message
-> IO Bool
questionDialog = questionDialogExt
fileSaveDialog :: FilePath -- ^ Defaultname for file
-> [(String, [String])] -- ^ Filter (name, pattern list)
-> Maybe (FilePath -> IO ()) -- ^ Action on save
-> IO (Maybe FilePath)
fileSaveDialog = fileSaveDialogExt
fileOpenDialog :: FilePath -- ^ Defaultname for file
-> [(String, [String])] -- ^ Filter (name, pattern list)
-> Maybe (FilePath -> IO ()) -- ^ Action on open
-> IO (Maybe FilePath)
fileOpenDialog = fileOpenDialogExt
-- | displays a theory with warning in a window
displayTheoryWithWarning :: String -- ^ Kind of theory
-> String -- ^ Name of theory
-> String -- ^ Warning
-> G_theory -- ^ Theory
-> IO ()
displayTheoryWithWarning = displayTheoryWithWarningExt
progressBar :: String -- ^ Title
-> String -- ^ Description
-> IO (Double -> String -> IO (), IO ())
progressBar = progressBarExt
pulseBar :: String -- ^ Title
-> String -- ^ Description
-> IO (String -> IO (), IO ())
pulseBar = pulseBarExt
-- | create a window with title and list of options, return selected option
listBox :: String -- ^ Title
-> [String] -- ^ Rows to display
-> IO (Maybe Int) -- ^ Selected row
listBox = listChoiceExt
-- | Display some (longish) text in an uneditable, scrollable editor.
createTextDisplay :: String -- ^ Title
-> String -- ^ Message
-> IO ()
createTextDisplay t m = textViewExt t m Nothing
-- | Display some (longish) text in an uneditable, scrollable editor.
createTextSaveDisplay :: String -- ^ Title
-> FilePath -- ^ Filename
-> String -- ^ Message
-> IO ()
createTextSaveDisplay t f m = textViewExt t m $ Just f
-- | opens a FileDialog and saves to the selected file if Save is clicked
askFileNameAndSave :: FilePath -- ^ default filename for saving the text
-> String -- ^ text to be saved
-> IO ()
askFileNameAndSave f m = do
fileSaveDialogExt f [] $ Just (\ f' -> writeFile f' m)
return ()
#elif defined UNI_PACKAGE
import GUI.HTkUtils
( listBox
, errorMess
, confirmMess
, messageMess
, createTextSaveDisplay
, askFileNameAndSave
, newFileDialogStr
, fileDialogStr
, displayTheoryWithWarning
, sync
)
import qualified GUI.HTkUtils (createTextDisplay)
-- | create a window which displays a given text
infoDialog :: String -- ^ Title
-> String -- ^ Message
-> IO ()
infoDialog _ m = messageMess m
-- | create a window which displays a given error
errorDialog :: String -- ^ Title
-> String -- ^ Message
-> IO ()
errorDialog _ m = errorMess m
-- | create a window which displays a given warning and ask for continue
warningDialog :: String -- ^ Title
-> String -- ^ Message
-> IO Bool
warningDialog _ = confirmMess
-- | create a window which displays a given question
questionDialog :: String -- ^ Title
-> String -- ^ Message
-> IO Bool
questionDialog _ = confirmMess
fileOpenDialog :: FilePath -- ^ Defaultname for file
-> [(String, [String])] -- ^ Filter (name, pattern list)
-> Maybe (FilePath -> IO ()) -- ^ Action on open
-> IO (Maybe FilePath)
fileOpenDialog f _ mAction = do
evnt <- fileDialogStr "Open..." f
mPath <- sync evnt
case mPath of
Just path -> case mAction of
Just action -> action path
Nothing -> return ()
Nothing -> return ()
return mPath
fileSaveDialog :: FilePath -- ^ Defaultname for file
-> [(String, [String])] -- ^ Filter (name, pattern list)
-> Maybe (FilePath -> IO ()) -- ^ Action on save
-> IO (Maybe FilePath)
fileSaveDialog f _ mAction = do
evnt <- newFileDialogStr "Save as..." f
mPath <- sync evnt
case mPath of
Just path -> case mAction of
Just action -> action path
Nothing -> return ()
Nothing -> return ()
return mPath
-- | Display some (longish) text in an uneditable, scrollable editor.
createTextDisplay :: String -- ^ Title
-> String -- ^ Message
-> IO ()
createTextDisplay t m = GUI.HTkUtils.createTextDisplay t m []
-- Not implemented in HTk
progressBar :: String -- ^ Title
-> String -- ^ Description
-> IO (Double -> String -> IO (), IO ())
progressBar _ _ = return (\ _ _ -> return (), return ())
-- Not implemented in HTk
pulseBar :: String -- ^ Title
-> String -- ^ Description
-> IO (String -> IO (), IO ())
pulseBar _ _ = return (\ _ -> return (), return ())
#else
import GUI.ConsoleUtils (listBox, createTextSaveDisplay, askFileNameAndSave)
#endif