GTK: implement file drag and drop
Still doesn't work on multiple rows. Also see #14
This commit is contained in:
parent
7f538f4fae
commit
8b8c9a669f
@ -84,6 +84,36 @@ setCallbacks mygui myview = do
|
|||||||
fmv@(FMTreeView treeView) -> do
|
fmv@(FMTreeView treeView) -> do
|
||||||
_ <- treeView `on` rowActivated
|
_ <- treeView `on` rowActivated
|
||||||
$ (\_ _ -> withItems mygui myview open)
|
$ (\_ _ -> withItems mygui myview open)
|
||||||
|
|
||||||
|
-- drag events
|
||||||
|
_ <- treeView `on` dragBegin $
|
||||||
|
\_ -> withItems mygui myview moveInit
|
||||||
|
_ <- treeView `on` dragDrop $
|
||||||
|
\dc p ts -> do
|
||||||
|
atom <- atomNew ("HSFM" :: String)
|
||||||
|
p' <- treeViewConvertWidgetToTreeCoords treeView p
|
||||||
|
mpath <- treeViewGetPathAtPos treeView p'
|
||||||
|
case mpath of
|
||||||
|
Nothing -> do
|
||||||
|
dragFinish dc False False ts
|
||||||
|
return False
|
||||||
|
Just _ -> do
|
||||||
|
dragGetData treeView dc atom ts
|
||||||
|
return True
|
||||||
|
_ <- treeView `on` dragDataReceived $
|
||||||
|
\dc p _ ts ->
|
||||||
|
liftIO $ do
|
||||||
|
signalStopEmission treeView "drag_data_received"
|
||||||
|
p' <- treeViewConvertWidgetToTreeCoords treeView p
|
||||||
|
mpath <- treeViewGetPathAtPos treeView p'
|
||||||
|
case mpath of
|
||||||
|
Nothing -> dragFinish dc False False ts
|
||||||
|
Just (tp, _, _) -> do
|
||||||
|
mitem <- rawPathToItem myview tp
|
||||||
|
forM_ mitem $ \item ->
|
||||||
|
operationFinal mygui myview (Just item)
|
||||||
|
dragFinish dc True False ts
|
||||||
|
|
||||||
commonGuiEvents fmv
|
commonGuiEvents fmv
|
||||||
return ()
|
return ()
|
||||||
fmv@(FMIconView iconView) -> do
|
fmv@(FMIconView iconView) -> do
|
||||||
@ -111,7 +141,7 @@ setCallbacks mygui myview = do
|
|||||||
_ <- menubarEditRename mygui `on` menuItemActivated $
|
_ <- menubarEditRename mygui `on` menuItemActivated $
|
||||||
liftIO $ withItems mygui myview renameF
|
liftIO $ withItems mygui myview renameF
|
||||||
_ <- menubarEditPaste mygui `on` menuItemActivated $
|
_ <- menubarEditPaste mygui `on` menuItemActivated $
|
||||||
liftIO $ operationFinal mygui myview
|
liftIO $ operationFinal mygui myview Nothing
|
||||||
_ <- menubarEditDelete mygui `on` menuItemActivated $
|
_ <- menubarEditDelete mygui `on` menuItemActivated $
|
||||||
liftIO $ withItems mygui myview del
|
liftIO $ withItems mygui myview del
|
||||||
|
|
||||||
@ -176,7 +206,7 @@ setCallbacks mygui myview = do
|
|||||||
_ <- view `on` keyPressEvent $ tryEvent $ do
|
_ <- view `on` keyPressEvent $ tryEvent $ do
|
||||||
[Control] <- eventModifier
|
[Control] <- eventModifier
|
||||||
"v" <- fmap glibToString eventKeyName
|
"v" <- fmap glibToString eventKeyName
|
||||||
liftIO $ operationFinal mygui myview
|
liftIO $ operationFinal mygui myview Nothing
|
||||||
|
|
||||||
-- righ-click
|
-- righ-click
|
||||||
_ <- view `on` buttonPressEvent $ do
|
_ <- view `on` buttonPressEvent $ do
|
||||||
@ -215,7 +245,7 @@ setCallbacks mygui myview = do
|
|||||||
_ <- rcFileRename mygui `on` menuItemActivated $
|
_ <- rcFileRename mygui `on` menuItemActivated $
|
||||||
liftIO $ withItems mygui myview renameF
|
liftIO $ withItems mygui myview renameF
|
||||||
_ <- rcFilePaste mygui `on` menuItemActivated $
|
_ <- rcFilePaste mygui `on` menuItemActivated $
|
||||||
liftIO $ operationFinal mygui myview
|
liftIO $ operationFinal mygui myview Nothing
|
||||||
_ <- rcFileDelete mygui `on` menuItemActivated $
|
_ <- rcFileDelete mygui `on` menuItemActivated $
|
||||||
liftIO $ withItems mygui myview del
|
liftIO $ withItems mygui myview del
|
||||||
_ <- rcFileCut mygui `on` menuItemActivated $
|
_ <- rcFileCut mygui `on` menuItemActivated $
|
||||||
@ -321,10 +351,12 @@ copyInit _ _ _ = withErrorDialog
|
|||||||
|
|
||||||
|
|
||||||
-- |Finalizes a file operation, such as copy or move.
|
-- |Finalizes a file operation, such as copy or move.
|
||||||
operationFinal :: MyGUI -> MyView -> IO ()
|
operationFinal :: MyGUI -> MyView -> Maybe Item -> IO ()
|
||||||
operationFinal _ myview = withErrorDialog $ do
|
operationFinal _ myview mitem = withErrorDialog $ do
|
||||||
op <- readTVarIO (operationBuffer myview)
|
op <- readTVarIO (operationBuffer myview)
|
||||||
cdir <- path <$> getCurrentDir myview
|
cdir <- case mitem of
|
||||||
|
Nothing -> path <$> getCurrentDir myview
|
||||||
|
Just x -> return $ path x
|
||||||
case op of
|
case op of
|
||||||
FMove (MP1 s) -> do
|
FMove (MP1 s) -> do
|
||||||
let cmsg = "Really move " ++ imsg s
|
let cmsg = "Really move " ++ imsg s
|
||||||
|
@ -156,6 +156,13 @@ createTreeView = do
|
|||||||
tvs <- treeViewGetSelection treeView
|
tvs <- treeViewGetSelection treeView
|
||||||
treeSelectionSetMode tvs SelectionMultiple
|
treeSelectionSetMode tvs SelectionMultiple
|
||||||
|
|
||||||
|
-- set drag and drop
|
||||||
|
tl <- targetListNew
|
||||||
|
atom <- atomNew ("HSFM" :: String)
|
||||||
|
targetListAdd tl atom [TargetSameApp] 0
|
||||||
|
treeViewEnableModelDragDest treeView tl [ActionCopy]
|
||||||
|
treeViewEnableModelDragSource treeView [Button1] tl [ActionCopy]
|
||||||
|
|
||||||
-- create final tree model columns
|
-- create final tree model columns
|
||||||
renderTxt <- cellRendererTextNew
|
renderTxt <- cellRendererTextNew
|
||||||
renderPix <- cellRendererPixbufNew
|
renderPix <- cellRendererPixbufNew
|
||||||
|
@ -67,24 +67,7 @@ getSelectedItems :: MyGUI
|
|||||||
-> IO [Item]
|
-> IO [Item]
|
||||||
getSelectedItems mygui myview = do
|
getSelectedItems mygui myview = do
|
||||||
tps <- getSelectedTreePaths mygui myview
|
tps <- getSelectedTreePaths mygui myview
|
||||||
getSelectedItems' mygui myview tps
|
catMaybes <$> mapM (rawPathToItem myview) tps
|
||||||
|
|
||||||
|
|
||||||
getSelectedItems' :: MyGUI
|
|
||||||
-> MyView
|
|
||||||
-> [TreePath]
|
|
||||||
-> IO [Item]
|
|
||||||
getSelectedItems' _ myview tps = do
|
|
||||||
rawModel' <- readTVarIO $ rawModel myview
|
|
||||||
sortedModel' <- readTVarIO $ sortedModel myview
|
|
||||||
filteredModel' <- readTVarIO $ filteredModel myview
|
|
||||||
iters <- catMaybes <$> mapM (treeModelGetIter sortedModel') tps
|
|
||||||
forM iters $ \iter -> do
|
|
||||||
cIter' <- treeModelSortConvertIterToChildIter sortedModel' iter
|
|
||||||
cIter <- treeModelFilterConvertIterToChildIter filteredModel' cIter'
|
|
||||||
treeModelGetRow rawModel' cIter
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- |Carry out an action on the currently selected item.
|
-- |Carry out an action on the currently selected item.
|
||||||
@ -129,8 +112,6 @@ getCurrentDir :: MyView
|
|||||||
getCurrentDir myview = readMVar (cwd myview)
|
getCurrentDir myview = readMVar (cwd myview)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- |Push a message to the status bar.
|
-- |Push a message to the status bar.
|
||||||
pushStatusBar :: MyGUI -> String -> IO (ContextId, MessageId)
|
pushStatusBar :: MyGUI -> String -> IO (ContextId, MessageId)
|
||||||
pushStatusBar mygui str = do
|
pushStatusBar mygui str = do
|
||||||
@ -146,3 +127,25 @@ popStatusbar mygui = do
|
|||||||
let sb = statusBar mygui
|
let sb = statusBar mygui
|
||||||
cid <- statusbarGetContextId sb "FM Status"
|
cid <- statusbarGetContextId sb "FM Status"
|
||||||
statusbarPop sb cid
|
statusbarPop sb cid
|
||||||
|
|
||||||
|
|
||||||
|
-- |Turn a path on the rawModel into a path that we can
|
||||||
|
-- use at the outermost model layer.
|
||||||
|
rawPathToIter :: MyView -> TreePath -> IO (Maybe TreeIter)
|
||||||
|
rawPathToIter myview tp = do
|
||||||
|
fmodel <- readTVarIO (filteredModel myview)
|
||||||
|
smodel <- readTVarIO (sortedModel myview)
|
||||||
|
msiter <- treeModelGetIter smodel tp
|
||||||
|
forM msiter $ \siter -> do
|
||||||
|
cIter <- treeModelSortConvertIterToChildIter smodel siter
|
||||||
|
treeModelFilterConvertIterToChildIter fmodel cIter
|
||||||
|
|
||||||
|
|
||||||
|
-- |Turn a path on the rawModel into the corresponding item
|
||||||
|
-- that we can use at the outermost model layer.
|
||||||
|
rawPathToItem :: MyView -> TreePath -> IO (Maybe Item)
|
||||||
|
rawPathToItem myview tp = do
|
||||||
|
rawModel' <- readTVarIO $ rawModel myview
|
||||||
|
miter <- rawPathToIter myview tp
|
||||||
|
forM miter $ \iter -> treeModelGetRow rawModel' iter
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user