Commands: refactoring to include in MetaModule

Just a small refactooring (well, now runCommand requires a command list, and
I added runCommand's that will take a string to run it against the default
command list) to include this module in MetaModule so that we can track it
in case of API changes (this patch has been requested by Spencer).
This commit is contained in:
Andrea Rossato
2007-07-28 13:20:29 +00:00
parent 1ab925579c
commit 773367e6b8
2 changed files with 20 additions and 16 deletions

View File

@@ -17,14 +17,18 @@
module XMonadContrib.Commands ( module XMonadContrib.Commands (
-- * Usage -- * Usage
-- $usage -- $usage
commandMap,
runCommand, runCommand,
runCommand',
workspaceCommands,
screenCommands,
defaultCommands defaultCommands
) where ) where
import XMonad import XMonad
import Operations import Operations
import {-# SOURCE #-} Config (workspaces, commands)
import XMonadContrib.Dmenu (dmenu) import XMonadContrib.Dmenu (dmenu)
import {-# SOURCE #-} Config (workspaces)
import qualified Data.Map as M import qualified Data.Map as M
import System.Exit import System.Exit
@@ -42,22 +46,16 @@ import Data.Maybe
-- --
-- and define the list commands: -- and define the list commands:
-- --
-- > commands = defaultCommands
--
-- Finally, add the following lines to Config.hs-boot:
--
-- > import XMonad (X)
-- > workspaces :: Int
-- > commands :: [(String, X ())] -- > commands :: [(String, X ())]
-- > commands = defaultCommands
-- --
-- A popup menu of internal xmonad commands will appear. You can -- A popup menu of internal xmonad commands will appear. You can
-- change the commands by changing the contents of the list -- change the commands by changing the contents of the list
-- 'commands'. (If you like it enough, you may even want to get rid -- 'commands'. (If you like it enough, you may even want to get rid
-- of many of your other key bindings!) -- of many of your other key bindings!)
commandMap :: [(String, X ())] -> M.Map String (X ())
commandMap :: M.Map String (X ()) commandMap c = M.fromList c
commandMap = M.fromList commands
workspaceCommands :: [(String, X ())] workspaceCommands :: [(String, X ())]
workspaceCommands = [((m ++ show i), f (fromIntegral i)) workspaceCommands = [((m ++ show i), f (fromIntegral i))
@@ -91,7 +89,13 @@ defaultCommands = workspaceCommands ++ screenCommands
, ("quit-wm", io $ exitWith ExitSuccess) , ("quit-wm", io $ exitWith ExitSuccess)
] ]
runCommand :: X () runCommand :: [(String, X ())] -> X ()
runCommand = do runCommand cl = do
choice <- dmenu (M.keys commandMap) let m = commandMap cl
fromMaybe (return ()) (M.lookup choice commandMap) choice <- dmenu (M.keys m)
fromMaybe (return ()) (M.lookup choice m)
runCommand' :: String -> X ()
runCommand' c = do
let m = commandMap defaultCommands
fromMaybe (return ()) (M.lookup c m)

View File

@@ -23,7 +23,7 @@ import XMonadContrib.Accordion ()
import XMonadContrib.Anneal () import XMonadContrib.Anneal ()
-- commented because of conflicts with 6.6's instances import XMonadContrib.BackCompat () -- commented because of conflicts with 6.6's instances import XMonadContrib.BackCompat ()
import XMonadContrib.Circle () import XMonadContrib.Circle ()
-- TODO commented because it requires hs-boot modifications import XMonadContrib.Commands () import XMonadContrib.Commands ()
import XMonadContrib.Combo () import XMonadContrib.Combo ()
import XMonadContrib.CopyWindow () import XMonadContrib.CopyWindow ()
import XMonadContrib.Decoration () import XMonadContrib.Decoration ()