Permalink
Browse files

Added Prompt.readURI function for convenience.

  • Loading branch information...
1 parent bd8f59c commit 5f39b27c2e4cd28f8eb0ce23bf09cf60de6b8384 koral committed Feb 22, 2012
Showing with 30 additions and 13 deletions.
  1. +2 −2 Hbro/Config.hs
  2. +0 −1 Hbro/Core.hs
  3. +21 −5 Hbro/Prompt.hs
  4. +7 −5 Hbro/Types.hs
View
@@ -105,8 +105,8 @@ defaultKeyBindings = [
("C-b", with (mStatusBar . mGUI) toggleVisibility),
("C-u", toggleSourceMode),
-- Prompt
- ("C-o", Prompt.read "Open URI" [] (mapM_ loadURI . parseURIReference)),
- ("M-o", withURI $ \uri -> Prompt.read "Open URI " (show uri) (mapM_ loadURI . parseURIReference)),
+ ("C-o", Prompt.readURI "Open URI" [] loadURI),
+ ("M-o", withURI $ \uri -> Prompt.readURI "Open URI " (show uri) loadURI),
-- Search
("/", Prompt.iread "Search " [] $ searchText False True True >=> const (return ())),
("C-f", Prompt.iread "Search " [] $ searchText False True True >=> const (return ())),
View
@@ -172,7 +172,6 @@ toggleSourceMode = do
webViewSetViewSourceMode view =<< (not `fmap` webViewGetViewSourceMode view)
reload
-
-- | Wrapper around webFramePrint function, provided for convenience.
printPage :: K ()
printPage = with (mWebView . mGUI) $ webViewGetMainFrame >=> webFramePrint
View
@@ -8,7 +8,7 @@ import Hbro.Types
import Control.Monad hiding(forM_, mapM_)
--import Control.Monad.Trans
---import Data.Foldable
+import Data.Foldable
import Data.IORef
import Graphics.Rendering.Pango.Enums
@@ -19,6 +19,8 @@ import Graphics.UI.Gtk.Entry.Editable
import Graphics.UI.Gtk.Entry.Entry
import Graphics.UI.Gtk.Layout.HBox
+import Network.URI
+
import Prelude hiding(mapM_)
import System.Console.CmdArgs (whenLoud)
@@ -62,11 +64,25 @@ incrementalRead = read' True
iread = incrementalRead
read' :: Bool -> String -> String -> (String -> K ()) -> K ()
-read' incremental description defaultText callback = with (mPromptBar . mGUI) $ \promptBar -> do
- open promptBar description defaultText
+read' incremental description startValue callback = with (mPromptBar . mGUI) $ \promptBar -> do
+ open promptBar description startValue
-- Register callback
case incremental of
True -> writeIORef (mIncrementalCallbackRef promptBar) callback
- _ -> writeIORef (mCallbackRef promptBar) callback
--- }}}
+ _ -> writeIORef (mCallbackRef promptBar) callback
+
+-- | "read"" for URI values
+readURI :: String
+ -> String
+ -> (URI -> K ())
+ -> K ()
+readURI description startValue callback = with (mPromptBar . mGUI) $ \promptBar -> do
+ open promptBar description startValue
+
+-- writeIORef (mIncrementalCallbackRef promptBar) checkURI
+ writeIORef (mCallbackRef promptBar) $ mapM_ callback . parseURIReference
+
+--checkURI :: String -> K ()
+--checkURI value = case isURI value of
+-- True ->
View
@@ -59,15 +59,15 @@ data CliOptions = CliOptions {
-- | Custom parameters provided by the user
data Config = {-forall a.-} Config {
--mCommonDirectories :: CommonDirectories, -- ^ Custom directories used to store various runtime and static files
- mSocketDir :: RefDirs -> FilePath, -- ^ Directory where 0MQ will be created ("/tmp" for example)
+ mSocketDir :: RefDirs -> FilePath, -- ^ Directory where 0MQ sockets will be created ("/tmp" for example)
mUIFile :: RefDirs -> FilePath, -- ^ Path to XML file describing UI (used by GtkBuilder)
mHomePage :: String, -- ^ Startup page
mWebSettings :: [AttrOp WebSettings], -- ^ WebSettings' attributes to use with webkit (see Webkit.WebSettings documentation)
-- mKeyEventHandler :: KeyEventCallback -> ConnectId WebView -> WebView -> EventM EKey Bool, -- ^ Key event handler, which forwards keystrokes to mKeyEventCallback
-- mKeyEventCallback :: Environment -> KeyEventCallback, -- ^ Main key event callback, assumed to deal with each keystroke separately
- mCommands :: CommandsList, -- ^ Custom commands to use with IPC sockets
- mHooks :: Hooks,
- mError :: Maybe String -- ^ Error
+ mCommands :: CommandsList, -- ^ Commands recognized through 0MQ sockets
+ mHooks :: Hooks, -- ^ Set of functions triggered on specific events
+ mError :: Maybe String -- ^ Error (used internally to notify about something wrong)
--mCustom :: a
}
@@ -115,6 +115,8 @@ data RefDirs = RefDirs {
mData :: FilePath -- ^ Data directory
}
+type PortableFilePath = RefDirs -> FilePath
+
-- | List of bound keys.
-- All callbacks are fed with the Environment instance.
--
@@ -133,4 +135,4 @@ type CommandsList = [(String, ([String] -> K String))]
type CommandsMap = Map String ([String] -> K String)
-- |
-data Button = ButtonL | ButtonM | ButtonR
+data Button = ButtonL | ButtonM | ButtonR

0 comments on commit 5f39b27

Please sign in to comment.