-- Author: Andy Stewart -- Maintainer: Andy Stewart -- -- Copyright (C) 2010 Andy Stewart, all rights reserved. -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveDataTypeable #-} module Manatee.Extension.Terminal.TerminalView where import Control.Applicative import Control.Concurrent.STM import Data.Map (Map) import Data.Text.Lazy (Text) import Data.Typeable import Graphics.UI.Gtk hiding (Statusbar, statusbarNew, get) import Graphics.UI.Gtk.Vte.Vte import Graphics.UI.Gtk.Gdk.SerializedEvent import Manatee.Core.Types import Manatee.Extension.Terminal.TerminalBuffer import Manatee.Toolkit.Gtk.Gtk import Manatee.Toolkit.Gtk.ScrolledWindow import Paths_manatee_terminal import System.FilePath import qualified Data.Map as M data TerminalView = TerminalView {terminalViewPlugId :: TVar PagePlugId ,terminalViewScrolledWindow :: ScrolledWindow ,terminalViewView :: Terminal ,terminalViewBuffer :: TerminalBuffer } deriving Typeable instance PageBuffer TerminalBuffer where pageBufferGetName = readTVarIO . terminalBufferDirectory pageBufferSetName _ _ = return () pageBufferClient = terminalBufferClient pageBufferCreateView a pId = PageViewWrap <$> terminalViewNew a pId pageBufferMode = terminalBufferMode pageBufferPackageName _ = fmap takeFileName getDataDir instance PageView TerminalView where pageViewBuffer = PageBufferWrap . terminalViewBuffer pageViewPlugId = terminalViewPlugId pageViewFocus = widgetGrabFocus . terminalViewView pageViewCopy = terminalViewCopy pageViewPaste = terminalViewPaste pageViewScrolledWindow = terminalViewScrolledWindow pageViewHandleKeyAction = terminalViewHandleKeyAction -- | New terminal view. terminalViewNew :: TerminalBuffer -> PagePlugId -> IO TerminalView terminalViewNew buffer plugId = do -- Create UI frame. scrolledWindow <- scrolledWindowNew_ -- Create view. terminal <- terminalNew terminalForkCommand terminal Nothing Nothing Nothing Nothing False False False scrolledWindow `containerAdd` terminal pId <- newTVarIO plugId let terminalView = TerminalView pId scrolledWindow terminal buffer -- Return view. return terminalView -- | Handle key action. terminalViewHandleKeyAction :: TerminalView -> Text -> SerializedEvent -> IO () terminalViewHandleKeyAction view keystoke sEvent = case M.lookup keystoke terminalViewKeymap of Just action -> action view Nothing -> widgetPropagateEvent (terminalViewView view) sEvent -- | Keymap. terminalViewKeymap :: Map Text (TerminalView -> IO ()) terminalViewKeymap = M.fromList [] -- | Terminal view copy. terminalViewCopy :: TerminalView -> IO Bool terminalViewCopy view = do terminalCopyClipboard (terminalViewView view) return True -- | Terminal view paste. terminalViewPaste :: TerminalView -> IO Bool terminalViewPaste view = do terminalPasteClipboard (terminalViewView view) return True