GTK: fix right-click when multiple files are selected

If the right click happens on an item that is already selected,
don't pass on the signal so the selection which may span across
multiple files is kept.

Otherwise, pass on the signal which means the item under the cursor
will be selected.

This currently misbehaves (as in: doesn't work) with IconView
properly.
This commit is contained in:
Julian Ospald 2016-04-09 16:26:12 +02:00
parent 478ffa0e98
commit 0e226d61ec
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -76,15 +76,15 @@ setCallbacks :: MyGUI -> MyView -> IO ()
setCallbacks mygui myview = do setCallbacks mygui myview = do
view' <- readTVarIO $ view myview view' <- readTVarIO $ view myview
case view' of case view' of
FMTreeView treeView -> do fmv@(FMTreeView treeView) -> do
_ <- treeView `on` rowActivated _ <- treeView `on` rowActivated
$ (\_ _ -> withItems mygui myview open) $ (\_ _ -> withItems mygui myview open)
commonGuiEvents treeView commonGuiEvents fmv
return () return ()
FMIconView iconView -> do fmv@(FMIconView iconView) -> do
_ <- iconView `on` itemActivated _ <- iconView `on` itemActivated
$ (\_ -> withItems mygui myview open) $ (\_ -> withItems mygui myview open)
commonGuiEvents iconView commonGuiEvents fmv
return () return ()
menubarCallbacks menubarCallbacks
where where
@ -120,7 +120,9 @@ setCallbacks mygui myview = do
_ <- menubarHelpAbout mygui `on` menuItemActivated $ _ <- menubarHelpAbout mygui `on` menuItemActivated $
liftIO showAboutDialog liftIO showAboutDialog
return () return ()
commonGuiEvents view = do commonGuiEvents fmv = do
let view = fmViewToContainer fmv
-- GUI events -- GUI events
_ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview _ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview
@ -172,10 +174,25 @@ setCallbacks mygui myview = do
eb <- eventButton eb <- eventButton
t <- eventTime t <- eventTime
case eb of case eb of
RightButton -> liftIO $ menuPopup (rcMenu mygui) RightButton -> do
_ <- liftIO $ menuPopup (rcMenu mygui)
$ Just (RightButton, t) $ Just (RightButton, t)
_ -> return () -- this is just to not screw with current selection
return False -- on right-click
-- TODO: this misbehaves under IconView
(x, y) <- eventCoordinates
mpath <- liftIO $ getPathAtPos fmv (x, y)
case mpath of
-- item under the cursor, only pass on the signal
-- if the item under the cursor is not within the current
-- selection
(Just tp) -> do
selectedTps <- liftIO $ getSelectedTreePaths mygui myview
return $ elem tp selectedTps
-- no item under the cursor, pass on the signal
Nothing -> return False
-- not right-click, so pass on the signal
_ -> return False
_ <- rcFileOpen mygui `on` menuItemActivated $ _ <- rcFileOpen mygui `on` menuItemActivated $
liftIO $ withItems mygui myview open liftIO $ withItems mygui myview open
_ <- rcFileExecute mygui `on` menuItemActivated $ _ <- rcFileExecute mygui `on` menuItemActivated $
@ -192,8 +209,16 @@ setCallbacks mygui myview = do
liftIO $ withItems mygui myview del liftIO $ withItems mygui myview del
_ <- rcFileCut mygui `on` menuItemActivated $ _ <- rcFileCut mygui `on` menuItemActivated $
liftIO $ withItems mygui myview moveInit liftIO $ withItems mygui myview moveInit
return () return ()
getPathAtPos fmv (x, y) =
case fmv of
FMTreeView treeView -> do
mp <- treeViewGetPathAtPos treeView (round x, round y)
return $ fmap (\(p, _, _) -> p) mp
FMIconView iconView ->
fmap (\tp -> if null tp then Nothing else Just tp)
$ iconViewGetPathAtPos iconView (round x) (round y)
-- |Go to the url given at the 'urlBar' and visualize it in the given -- |Go to the url given at the 'urlBar' and visualize it in the given