@@ -25,14 +25,22 @@ module VCSGui.Common.Commit (
25
25
26
26
import qualified VCSWrapper.Common as Wrapper
27
27
import qualified VCSGui.Common.GtkHelper as H
28
- import Graphics.UI.Gtk
29
28
import Control.Monad.Trans (liftIO )
30
29
import Control.Monad
31
30
import Control.Monad.Reader
32
31
import Data.Maybe
33
32
import Paths_vcsgui (getDataFileName )
34
33
import qualified Data.Text as T (unpack , pack )
35
34
import Data.Text (Text )
35
+ import GI.Gtk.Objects.TreeView (TreeView (.. ))
36
+ import Data.GI.Gtk.ModelView.SeqStore
37
+ (seqStoreAppend , seqStoreClear , seqStoreToList , SeqStore (.. ))
38
+ import GI.Gtk.Objects.Action (onActionActivate )
39
+ import GI.Gtk.Objects.Widget (widgetShowAll )
40
+ import GI.Gtk.Objects.Builder (builderGetObject , Builder (.. ))
41
+ import Foreign.ForeignPtr (ForeignPtr )
42
+ import Data.GI.Base.BasicTypes (NullToNothing (.. ), GObject )
43
+ import Data.GI.Base.ManagedPtr (unsafeCastTo )
36
44
37
45
--
38
46
-- glade path and object accessors
@@ -55,9 +63,9 @@ type OkCallBack = Text -- ^ Commit message as specified in the GUI.
55
63
-> [Option ] -- ^ options (this is currently not implemented i.e. '[]' is passed)
56
64
-> Wrapper. Ctx ()
57
65
58
- -- | fn to set listStore model for treeview
66
+ -- | fn to set seqStore model for treeview
59
67
type TreeViewSetter = TreeView
60
- -> Wrapper. Ctx (ListStore SCFile )
68
+ -> Wrapper. Ctx (SeqStore SCFile )
61
69
62
70
63
71
data CommitGUI = CommitGUI {
@@ -110,7 +118,7 @@ showCommitGUI setUpTreeView okCallback = do
110
118
liftIO $ H. registerClose $ windowCommit gui
111
119
liftIO $ H. registerCloseAction (actCancel gui) (windowCommit gui)
112
120
config <- ask
113
- liftIO $ on (H. getItem (actCommit gui)) actionActivated $ do
121
+ liftIO $ onActionActivate (H. getItem (actCommit gui)) $ do
114
122
let (store,_) = H. getItem (treeViewFiles gui)
115
123
selectedFiles <- getSelectedFiles store
116
124
mbMsg <- H. get (txtViewMsg gui)
@@ -129,7 +137,7 @@ showCommitGUI setUpTreeView okCallback = do
129
137
130
138
131
139
132
- loadCommitGUI :: TreeViewSetter -- ^ fn to set listStore model for treeview
140
+ loadCommitGUI :: TreeViewSetter -- ^ fn to set seqStore model for treeview
133
141
-> Wrapper. Ctx CommitGUI
134
142
loadCommitGUI setUpTreeView = do
135
143
gladepath <- liftIO getGladepath
@@ -145,9 +153,9 @@ loadCommitGUI setUpTreeView = do
145
153
---- HELPERS
146
154
----
147
155
148
- getSelectedFiles :: ListStore SCFile -> IO [FilePath ]
149
- getSelectedFiles listStore = do
150
- listedFiles <- listStoreToList listStore
156
+ getSelectedFiles :: SeqStore SCFile -> IO [FilePath ]
157
+ getSelectedFiles seqStore = do
158
+ listedFiles <- seqStoreToList seqStore
151
159
let selectedFiles = map (\ scf -> filePath scf )
152
160
$ filter (\ scf -> selected scf) listedFiles
153
161
return (selectedFiles)
@@ -156,39 +164,39 @@ getTreeViewFromGladeCustomStore :: Builder
156
164
-> Text
157
165
-> TreeViewSetter
158
166
-> Wrapper. Ctx (H. TreeViewItem SCFile )
159
- getTreeViewFromGladeCustomStore builder name setupListStore = do
160
- (_, tView) <- liftIO $ wrapWidget builder castToTreeView name
161
- store <- setupListStore tView
162
- let getter = getFromListStore (store, tView)
163
- setter = setToListStore (store, tView)
167
+ getTreeViewFromGladeCustomStore builder name setupSeqStore = do
168
+ (_, tView) <- liftIO $ wrapWidget builder TreeView name
169
+ store <- setupSeqStore tView
170
+ let getter = getFromSeqStore (store, tView)
171
+ setter = setToSeqStore (store, tView)
164
172
return (name, (store, tView), (getter, setter))
165
173
166
174
---
167
175
--- same as gtkhelper, but avoiding exposing it
168
176
---
169
- wrapWidget :: GObjectClass objClass =>
177
+ wrapWidget :: GObject objClass =>
170
178
Builder
171
- -> (GObject -> objClass )
179
+ -> (ForeignPtr objClass -> objClass )
172
180
-> Text -> IO (Text , objClass )
173
- wrapWidget builder cast name = do
181
+ wrapWidget builder constructor name = do
174
182
putStrLn $ " cast " ++ T. unpack name
175
- gobj <- builderGetObject builder cast name
183
+ gobj <- nullToNothing ( builderGetObject builder name) >>= unsafeCastTo constructor . fromJust
176
184
return (name, gobj)
177
185
178
- getFromListStore :: (ListStore a , TreeView )
186
+ getFromSeqStore :: (SeqStore a , TreeView )
179
187
-> IO (Maybe [a ])
180
- getFromListStore (store, _) = do
181
- list <- listStoreToList store
188
+ getFromSeqStore (store, _) = do
189
+ list <- seqStoreToList store
182
190
if null list
183
191
then return Nothing
184
192
else return $ Just list
185
193
186
- setToListStore :: (ListStore a , TreeView )
194
+ setToSeqStore :: (SeqStore a , TreeView )
187
195
-> [a ]
188
196
-> IO ()
189
- setToListStore (store, view) newList = do
190
- listStoreClear store
191
- mapM_ (listStoreAppend store) newList
197
+ setToSeqStore (store, view) newList = do
198
+ seqStoreClear store
199
+ mapM_ (seqStoreAppend store) newList
192
200
return ()
193
201
194
202
0 commit comments