Skip to content

Commit

Permalink
Migrate to gtk 0.13.*
Browse files Browse the repository at this point in the history
  • Loading branch information
YoEight committed Jan 18, 2015
1 parent 77be489 commit dd57985
Show file tree
Hide file tree
Showing 16 changed files with 940 additions and 54 deletions.
7 changes: 4 additions & 3 deletions Dhek/Engine/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Data.List (dropWhileEnd)
import Control.Lens hiding (zoom)
import Control.Monad.State
import Control.Monad.RWS.Strict
import Data.Text (Text)
import qualified Graphics.UI.Gtk as Gtk
import qualified Graphics.UI.Gtk.Poppler.Document as Poppler
import qualified Graphics.UI.Gtk.Poppler.Page as Poppler
Expand Down Expand Up @@ -285,7 +286,7 @@ engineModePointerContext xs k i (x,y) = do

--------------------------------------------------------------------------------
engineModeKbContext :: [Gtk.Modifier]
-> String
-> Text
-> RuntimeEnv
-> (KbEnv -> M a)
-> IO ()
Expand All @@ -310,11 +311,11 @@ engineModeRelease :: [Gtk.Modifier] -> RuntimeEnv -> Pos -> IO ()
engineModeRelease modf env pos = engineModePointerContext modf release env pos

--------------------------------------------------------------------------------
engineModeKeyPress :: [Gtk.Modifier] -> String -> RuntimeEnv -> IO ()
engineModeKeyPress :: [Gtk.Modifier] -> Text -> RuntimeEnv -> IO ()
engineModeKeyPress modf name env = engineModeKbContext modf name env keyPress

--------------------------------------------------------------------------------
engineModeKeyRelease :: [Gtk.Modifier] -> String -> RuntimeEnv -> IO ()
engineModeKeyRelease :: [Gtk.Modifier] -> Text -> RuntimeEnv -> IO ()
engineModeKeyRelease modf name env = engineModeKbContext modf name env keyRelease

--------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Dhek/Engine/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Control.Applicative
import Control.Lens
import Control.Monad.State
import qualified Data.IntMap as I
import Data.Text
import Graphics.UI.Gtk (Modifier)

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -83,7 +84,7 @@ data DrawEnv
--------------------------------------------------------------------------------
data KbEnv
= KbEnv
{ kbKeyName :: String
{ kbKeyName :: Text
, kbModifier :: [Modifier]
}

Expand Down
24 changes: 15 additions & 9 deletions Dhek/GUI.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
-- |
-- Module : Dhek.GUI
Expand All @@ -24,10 +25,12 @@ import Control.Monad.Trans (MonadIO(..))
import Data.Foldable (Foldable, foldr, for_, traverse_)
import Data.IORef
import Data.Maybe
import Data.Monoid ((<>))
import Foreign.Ptr

--------------------------------------------------------------------------------
import Control.Lens ((^.))
import Data.Text (pack)
import qualified Graphics.Rendering.Cairo as Cairo
import qualified Graphics.UI.Gtk as Gtk
import qualified Graphics.UI.Gtk.Poppler.Page as Poppler
Expand Down Expand Up @@ -70,7 +73,7 @@ data GUI =
, guiValueEntry :: Gtk.Entry
, guiTypeCombo :: Gtk.ComboBox
, guiRectTreeSelection :: Gtk.TreeSelection
, guiTypeStore :: Gtk.ListStore String
, guiTypeStore :: Gtk.ListStore Gtk.ComboBoxText
, guiValueEntryAlign :: Gtk.Alignment
, guiWindowVBox :: Gtk.VBox
, guiWindowHBox :: Gtk.HBox
Expand Down Expand Up @@ -102,7 +105,10 @@ initGUI = do
where
settings :: [String] -> Gtk.Settings -> IO [String]
settings gui gs = do
Gtk.settingsSetLongProperty gs "gtk-button-images" 1 "Dhek"
Gtk.settingsSetLongProperty gs
("gtk-button-images" :: String)
1
"Dhek"
return gui

makeGUI :: IO GUI
Expand Down Expand Up @@ -213,7 +219,7 @@ makeGUI = do

-- Button Applidok
kimg <- loadImage Resources.applidok
akb <- Gtk.toolButtonNew (Just kimg) Nothing
akb <- Gtk.toolButtonNew (Just kimg) (Nothing :: Maybe String)
Gtk.set akb [Gtk.widgetTooltipText Gtk.:=
Just $ msgStr MsgApplidokTooltip]

Expand Down Expand Up @@ -246,7 +252,7 @@ makeGUI = do

-- Drawing Area tooltip
drawpop <- Gtk.windowNewPopup
dplabel <- Gtk.labelNew Nothing
dplabel <- Gtk.labelNew (Nothing :: Maybe String)
Gtk.labelSetMarkup dplabel $ msgStr MsgDuplicationModePopup
Gtk.containerAdd drawpop dplabel
Gtk.windowSetTypeHint drawpop Gtk.WindowTypeHintTooltip
Expand Down Expand Up @@ -381,7 +387,7 @@ makeGUI = do
-- Status bar
sbar <- Gtk.statusbarNew
sbalign <- Gtk.alignmentNew 0 1 1 0
ctxId <- Gtk.statusbarGetContextId sbar "mode"
ctxId <- Gtk.statusbarGetContextId sbar ("mode" :: String)
Gtk.statusbarSetHasResizeGrip sbar False
Gtk.containerAdd sbalign sbar
Gtk.boxPackEnd vbox sbalign Gtk.PackNatural 0
Expand Down Expand Up @@ -512,20 +518,20 @@ layoutMapping r
| r ^. rectType == "radio" || r ^. rectType == "comboitem" =
let value = fromMaybe "" (r ^. rectValue)
name = r ^. rectName
label = name ++ " (" ++ value ++ ")" in
label = name <> " (" <> value <> ")" in
[Gtk.cellText Gtk.:= label]
| r ^. rectType == "textcell" =
let idx = maybe "" show (r ^. rectIndex)
let idx = maybe "" (pack . show) (r ^. rectIndex)
name = r ^. rectName
label = name ++ " (" ++ idx ++ ")" in
label = name <> " (" <> idx <> ")" in
[Gtk.cellText Gtk.:= label]
| otherwise = [Gtk.cellText Gtk.:= r ^. rectName]

--------------------------------------------------------------------------------
createToolButton :: Ptr Gtk.InlineImage -> String -> IO Gtk.ToolButton
createToolButton img msg
= do imgb <- loadImage img
b <- Gtk.toolButtonNew (Just imgb) Nothing
b <- Gtk.toolButtonNew (Just imgb) (Nothing :: Maybe String)
Gtk.set b [Gtk.widgetTooltipText Gtk.:=
Just msg]
return b
Expand Down
15 changes: 8 additions & 7 deletions Dhek/GUI/Action.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
-- |
-- Module : Dhek.GUI.Action
Expand Down Expand Up @@ -36,13 +37,13 @@ module Dhek.GUI.Action
--------------------------------------------------------------------------------
import Data.Char (isSpace)
import Data.Foldable (for_, traverse_)
import Data.List (dropWhileEnd)
import Data.Maybe (fromMaybe)
import Data.Traversable (for, sequenceA)
import Foreign.Ptr

--------------------------------------------------------------------------------
import Control.Lens
import qualified Data.Text as T
import qualified Graphics.UI.Gtk as Gtk

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -76,7 +77,7 @@ gtkUnselect gui = do
Gtk.widgetSetSensitive (guiNameEntry gui) False
Gtk.widgetSetSensitive (guiRemoveButton gui) False
Gtk.widgetSetSensitive (guiApplyButton gui) False
Gtk.entrySetText (guiNameEntry gui) ""
Gtk.entrySetText (guiNameEntry gui) ("" :: String)
Gtk.comboBoxSetActive (guiTypeCombo gui) (- 1)
gtkSetValuePropVisible False gui
gtkSetIndexPropVisible False gui
Expand All @@ -94,7 +95,7 @@ gtkSelectRect r gui = do
Gtk.entrySetText (guiNameEntry gui) name

case r ^. rectValue of
Nothing -> Gtk.entrySetText (guiValueEntry gui) ""
Nothing -> Gtk.entrySetText (guiValueEntry gui) ("" :: String)
Just v -> Gtk.entrySetText (guiValueEntry gui) v

case r ^. rectIndex of
Expand Down Expand Up @@ -192,11 +193,11 @@ gtkRemoveRect r gui = do
Gtk.listStoreRemove (guiRectStore gui) idx

--------------------------------------------------------------------------------
gtkLookupEntryText :: Gtk.Entry -> IO (Maybe String)
gtkLookupEntryText :: Gtk.Entry -> IO (Maybe T.Text)
gtkLookupEntryText entry = do
txt <- Gtk.entryGetText entry
let txt1 = trimString txt
r = if null txt1 then Nothing else Just txt1
r = if T.null txt1 then Nothing else Just txt1
return r

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -335,5 +336,5 @@ lookupStoreIter predicate store = Gtk.treeModelGetIterFirst store >>= go
go _ = return Nothing

--------------------------------------------------------------------------------
trimString :: String -> String
trimString = dropWhileEnd isSpace . dropWhile isSpace
trimString :: T.Text -> T.Text
trimString = T.dropWhileEnd isSpace . T.dropWhile isSpace
5 changes: 4 additions & 1 deletion Dhek/I18N.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import System.Process

import Data.Text (Text, unpack, pack)
import Distribution.System (OS(..), buildOS)
import System.FilePath
import Text.Shakespeare.I18N

data Dhek = Dhek

mkMessage "Dhek" "messages" "en"
mkMessage "Dhek"
(joinPath ["messages", "main"])
"en"

mkI18N :: IO (DhekMessage -> String)
mkI18N = fmap (\l -> unpack . renderMessage Dhek [l]) determineLang
Expand Down
6 changes: 4 additions & 2 deletions Dhek/Mode/Normal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
-- |
-- Module : Dhek.Mode.Normal
Expand All @@ -19,6 +20,7 @@ import Data.Traversable
--------------------------------------------------------------------------------
import Control.Lens hiding (Action, act)
import Control.Monad.RWS hiding (mapM_)
import Data.Text (Text, pack)
import qualified Graphics.Rendering.Cairo as Cairo
import qualified Graphics.UI.Gtk as Gtk

Expand Down Expand Up @@ -436,7 +438,7 @@ normalDrawingRelease v
= when (w*h >= 30) $
do rid <- engineDrawState.drawFreshId <+= 1
let r1 = r & rectId .~ rid
& rectName %~ (++ show rid)
& rectName %~ (<> (pack $ show rid))

-- New rectangle
gui <- asks inputGUI
Expand Down Expand Up @@ -581,7 +583,7 @@ guideRange opts
= 10 / ratio where ratio = drawRatio opts

--------------------------------------------------------------------------------
statusNamePressed :: String -> Bool
statusNamePressed :: Text -> Bool
statusNamePressed n
| "Alt_L" <- n = True
| "Alt_R" <- n = True
Expand Down
3 changes: 2 additions & 1 deletion Dhek/Mode/Selection.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
--------------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -709,7 +710,7 @@ selectionModeManager handler gui = do
createToolbarButton :: GUI -> Ptr Gtk.InlineImage -> IO Gtk.ToolButton
createToolbarButton gui img
= do bimg <- loadImage img
b <- Gtk.toolButtonNew (Just bimg) Nothing
b <- Gtk.toolButtonNew (Just bimg) (Nothing :: Maybe String)
Gtk.toolbarInsert (guiModeToolbar gui) b (-1)
Gtk.widgetShowAll b
Gtk.widgetSetSensitive b False
Expand Down
1 change: 1 addition & 0 deletions Dhek/Signal.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
-- |
-- Module : Dhek.Signal
Expand Down
15 changes: 8 additions & 7 deletions Dhek/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import Data.Aeson hiding (Array)
import Data.Aeson.Types (Parser)
import Data.IntMap (IntMap, empty, fromList)
import qualified Data.Map as Map
import Data.Monoid (Monoid (..))
import Data.Monoid (Monoid (..), (<>))
import Data.Text (Text, pack)
import qualified Data.Vector as V
import qualified Graphics.UI.Gtk.Poppler.Document as Poppler

Expand Down Expand Up @@ -72,7 +73,7 @@ data Boards
--------------------------------------------------------------------------------
data Grouped
= Simple Rect
| Grouped String GType [Rect]
| Grouped Text GType [Rect]

--------------------------------------------------------------------------------
data GType = TextCell
Expand All @@ -84,9 +85,9 @@ data Rect
, _rectPoint :: !Point2D
, _rectHeight :: !Double
, _rectWidth :: !Double
, _rectName :: !String
, _rectType :: !String
, _rectValue :: !(Maybe String)
, _rectName :: !Text
, _rectType :: !Text
, _rectValue :: !(Maybe Text)
, _rectIndex :: !(Maybe Int)
}
deriving (Eq, Show)
Expand Down Expand Up @@ -226,7 +227,7 @@ toJsonGrouped (Grouped name typ rs)
TextCell -> toJsonTextCell name rs

--------------------------------------------------------------------------------
toJsonTextCell :: String -> [Rect] -> Value
toJsonTextCell :: Text -> [Rect] -> Value
toJsonTextCell name rs
= object [ "type" .= ("celltext" :: String)
, "name" .= name
Expand Down Expand Up @@ -341,7 +342,7 @@ addRect page x = execState action
action = do
i <- use boardsState
boardsState += 1
let x' = x & rectId .~ i & rectName %~ (++ show i)
let x' = x & rectId .~ i & rectName %~ (<> (pack $ show i))
(boardsMap.at page.traverse.boardRects.at i) ?= x'

--------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit dd57985

Please sign in to comment.