Skip to content

Commit

Permalink
added the +NEW tab to collect up to 16 buttons
Browse files Browse the repository at this point in the history
This is added as first tab, and special check in change page
for this (needs fixing).

should this always be the last tab?
need to add config file option to set table size

Signed-off-by: Christopher Hall <hsw@ms2.hinet.net>
  • Loading branch information
hxw committed Jun 29, 2012
1 parent 8f497c1 commit 929b361
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions TerminalUI.hs
Expand Up @@ -4,6 +4,7 @@
module TerminalUI where

import Data.Maybe( fromJust )
import Data.Foldable( foldlM )
import Control.Monad.Trans( liftIO )
import System.Process( ProcessHandle )

Expand Down Expand Up @@ -39,14 +40,24 @@ run (orient, tabList, buttonList) = do
GTK.on notebook GTK.switchPage $ pageChange toplevel notebook
GTK.widgetSetCanFocus notebook False

-- create the buttons page
table <- GTK.tableNew 4 4 True
GTK.widgetShowAll table
page <- GTK.notebookAppendPage notebook table "+NEW"


-- create all the initial table
mapM_ (\tab -> do
let (title, start, dir, command, sendList) = tab
addPane notebook title start dir command sendList) tabList

-- create buttons
-- ***TODO*** ?? where to put? on a special tab?
-- ????
foldlM (\(x, y) button -> do
let (title, start, dir, command, sendList) = button
addButton table x y notebook title start dir command sendList
let x1 = x + 1
if x > 4 then return (0, y + 1) else return (x1, y)
) (0, 0) buttonList

-- link up the close button
GTK.on toplevel GTK.deleteEvent $ liftIO $ checkExit
Expand All @@ -70,6 +81,18 @@ exitNotice = do
GTK.widgetDestroy dialog


-- add buttons to the button menu
addButton :: GTK.Table -> Int -> Int -> GTK.Notebook -> String -> Bool -> Maybe String -> CP.CommandList -> [String] -> IO ()
addButton table x y notebook title autoStart dir commandList sendList = do
button <- GTK.buttonNewWithLabel title
GTK.on button GTK.buttonActivated $ (addPane notebook title autoStart dir commandList sendList >> return ())

GTK.widgetShowAll button
GTK.tableAttachDefaults table button x (x + 1) y (y + 1)
return ()


-- add auto/manual stared panes
addPane :: GTK.Notebook -> String -> Bool -> Maybe String -> CP.CommandList -> [String] -> IO Int
addPane notebook title autoStart dir commandList sendList = do
vbox <- GTK.vBoxNew False 0
Expand Down Expand Up @@ -160,6 +183,9 @@ unplug button socket refproc = do
-- change the main title to be the tab name
pageChange :: GTK.Window -> GTK.Notebook -> Int -> IO ()
pageChange window notebook page = do
if page == 0 then return () else xpageChange window notebook page

xpageChange window notebook page = do
vBox <- GTK.notebookGetNthPage notebook page
children <- GTK.containerGetChildren $ GTK.castToVBox $ fromJust vBox

Expand Down
1 change: 1 addition & 0 deletions config.rc
Expand Up @@ -44,6 +44,7 @@ command gvim {
pane p1 "Project 1" {
run urxvt
start auto (* does not apply to button *)
# start manual
#cwd "/tmp"
send-line "export PROJECT=p1"
send-line "echo 'Hello World!'\" [aa]{BB}\""
Expand Down

0 comments on commit 929b361

Please sign in to comment.