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