[log] Keep logs in memory at all time. Fixes crashes and increases speed.

This commit is contained in:
Hylke Bons 2011-02-07 14:53:57 +00:00
parent de7009d151
commit 761fef8e97
7 changed files with 58 additions and 40 deletions

View file

@ -40,7 +40,7 @@ namespace SparkleShare {
{ {
LocalPath = path; LocalPath = path;
Delegate = new LogDelegate (); Delegate = new LogDelegate ();
SetFrame (new RectangleF (0, 0, 480, 640), true); SetFrame (new RectangleF (0, 0, 480, 640), true);
@ -56,8 +56,10 @@ namespace SparkleShare {
HasShadow = true; HasShadow = true;
BackingType = NSBackingStore.Buffered; BackingType = NSBackingStore.Buffered;
CreateEventLog ();
ContentView.AddSubview (CreateEventLog ()); UpdateEventLog ();
ContentView.AddSubview (WebView);
OpenFolderButton = new NSButton (new RectangleF (16, 12, 120, 31)) { OpenFolderButton = new NSButton (new RectangleF (16, 12, 120, 31)) {
Title = "Open Folder", Title = "Open Folder",
@ -90,20 +92,14 @@ namespace SparkleShare {
OrderFrontRegardless (); OrderFrontRegardless ();
} }
public void UpdateEventLog () public void UpdateEventLog ()
{ {
}
private WebView CreateEventLog ()
{
RectangleF frame = new RectangleF (0, (12 + 31 + 16), 480, 618 - (12 + 31 + 16));
string folder_name = Path.GetFileName (LocalPath); string folder_name = Path.GetFileName (LocalPath);
string html = SparkleShare.Controller.GetHTMLLog (folder_name); string html = SparkleShare.Controller.GetHTMLLog (folder_name);
@ -112,11 +108,19 @@ namespace SparkleShare {
html = html.Replace ("<!-- $secondary-font-color -->", "#bbb"); html = html.Replace ("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5"); html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace ("<!-- $a-color -->", "#0085cf"); html = html.Replace ("<!-- $a-color -->", "#0085cf");
WebView = new WebView (frame, "", "");
WebView.MainFrame.LoadHtmlString (html, new NSUrl ("")); WebView.MainFrame.LoadHtmlString (html, new NSUrl (""));
WebView.PolicyDelegate = new SparkleWebPolicyDelegate ();
}
private WebView CreateEventLog ()
{
WebView = new WebView (new RectangleF (0, 59, 480, 559), "", ""){
PolicyDelegate = new SparkleWebPolicyDelegate ()
};
return WebView; return WebView;
} }
@ -126,13 +130,12 @@ namespace SparkleShare {
public class LogDelegate : NSWindowDelegate { public class LogDelegate : NSWindowDelegate {
public override void WillClose (NSNotification notification) public override bool WindowShouldClose (NSObject sender)
{ {
(sender as SparkleLog).OrderOut (this);
return false;
InvokeOnMainThread (delegate {
SparkleUI.OpenLogs.Remove ((SparkleLog) notification.Object);
});
} }
} }
@ -141,7 +144,8 @@ namespace SparkleShare {
public class SparkleWebPolicyDelegate : WebPolicyDelegate { public class SparkleWebPolicyDelegate : WebPolicyDelegate {
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info, public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
NSUrlRequest request, WebFrame frame, NSObject decision_token) { NSUrlRequest request, WebFrame frame, NSObject decision_token)
{
string file_path = request.Url.ToString (); string file_path = request.Url.ToString ();
file_path = file_path.Replace ("%20", "\\ "); file_path = file_path.Replace ("%20", "\\ ");

View file

@ -61,11 +61,18 @@ namespace SparkleShare {
if (!Directory.Exists (SparklePaths.SparklePath)) { if (!Directory.Exists (SparklePaths.SparklePath)) {
Directory.CreateDirectory (SparklePaths.SparklePath); Directory.CreateDirectory (SparklePaths.SparklePath);
string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "sparkleshare-folder.icns");
NSWorkspace.SharedWorkspace.SetIconforFile (NSImage.ImageNamed ("sparkleshare.icns"), NSImage folder_icon = new NSImage (folder_icon_path);
NSWorkspace.SharedWorkspace.SetIconforFile (folder_icon,
SparklePaths.SparklePath, 0); SparklePaths.SparklePath, 0);
return true; return true;
} else { } else {
@ -82,11 +89,9 @@ namespace SparkleShare {
{ {
string folder = Path.Combine (SparklePaths.SparklePath, subfolder); string folder = Path.Combine (SparklePaths.SparklePath, subfolder);
folder.Replace (" ", "\\ "); // Escape space-characters
Process process = new Process ();
process.StartInfo.Arguments = folder.Replace (" ", "\\ "); // Escape space-characters NSWorkspace.SharedWorkspace.OpenFile (folder);
process.StartInfo.FileName = "open";
process.Start ();
} }

View file

@ -53,7 +53,7 @@ namespace SparkleShare {
public SparkleStatusIcon () : base () public SparkleStatusIcon () : base ()
{ {
Animation = CreateAnimation (); Animation = CreateAnimation ();
@ -161,15 +161,14 @@ namespace SparkleShare {
SparkleShare.Controller.OpenSparkleShareFolder (); SparkleShare.Controller.OpenSparkleShareFolder ();
}; };
//FolderMenuItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkleshare.icns"); FolderMenuItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkleshare-mac-16.png");
FolderMenuItem.Image = NSImage.ImageNamed ("NSFolder");
FolderMenuItem.Image.Size = new SizeF (16, 16); FolderMenuItem.Image.Size = new SizeF (16, 16);
Menu.AddItem (FolderMenuItem); Menu.AddItem (FolderMenuItem);
if (SparkleShare.Controller.Folders.Count > 0) { if (SparkleShare.Controller.Folders.Count > 0) {
FolderMenuItems = new NSMenuItem [SparkleShare.Controller.Folders.Count]; FolderMenuItems = new NSMenuItem [SparkleShare.Controller.Folders.Count];
Tasks = new EventHandler [SparkleShare.Controller.Folders.Count]; Tasks = new EventHandler [SparkleShare.Controller.Folders.Count];
@ -198,7 +197,13 @@ namespace SparkleShare {
} else { } else {
// TODO: No Remote Folders Yet FolderMenuItems = new NSMenuItem [1];
FolderMenuItems [0] = new NSMenuItem () {
Title = "No Remote Folders Yet"
};
Menu.AddItem (FolderMenuItems [0]);
} }
@ -251,7 +256,10 @@ namespace SparkleShare {
}; };
AboutMenuItem.Activated += delegate { AboutMenuItem.Activated += delegate {
// TODO
NSUrl url = new NSUrl ("http://www.sparkleshare.org/");
NSWorkspace.SharedWorkspace.OpenUrl (url);
}; };
Menu.AddItem (AboutMenuItem); Menu.AddItem (AboutMenuItem);
@ -269,7 +277,7 @@ namespace SparkleShare {
{ {
return delegate { return delegate {
SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) { SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) {
return l.LocalPath.Equals (path); return l.LocalPath.Equals (path);
}); });
@ -281,13 +289,13 @@ namespace SparkleShare {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SparkleUI.OpenLogs.Add (new SparkleLog (path)); SparkleUI.OpenLogs.Add (new SparkleLog (path));
}); });
} else { } else {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
log.OrderFrontRegardless (); log.OrderFront (this);
}); });
} }
}; };
@ -382,9 +390,6 @@ namespace SparkleShare {
{ {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
foreach (SparkleLog log in SparkleUI.OpenLogs)
log.OrderFrontRegardless ();
SparkleUI.NewEvents = 0; SparkleUI.NewEvents = 0;
NSApplication.SharedApplication.DockTile.BadgeLabel = null; NSApplication.SharedApplication.DockTile.BadgeLabel = null;

View file

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Timers; using System.Timers;
using MonoMac.Foundation; using MonoMac.Foundation;
using MonoMac.AppKit; using MonoMac.AppKit;
@ -44,9 +45,12 @@ namespace SparkleShare {
NSApplication.Init (); NSApplication.Init ();
// TODO: Getting crashes when I remove this
NSApplication.SharedApplication.ApplicationIconImage NSApplication.SharedApplication.ApplicationIconImage
= NSImage.ImageNamed ("sparkleshare.icns"); = NSImage.ImageNamed ("sparkleshare.icns");
OpenLogs = new List <SparkleLog> (); OpenLogs = new List <SparkleLog> ();
StatusIcon = new SparkleStatusIcon (); StatusIcon = new SparkleStatusIcon ();

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 KiB