event log: Move logic from UI to controller
This commit is contained in:
parent
821eca52ec
commit
5e4cc8ca15
|
@ -210,7 +210,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public void LinkClicked (string href)
|
public void LinkClicked (string href)
|
||||||
{
|
{
|
||||||
if (href.StartsWith ("about:") || string.IsNullOrEmpty (href))
|
if (string.IsNullOrEmpty (href) || href.StartsWith ("about:"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
href = href.Replace ("%20", " ");
|
href = href.Replace ("%20", " ");
|
||||||
|
|
|
@ -29,10 +29,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
private Label size_label;
|
private Label size_label;
|
||||||
private Label history_label;
|
private Label history_label;
|
||||||
private ComboBox combo_box;
|
|
||||||
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 VBox spinner_wrapper;
|
private VBox spinner_wrapper;
|
||||||
private Spinner spinner;
|
private Spinner spinner;
|
||||||
|
@ -75,10 +72,7 @@ namespace SparkleShare {
|
||||||
css_provider.LoadFromData ("GtkEventBox { background-color: #ffffff; }");
|
css_provider.LoadFromData ("GtkEventBox { background-color: #ffffff; }");
|
||||||
this.content_wrapper.StyleContext.AddProvider (css_provider, 800);
|
this.content_wrapper.StyleContext.AddProvider (css_provider, 800);
|
||||||
|
|
||||||
this.web_view = new WebView () { Editable = false };
|
this.web_view = CreateWebView ();
|
||||||
this.web_view.Settings.EnablePlugins = false;
|
|
||||||
|
|
||||||
//this.web_view.NavigationRequested += WebViewNavigationRequested;
|
|
||||||
this.scrolled_window.Add (this.web_view);
|
this.scrolled_window.Add (this.web_view);
|
||||||
|
|
||||||
this.spinner_wrapper = new VBox (false, 0);
|
this.spinner_wrapper = new VBox (false, 0);
|
||||||
|
@ -90,11 +84,6 @@ namespace SparkleShare {
|
||||||
|
|
||||||
this.content_wrapper.Add (this.spinner_wrapper);
|
this.content_wrapper.Add (this.spinner_wrapper);
|
||||||
|
|
||||||
this.layout_horizontal = new HBox (false, 0);
|
|
||||||
this.layout_horizontal.PackStart (layout_sizes, true, true, 12);
|
|
||||||
|
|
||||||
layout_vertical.PackStart (this.layout_horizontal, false, false, 0);
|
|
||||||
layout_vertical.PackStart (new HSeparator (), false, false, 0);
|
|
||||||
layout_vertical.PackStart (this.content_wrapper, true, true, 0);
|
layout_vertical.PackStart (this.content_wrapper, true, true, 0);
|
||||||
|
|
||||||
Add (layout_vertical);
|
Add (layout_vertical);
|
||||||
|
@ -135,14 +124,6 @@ namespace SparkleShare {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Controller.UpdateChooserEvent += delegate (string [] folders) {
|
|
||||||
Application.Invoke (delegate { UpdateChooser (folders); });
|
|
||||||
};
|
|
||||||
|
|
||||||
Controller.UpdateChooserEnablementEvent += delegate (bool enabled) {
|
|
||||||
Application.Invoke (delegate { this.combo_box.Sensitive = enabled; });
|
|
||||||
};
|
|
||||||
|
|
||||||
Controller.UpdateContentEvent += delegate (string html) {
|
Controller.UpdateContentEvent += delegate (string html) {
|
||||||
Application.Invoke (delegate { UpdateContent (html); });
|
Application.Invoke (delegate { UpdateContent (html); });
|
||||||
};
|
};
|
||||||
|
@ -179,67 +160,6 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateChooser (string [] folders)
|
|
||||||
{
|
|
||||||
if (folders == null)
|
|
||||||
folders = Controller.Folders;
|
|
||||||
|
|
||||||
if (this.combo_box_wrapper != null && this.combo_box_wrapper.Parent != null) {
|
|
||||||
this.layout_horizontal.Remove (this.combo_box_wrapper);
|
|
||||||
this.combo_box_wrapper.Remove (this.combo_box);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.combo_box_wrapper = new HBox (false, 0);
|
|
||||||
this.combo_box = new ComboBox ();
|
|
||||||
|
|
||||||
CellRendererText cell = new CellRendererText();
|
|
||||||
this.combo_box.PackStart (cell, false);
|
|
||||||
this.combo_box.AddAttribute (cell, "text", 0);
|
|
||||||
|
|
||||||
ListStore store = new ListStore (typeof (string));
|
|
||||||
|
|
||||||
store.AppendValues ("Summary");
|
|
||||||
store.AppendValues ("---");
|
|
||||||
|
|
||||||
this.combo_box.Model = store;
|
|
||||||
this.combo_box.Active = 0;
|
|
||||||
|
|
||||||
int row = 2;
|
|
||||||
foreach (string folder in folders) {
|
|
||||||
store.AppendValues (folder);
|
|
||||||
|
|
||||||
if (folder.Equals (Controller.SelectedFolder))
|
|
||||||
this.combo_box.Active = row;
|
|
||||||
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.combo_box.RowSeparatorFunc = delegate (ITreeModel model, TreeIter iter) {
|
|
||||||
string item = (string) this.combo_box.Model.GetValue (iter, 0);
|
|
||||||
return (item == "---");
|
|
||||||
};
|
|
||||||
|
|
||||||
this.combo_box.Changed += delegate {
|
|
||||||
TreeIter iter;
|
|
||||||
this.combo_box.GetActiveIter (out iter);
|
|
||||||
string selection = (string) this.combo_box.Model.GetValue (iter, 0);
|
|
||||||
TreePath path = this.combo_box.Model.GetPath (iter);
|
|
||||||
|
|
||||||
if (path.Indices [0] == 0)
|
|
||||||
Controller.SelectedFolder = null;
|
|
||||||
else
|
|
||||||
Controller.SelectedFolder = selection;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.combo_box_wrapper.Add (this.combo_box);
|
|
||||||
this.combo_box.GrabFocus ();
|
|
||||||
|
|
||||||
this.layout_horizontal.BorderWidth = 6;
|
|
||||||
this.layout_horizontal.PackStart (this.combo_box_wrapper, false, false, 0);
|
|
||||||
this.layout_horizontal.ShowAll ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void UpdateContent (string html)
|
public void UpdateContent (string html)
|
||||||
{
|
{
|
||||||
string pixmaps_path = IO.Path.Combine (UserInterface.AssetsPath, "pixmaps");
|
string pixmaps_path = IO.Path.Combine (UserInterface.AssetsPath, "pixmaps");
|
||||||
|
@ -275,19 +195,9 @@ namespace SparkleShare {
|
||||||
this.scrolled_window.Remove (this.scrolled_window.Child);
|
this.scrolled_window.Remove (this.scrolled_window.Child);
|
||||||
this.web_view.Dispose ();
|
this.web_view.Dispose ();
|
||||||
|
|
||||||
this.web_view = new WebView () { Editable = false };
|
this.web_view = CreateWebView ();
|
||||||
this.web_view.LoadHtml (html, "file:///");
|
this.web_view.LoadHtml (html, "file:///");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
web_view.DecidePolicy += delegate(object o, DecidePolicyArgs args) {
|
|
||||||
Console.WriteLine (":::: " + (args.Decision as NavigationPolicyDecision).NavigationAction.Request.Uri);
|
|
||||||
// if (args.Decision. == PolicyDecisionType.NavigationAction) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
};
|
|
||||||
|
|
||||||
//this.web_view.NavigationRequested += WebViewNavigationRequested;
|
|
||||||
this.scrolled_window.Add (this.web_view);
|
this.scrolled_window.Add (this.web_view);
|
||||||
|
|
||||||
this.content_wrapper.Remove (this.content_wrapper.Child);
|
this.content_wrapper.Remove (this.content_wrapper.Child);
|
||||||
|
@ -295,14 +205,43 @@ namespace SparkleShare {
|
||||||
this.scrolled_window.ShowAll ();
|
this.scrolled_window.ShowAll ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private void WebViewNavigationRequested (object o, WebKit2.NavigationRequestedArgs args) {
|
|
||||||
Controller.LinkClicked (args.Request.Uri);
|
|
||||||
|
|
||||||
// Don't follow HREFs (as this would cause a page refresh)
|
WebView CreateWebView ()
|
||||||
if (!args.Request.Uri.Equals ("file:"))
|
{
|
||||||
args.RetVal = 1;
|
var web_view = new SparkleWebView { Editable = false };
|
||||||
}*/
|
web_view.Settings.EnablePlugins = false;
|
||||||
|
|
||||||
|
web_view.LinkClicked += Controller.LinkClicked;
|
||||||
|
|
||||||
|
return web_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SparkleWebView : WebView {
|
||||||
|
|
||||||
|
public event LinkClickedHandler LinkClicked = delegate { };
|
||||||
|
public delegate void LinkClickedHandler (string href);
|
||||||
|
|
||||||
|
|
||||||
|
protected override bool OnDecidePolicy (PolicyDecision decision, PolicyDecisionType decision_type)
|
||||||
|
{
|
||||||
|
if (decision_type != PolicyDecisionType.NavigationAction) {
|
||||||
|
decision.Use ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
string uri = (decision as NavigationPolicyDecision).Request.Uri;
|
||||||
|
|
||||||
|
if (uri.Equals ("file:///")) {
|
||||||
|
decision.Use ();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkClicked (uri);
|
||||||
|
decision.Ignore ();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue