mac: Fix memory warnings in event log

This commit is contained in:
Hylke Bons 2012-03-01 20:10:39 +00:00
parent c8204870d5
commit bc749a31f5

View file

@ -31,15 +31,8 @@ namespace SparkleShare {
public SparkleEventLogController Controller = new SparkleEventLogController ();
private WebView web_view = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
PolicyDelegate = new SparkleWebPolicyDelegate ()
};
private NSBox separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
BorderColor = NSColor.LightGray,
BoxType = NSBoxType.NSBoxCustom
};
private WebView web_view;
private NSBox separator;
private NSPopUpButton popup_button;
private NSProgressIndicator progress_indicator;
private NSTextField size_label;
@ -49,14 +42,18 @@ namespace SparkleShare {
private NSButton hidden_close_button;
public SparkleEventLog (IntPtr handle) : base (handle) { }
public SparkleEventLog (IntPtr handle) : base (handle)
{
}
// TODO: Window needs to be made resizable
public SparkleEventLog () : base ()
{
using (var a = new NSAutoreleasePool ())
{
Title = "Recent Changes";
Delegate = new SparkleEventsDelegate ();
// TODO: Window needs to be made resizable
SetFrame (new RectangleF (0, 0, 480, 640), true);
Center ();
@ -71,6 +68,11 @@ namespace SparkleShare {
BackingType = NSBackingStore.Buffered;
this.web_view = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
PolicyDelegate = new SparkleWebPolicyDelegate ()
};
this.hidden_close_button = new NSButton () {
Frame = new RectangleF (0, 0, 0, 0),
KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask,
@ -81,8 +83,6 @@ namespace SparkleShare {
Controller.WindowClosed ();
};
ContentView.AddSubview (this.hidden_close_button);
this.size_label = new NSTextField () {
Alignment = NSTextAlignment.Right,
@ -126,11 +126,10 @@ namespace SparkleShare {
};
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);
this.separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
BorderColor = NSColor.LightGray,
BoxType = NSBoxType.NSBoxCustom
};
this.progress_indicator = new NSProgressIndicator () {
@ -140,62 +139,91 @@ namespace SparkleShare {
};
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.hidden_close_button);
(this.web_view.PolicyDelegate as SparkleWebPolicyDelegate)
.LinkClicked += delegate (string href) {
(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);
});
}
};
Controller.ShowWindowEvent += delegate {
using (var a = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
OrderFrontRegardless ();
UpdateContent (null);
UpdateChooser (null);
});
}
};
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 void UpdateChooser (string [] folders)
{
using (var a = new NSAutoreleasePool ())
{
if (folders == null)
folders = Controller.Folders;
@ -225,12 +253,14 @@ namespace SparkleShare {
ContentView.AddSubview (this.popup_button);
}
}
public void UpdateContent (string html)
{
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
Thread thread = new Thread (new ThreadStart (delegate {
using (var a = new NSAutoreleasePool ())
{
if (html == null)
html = Controller.HTML;
@ -262,7 +292,6 @@ namespace SparkleShare {
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "document-moved-12.png"));
InvokeOnMainThread (delegate {
if (this.progress_indicator.Superview == ContentView)
this.progress_indicator.RemoveFromSuperview ();
@ -270,11 +299,11 @@ namespace SparkleShare {
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
ContentView.AddSubview (this.web_view);
});
}
}));
thread.Start ();
}
}
public override void OrderFrontRegardless ()