GTK: fix relative dirs to work outside of project basedir

Fixes #23
This commit is contained in:
Julian Ospald 2015-12-29 00:48:54 +01:00
parent ccc2f6f331
commit c6efdedf2d
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
4 changed files with 21 additions and 7 deletions

View File

@ -17,6 +17,7 @@ data-files: data/Gtk/builder.xml
data/Gtk/icons/gtk-directory.png
data/Gtk/icons/gtk-file.png
data/Gtk/icons/hsfm.png
hsfm.cabal
LICENSE

View File

@ -84,6 +84,10 @@ import IO.Error
import IO.File
import IO.Utils
import MyPrelude
import Paths_hsfm
(
getDataFileName
)
import Safe
(
headDef
@ -160,7 +164,7 @@ startMainWindow startdir = do
operationBuffer <- newTVarIO None
builder <- builderNew
builderAddFromFile builder "data/Gtk/builder.xml"
builderAddFromFile builder =<< getDataFileName "data/Gtk/builder.xml"
-- get the pre-defined gui widgets
rootWin <- builderGetObject builder castToWindow
@ -288,6 +292,6 @@ startMainWindow startdir = do
containerAdd scroll treeView
-- sets the default icon
windowSetDefaultIconFromFile "data/Gtk/icons/hsfm.png"
windowSetDefaultIconFromFile =<< getDataFileName "data/Gtk/icons/hsfm.png"
widgetShowAll rootWin

View File

@ -63,7 +63,10 @@ import Graphics.UI.Gtk
import GUI.Gtk.Data
import IO.Error
import IO.File
import Paths_hsfm
(
getDataFileName
)
@ -143,9 +146,11 @@ withCopyModeDialog fa =
showAboutDialog :: IO ()
showAboutDialog = do
ad <- aboutDialogNew
lstr <- readFile "LICENSE"
hsfmicon <- pixbufNewFromFile "data/Gtk/icons/hsfm.png"
pdesc <- packageDescription <$> readPackageDescription silent "hsfm.cabal"
lstr <- readFile =<< getDataFileName "LICENSE"
hsfmicon <- pixbufNewFromFile =<< getDataFileName "data/Gtk/icons/hsfm.png"
pdesc <- fmap packageDescription
(readPackageDescription silent
=<< getDataFileName "hsfm.cabal")
set ad
[ aboutDialogProgramName := (unPackageName . pkgName . package) pdesc
, aboutDialogName := (unPackageName . pkgName . package) pdesc

View File

@ -24,6 +24,10 @@ module GUI.Gtk.Icons where
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Gdk.Pixbuf
import Paths_hsfm
(
getDataFileName
)
-- |Icon type we use in our GUI.
@ -44,7 +48,7 @@ getIcon icon itheme isize = do
mpix <- iconThemeLoadIcon itheme iname isize IconLookupUseBuiltin
case mpix of
Just pix -> return pix
Nothing -> pixbufNewFromFile ("data/Gtk/icons/" ++ iname)
Nothing -> pixbufNewFromFile =<< getDataFileName ("data/Gtk/icons/" ++ iname)
where
iconToStr IFolder = "gtk-directory"
iconToStr IFile = "gtk-file"