From 077ac8122734c4d94f070481e4754fd81021eba5 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 3 Jun 2016 14:25:17 +0200 Subject: [PATCH] GTK: improve tab opening When multiple folders are selected, a regular 'open' will open new tabs for each of them without changing the current view. --- data/Gtk/builder.xml | 14 ------------- src/HSFM/GUI/Gtk/Callbacks.hs | 38 ++++++++++++++++------------------- src/HSFM/GUI/Gtk/Data.hs | 1 - src/HSFM/GUI/Gtk/MyView.hs | 2 -- 4 files changed, 17 insertions(+), 38 deletions(-) diff --git a/data/Gtk/builder.xml b/data/Gtk/builder.xml index a259a72..fd6ee08 100644 --- a/data/Gtk/builder.xml +++ b/data/Gtk/builder.xml @@ -525,15 +525,6 @@ False - - - New Tab here - True - False - image9 - False - - @@ -643,11 +634,6 @@ False gtk-add - - True - False - gtk-add - True False diff --git a/src/HSFM/GUI/Gtk/Callbacks.hs b/src/HSFM/GUI/Gtk/Callbacks.hs index de96bf6..2c94a2d 100644 --- a/src/HSFM/GUI/Gtk/Callbacks.hs +++ b/src/HSFM/GUI/Gtk/Callbacks.hs @@ -229,9 +229,7 @@ setViewCallbacks mygui myview = do _ <- viewBox myview `on` keyPressEvent $ tryEvent $ do [Control] <- eventModifier "t" <- fmap glibToString eventKeyName - liftIO $ void $ do - cwd <- getCurrentDir myview - newTabHere mygui cwd + liftIO $ void $ newTab' mygui myview _ <- viewBox myview `on` keyPressEvent $ tryEvent $ do [Control] <- eventModifier "w" <- fmap glibToString eventKeyName @@ -273,7 +271,7 @@ setViewCallbacks mygui myview = do -- if the item under the cursor is not within the current -- selection (Just item) -> do - liftIO $ newTabHere mygui item + liftIO $ opeInNewTab mygui item return True -- no item under the cursor, pass on the signal Nothing -> return False @@ -297,12 +295,7 @@ setViewCallbacks mygui myview = do _ <- (rcFileNewDir . rcmenu) myview `on` menuItemActivated $ liftIO $ newDir mygui myview _ <- (rcFileNewTab . rcmenu) myview `on` menuItemActivated $ - liftIO $ do - cwd <- getCurrentDir myview - newTabHere mygui cwd - _ <- (rcFileNewTabHere . rcmenu) myview `on` menuItemActivated $ - liftIO $ withItems mygui myview $ \items mygui' _ -> - forM_ items $ newTabHere mygui' + liftIO $ newTab' mygui myview _ <- (rcFileCopy . rcmenu) myview `on` menuItemActivated $ liftIO $ withItems mygui myview copyInit _ <- (rcFileRename . rcmenu) myview `on` menuItemActivated $ @@ -355,12 +348,16 @@ closeTab mygui myview = do when (n > 1) $ void $ destroyView mygui myview -newTabHere :: MyGUI -> Item -> IO () -newTabHere mygui item@(DirOrSym _) = +newTab' :: MyGUI -> MyView -> IO () +newTab' mygui myview = do + cwd <- getCurrentDir myview + void $ withErrorDialog $ newTab mygui createTreeView cwd (-1) + + +opeInNewTab :: MyGUI -> Item -> IO () +opeInNewTab mygui item@(DirOrSym _) = void $ withErrorDialog $ newTab mygui createTreeView item (-1) -newTabHere _ _ = return () - - +opeInNewTab _ _ = return () @@ -520,12 +517,11 @@ open [item] mygui myview = withErrorDialog $ goDir True mygui myview nv r -> void $ openFile . path $ r --- this throws on the first error that occurs -open (FileLikeList fs) _ _ = withErrorDialog $ - forM_ fs $ \f -> void $ openFile . path $ f -open _ _ _ = withErrorDialog - . throwIO $ InvalidOperation - "Operation not supported on multiple files" +open items mygui _ = do + let dirs = filter (fst . sdir) items + files = filter (fst . sfileLike) items + forM_ dirs (withErrorDialog . opeInNewTab mygui) + forM_ files (withErrorDialog . openFile . path) -- |Go up one directory and visualize it in the treeView. diff --git a/src/HSFM/GUI/Gtk/Data.hs b/src/HSFM/GUI/Gtk/Data.hs index f95e241..0cf242b 100644 --- a/src/HSFM/GUI/Gtk/Data.hs +++ b/src/HSFM/GUI/Gtk/Data.hs @@ -108,7 +108,6 @@ data RightClickMenu = MkRightClickMenu { , rcFileNewRegFile :: !ImageMenuItem , rcFileNewDir :: !ImageMenuItem , rcFileNewTab :: !ImageMenuItem - , rcFileNewTabHere :: !ImageMenuItem , rcFileCut :: !ImageMenuItem , rcFileCopy :: !ImageMenuItem , rcFileRename :: !ImageMenuItem diff --git a/src/HSFM/GUI/Gtk/MyView.hs b/src/HSFM/GUI/Gtk/MyView.hs index 604f6f1..6b95bcd 100644 --- a/src/HSFM/GUI/Gtk/MyView.hs +++ b/src/HSFM/GUI/Gtk/MyView.hs @@ -163,8 +163,6 @@ createMyView mygui iofmv = do "rcFileNewDir" rcFileNewTab <- builderGetObject builder castToImageMenuItem "rcFileNewTab" - rcFileNewTabHere <- builderGetObject builder castToImageMenuItem - "rcFileNewTabHere" rcFileCut <- builderGetObject builder castToImageMenuItem "rcFileCut" rcFileCopy <- builderGetObject builder castToImageMenuItem