Ticket #1179: dnd-iconview.hs

File dnd-iconview.hs, 2.3 kB (added by guest, 5 years ago)

broken example using IconViews?

Line 
1import System.IO
2import Graphics.UI.Gtk as Gtk
3import Graphics.UI.Gtk.Gdk.EventM as GdkE
4import Graphics.UI.Gtk.Glade as Glade
5import Graphics.UI.Gtk.ModelView as MV
6import Control.Monad.Trans ( liftIO )
7
8_STRING_COLUMN :: MV.ColumnId String String
9_STRING_COLUMN = MV.makeColumnIdString 1
10
11
12defaultDrag :: Gtk.SelectionTypeTag -- ^ Selection to set data with.
13               -> Maybe ( Gtk.DragSourceIface model row ) -- ^ The DragSource.
14defaultDrag tag = (Just Gtk.DragSourceIface
15    {
16        treeDragSourceRowDraggable = \_ _ -> return True,
17        treeDragSourceDragDataGet = \_ (i:_) -> do
18            Gtk.selectionDataSet tag [i]
19            return True,
20        treeDragSourceDragDataDelete = \_ _ -> return False
21    })
22
23defaultDrop tag sourceStore =
24  (Just Gtk.DragDestIface
25  {
26    treeDragDestRowDropPossible = \_ _ -> do liftIO $ putStrLn "checking if ListStore drop is possible"
27                                             return True,
28    treeDragDestDragDataReceived = \destStore _ -> do
29      liftIO $ MV.listStorePrepend destStore "world"
30      liftIO $ putStrLn "prepending to ListStore"
31      return True
32  })
33
34main = do
35  Gtk.initGUI
36
37  win <- Gtk.windowNew
38  Gtk.onDestroy win Gtk.mainQuit
39  hbox <- Gtk.hBoxNew True 10
40 
41  targetl <- Gtk.targetListNew
42  Gtk.targetListAdd targetl MV.targetTreeModelRow [TargetSameApp] 0
43 
44  -- setup the Source widget
45  ivSource <- Gtk.iconViewNew
46  storeSource <- MV.listStoreNewDND ["hello"] (defaultDrag Gtk.selectionTypeInteger) Nothing
47  MV.treeModelSetColumn storeSource _STRING_COLUMN id
48  MV.iconViewSetModel ivSource (Just storeSource)
49  MV.iconViewSetTextColumn ivSource _STRING_COLUMN
50  MV.iconViewEnableModelDragSource ivSource [GdkE.Button1] targetl [Gtk.ActionCopy]
51
52  -- setup the Destination widget
53  ivDest <- Gtk.iconViewNew
54 
55  -- broken
56  storeDest <- MV.listStoreNewDND [] Nothing (defaultDrop Gtk.selectionTypeInteger storeSource)
57 
58  -- works!
59  --storeDest <- MV.listStoreNewDND ["something"] Nothing (defaultDrop Gtk.selectionTypeInteger storeSource)
60 
61  MV.treeModelSetColumn storeDest _STRING_COLUMN id
62  MV.iconViewSetModel ivDest (Just storeDest)
63  MV.iconViewSetTextColumn ivDest _STRING_COLUMN
64  MV.iconViewEnableModelDragDest ivDest targetl [Gtk.ActionCopy]
65 
66  hbox `Gtk.containerAdd` ivSource
67  hbox `Gtk.containerAdd` ivDest
68  win `Gtk.containerAdd` hbox
69  Gtk.widgetShowAll win
70  Gtk.mainGUI