[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 1ea70f7707
commit e6e0e3608f
7 changed files with 58 additions and 40 deletions

View file

@ -40,7 +40,7 @@ namespace SparkleShare {
{
LocalPath = path;
Delegate = new LogDelegate ();
SetFrame (new RectangleF (0, 0, 480, 640), true);
@ -56,8 +56,10 @@ namespace SparkleShare {
HasShadow = true;
BackingType = NSBackingStore.Buffered;
ContentView.AddSubview (CreateEventLog ());
CreateEventLog ();
UpdateEventLog ();
ContentView.AddSubview (WebView);
OpenFolderButton = new NSButton (new RectangleF (16, 12, 120, 31)) {
Title = "Open Folder",
@ -90,20 +92,14 @@ namespace SparkleShare {
OrderFrontRegardless ();
}
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 html = SparkleShare.Controller.GetHTMLLog (folder_name);
@ -112,11 +108,19 @@ namespace SparkleShare {
html = html.Replace ("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace ("<!-- $a-color -->", "#0085cf");
WebView = new WebView (frame, "", "");
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;
}
@ -126,13 +130,12 @@ namespace SparkleShare {
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 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 ();
file_path = file_path.Replace ("%20", "\\ ");

View file

@ -61,11 +61,18 @@ namespace SparkleShare {
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);
return true;
} else {
@ -82,11 +89,9 @@ namespace SparkleShare {
{
string folder = Path.Combine (SparklePaths.SparklePath, subfolder);
Process process = new Process ();
process.StartInfo.Arguments = folder.Replace (" ", "\\ "); // Escape space-characters
process.StartInfo.FileName = "open";
process.Start ();
folder.Replace (" ", "\\ "); // Escape space-characters
NSWorkspace.SharedWorkspace.OpenFile (folder);
}

View file

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

View file

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