mac: clean up

This commit is contained in:
Hylke Bons 2012-11-24 11:27:45 +00:00
parent 5f6c00f773
commit 22c3fc059d
7 changed files with 76 additions and 139 deletions

View file

@ -31,14 +31,9 @@ namespace SparkleShare {
private NSImage about_image; private NSImage about_image;
private NSImageView about_image_view; private NSImageView about_image_view;
private NSTextField version_text_field; private NSTextField version_text_field, updates_text_field, credits_text_field;
private NSTextField updates_text_field;
private NSTextField credits_text_field;
private NSButton hidden_close_button; private NSButton hidden_close_button;
private SparkleLink website_link; private SparkleLink website_link, credits_link, report_problem_link, debug_log_link;
private SparkleLink credits_link;
private SparkleLink report_problem_link;
private SparkleLink debug_log_link;
public SparkleAbout (IntPtr handle) : base (handle) { } public SparkleAbout (IntPtr handle) : base (handle) { }

View file

@ -16,7 +16,6 @@
using System; using System;
using System.IO;
using MonoMac.AppKit; using MonoMac.AppKit;
using MonoMac.Foundation; using MonoMac.Foundation;
@ -44,10 +43,7 @@ namespace SparkleShare {
NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;
center.ShouldPresentNotification = delegate { return true; }; center.ShouldPresentNotification = delegate { return true; };
center.DidActivateNotification += delegate { Controller.BubbleClicked (); };
center.DidActivateNotification += delegate {
Controller.BubbleClicked ();
};
center.ScheduleNotification (notification); center.ScheduleNotification (notification);
}); });

View file

@ -36,10 +36,7 @@ namespace SparkleShare {
private NSBox background; private NSBox background;
private NSPopUpButton popup_button; private NSPopUpButton popup_button;
private NSProgressIndicator progress_indicator; private NSProgressIndicator progress_indicator;
private NSTextField size_label; private NSTextField size_label, size_label_value, history_label, history_label_value;
private NSTextField size_label_value;
private NSTextField history_label;
private NSTextField history_label_value;
private NSButton hidden_close_button; private NSButton hidden_close_button;
@ -174,9 +171,7 @@ namespace SparkleShare {
ContentView.AddSubview (this.hidden_close_button); ContentView.AddSubview (this.hidden_close_button);
(Delegate as SparkleEventsDelegate).WindowResized += delegate (SizeF new_window_size) { (Delegate as SparkleEventsDelegate).WindowResized += delegate (SizeF new_window_size) {
Program.Controller.Invoke (() => { Program.Controller.Invoke (() => Relayout (new_window_size));
Relayout (new_window_size);
});
}; };
@ -254,37 +249,31 @@ namespace SparkleShare {
this.size_label.Frame = new RectangleF ( this.size_label.Frame = new RectangleF (
new PointF (this.size_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), new PointF (this.size_label.Frame.X, new_window_size.Height - TitlebarHeight - 30),
this.size_label.Frame.Size this.size_label.Frame.Size);
);
this.size_label_value.Frame = new RectangleF ( this.size_label_value.Frame = new RectangleF (
new PointF (this.size_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), new PointF (this.size_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30),
this.size_label_value.Frame.Size this.size_label_value.Frame.Size);
);
this.history_label.Frame = new RectangleF ( this.history_label.Frame = new RectangleF (
new PointF (this.history_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), new PointF (this.history_label.Frame.X, new_window_size.Height - TitlebarHeight - 30),
this.history_label.Frame.Size this.history_label.Frame.Size);
);
this.history_label_value.Frame = new RectangleF ( this.history_label_value.Frame = new RectangleF (
new PointF (this.history_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), new PointF (this.history_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30),
this.history_label_value.Frame.Size this.history_label_value.Frame.Size);
);
this.progress_indicator.Frame = new RectangleF (
new PointF (new_window_size.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
this.progress_indicator.Frame.Size);
this.popup_button.RemoveFromSuperview (); // Needed to prevent redraw glitches this.popup_button.RemoveFromSuperview (); // Needed to prevent redraw glitches
this.popup_button.Frame = new RectangleF ( this.popup_button.Frame = new RectangleF (
new PointF (new_window_size.Width - this.popup_button.Frame.Width - 12, new_window_size.Height - TitlebarHeight - 33), new PointF (new_window_size.Width - this.popup_button.Frame.Width - 12, new_window_size.Height - TitlebarHeight - 33),
this.popup_button.Frame.Size this.popup_button.Frame.Size);
);
ContentView.AddSubview (this.popup_button); ContentView.AddSubview (this.popup_button);
this.progress_indicator.Frame = new RectangleF (
new PointF (new_window_size.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10),
this.progress_indicator.Frame.Size
);
} }

View file

@ -34,8 +34,7 @@ namespace SparkleShare {
private NSImage side_splash; private NSImage side_splash;
private NSImageView side_splash_view; private NSImageView side_splash_view;
private NSTextField header_text_field; private NSTextField header_text_field, description_text_field;
private NSTextField description_text_field;
public SparkleSetupWindow () : base () public SparkleSetupWindow () : base ()

View file

@ -21,25 +21,18 @@ using System.IO;
using MonoMac.Foundation; using MonoMac.Foundation;
using MonoMac.AppKit; using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
namespace SparkleShare { namespace SparkleShare {
public class SparkleStatusIcon : NSObject { public class SparkleStatusIcon {
public SparkleStatusIconController Controller = new SparkleStatusIconController (); public SparkleStatusIconController Controller = new SparkleStatusIconController ();
private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
private NSMenu menu, submenu;
private NSMenu menu; private NSMenuItem state_item, folder_item, add_item, about_item, recent_events_item, quit_item;
private NSMenu submenu; private NSMenuItem [] folder_menu_items, error_menu_items, try_again_menu_items;
private NSMenuItem state_item;
private NSMenuItem folder_item;
private NSMenuItem add_item;
private NSMenuItem about_item;
private NSMenuItem recent_events_item;
private NSMenuItem quit_item;
private NSImage syncing_idle_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle.png")); private NSImage syncing_idle_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle.png"));
private NSImage syncing_up_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up.png")); private NSImage syncing_up_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up.png"));
@ -52,17 +45,13 @@ namespace SparkleShare {
private NSImage syncing_down_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down-active.png")); private NSImage syncing_down_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down-active.png"));
private NSImage syncing_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-active.png")); private NSImage syncing_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-active.png"));
private NSImage syncing_error_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error-active.png")); private NSImage syncing_error_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error-active.png"));
private NSImage folder_image = NSImage.ImageNamed ("NSFolder"); private NSImage folder_image = NSImage.ImageNamed ("NSFolder");
private NSImage caution_image = NSImage.ImageNamed ("NSCaution"); private NSImage caution_image = NSImage.ImageNamed ("NSCaution");
private NSImage sparkleshare_image = NSImage.ImageNamed ("sparkleshare-folder"); private NSImage sparkleshare_image = NSImage.ImageNamed ("sparkleshare-folder");
private NSMenuItem [] folder_menu_items;
private NSMenuItem [] error_menu_items;
private NSMenuItem [] try_again_menu_items;
public SparkleStatusIcon ()
public SparkleStatusIcon () : base ()
{ {
this.status_item.HighlightMode = true; this.status_item.HighlightMode = true;
this.status_item.Image = this.syncing_idle_image; this.status_item.Image = this.syncing_idle_image;
@ -102,7 +91,7 @@ namespace SparkleShare {
} }
} }
this.status_item.Image.Size = new SizeF (16, 16); this.status_item.Image.Size = new SizeF (16, 16);
this.status_item.AlternateImage.Size = new SizeF (16, 16); this.status_item.AlternateImage.Size = new SizeF (16, 16);
}); });
}; };
@ -123,98 +112,78 @@ namespace SparkleShare {
public void CreateMenu () public void CreateMenu ()
{ {
this.menu = new NSMenu (); this.menu = new NSMenu () { AutoEnablesItems = false };
this.menu.AutoEnablesItems = false;
this.state_item = new NSMenuItem () { this.state_item = new NSMenuItem () {
Title = Controller.StateText, Title = Controller.StateText,
Enabled = false Enabled = false
}; };
this.folder_item = new NSMenuItem () { this.folder_item = new NSMenuItem () {
Title = "SparkleShare", Title = "SparkleShare",
Enabled = true Enabled = true
}; };
this.folder_item.Image = this.sparkleshare_image; this.folder_item.Image = this.sparkleshare_image;
this.folder_item.Image.Size = new SizeF (16, 16); this.folder_item.Image.Size = new SizeF (16, 16);
this.add_item = new NSMenuItem () { this.add_item = new NSMenuItem () {
Title = "Add Hosted Project…", Title = "Add Hosted Project…",
Enabled = true Enabled = true
}; };
this.add_item.Activated += delegate { this.add_item.Activated += Controller.AddHostedProjectClicked;
Controller.AddHostedProjectClicked ();
};
this.recent_events_item = new NSMenuItem () { this.recent_events_item = new NSMenuItem () {
Title = "Recent Changes…", Title = "Recent Changes…",
Enabled = Controller.RecentEventsItemEnabled Enabled = Controller.RecentEventsItemEnabled
}; };
if (Controller.Folders.Length > 0) { if (Controller.RecentEventsItemEnabled)
this.recent_events_item.Activated += delegate { this.recent_events_item.Activated += Controller.RecentEventsClicked;
Controller.RecentEventsClicked ();
};
}
this.about_item = new NSMenuItem () { this.about_item = new NSMenuItem () {
Title = "About SparkleShare", Title = "About SparkleShare",
Enabled = true Enabled = true
}; };
this.about_item.Activated += delegate { this.about_item.Activated += Controller.AboutClicked;
Controller.AboutClicked ();
};
this.quit_item = new NSMenuItem () { this.quit_item = new NSMenuItem () {
Title = "Quit", Title = "Quit",
Enabled = Controller.QuitItemEnabled Enabled = Controller.QuitItemEnabled
}; };
this.quit_item.Activated += delegate { this.quit_item.Activated += Controller.QuitClicked;
Controller.QuitClicked ();
};
this.menu.AddItem (this.state_item); this.folder_menu_items = new NSMenuItem [Controller.Folders.Length];
this.menu.AddItem (NSMenuItem.SeparatorItem); this.error_menu_items = new NSMenuItem [Controller.Folders.Length];
this.menu.AddItem (this.folder_item);
this.submenu = new NSMenu ();
this.submenu.AddItem (this.recent_events_item);
this.submenu.AddItem (this.add_item);
this.submenu.AddItem (NSMenuItem.SeparatorItem);
this.submenu.AddItem (this.about_item);
this.folder_item.Submenu = this.submenu;
this.folder_menu_items = new NSMenuItem [Controller.Folders.Length];
this.error_menu_items = new NSMenuItem [Controller.Folders.Length];
this.try_again_menu_items = new NSMenuItem [Controller.Folders.Length]; this.try_again_menu_items = new NSMenuItem [Controller.Folders.Length];
if (Controller.Folders.Length > 0) { if (Controller.Folders.Length > 0) {
int i = 0; int i = 0;
foreach (string folder_name in Controller.Folders) { foreach (string folder_name in Controller.Folders) {
NSMenuItem item = new NSMenuItem (); NSMenuItem item = new NSMenuItem () { Title = folder_name };
item.Title = folder_name;
this.folder_menu_items [i] = item; this.folder_menu_items [i] = item;
if (!string.IsNullOrEmpty (Controller.FolderErrors [i])) { if (!string.IsNullOrEmpty (Controller.FolderErrors [i])) {
item.Image = this.caution_image; item.Image = this.caution_image;
item.Submenu = new NSMenu (); item.Submenu = new NSMenu ();
this.error_menu_items [i] = new NSMenuItem () { this.error_menu_items [i] = new NSMenuItem ();
Title = Controller.FolderErrors [i] this.error_menu_items [i].Title = Controller.FolderErrors [i];
};
this.try_again_menu_items [i] = new NSMenuItem ();
this.try_again_menu_items [i].Title = "Try Again";
this.try_again_menu_items [i] = new NSMenuItem ();
this.try_again_menu_items [i].Title = "Try Again";
this.try_again_menu_items [i].Activated += Controller.TryAgainDelegate (folder_name);; this.try_again_menu_items [i].Activated += Controller.TryAgainDelegate (folder_name);;
item.Submenu.AddItem (this.error_menu_items [i]); item.Submenu.AddItem (this.error_menu_items [i]);
item.Submenu.AddItem (NSMenuItem.SeparatorItem); item.Submenu.AddItem (NSMenuItem.SeparatorItem);
item.Submenu.AddItem (this.try_again_menu_items [i]); item.Submenu.AddItem (this.try_again_menu_items [i]);
@ -225,37 +194,31 @@ namespace SparkleShare {
} }
item.Image.Size = new SizeF (16, 16); item.Image.Size = new SizeF (16, 16);
i++; i++;
}; };
} }
this.menu.AddItem (this.state_item);
this.menu.AddItem (NSMenuItem.SeparatorItem);
this.menu.AddItem (this.folder_item);
this.submenu = new NSMenu ();
this.submenu.AddItem (this.recent_events_item);
this.submenu.AddItem (this.add_item);
this.submenu.AddItem (NSMenuItem.SeparatorItem);
this.submenu.AddItem (this.about_item);
this.folder_item.Submenu = this.submenu;
foreach (NSMenuItem item in this.folder_menu_items) foreach (NSMenuItem item in this.folder_menu_items)
this.menu.AddItem (item); this.menu.AddItem (item);
this.menu.AddItem (NSMenuItem.SeparatorItem); this.menu.AddItem (NSMenuItem.SeparatorItem);
this.menu.AddItem (this.quit_item); this.menu.AddItem (this.quit_item);
this.menu.Delegate = new SparkleStatusIconMenuDelegate ();
this.status_item.Menu = this.menu; this.status_item.Menu = this.menu;
} }
} }
public class SparkleStatusIconMenuDelegate : NSMenuDelegate {
public SparkleStatusIconMenuDelegate ()
{
}
public SparkleStatusIconMenuDelegate (IntPtr handle) : base (handle)
{
}
public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item)
{
}
}
} }

View file

@ -48,11 +48,11 @@ namespace SparkleShare {
NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns"); NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns");
Setup = new SparkleSetup (); Setup = new SparkleSetup ();
EventLog = new SparkleEventLog (); EventLog = new SparkleEventLog ();
About = new SparkleAbout (); About = new SparkleAbout ();
Bubbles = new SparkleBubbles (); Bubbles = new SparkleBubbles ();
StatusIcon = new SparkleStatusIcon (); StatusIcon = new SparkleStatusIcon ();
}); });
Program.Controller.UIHasLoaded (); Program.Controller.UIHasLoaded ();

View file

@ -46,7 +46,7 @@ namespace SparkleShare {
public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled); public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled);
public IconState CurrentState = IconState.Idle; public IconState CurrentState = IconState.Idle;
public string StateText = "Welcome to SparkleShare!"; public string StateText = "Welcome to SparkleShare!";
public string [] Folders; public string [] Folders;
public string [] FolderErrors; public string [] FolderErrors;
@ -201,20 +201,13 @@ namespace SparkleShare {
public void TryAgainClicked (string subfolder) public void TryAgainClicked (string subfolder)
{ {
foreach (SparkleRepoBase repo in Program.Controller.Repositories) { foreach (SparkleRepoBase repo in Program.Controller.Repositories)
if (repo.Name.Equals (subfolder)) if (repo.Name.Equals (subfolder))
new Thread (() => repo.ForceRetry ()).Start (); new Thread (() => repo.ForceRetry ()).Start ();
}
} }
public void AddHostedProjectClicked () public void RecentEventsClicked (object sender, EventArgs args)
{
new Thread (() => Program.Controller.ShowSetupWindow (PageType.Add)).Start ();
}
public void RecentEventsClicked ()
{ {
new Thread (() => { new Thread (() => {
while (!Program.Controller.RepositoriesLoaded) while (!Program.Controller.RepositoriesLoaded)
@ -226,13 +219,19 @@ namespace SparkleShare {
} }
public void AboutClicked () public void AddHostedProjectClicked (object sender, EventArgs args)
{
new Thread (() => Program.Controller.ShowSetupWindow (PageType.Add)).Start ();
}
public void AboutClicked (object sender, EventArgs args)
{ {
Program.Controller.ShowAboutWindow (); Program.Controller.ShowAboutWindow ();
} }
public void QuitClicked () public void QuitClicked (object sender, EventArgs args)
{ {
Program.Controller.Quit (); Program.Controller.Quit ();
} }
@ -240,17 +239,13 @@ namespace SparkleShare {
public EventHandler OpenFolderDelegate (string subfolder) public EventHandler OpenFolderDelegate (string subfolder)
{ {
return delegate { return delegate { SubfolderClicked (subfolder); };
SubfolderClicked (subfolder);
};
} }
public EventHandler TryAgainDelegate (string subfolder) public EventHandler TryAgainDelegate (string subfolder)
{ {
return delegate { return delegate { TryAgainClicked (subfolder); };
TryAgainClicked (subfolder);
};
} }