Skip to content

Commit

Permalink
Add a branch label in the workspace window
Browse files Browse the repository at this point in the history
Add the name of the current Git branch with the Git logo in the
workspace window.
Working on catching the exception when you're not in a Git project.
  • Loading branch information
NWuensche committed Sep 3, 2016
1 parent e674e1b commit 2173f0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions leksah.cabal
Expand Up @@ -63,6 +63,7 @@ data-files:
pics/ide_error_next.png
pics/ide_error_prev.png
pics/ide_function.png
pics/ide_git.png
pics/ide_instance.png
pics/ide_konstructor.png
pics/ide_make.png
Expand Down
Binary file added pics/ide_git.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/IDE/Command.hs
Expand Up @@ -717,7 +717,7 @@ newIcons = catch (do
"ide_debug", "ide_step", "ide_local", "ide_module", "ide_continue", "ide_rebuild_meta",
"ide_empty","ide_source_local", "ide_js", "ide_folder", "ide_source_folder",
"ide_cabal_file", "ide_package", "ide_component", "ide_source_dependency", "ide_error",
"ide_warning", "ide_suggestion" ]
"ide_warning", "ide_suggestion", "ide_git" ]
iconFactoryAddDefault iconFactory)
(\(e :: SomeException) -> getDataDir >>= \dataDir -> throwIDE (T.pack $ printf (__ "Can't load icons from %s %s") dataDir (show e)))
where
Expand Down
30 changes: 18 additions & 12 deletions src/IDE/Pane/Workspace.hs
Expand Up @@ -125,6 +125,7 @@ import Data.GI.Gtk.ModelView.CustomStore
import Data.Int (Int32)
import Data.GI.Gtk.ModelView.Types
(treePathGetIndices', treePathNewFromIndices')
import VCSWrapper.Git as Git


-- | The data for a single record in the Workspace Pane
Expand Down Expand Up @@ -160,8 +161,8 @@ toMarkup record pkg = do
mbActivePackage <- readIDE activePack
mbActiveComponent <- readIDE activeExe

return . size $ case record of
(PackageRecord p) ->
case record of
(PackageRecord p) -> return $
let active = Just pkg == mbActivePackage
pkgText = (if active then bold else id)
(packageIdentifierToString (ipdPackageId p))
Expand All @@ -172,24 +173,28 @@ toMarkup record pkg = do
else ""
pkgDir = gray . T.pack $ ipdPackageDir p
in (pkgText <> " " <> componentText <> " " <> pkgDir)
(FileRecord f) -> T.pack $ takeFileName f
(DirRecord f _) | ipdPackageDir pkg == f -> "Files"
| otherwise -> T.pack $ last (splitDirectories f)
AddSourcesRecord -> "Source Dependencies"
(FileRecord f) -> return $ T.pack $ takeFileName f
(DirRecord f _)
| ipdPackageDir pkg == f -> return $ "Files"
| otherwise -> return $ T.pack $ last (splitDirectories f)
AddSourcesRecord -> return $ "Source Dependencies"
(AddSourceRecord p) -> do
let pkgText = packageIdentifierToString (ipdPackageId p)
dirText = gray (T.pack (ipdPackageDir p))
pkgText <> " " <> dirText
ComponentsRecord -> "Components"
let dirText = gray (T.pack (ipdPackageDir p))
return $ pkgText <> " " <> dirText
ComponentsRecord -> return $ "Components"
(ComponentRecord comp) -> do
let active = Just pkg == mbActivePackage &&
(mbActiveComponent == Nothing && comp == "library"
||
Just comp == mbActiveComponent)
(if active then bold else id) comp
GitRecord -> "Git"
return $ (if active then bold else id) comp
GitRecord -> do
bold ("Git" ++ getBranch)
let dir = ipdPackageDir pkg
let conf = Git.makeConfig (Just dir) Nothing Nothing
liftIO $ Git.runVcs conf $ do
(branch,_) <- localBranches -- TODO What if there is no branch?
return branch
where
bold str = "<b>" <> str <> "</b>"
italic str = "<i>" <> str <> "</i>"
Expand All @@ -210,6 +215,7 @@ toIcon record = case record of
ComponentsRecord -> "ide_component"
AddSourcesRecord -> "ide_source_dependency"
AddSourceRecord _ -> "ide_package"
GitRecord -> "ide_git"
_ -> ""


Expand Down

0 comments on commit 2173f0c

Please sign in to comment.