eventlog: Use new WebKit bindings and clean up

This commit is contained in:
Hylke Bons 2013-10-10 16:09:22 +02:00
parent d7ed89e517
commit 44c5d24f35
2 changed files with 61 additions and 75 deletions

View file

@ -55,7 +55,7 @@
background-color: #fefefe; background-color: #fefefe;
color: <!-- $body-color -->; color: <!-- $body-color -->;
font-size: <!-- $body-font-size -->; font-size: <!-- $body-font-size -->;
font-family: <!-- $body-font-family -->; font-family: "<!-- $body-font-family -->";
margin: 0; margin: 0;
-webkit-user-select: none; -webkit-user-select: none;
} }

View file

@ -20,10 +20,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using Gtk; using Gtk;
using Mono.Unix; using WebKit;
// using WebKit;
using IO = System.IO;
namespace SparkleShare { namespace SparkleShare {
@ -33,54 +30,29 @@ namespace SparkleShare {
private Label size_label; private Label size_label;
private Label history_label; private Label history_label;
private HBox layout_horizontal;
private ComboBox combo_box; private ComboBox combo_box;
private HBox combo_box_wrapper;
private EventBox content_wrapper; private EventBox content_wrapper;
private HBox combo_box_wrapper;
private HBox layout_horizontal;
private ScrolledWindow scrolled_window; private ScrolledWindow scrolled_window;
// private WebView web_view;
private VBox spinner_wrapper; private VBox spinner_wrapper;
private Spinner spinner; private Spinner spinner;
private WebView web_view;
public SparkleEventLog () : base ("") public SparkleEventLog () : base ("Recent Changes")
{ {
Gdk.Rectangle monitor_0_rect = Gdk.Screen.Default.GetMonitorGeometry (0); Gdk.Rectangle monitor_0_rect = Gdk.Screen.Default.GetMonitorGeometry (0);
SetSizeRequest (480, (int) (monitor_0_rect.Height * 0.8)); SetSizeRequest (480, (int) (monitor_0_rect.Height * 0.8));
IconName = "folder-sparkleshare";
int x = (int) (monitor_0_rect.Width * 0.61); int x = (int) (monitor_0_rect.Width * 0.61);
int y = (int) (monitor_0_rect.Height * 0.5 - (HeightRequest * 0.5)); int y = (int) (monitor_0_rect.Height * 0.5 - (HeightRequest * 0.5));
Move (x, y); Move (x, y);
Resizable = true; this.size_label = new Label () { Xalign = 0, Markup = "<b>Size:</b> …" };
BorderWidth = 0; this.history_label = new Label () { Xalign = 0, Markup = "<b>History:</b> …" };
Title = "Recent Changes";
IconName = "folder-sparkleshare";
DeleteEvent += delegate (object o, DeleteEventArgs args) {
Controller.WindowClosed ();
args.RetVal = true;
};
KeyPressEvent += delegate (object o, KeyPressEventArgs args) {
if (args.Event.Key == Gdk.Key.Escape ||
(args.Event.State == Gdk.ModifierType.ControlMask && args.Event.Key == Gdk.Key.w)) {
Controller.WindowClosed ();
}
};
this.size_label = new Label () {
Markup = "<b>Size:</b> …",
Xalign = 0
};
this.history_label = new Label () {
Markup = "<b>History:</b> …",
Xalign = 0
};
HBox layout_sizes = new HBox (false, 12); HBox layout_sizes = new HBox (false, 12);
layout_sizes.Add (this.size_label); layout_sizes.Add (this.size_label);
@ -95,11 +67,10 @@ namespace SparkleShare {
this.content_wrapper.OverrideBackgroundColor (StateFlags.Normal, this.content_wrapper.OverrideBackgroundColor (StateFlags.Normal,
new Gdk.RGBA () { Red = 1, Green = 1, Blue=1, Alpha = 1 }); new Gdk.RGBA () { Red = 1, Green = 1, Blue=1, Alpha = 1 });
// this.web_view = new WebView () { Editable = false }; this.web_view = new WebView () { Editable = false };
// this.web_view.NavigationRequested += WebViewNavigationRequested; this.web_view.NavigationRequested += WebViewNavigationRequested;
// this.scrolled_window.Add (this.web_view); this.scrolled_window.Add (this.web_view);
this.scrolled_window.AddWithViewport (new Button ("WebView"));
this.spinner_wrapper = new VBox (false, 0); this.spinner_wrapper = new VBox (false, 0);
this.spinner_wrapper.PackStart (new Label(""), true, true, 0); this.spinner_wrapper.PackStart (new Label(""), true, true, 0);
@ -137,8 +108,8 @@ namespace SparkleShare {
Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) {
Application.Invoke (delegate { Application.Invoke (delegate {
FileChooserDialog dialog = new FileChooserDialog ("Restore from History", FileChooserDialog dialog = new FileChooserDialog ("Restore from History", this,
this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Ok); FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Ok);
dialog.CurrentName = file_name; dialog.CurrentName = file_name;
dialog.DoOverwriteConfirmation = true; dialog.DoOverwriteConfirmation = true;
@ -154,9 +125,7 @@ namespace SparkleShare {
}; };
Controller.UpdateChooserEvent += delegate (string [] folders) { Controller.UpdateChooserEvent += delegate (string [] folders) {
Application.Invoke (delegate { Application.Invoke (delegate { UpdateChooser (folders); });
UpdateChooser (folders);
});
}; };
Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { Controller.UpdateChooserEnablementEvent += delegate (bool enabled) {
@ -174,7 +143,6 @@ namespace SparkleShare {
this.content_wrapper.Add (this.spinner_wrapper); this.content_wrapper.Add (this.spinner_wrapper);
this.spinner.Start (); this.spinner.Start ();
this.content_wrapper.ShowAll ();
}); });
}; };
@ -182,23 +150,24 @@ namespace SparkleShare {
Application.Invoke (delegate { Application.Invoke (delegate {
this.size_label.Markup = "<b>Size</b> " + size; this.size_label.Markup = "<b>Size</b> " + size;
this.history_label.Markup = "<b>History</b> " + history_size; this.history_label.Markup = "<b>History</b> " + history_size;
this.size_label.ShowAll ();
this.history_label.ShowAll ();
}); });
}; };
DeleteEvent += delegate (object o, DeleteEventArgs args) {
Controller.WindowClosed ();
args.RetVal = true;
};
KeyPressEvent += delegate (object o, KeyPressEventArgs args) {
if (args.Event.Key == Gdk.Key.Escape ||
(args.Event.State == Gdk.ModifierType.ControlMask && args.Event.Key == Gdk.Key.w)) {
Controller.WindowClosed ();
}
};
} }
/*
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 UpdateChooser (string [] folders) public void UpdateChooser (string [] folders)
{ {
if (folders == null) if (folders == null)
@ -225,12 +194,12 @@ namespace SparkleShare {
this.combo_box.Active = 0; this.combo_box.Active = 0;
int row = 2; int row = 2;
foreach (string folder in folders) { foreach (string folder in folders) {
store.AppendValues (folder); store.AppendValues (folder);
if (folder.Equals (Controller.SelectedFolder)) if (folder.Equals (Controller.SelectedFolder))
this.combo_box.Active = row; this.combo_box.Active = row;
row++; row++;
} }
@ -262,35 +231,52 @@ namespace SparkleShare {
public void UpdateContent (string html) public void UpdateContent (string html)
{ {
string pixmaps_path = IO.Path.Combine (SparkleUI.AssetsPath, "pixmaps"); string pixmaps_path = new string [] {SparkleUI.AssetsPath, "pixmaps"}.Combine ();
string icons_path = new string [] {SparkleUI.AssetsPath, "icons", "hicolor", "12x12", "status"}.Combine (); string icons_path = new string [] {SparkleUI.AssetsPath, "icons", "hicolor", "12x12", "status"}.Combine ();
html = html.Replace ("<!-- $a-hover-color -->", "#009ff8"); html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace ("<!-- $a-color -->", "#0085cf"); html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.RGBAToHex (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Normal)));
html = html.Replace ("<!-- $body-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Normal))); html = html.Replace ("<!-- $body-font-family -->", StyleContext.GetFont (StateFlags.Normal).Family);
html = html.Replace ("<!-- $body-font-family -->", "\"" + StyleContext.GetFont (StateFlags.Normal).Family + "\"");
html = html.Replace ("<!-- $body-font-size -->", (double) (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px"); html = html.Replace ("<!-- $body-font-size -->", (double) (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $body-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Normal)));
html = html.Replace ("<!-- $body-background-color -->",
SparkleUIHelpers.RGBAToHex (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Normal)));
html = html.Replace ("<!-- $day-entry-header-font-size -->", (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px"); html = html.Replace ("<!-- $day-entry-header-font-size -->", (StyleContext.GetFont (StateFlags.Normal).Size / 1024 + 3) + "px");
html = html.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetBackgroundColor (StateFlags.Normal))); html = html.Replace ("<!-- $day-entry-header-background-color -->",
SparkleUIHelpers.RGBAToHex (StyleContext.GetBackgroundColor (StateFlags.Normal)));
html = html.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive))); html = html.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive)));
html = html.Replace ("<!-- $small-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive))); html = html.Replace ("<!-- $small-color -->", SparkleUIHelpers.RGBAToHex (StyleContext.GetColor (StateFlags.Insensitive)));
html = html.Replace ("<!-- $small-font-size -->", "85%"); html = html.Replace ("<!-- $small-font-size -->", "90%");
html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path); html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path);
html = html.Replace ("<!-- $document-added-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-added.png")); html = html.Replace ("<!-- $document-added-background-image -->", "file://" + new string [] {icons_path, "document-added.png"}.Combine ());
html = html.Replace ("<!-- $document-edited-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-edited.png")); html = html.Replace ("<!-- $document-edited-background-image -->", "file://" + new string [] {icons_path, "document-edited.png"}.Combine ());
html = html.Replace ("<!-- $document-deleted-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-deleted.png")); html = html.Replace ("<!-- $document-deleted-background-image -->", "file://" + new string [] {icons_path, "document-deleted.png"}.Combine ());
html = html.Replace ("<!-- $document-moved-background-image -->", "file://" + IO.Path.Combine (icons_path, "document-moved.png")); html = html.Replace ("<!-- $document-moved-background-image -->", "file://" + new string [] {icons_path, "document-moved.png"}.Combine ());
this.spinner.Stop (); this.spinner.Stop ();
/*
this.web_view.NavigationRequested -= WebViewNavigationRequested; this.web_view.NavigationRequested -= WebViewNavigationRequested;
this.web_view.LoadHtmlString (html, "file://"); this.web_view.LoadString (html, "text/html", "UTF-8", "file://");
this.web_view.NavigationRequested += WebViewNavigationRequested; this.web_view.NavigationRequested += WebViewNavigationRequested;
*/
this.content_wrapper.Remove (this.content_wrapper.Child); this.content_wrapper.Remove (this.content_wrapper.Child);
this.content_wrapper.Add (this.scrolled_window); this.content_wrapper.Add (this.scrolled_window);
this.content_wrapper.ShowAll (); this.content_wrapper.ShowAll ();
} }
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;
}
} }
} }