GTK: fix switchView
This commit is contained in:
parent
e310879d61
commit
e72bff4180
@ -57,7 +57,7 @@ main = do
|
|||||||
|
|
||||||
_ <- initGUI
|
_ <- initGUI
|
||||||
mygui <- createMyGUI
|
mygui <- createMyGUI
|
||||||
_ <- newTab mygui createTreeView file
|
_ <- newTab mygui createTreeView file (-1)
|
||||||
|
|
||||||
setGUICallbacks mygui
|
setGUICallbacks mygui
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ import Control.Monad
|
|||||||
forM
|
forM
|
||||||
, forM_
|
, forM_
|
||||||
, join
|
, join
|
||||||
, unless
|
|
||||||
, void
|
, void
|
||||||
, when
|
, when
|
||||||
)
|
)
|
||||||
@ -56,10 +55,6 @@ import Data.Foldable
|
|||||||
(
|
(
|
||||||
for_
|
for_
|
||||||
)
|
)
|
||||||
import Data.Maybe
|
|
||||||
(
|
|
||||||
fromJust
|
|
||||||
)
|
|
||||||
import Graphics.UI.Gtk
|
import Graphics.UI.Gtk
|
||||||
import qualified HPath as P
|
import qualified HPath as P
|
||||||
import HPath
|
import HPath
|
||||||
@ -83,11 +78,6 @@ import System.Glib.UTFString
|
|||||||
(
|
(
|
||||||
glibToString
|
glibToString
|
||||||
)
|
)
|
||||||
import System.IO.Error
|
|
||||||
(
|
|
||||||
catchIOError
|
|
||||||
, isUserError
|
|
||||||
)
|
|
||||||
import System.Posix.Env.ByteString
|
import System.Posix.Env.ByteString
|
||||||
(
|
(
|
||||||
getEnv
|
getEnv
|
||||||
@ -367,44 +357,10 @@ closeTab mygui myview = do
|
|||||||
|
|
||||||
newTabHere :: MyGUI -> Item -> IO ()
|
newTabHere :: MyGUI -> Item -> IO ()
|
||||||
newTabHere mygui item@(DirOrSym _) =
|
newTabHere mygui item@(DirOrSym _) =
|
||||||
void $ withErrorDialog $ newTab mygui createTreeView item
|
void $ withErrorDialog $ newTab mygui createTreeView item (-1)
|
||||||
newTabHere _ _ = return ()
|
newTabHere _ _ = return ()
|
||||||
|
|
||||||
|
|
||||||
-- |Creates a new tab with its own view and refreshes the view.
|
|
||||||
newTab :: MyGUI -> IO FMView -> Item -> IO MyView
|
|
||||||
newTab mygui iofmv item = do
|
|
||||||
-- create eventbox with label
|
|
||||||
label <- labelNewWithMnemonic
|
|
||||||
(maybe (P.fromAbs $ path item) P.fromRel $ P.basename $ path item)
|
|
||||||
ebox <- eventBoxNew
|
|
||||||
eventBoxSetVisibleWindow ebox False
|
|
||||||
containerAdd ebox label
|
|
||||||
widgetShowAll label
|
|
||||||
|
|
||||||
myview <- createMyView mygui iofmv
|
|
||||||
_ <- notebookAppendPageMenu (notebook mygui) (viewBox myview)
|
|
||||||
ebox ebox
|
|
||||||
|
|
||||||
notebookSetTabReorderable (notebook mygui) (viewBox myview) True
|
|
||||||
|
|
||||||
catchIOError (refreshView mygui myview item) $ \e -> do
|
|
||||||
unless (isUserError e) (ioError e)
|
|
||||||
file <- readFile getFileInfo . fromJust . P.parseAbs . fromString
|
|
||||||
$ "/"
|
|
||||||
refreshView mygui myview file
|
|
||||||
labelSetText label (fromString "/")
|
|
||||||
|
|
||||||
-- close callback
|
|
||||||
_ <- ebox `on` buttonPressEvent $ do
|
|
||||||
eb <- eventButton
|
|
||||||
case eb of
|
|
||||||
MiddleButton -> do
|
|
||||||
_ <- liftIO $ closeTab mygui myview
|
|
||||||
return True
|
|
||||||
_ -> return False
|
|
||||||
|
|
||||||
return myview
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
--}
|
--}
|
||||||
|
|
||||||
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
|
|
||||||
module HSFM.GUI.Gtk.MyView where
|
module HSFM.GUI.Gtk.MyView where
|
||||||
@ -32,6 +33,16 @@ import Control.Concurrent.STM
|
|||||||
newTVarIO
|
newTVarIO
|
||||||
, readTVarIO
|
, readTVarIO
|
||||||
)
|
)
|
||||||
|
import Control.Monad
|
||||||
|
(
|
||||||
|
unless
|
||||||
|
, void
|
||||||
|
, when
|
||||||
|
)
|
||||||
|
import Control.Monad.IO.Class
|
||||||
|
(
|
||||||
|
liftIO
|
||||||
|
)
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
(
|
(
|
||||||
for_
|
for_
|
||||||
@ -41,6 +52,10 @@ import Data.Maybe
|
|||||||
catMaybes
|
catMaybes
|
||||||
, fromJust
|
, fromJust
|
||||||
)
|
)
|
||||||
|
import Data.String
|
||||||
|
(
|
||||||
|
fromString
|
||||||
|
)
|
||||||
import Graphics.UI.Gtk
|
import Graphics.UI.Gtk
|
||||||
import {-# SOURCE #-} HSFM.GUI.Gtk.Callbacks (setViewCallbacks)
|
import {-# SOURCE #-} HSFM.GUI.Gtk.Callbacks (setViewCallbacks)
|
||||||
import qualified HPath as P
|
import qualified HPath as P
|
||||||
@ -64,7 +79,9 @@ import System.INotify
|
|||||||
)
|
)
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
(
|
(
|
||||||
ioError
|
catchIOError
|
||||||
|
, ioError
|
||||||
|
, isUserError
|
||||||
)
|
)
|
||||||
import System.Posix.FilePath
|
import System.Posix.FilePath
|
||||||
(
|
(
|
||||||
@ -73,6 +90,43 @@ import System.Posix.FilePath
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- |Creates a new tab with its own view and refreshes the view.
|
||||||
|
newTab :: MyGUI -> IO FMView -> Item -> Int -> IO MyView
|
||||||
|
newTab mygui iofmv item pos = do
|
||||||
|
-- create eventbox with label
|
||||||
|
label <- labelNewWithMnemonic
|
||||||
|
(maybe (P.fromAbs $ path item) P.fromRel $ P.basename $ path item)
|
||||||
|
ebox <- eventBoxNew
|
||||||
|
eventBoxSetVisibleWindow ebox False
|
||||||
|
containerAdd ebox label
|
||||||
|
widgetShowAll label
|
||||||
|
|
||||||
|
myview <- createMyView mygui iofmv
|
||||||
|
_ <- notebookInsertPageMenu (notebook mygui) (viewBox myview)
|
||||||
|
ebox ebox pos
|
||||||
|
|
||||||
|
notebookSetTabReorderable (notebook mygui) (viewBox myview) True
|
||||||
|
|
||||||
|
catchIOError (refreshView mygui myview item) $ \e -> do
|
||||||
|
unless (isUserError e) (ioError e)
|
||||||
|
file <- readFile getFileInfo . fromJust . P.parseAbs . fromString
|
||||||
|
$ "/"
|
||||||
|
refreshView mygui myview file
|
||||||
|
labelSetText label (fromString "/" :: String)
|
||||||
|
|
||||||
|
-- close callback
|
||||||
|
_ <- ebox `on` buttonPressEvent $ do
|
||||||
|
eb <- eventButton
|
||||||
|
case eb of
|
||||||
|
MiddleButton -> liftIO $ do
|
||||||
|
n <- notebookGetNPages (notebook mygui)
|
||||||
|
when (n > 1) $ void $ destroyView mygui myview
|
||||||
|
return True
|
||||||
|
_ -> return False
|
||||||
|
|
||||||
|
return myview
|
||||||
|
|
||||||
|
|
||||||
-- |Constructs the initial MyView object with a few dummy models.
|
-- |Constructs the initial MyView object with a few dummy models.
|
||||||
-- It also initializes the callbacks.
|
-- It also initializes the callbacks.
|
||||||
createMyView :: MyGUI
|
createMyView :: MyGUI
|
||||||
@ -162,11 +216,10 @@ switchView mygui myview iofmv = do
|
|||||||
oldpage <- destroyView mygui myview
|
oldpage <- destroyView mygui myview
|
||||||
|
|
||||||
-- create new view and tab page where the previous one was
|
-- create new view and tab page where the previous one was
|
||||||
nview <- createMyView mygui iofmv
|
nview <- newTab mygui iofmv cwd oldpage
|
||||||
newpage <- notebookInsertPage (notebook mygui) (viewBox nview)
|
|
||||||
(maybe (P.fromAbs $ path cwd) P.fromRel
|
page <- fromJust <$> notebookPageNum (notebook mygui) (viewBox nview)
|
||||||
$ P.basename . path $ cwd) oldpage
|
notebookSetCurrentPage (notebook mygui) page
|
||||||
notebookSetCurrentPage (notebook mygui) newpage
|
|
||||||
|
|
||||||
refreshView mygui nview cwd
|
refreshView mygui nview cwd
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user