GTK: fix various glitches when opening tabs
This commit is contained in:
parent
d14caf5269
commit
89b231a2c9
@ -502,6 +502,17 @@ handleDT p
|
|||||||
= handleIOError $ \e -> return $ Failed p e
|
= handleIOError $ \e -> return $ Failed p e
|
||||||
|
|
||||||
|
|
||||||
|
-- |Carries out the action. If the action returns a file
|
||||||
|
-- with a failed constructor, rethrows the IOError within.
|
||||||
|
-- Otherwise, returns the file unchanged.
|
||||||
|
rethrowFailed :: IO (File a) -> IO (File a)
|
||||||
|
rethrowFailed a = do
|
||||||
|
file <- a
|
||||||
|
case file of
|
||||||
|
(Failed _ e) -> ioError e
|
||||||
|
_ -> return file
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---- SYMLINK HELPERS: ----
|
---- SYMLINK HELPERS: ----
|
||||||
|
|
||||||
|
@ -29,27 +29,35 @@ import Data.Maybe
|
|||||||
)
|
)
|
||||||
import Graphics.UI.Gtk
|
import Graphics.UI.Gtk
|
||||||
import qualified HPath as P
|
import qualified HPath as P
|
||||||
|
import HSFM.FileSystem.FileType
|
||||||
import HSFM.GUI.Gtk.Callbacks
|
import HSFM.GUI.Gtk.Callbacks
|
||||||
import HSFM.GUI.Gtk.Data
|
import HSFM.GUI.Gtk.Data
|
||||||
import HSFM.GUI.Gtk.MyGUI
|
import HSFM.GUI.Gtk.MyGUI
|
||||||
import HSFM.GUI.Gtk.MyView
|
import HSFM.GUI.Gtk.MyView
|
||||||
|
import Prelude hiding(readFile)
|
||||||
import Safe
|
import Safe
|
||||||
(
|
(
|
||||||
headDef
|
headDef
|
||||||
)
|
)
|
||||||
|
import System.IO.Error
|
||||||
|
(
|
||||||
|
catchIOError
|
||||||
|
)
|
||||||
import qualified System.Posix.Env.ByteString as SPE
|
import qualified System.Posix.Env.ByteString as SPE
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
_ <- initGUI
|
|
||||||
|
|
||||||
args <- SPE.getArgs
|
args <- SPE.getArgs
|
||||||
let mdir = fromMaybe (fromJust $ P.parseAbs "/")
|
let mdir = fromMaybe (fromJust $ P.parseAbs "/")
|
||||||
(P.parseAbs . headDef "/" $ args)
|
(P.parseAbs . headDef "/" $ args)
|
||||||
|
|
||||||
|
file <- catchIOError (rethrowFailed $ readFile getFileInfo mdir) $
|
||||||
|
\_ -> readFile getFileInfo . fromJust $ P.parseAbs "/"
|
||||||
|
|
||||||
|
_ <- initGUI
|
||||||
mygui <- createMyGUI
|
mygui <- createMyGUI
|
||||||
_ <- newTab mygui createTreeView mdir
|
_ <- newTab mygui createTreeView file
|
||||||
|
|
||||||
setGUICallbacks mygui
|
setGUICallbacks mygui
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ closeTab mygui myview = do
|
|||||||
|
|
||||||
newTabHere :: MyGUI -> Item -> IO ()
|
newTabHere :: MyGUI -> Item -> IO ()
|
||||||
newTabHere mygui item@(DirOrSym _) =
|
newTabHere mygui item@(DirOrSym _) =
|
||||||
void $ newTab mygui createTreeView (path item)
|
void $ withErrorDialog $ newTab mygui createTreeView item
|
||||||
newTabHere _ _ = return ()
|
newTabHere _ _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@ import Data.Maybe
|
|||||||
catMaybes
|
catMaybes
|
||||||
, fromJust
|
, fromJust
|
||||||
)
|
)
|
||||||
|
import Data.String
|
||||||
|
(
|
||||||
|
fromString
|
||||||
|
)
|
||||||
import HPath.IO.Errors
|
import HPath.IO.Errors
|
||||||
(
|
(
|
||||||
canOpenDirectory
|
canOpenDirectory
|
||||||
@ -81,6 +85,11 @@ import System.INotify
|
|||||||
, killINotify
|
, killINotify
|
||||||
, EventVariety(..)
|
, EventVariety(..)
|
||||||
)
|
)
|
||||||
|
import System.IO.Error
|
||||||
|
(
|
||||||
|
catchIOError
|
||||||
|
, ioError
|
||||||
|
)
|
||||||
import System.Posix.FilePath
|
import System.Posix.FilePath
|
||||||
(
|
(
|
||||||
pathSeparator
|
pathSeparator
|
||||||
@ -90,16 +99,21 @@ import System.Posix.FilePath
|
|||||||
|
|
||||||
|
|
||||||
-- |Creates a new tab with its own view and refreshes the view.
|
-- |Creates a new tab with its own view and refreshes the view.
|
||||||
newTab :: MyGUI -> IO FMView -> Path Abs -> IO MyView
|
newTab :: MyGUI -> IO FMView -> Item -> IO MyView
|
||||||
newTab mygui iofmv path = do
|
newTab mygui iofmv item = do
|
||||||
myview <- createMyView mygui iofmv
|
myview <- createMyView mygui iofmv
|
||||||
i <- notebookAppendPage (notebook mygui) (viewBox myview)
|
i <- notebookAppendPage (notebook mygui) (viewBox myview)
|
||||||
(maybe (P.fromAbs path) P.fromRel $ P.basename path)
|
(maybe (P.fromAbs $ path item) P.fromRel $ P.basename $ path item)
|
||||||
mpage <- notebookGetNthPage (notebook mygui) i
|
mpage <- notebookGetNthPage (notebook mygui) i
|
||||||
forM_ mpage $ \page -> notebookSetTabReorderable (notebook mygui)
|
forM_ mpage $ \page -> notebookSetTabReorderable (notebook mygui)
|
||||||
page
|
page
|
||||||
True
|
True
|
||||||
refreshView mygui myview (Just path)
|
catchIOError (refreshView' mygui myview item) $ \e -> do
|
||||||
|
forM_ mpage $ \page -> do
|
||||||
|
refreshView mygui myview (P.parseAbs $ fromString "/")
|
||||||
|
notebookSetTabLabelText (notebook mygui) page "/"
|
||||||
|
ioError e
|
||||||
|
|
||||||
return myview
|
return myview
|
||||||
|
|
||||||
|
|
||||||
@ -324,6 +338,9 @@ refreshView mygui myview mfp =
|
|||||||
--
|
--
|
||||||
-- If the directory is not a Dir or a Symlink pointing to a Dir, then
|
-- If the directory is not a Dir or a Symlink pointing to a Dir, then
|
||||||
-- calls `refreshView` with the 3rd argument being Nothing.
|
-- calls `refreshView` with the 3rd argument being Nothing.
|
||||||
|
--
|
||||||
|
-- Does not do fallbacks if the directory cannot be read, but
|
||||||
|
-- throws an error.
|
||||||
refreshView' :: MyGUI
|
refreshView' :: MyGUI
|
||||||
-> MyView
|
-> MyView
|
||||||
-> Item
|
-> Item
|
||||||
|
Loading…
Reference in New Issue
Block a user