private void WebViewNavigationRequested(object o, WebKit.NavigationRequestedArgs args) { Controller.LinkClicked(args.Request.Uri); // Don't follow HREFs (as this would cause a page refresh) if (!args.Request.Uri.Equals("file:")) { args.RetVal = 1; } }
public void UpdateContent(string html) { string pixmaps_path = "file://" + NSBundle.MainBundle.ResourcePath; html = html.Replace("<!-- $body-font-family -->", "Helvetica Neue"); html = html.Replace("<!-- $day-entry-header-font-size -->", "13.6px"); html = html.Replace("<!-- $body-font-size -->", "13.4px"); html = html.Replace("<!-- $secondary-font-color -->", "#bbb"); html = html.Replace("<!-- $small-color -->", "#ddd"); html = html.Replace("<!-- $small-font-size -->", "10px"); html = html.Replace("<!-- $day-entry-header-background-color -->", "#f5f5f5"); html = html.Replace("<!-- $a-color -->", "#009ff8"); html = html.Replace("<!-- $a-hover-color -->", "#009ff8"); html = html.Replace("<!-- $pixmaps-path -->", pixmaps_path); html = html.Replace("<!-- $document-added-background-image -->", pixmaps_path + "/document-added-12.png"); html = html.Replace("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png"); html = html.Replace("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png"); html = html.Replace("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png"); this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "") { Frame = new RectangleF(new PointF(0, 0), new SizeF(ContentView.Frame.Width, ContentView.Frame.Height - 39)) }; this.web_view.MainFrame.LoadHtmlString(html, new NSUrl("")); this.web_view.PolicyDelegate = new SparkleWebPolicyDelegate(); ContentView.AddSubview(this.web_view); (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate(string href) { if (href.StartsWith("file:///")) { href = href.Substring(7); } Controller.LinkClicked(href); }; this.progress_indicator.Hidden = true; }
public override void DecidePolicyForNavigation(WebView web_view, NSDictionary action_info, NSUrlRequest request, WebFrame frame, NSObject decision_token) { SparkleEventLogController.LinkClicked(request.Url.ToString()); }
public SparkleEventLog() : base() { using (var a = new NSAutoreleasePool()) { Title = "Recent Changes"; Delegate = new SparkleEventsDelegate(); // TODO: Make window resizable int width = 480; int height = 640; float x = (float)(NSScreen.MainScreen.Frame.Width * 0.61); float y = (float)(NSScreen.MainScreen.Frame.Height * 0.5 - (height * 0.5)); SetFrame(new RectangleF(x, y, width, height), true); StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled); MaxSize = new SizeF(480, 640); MinSize = new SizeF(480, 640); HasShadow = true; BackingType = NSBackingStore.Buffered; this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "") { PolicyDelegate = new SparkleWebPolicyDelegate() }; this.hidden_close_button = new NSButton() { Frame = new RectangleF(0, 0, 0, 0), KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, KeyEquivalent = "w" }; this.hidden_close_button.Activated += delegate { Controller.WindowClosed(); }; this.size_label = new NSTextField() { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF(0, 588, 60, 20), StringValue = "Size:", Font = SparkleUI.BoldFont }; this.size_label_value = new NSTextField() { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF(60, 588, 75, 20), StringValue = "…", Font = SparkleUI.Font }; this.history_label = new NSTextField() { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF(130, 588, 60, 20), StringValue = "History:", Font = SparkleUI.BoldFont }; this.history_label_value = new NSTextField() { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF(190, 588, 75, 20), StringValue = "…", Font = SparkleUI.Font }; this.separator = new NSBox(new RectangleF(0, 579, 480, 1)) { BorderColor = NSColor.LightGray, BoxType = NSBoxType.NSBoxCustom }; this.background = new NSBox(new RectangleF(0, -1, 481, 581)) { FillColor = NSColor.White, BoxType = NSBoxType.NSBoxCustom }; this.progress_indicator = new NSProgressIndicator() { Style = NSProgressIndicatorStyle.Spinning, Frame = new RectangleF(this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20) }; this.progress_indicator.StartAnimation(this); ContentView.AddSubview(this.size_label); ContentView.AddSubview(this.size_label_value); ContentView.AddSubview(this.history_label); ContentView.AddSubview(this.history_label_value); ContentView.AddSubview(this.separator); ContentView.AddSubview(this.progress_indicator); ContentView.AddSubview(this.background); ContentView.AddSubview(this.hidden_close_button); (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate(string href) { Controller.LinkClicked(href); }; } // Hook up the controller events Controller.HideWindowEvent += delegate { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { PerformClose(this); if (this.web_view.Superview == ContentView) { this.web_view.RemoveFromSuperview(); } }); } }; Controller.ShowWindowEvent += delegate { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { OrderFrontRegardless(); }); } }; Controller.UpdateChooserEvent += delegate(string [] folders) { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { UpdateChooser(folders); }); } }; Controller.UpdateContentEvent += delegate(string html) { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { UpdateContent(html); }); } }; Controller.ContentLoadingEvent += delegate { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { if (this.web_view.Superview == ContentView) { this.web_view.RemoveFromSuperview(); } ContentView.AddSubview(this.progress_indicator); }); } }; Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) { using (var a = new NSAutoreleasePool()) { InvokeOnMainThread(delegate { this.size_label_value.StringValue = size; this.history_label_value.StringValue = history_size; }); } }; }
public SparkleEventLog() : base("") { SetSizeRequest(480, 640); SetPosition(WindowPosition.Center); Resizable = true; BorderWidth = 0; Title = _("Recent Events"); IconName = "folder-sparkleshare"; DeleteEvent += Close; this.size_label = new Label() { Markup = "<b>Size:</b> " + Controller.Size + " " + "<b>History:</b> " + Controller.HistorySize }; VBox layout_vertical = new VBox(false, 0); this.spinner = new SparkleSpinner(22); this.content_wrapper = new EventBox(); this.scrolled_window = new ScrolledWindow(); this.web_view = new WebView() { Editable = false }; this.web_view.HoveringOverLink += delegate(object o, WebKit.HoveringOverLinkArgs args) { this.link_status = args.Link; }; this.web_view.NavigationRequested += delegate(object o, WebKit.NavigationRequestedArgs args) { if (args.Request.Uri == this.link_status) { SparkleEventLogController.LinkClicked(args.Request.Uri); } // Don't follow HREFs (as this would cause a page refresh) if (!args.Request.Uri.Equals("file:")) { args.RetVal = 1; } }; this.scrolled_window.Add(this.web_view); this.content_wrapper.Add(this.spinner); this.spinner.Start(); this.layout_horizontal = new HBox(false, 0); this.layout_horizontal.PackStart(this.size_label, true, true, 0); this.layout_horizontal.PackStart(new Label(" "), false, false, 0); layout_vertical.PackStart(this.layout_horizontal, false, false, 0); layout_vertical.PackStart(CreateShortcutsBar(), false, false, 0); layout_vertical.PackStart(this.content_wrapper, true, true, 0); Add(layout_vertical); ShowAll(); UpdateChooser(null); UpdateContent(null); // Hook up the controller events Controller.UpdateChooserEvent += delegate(string [] folders) { Application.Invoke(delegate { UpdateChooser(folders); }); }; Controller.UpdateContentEvent += delegate(string html) { Application.Invoke(delegate { UpdateContent(html); }); }; Controller.ContentLoadingEvent += delegate { Application.Invoke(delegate { if (this.content_wrapper.Child != null) { this.content_wrapper.Remove(this.content_wrapper.Child); } this.content_wrapper.Add(this.spinner); this.spinner.Start(); this.content_wrapper.ShowAll(); }); }; Controller.UpdateSizeInfoEvent += delegate(string size, string history_size) { Application.Invoke(delegate { this.size_label.Markup = "<b>Size:</b> " + size + " " + "<b>History:</b> " + history_size; this.size_label.ShowAll(); }); }; }
public void UpdateContent(string html) { Thread thread = new Thread( new ThreadStart(delegate { using (var a = new NSAutoreleasePool()) { if (html == null) { html = Controller.HTML; } string pixmaps_path = "file://" + Path.Combine( NSBundle.MainBundle.ResourcePath, "Pixmaps"); html = html.Replace("<!-- $body-font-family -->", "Lucida Grande"); html = html.Replace("<!-- $day-entry-header-font-size -->", "13.6px"); html = html.Replace("<!-- $body-font-size -->", "13.4px"); html = html.Replace("<!-- $secondary-font-color -->", "#bbb"); html = html.Replace("<!-- $small-color -->", "#ddd"); html = html.Replace("<!-- $day-entry-header-background-color -->", "#f5f5f5"); html = html.Replace("<!-- $a-color -->", "#0085cf"); html = html.Replace("<!-- $a-hover-color -->", "#009ff8"); html = html.Replace("<!-- $pixmaps-path -->", pixmaps_path); html = html.Replace("<!-- $document-added-background-image -->", pixmaps_path + "/document-added-12.png"); html = html.Replace("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png"); html = html.Replace("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png"); html = html.Replace("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png"); InvokeOnMainThread(delegate { if (this.progress_indicator.Superview == ContentView) { this.progress_indicator.RemoveFromSuperview(); } this.web_view = new WebView(new RectangleF(0, 0, 481, 579), "", "") { Frame = new RectangleF(new PointF(0, 0), new SizeF(ContentView.Frame.Width, ContentView.Frame.Height - 39)) }; this.web_view.MainFrame.LoadHtmlString(html, new NSUrl("")); web_view.PolicyDelegate = new SparkleWebPolicyDelegate(); ContentView.AddSubview(this.web_view); (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate(string href) { if (href.StartsWith("file:///")) { href = href.Substring(7); } Controller.LinkClicked(href); }; }); } } )); thread.Start(); }