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

View file

@ -152,7 +152,7 @@ namespace SparkleShare {
(this.web_view.PolicyDelegate as
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.AddItems (folders);
this.popup_button.Activated += delegate {
if (this.popup_button.IndexOfSelectedItem == 0)
Controller.SelectedFolder = null;
else
Controller.SelectedFolder = this.popup_button.SelectedItem.Title;
this.popup_button.Activated += delegate { // FIXME: Still causes some memory leak warnings
using (var b = new NSAutoreleasePool ())
{
InvokeOnMainThread (delegate {
if (this.popup_button.IndexOfSelectedItem == 0)
Controller.SelectedFolder = null;
else
Controller.SelectedFolder = this.popup_button.SelectedItem.Title;
});
}
};
ContentView.AddSubview (this.popup_button);

View file

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