module VCSGui.Git.Log (
showLogGUI
) where
import qualified Graphics.UI.Gtk as Gtk
import qualified VCSGui.Common.Log as Common
import qualified VCSWrapper.Git as Git
import Control.Monad.Reader (liftIO)
import Data.Maybe (fromMaybe)
import VCSGui.Common.Helpers (emptyTextToNothing)
import qualified Data.Text as T (unpack, pack)
import Data.Text (Text)
showLogGUI :: Git.Ctx ()
showLogGUI = do
log <- Git.simpleLog Nothing
branches <- Git.localBranches
Common.showLogGUI log [] (Just (branches, \branch -> Git.simpleLog (Just branch))) checkout False
where
checkout log Nothing = Git.checkout (Just $ Git.commitID log) Nothing
checkout log (Just selBranch) = do
revBranch <- Git.revparse selBranch
case ((Git.commitID log) == revBranch) of
True -> do
liftIO $ putStrLn "checking out selected Branch"
Git.checkout (Just selBranch) Nothing
False -> do
liftIO $ putStrLn $ "checking out Commit " ++ (T.unpack $ Git.commitID log) ++ ", asking for new branchname"
mbBranchname <- liftIO $ askForNewBranchname
Git.checkout (Just $ Git.commitID log) (mbBranchname)
askForNewBranchname :: IO (Maybe Text)
askForNewBranchname = do
dialog <- Gtk.dialogNew
Gtk.dialogAddButton dialog ("gtk-ok"::Text) Gtk.ResponseOk
#if defined(MIN_VERSION_gtk3)
upper <- Gtk.dialogGetContentArea dialog
#else
upper <- Gtk.dialogGetUpper dialog
#endif
inputBranch <- Gtk.entryNew
lblBranch <- Gtk.labelNew $ Just ("Enter a new branchname (empty for anonym branch):" :: Text)
box <- Gtk.hBoxNew False 2
Gtk.containerAdd (Gtk.castToBox upper) box
Gtk.containerAdd box lblBranch
Gtk.containerAdd box inputBranch
Gtk.widgetShowAll dialog
_ <- Gtk.dialogRun dialog
branchname <- Gtk.entryGetText inputBranch
Gtk.widgetDestroy dialog
return $ emptyTextToNothing branchname