mac: Fix more memory warnings

This commit is contained in:
Hylke Bons 2012-03-01 20:46:25 +00:00
parent bc749a31f5
commit 84413d2c53
3 changed files with 139 additions and 107 deletions

View file

@ -41,126 +41,147 @@ namespace SparkleShare {
public SparkleAbout () : base () public SparkleAbout () : base ()
{ {
SetFrame (new RectangleF (0, 0, 640, 281), true); using (var a = new NSAutoreleasePool ())
Center (); {
SetFrame (new RectangleF (0, 0, 640, 281), true);
Center ();
Delegate = new SparkleAboutDelegate (); Delegate = new SparkleAboutDelegate ();
StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled); StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled);
Title = "About SparkleShare"; Title = "About SparkleShare";
MaxSize = new SizeF (640, 281); MaxSize = new SizeF (640, 281);
MinSize = new SizeF (640, 281); MinSize = new SizeF (640, 281);
HasShadow = true; HasShadow = true;
BackingType = NSBackingStore.Buffered; BackingType = NSBackingStore.Buffered;
CreateAbout (); CreateAbout ();
}
Controller.HideWindowEvent += delegate { Controller.HideWindowEvent += delegate {
InvokeOnMainThread (delegate { using (var a = new NSAutoreleasePool ())
PerformClose (this); {
}); InvokeOnMainThread (delegate {
PerformClose (this);
});
}
}; };
Controller.ShowWindowEvent += delegate { Controller.ShowWindowEvent += delegate {
InvokeOnMainThread (delegate { using (var a = new NSAutoreleasePool ())
OrderFrontRegardless (); {
}); InvokeOnMainThread (delegate {
OrderFrontRegardless ();
});
}
}; };
Controller.NewVersionEvent += delegate (string new_version) { Controller.NewVersionEvent += delegate (string new_version) {
InvokeOnMainThread (delegate { using (var a = new NSAutoreleasePool ())
UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!"; {
UpdatesTextField.TextColor = InvokeOnMainThread (delegate {
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f); UpdatesTextField.StringValue = "A newer version (" + new_version + ") is available!";
}); UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f);
});
}
}; };
Controller.VersionUpToDateEvent += delegate { Controller.VersionUpToDateEvent += delegate {
InvokeOnMainThread (delegate { using (var a = new NSAutoreleasePool ())
UpdatesTextField.StringValue = "You are running the latest version."; {
UpdatesTextField.TextColor = InvokeOnMainThread (delegate {
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f); UpdatesTextField.StringValue = "You are running the latest version.";
}); UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f);
});
}
}; };
Controller.CheckingForNewVersionEvent += delegate { Controller.CheckingForNewVersionEvent += delegate {
InvokeOnMainThread (delegate { using (var a = new NSAutoreleasePool ())
UpdatesTextField.StringValue = "Checking for updates..."; {
UpdatesTextField.TextColor = InvokeOnMainThread (delegate {
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f); // Tango Sky Blue #1 UpdatesTextField.StringValue = "Checking for updates...";
}); UpdatesTextField.TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f); // Tango Sky Blue #1
});
}
}; };
} }
private void CreateAbout () private void CreateAbout ()
{ {
string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, using (var a = new NSAutoreleasePool ())
"Pixmaps", "about.png"); {
string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "about.png");
AboutImage = new NSImage (about_image_path) { AboutImage = new NSImage (about_image_path) {
Size = new SizeF (640, 260) Size = new SizeF (640, 260)
}; };
AboutImageView = new NSImageView () { AboutImageView = new NSImageView () {
Image = AboutImage, Image = AboutImage,
Frame = new RectangleF (0, 0, 640, 260) Frame = new RectangleF (0, 0, 640, 260)
}; };
VersionTextField = new NSTextField () { VersionTextField = new NSTextField () {
StringValue = "version " + Controller.RunningVersion, StringValue = "version " + Controller.RunningVersion,
Frame = new RectangleF (295, 140, 318, 22), Frame = new RectangleF (295, 140, 318, 22),
BackgroundColor = NSColor.White, BackgroundColor = NSColor.White,
Bordered = false, Bordered = false,
Editable = false, Editable = false,
DrawsBackground = false, DrawsBackground = false,
TextColor = NSColor.White, TextColor = NSColor.White,
Font = NSFontManager.SharedFontManager.FontWithFamily Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11) ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11)
}; };
UpdatesTextField = new NSTextField () { UpdatesTextField = new NSTextField () {
StringValue = "Checking for updates...", StringValue = "Checking for updates...",
Frame = new RectangleF (295, Frame.Height - 232, 318, 98), Frame = new RectangleF (295, Frame.Height - 232, 318, 98),
Bordered = false, Bordered = false,
Editable = false, Editable = false,
DrawsBackground = false, DrawsBackground = false,
Font = NSFontManager.SharedFontManager.FontWithFamily Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11), ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
TextColor = TextColor =
NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f) // Tango Sky Blue #1 NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f) // Tango Sky Blue #1
}; };
CreditsTextField = new NSTextField () { CreditsTextField = new NSTextField () {
StringValue = @"Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others." + StringValue = @"Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others." +
"\n" + "\n" +
"\n" + "\n" +
"SparkleShare is Free and Open Source Software. You are free to use, modify, and redistribute it " + "SparkleShare is Free and Open Source Software. You are free to use, modify, and redistribute it " +
"under the GNU General Public License version 3 or later.", "under the GNU General Public License version 3 or later.",
Frame = new RectangleF (295, Frame.Height - 260, 318, 98), Frame = new RectangleF (295, Frame.Height - 260, 318, 98),
TextColor = NSColor.White, TextColor = NSColor.White,
DrawsBackground = false, DrawsBackground = false,
Bordered = false, Bordered = false,
Editable = false, Editable = false,
Font = NSFontManager.SharedFontManager.FontWithFamily Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Unbold, 0, 11), ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11),
}; };
// WebsiteButton.Activated += delegate { // WebsiteButton.Activated += delegate {
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/"); // NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
// NSWorkspace.SharedWorkspace.OpenUrl (url); // NSWorkspace.SharedWorkspace.OpenUrl (url);
// }; // };
// CreditsButton.Activated += delegate { // CreditsButton.Activated += delegate {
// NSUrl url = new NSUrl ("http://www.sparkleshare.org/credits/"); // NSUrl url = new NSUrl ("http://www.sparkleshare.org/credits/");
// NSWorkspace.SharedWorkspace.OpenUrl (url); // NSWorkspace.SharedWorkspace.OpenUrl (url);
// }; // };
ContentView.AddSubview (AboutImageView); ContentView.AddSubview (AboutImageView);
ContentView.AddSubview (VersionTextField); ContentView.AddSubview (VersionTextField);
ContentView.AddSubview (UpdatesTextField); ContentView.AddSubview (UpdatesTextField);
ContentView.AddSubview (CreditsTextField); ContentView.AddSubview (CreditsTextField);
}
} }

View file

@ -152,7 +152,7 @@ namespace SparkleShare {
(this.web_view.PolicyDelegate as (this.web_view.PolicyDelegate as
SparkleWebPolicyDelegate).LinkClicked += delegate (string href) { SparkleWebPolicyDelegate).LinkClicked += delegate (string href) {
Controller.LinkClicked (href); Controller.LinkClicked (href);
}; };
} }
@ -244,11 +244,16 @@ namespace SparkleShare {
this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem);
this.popup_button.AddItems (folders); this.popup_button.AddItems (folders);
this.popup_button.Activated += delegate { this.popup_button.Activated += delegate { // FIXME: Still causes some memory leak warnings
if (this.popup_button.IndexOfSelectedItem == 0) using (var b = new NSAutoreleasePool ())
Controller.SelectedFolder = null; {
else InvokeOnMainThread (delegate {
Controller.SelectedFolder = this.popup_button.SelectedItem.Title; if (this.popup_button.IndexOfSelectedItem == 0)
Controller.SelectedFolder = null;
else
Controller.SelectedFolder = this.popup_button.SelectedItem.Title;
});
}
}; };
ContentView.AddSubview (this.popup_button); ContentView.AddSubview (this.popup_button);

View file

@ -42,11 +42,11 @@ namespace SparkleShare {
public SparkleUI () public SparkleUI ()
{ {
// Use translations using (var a = new NSAutoreleasePool ())
Catalog.Init ("sparkleshare", {
Path.Combine (NSBundle.MainBundle.ResourcePath, "Translations")); // Use translations
Catalog.Init ("sparkleshare",
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { Path.Combine (NSBundle.MainBundle.ResourcePath, "Translations"));
// Needed for Growl // Needed for Growl
GrowlApplicationBridge.WeakDelegate = this; GrowlApplicationBridge.WeakDelegate = this;
@ -77,13 +77,16 @@ namespace SparkleShare {
public void SetFolderIcon () public void SetFolderIcon ()
{ {
string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath, using (var a = new NSAutoreleasePool ())
"sparkleshare-mac.icns"); {
string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"sparkleshare-mac.icns");
NSImage folder_icon = new NSImage (folder_icon_path); NSImage folder_icon = new NSImage (folder_icon_path);
NSWorkspace.SharedWorkspace.SetIconforFile (folder_icon, NSWorkspace.SharedWorkspace.SetIconforFile (folder_icon,
Program.Controller.SparklePath, 0); Program.Controller.SparklePath, 0);
}
} }
@ -114,7 +117,10 @@ namespace SparkleShare {
private void ShowDockIcon () private void ShowDockIcon ()
{ {
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; using (var a = new NSAutoreleasePool ())
{
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;
}
} }