From eae68cc0ea6ecf9e424659bd7f436ead167b707c Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 28 Dec 2015 02:02:06 +0100 Subject: [PATCH] GTK: make the statusBar show the operation buffer --- data/Gtk/builder.xml | 51 +++++++++++++++++++++++++++++++++------- src/GUI/Gtk.hs | 2 ++ src/GUI/Gtk/Callbacks.hs | 19 +++++++++------ src/GUI/Gtk/Data.hs | 1 + src/GUI/Gtk/Utils.hs | 8 +++++++ 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/data/Gtk/builder.xml b/data/Gtk/builder.xml index b052594..e82a7bb 100644 --- a/data/Gtk/builder.xml +++ b/data/Gtk/builder.xml @@ -94,6 +94,11 @@ False gtk-edit + + True + False + gtk-cancel + False @@ -314,17 +319,45 @@ - + True False - 10 - 10 - 10 - 10 - 6 - 6 - vertical - 2 + + + True + False + 10 + 10 + 10 + 10 + 6 + 6 + vertical + 2 + + + True + True + 0 + + + + + True + True + True + 5 + 5 + 5 + 5 + image3 + + + False + True + 1 + + False diff --git a/src/GUI/Gtk.hs b/src/GUI/Gtk.hs index 710f000..1c790a7 100644 --- a/src/GUI/Gtk.hs +++ b/src/GUI/Gtk.hs @@ -191,6 +191,8 @@ startMainWindow startdir = do "urlBar" statusBar <- builderGetObject builder castToStatusbar "statusBar" + clearStatusBar <- builderGetObject builder castToButton + "clearStatusBar" rcMenu <- builderGetObject builder castToMenu "rcMenu" rcFileOpen <- builderGetObject builder castToImageMenuItem diff --git a/src/GUI/Gtk/Callbacks.hs b/src/GUI/Gtk/Callbacks.hs index 7080309..f8fc7a4 100644 --- a/src/GUI/Gtk/Callbacks.hs +++ b/src/GUI/Gtk/Callbacks.hs @@ -86,6 +86,12 @@ setCallbacks mygui myview = do -- GUI events _ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview _ <- treeView mygui `on` rowActivated $ (\_ _ -> withRows mygui myview open) + _ <- refreshView mygui `on` buttonActivated $ do + cdir <- liftIO $ getCurrentDir myview + refreshTreeView' mygui myview cdir + _ <- clearStatusBar mygui `on` buttonActivated $ do + popStatusbar mygui + writeTVarIO (operationBuffer myview) None -- key events _ <- rootWin mygui `on` keyPressEvent $ tryEvent $ do @@ -123,10 +129,6 @@ setCallbacks mygui myview = do "v" <- fmap glibToString eventKeyName liftIO $ operationFinal mygui myview - _ <- refreshView mygui `on` buttonActivated $ do - cdir <- liftIO $ getCurrentDir myview - refreshTreeView' mygui myview cdir - -- menubar-file _ <- menubarFileQuit mygui `on` menuItemActivated $ mainQuit _ <- menubarFileOpen mygui `on` menuItemActivated $ @@ -177,7 +179,6 @@ setCallbacks mygui myview = do _ <- rcFileCut mygui `on` menuItemActivated $ liftIO $ withRows mygui myview moveInit - return () @@ -240,8 +241,10 @@ del _ _ _ = withErrorDialog -- -- * 'operationBuffer' writes moveInit :: [Row] -> MyGUI -> MyView -> IO () -moveInit [row] mygui myview = +moveInit [row] mygui myview = do writeTVarIO (operationBuffer myview) (FMove . MP1 $ row) + let sbmsg = "Move buffer: " ++ fullPath row + void $ pushStatusBar mygui sbmsg moveInit _ _ _ = withErrorDialog . throw $ InvalidOperation "Operation not supported on multiple files" @@ -252,8 +255,10 @@ moveInit _ _ _ = withErrorDialog -- -- * 'operationBuffer' writes copyInit :: [Row] -> MyGUI -> MyView -> IO () -copyInit [row] mygui myview = +copyInit [row] mygui myview = do writeTVarIO (operationBuffer myview) (FCopy . CP1 $ row) + let sbmsg = "Copy buffer: " ++ fullPath row + void $ pushStatusBar mygui sbmsg copyInit _ _ _ = withErrorDialog . throw $ InvalidOperation "Operation not supported on multiple files" diff --git a/src/GUI/Gtk/Data.hs b/src/GUI/Gtk/Data.hs index 52dfa72..50d40c8 100644 --- a/src/GUI/Gtk/Data.hs +++ b/src/GUI/Gtk/Data.hs @@ -73,6 +73,7 @@ data MyGUI = MkMyGUI { , refreshView :: Button , urlBar :: Entry , statusBar :: Statusbar + , clearStatusBar :: Button , treeView :: TreeView -- |first column , cF :: TreeViewColumn diff --git a/src/GUI/Gtk/Utils.hs b/src/GUI/Gtk/Utils.hs index 70107ea..97f2747 100644 --- a/src/GUI/Gtk/Utils.hs +++ b/src/GUI/Gtk/Utils.hs @@ -294,3 +294,11 @@ pushStatusBar mygui str = do cid <- statusbarGetContextId sb "FM Status" mid <- statusbarPush sb cid str return (cid, mid) + + +-- |Pop a message from the status bar. +popStatusbar :: MyGUI -> IO () +popStatusbar mygui = do + let sb = statusBar mygui + cid <- statusbarGetContextId sb "FM Status" + statusbarPop sb cid