mac: clean up

This commit is contained in:
Hylke Bons 2012-11-30 00:23:31 +00:00
parent 7a7f591cd6
commit b7808ecbe4
3 changed files with 39 additions and 83 deletions

View file

@ -56,8 +56,6 @@ namespace SparkleShare {
this.status_item.HighlightMode = true;
this.status_item.Image = this.syncing_idle_image;
this.status_item.AlternateImage = this.syncing_idle_image_active;
this.status_item.Image.Size = new SizeF (16, 16);
this.status_item.AlternateImage.Size = new SizeF (16, 16);
CreateMenu ();
@ -90,9 +88,6 @@ namespace SparkleShare {
break;
}
}
this.status_item.Image.Size = new SizeF (16, 16);
this.status_item.AlternateImage.Size = new SizeF (16, 16);
});
};
@ -114,13 +109,11 @@ namespace SparkleShare {
{
this.menu = new NSMenu () { AutoEnablesItems = false };
this.state_item = new NSMenuItem () {
Title = Controller.StateText,
Enabled = false
};
this.folder_item = new NSMenuItem () {
Title = "SparkleShare",
Enabled = true
@ -129,40 +122,26 @@ namespace SparkleShare {
this.folder_item.Image = this.sparkleshare_image;
this.folder_item.Image.Size = new SizeF (16, 16);
this.add_item = new NSMenuItem () {
Title = "Add Hosted Project…",
Enabled = true
};
this.add_item.Activated += Controller.AddHostedProjectClicked;
this.recent_events_item = new NSMenuItem () {
Title = "Recent Changes…",
Enabled = Controller.RecentEventsItemEnabled
};
if (Controller.RecentEventsItemEnabled)
this.recent_events_item.Activated += Controller.RecentEventsClicked;
this.about_item = new NSMenuItem () {
Title = "About SparkleShare",
Enabled = true
};
this.about_item.Activated += Controller.AboutClicked;
this.quit_item = new NSMenuItem () {
Title = "Quit",
Enabled = Controller.QuitItemEnabled
};
this.quit_item.Activated += Controller.QuitClicked;
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];
@ -198,6 +177,14 @@ namespace SparkleShare {
};
}
if (Controller.RecentEventsItemEnabled)
this.recent_events_item.Activated += Controller.RecentEventsClicked;
this.add_item.Activated += Controller.AddHostedProjectClicked;
this.about_item.Activated += Controller.AboutClicked;
this.quit_item.Activated += Controller.QuitClicked;
this.menu.AddItem (this.state_item);
this.menu.AddItem (NSMenuItem.SeparatorItem);

View file

@ -16,12 +16,9 @@
using System;
using System.Drawing;
using System.IO;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
namespace SparkleShare {
@ -43,8 +40,8 @@ namespace SparkleShare {
public SparkleUI ()
{
Program.Controller.Invoke (() => {
NSWorkspace.SharedWorkspace.SetIconforFile (NSImage.ImageNamed ("sparkleshare-folder.icns"),
Program.Controller.FoldersPath, 0);
NSWorkspace.SharedWorkspace.SetIconforFile (
NSImage.ImageNamed ("sparkleshare-folder.icns"), Program.Controller.FoldersPath, 0);
NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns");
@ -68,22 +65,7 @@ namespace SparkleShare {
public void UpdateDockIconVisibility ()
{
if (Setup.IsVisible || EventLog.IsVisible || About.IsVisible)
ShowDockIcon ();
else
HideDockIcon ();
}
private void HideDockIcon ()
{
// Currently not supported by Apple's API
// NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.None;
}
private void ShowDockIcon ()
{
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;
NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;
}
}
@ -96,4 +78,3 @@ namespace SparkleShare {
}
}
}

View file

@ -68,18 +68,9 @@ namespace SparkleShare {
UpdateSizeInfoEvent ("…", "…");
new Thread (() => {
Stopwatch watch = new Stopwatch ();
watch.Start ();
SparkleDelay delay = new SparkleDelay ();
string html = HTML;
watch.Stop ();
// A short delay is less annoying than
// a flashing window
int delay = 500;
if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);
delay.Stop ();
if (!string.IsNullOrEmpty (html))
UpdateContentEvent (html);
@ -161,16 +152,9 @@ namespace SparkleShare {
if (this.selected_folder == null) {
new Thread (() => {
Stopwatch watch = new Stopwatch ();
watch.Start ();
SparkleDelay delay = new SparkleDelay ();
string html = HTML;
watch.Stop ();
int delay = 500;
if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);
delay.Stop ();
UpdateChooserEvent (Folders);
UpdateChooserEnablementEvent (true);
@ -195,16 +179,9 @@ namespace SparkleShare {
ContentLoadingEvent ();
UpdateSizeInfoEvent ("…", "…");
Stopwatch watch = new Stopwatch ();
watch.Start ();
SparkleDelay delay = new SparkleDelay ();
string html = HTML;
watch.Stop ();
int delay = 500;
if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);
delay.Stop ();
if (!string.IsNullOrEmpty (html))
UpdateContentEvent (html);
@ -287,17 +264,10 @@ namespace SparkleShare {
continue;
new Thread (() => {
Stopwatch watch = new Stopwatch ();
watch.Start ();
List<SparkleChangeSet> change_sets = repo.GetChangeSets (file_path);
string html = GetHistoryHTMLLog (change_sets, file_path);
watch.Stop ();
int delay = 500;
if (watch.ElapsedMilliseconds < delay)
Thread.Sleep (delay - (int) watch.ElapsedMilliseconds);
SparkleDelay delay = new SparkleDelay ();
List<SparkleChangeSet> change_sets = repo.GetChangeSets (file_path);
string html = GetHistoryHTMLLog (change_sets, file_path);
delay.Stop ();
if (!string.IsNullOrEmpty (html))
UpdateContentEvent (html);
@ -627,5 +597,23 @@ namespace SparkleShare {
public string FilePath;
public string Revision;
}
private class SparkleDelay : Stopwatch {
public SparkleDelay () : base ()
{
Start ();
}
new public void Stop ()
{
base.Stop ();
if (ElapsedMilliseconds < 500)
Thread.Sleep (500 - (int) ElapsedMilliseconds);
}
}
}
}