Created
July 10, 2009 02:46
-
-
Save pzurek/144209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
to compile use: | |
fsc FebKit.fs -r "/usr/lib/cli/webkit-sharp-1.0/webkit-sharp.dll" -r "/usr/lib/mono/gtk-sharp-2.0/gtk-sharp.dll" -r "/usr/lib/mono/gtk-sharp-2.0/gdk-sharp.dll" -r "/usr/lib/mono/gtk-sharp-2.0/atk-sharp.dll" -r "/usr/lib/mono/gtk-sharp-2.0/glib-sharp.dll" | |
*) | |
#light | |
open System | |
open WebKit | |
open Gtk | |
Gtk.Application.Init() | |
let url = "http://piotrzurek.net" | |
let window = new Window("FebKit") | |
let webViewContainer = new ScrolledWindow() | |
let webView = new WebView() | |
let toolbar = new Toolbar() | |
let urlToolItem = new ToolItem(); | |
let urlEntry = new Entry(url) | |
let addressHBox = new HBox() | |
let statusbar = new Statusbar() | |
let vBox = new VBox() | |
let backAction = new Action("back", "Go Back", null, "gtk-go-back") | |
let forwardAction = new Action("forward", "Go Forward", null, "gtk-go-forward") | |
let stopAction = new Action("stop", "Stop", null, "gtk-stop") | |
let refreshAction = new Action("refresh", "Refresh", null, "gtk-refresh") | |
let openUrl address = | |
webView.Open(address) | |
urlEntry.Text <- address | |
let setWindowTitle title = | |
if String.IsNullOrEmpty(title) then window.Title <- "FebKit" | |
else window.Title <- title | |
let commitLoad uri = | |
urlEntry.Text <- uri | |
stopAction.Sensitive <- true | |
refreshAction.Sensitive <- false | |
//updateBackForwardButtons | |
(* | |
let disableButtons = | |
backAction.Sensitive <- false | |
forwardAction.Sensitive <- false | |
stopAction.Sensitive <- false | |
refreshAction.Sensitive <- false | |
let updateBackForwardButtons = | |
backAction.Sensitive <- webView.CanGoBack() | |
forwardAction.Sensitive <- webView.CanGoForward() | |
*) | |
let finishLoad wView = | |
stopAction.Sensitive <- false | |
refreshAction.Sensitive <- true | |
//updateBackForwardButtons | |
webView.Editable <- false | |
webView.MaintainsBackForwardList <- true | |
webView.TitleChanged.Add(fun e -> setWindowTitle e.Title) | |
webView.LoadCommitted.Add(fun e -> commitLoad(e.Frame.Uri)) | |
webView.LoadFinished.Add(fun _ -> finishLoad(webView)) | |
webView.HoveringOverLink.Add(fun args -> if args.Link = null then ignore() | |
else statusbar.Push((uint32)1, args.Link) |> ignore) | |
urlToolItem.Expand <- true | |
urlEntry.Activated.Add(fun _ -> webView.Open(urlEntry.Text)) | |
backAction.Activated.Add(fun _ -> webView.GoBack()) | |
forwardAction.Activated.Add(fun _ -> webView.GoForward()) | |
stopAction.Activated.Add(fun _ -> webView.StopLoading()) | |
refreshAction.Activated.Add(fun _ -> webView.Reload()) | |
urlToolItem.Add(urlEntry) | |
toolbar.BorderWidth <- (uint32)6 | |
toolbar.ToolbarStyle <- ToolbarStyle.Icons | |
toolbar.Add(backAction.CreateToolItem()) | |
toolbar.Add(forwardAction.CreateToolItem()) | |
toolbar.Add(stopAction.CreateToolItem()) | |
toolbar.Add(refreshAction.CreateToolItem()) | |
toolbar.Add(urlToolItem) | |
webViewContainer.ShadowType <- ShadowType.EtchedIn | |
webViewContainer.Add(webView) | |
vBox.PackStart(toolbar, false, false, (uint32)0) | |
vBox.PackStart(webViewContainer) | |
vBox.PackEnd(statusbar, false, false, (uint32)0) | |
window.Add(vBox) | |
window.WindowPosition <- Gtk.WindowPosition.Center | |
window.SetDefaultSize(1200, 800) | |
window.Destroyed.Add(fun _ -> Application.Quit()) | |
webView.Open(url) | |
window.ShowAll() | |
Gtk.Application.Run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment