More work on [osx]

This commit is contained in:
Hylke Bons 2010-12-18 21:37:50 +01:00
parent 81b28a1e56
commit c75ac74764
11 changed files with 192 additions and 374 deletions

View file

@ -1,60 +0,0 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Drawing;
using System.Timers;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {
public partial class AppDelegate : NSApplicationDelegate {
// Workaround to be able to work with SparkleUI as the main class
}
public class SparkleUI : AppDelegate
{
public SparkleStatusIcon StatusIcon;
public SparkleUI ()
{
NSApplication.Init ();
//NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
//NSApplication.SharedApplication.applicationIconImage = NSImage.ImageNamed ("sparkleshare.icns");
//StatusIcon = new SparkleStatusIcon ();
}
public void Run ()
{
NSApplication.Main (new string [0]);
}
}
}

View file

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace SparkleShare
{
public partial class MainWindow : MonoMac.AppKit.NSWindow
{
#region Constructors
// Called when created from unmanaged code
public MainWindow (IntPtr handle) : base(handle)
{
Initialize ();
}
// Called when created directly from a XIB file
[Export("initWithCoder:")]
public MainWindow (NSCoder coder) : base(coder)
{
Initialize ();
}
// Shared initialization code
void Initialize ()
{
}
#endregion
}
}

View file

@ -1,23 +0,0 @@
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
namespace SparkleShare {
// Should subclass MonoMac.AppKit.NSWindow
[MonoMac.Foundation.Register("MainWindow")]
public partial class MainWindow {
}
// Should subclass MonoMac.AppKit.NSWindowController
[MonoMac.Foundation.Register("MainWindowController")]
public partial class MainWindowController {
}
}

View file

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace SparkleShare
{
public partial class MainWindowController : MonoMac.AppKit.NSWindowController
{
#region Constructors
// Called when created from unmanaged code
public MainWindowController (IntPtr handle) : base(handle)
{
Initialize ();
}
// Called when created directly from a XIB file
[Export("initWithCoder:")]
public MainWindowController (NSCoder coder) : base(coder)
{
Initialize ();
}
// Call to load from the XIB/NIB file
public MainWindowController () : base("MainWindow")
{
Initialize ();
}
// Shared initialization code
void Initialize ()
{
}
#endregion
//strongly typed window accessor
public new MainWindow Window {
get { return (MainWindow)base.Window; }
}
}
}

View file

@ -61,7 +61,7 @@ namespace SparkleShare {
};
OpenFolderButton.Activated += delegate {
// SparkleShare.Controller.OpenSparkleShareFolder (LocalPath);
SparkleShare.Controller.OpenSparkleShareFolder (LocalPath);
};
ContentView.AddSubview (OpenFolderButton);
@ -73,7 +73,7 @@ namespace SparkleShare {
};
CloseButton.Activated += delegate {
Close ();
PerformClose (this);
};
ContentView.AddSubview (CloseButton);
@ -87,14 +87,16 @@ namespace SparkleShare {
}
new public void Close ()
public override void PerformClose (NSObject sender)
{
InvokeOnMainThread (delegate {
base.Close ();
InvokeOnMainThread (delegate {
Console.WriteLine ("!!!!!!!!!!");
SparkleUI.OpenLogs.Remove ((SparkleLog) this);
base.PerformClose (this);
});
}

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using SparkleLib;
using System;
using System.Diagnostics;
using System.IO;
@ -66,7 +67,12 @@ namespace SparkleShare {
public override void OpenSparkleShareFolder (string subfolder)
{
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 ();
}

View file

@ -47,7 +47,6 @@
<Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="MainMenu.xib.designer.cs">
<DependentUpon>MainMenu.xib</DependentUpon>
</Compile>
@ -61,6 +60,8 @@
<Link>SparkleController.cs</Link>
</Compile>
<Compile Include="SparkleMacController.cs" />
<Compile Include="SparkleUI.cs" />
<Compile Include="SparkleWindow.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />
@ -80,6 +81,9 @@
<Content Include="Pixmaps\idle3.png" />
<Content Include="Pixmaps\sparkleshare-idle.png" />
<Content Include="Pixmaps\sparkleshare-idle-focus.png" />
<Content Include="..\..\..\data\side-splash.png">
<Link>Pixmaps\side-splash.png</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\SparkleLib\SparkleLib.csproj">

View file

@ -58,45 +58,45 @@ namespace SparkleShare {
StatusItem.HighlightMode = true;
SetAnimationState ();
SetNormalState ();
CreateMenu ();
/* SparkleShare.Controller.FolderSizeChanged += delegate {
Application.Invoke (delegate {
SparkleShare.Controller.FolderSizeChanged += delegate {
InvokeOnMainThread (delegate {
UpdateMenu ();
});
};
SparkleShare.Controller.FolderListChanged += delegate {
Application.Invoke (delegate {
InvokeOnMainThread (delegate {
SetNormalState ();
CreateMenu ();
});
};
SparkleShare.Controller.OnIdle += delegate {
Application.Invoke (delegate {
InvokeOnMainThread (delegate {
SetNormalState ();
UpdateMenu ();
});
};
SparkleShare.Controller.OnSyncing += delegate {
Application.Invoke (delegate {
InvokeOnMainThread (delegate {
SetAnimationState ();
UpdateMenu ();
});
};
SparkleShare.Controller.OnError += delegate {
Application.Invoke (delegate {
InvokeOnMainThread (delegate {
SetNormalState (true);
UpdateMenu ();
});
};
*/
}
@ -119,10 +119,10 @@ namespace SparkleShare {
InvokeOnMainThread (delegate {
StatusItem.AlternateImage = NSImage.ImageNamed ("idle" + FrameNumber + ".png");
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle" + FrameNumber + ".png");
StatusItem.AlternateImage.Size = new SizeF (16, 16);
StatusItem.Image = NSImage.ImageNamed ("idle" + FrameNumber + ".png");
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle" + FrameNumber + ".png");
StatusItem.Image.Size = new SizeF (16, 16);
});
@ -138,7 +138,7 @@ namespace SparkleShare {
// user clicks the status icon
public void CreateMenu ()
{
Menu = new NSMenu ();
StateMenuItem = new NSMenuItem () {
@ -154,49 +154,49 @@ namespace SparkleShare {
};
FolderMenuItem.Activated += delegate {
// SparkleShare.Controller.OpenSparkleShareFolder ();
SparkleShare.Controller.OpenSparkleShareFolder ();
};
FolderMenuItem.Image = NSImage.ImageNamed ("sparkleshare.icns");
//FolderMenuItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkleshare.icns");
FolderMenuItem.Image = NSImage.ImageNamed ("NSFolder");
FolderMenuItem.Image.Size = new SizeF (16, 16);
Menu.AddItem (FolderMenuItem);
FolderMenuItems = new NSMenuItem [2] {
new NSMenuItem () { Title = "gnome-design" },
new NSMenuItem () { Title = "tango-icons" }
};
// if (SparkleShare.Controller.Folders.Count > 0) {
if (SparkleShare.Controller.Folders.Count > 0) {
// foreach (string path in SparkleShare.Controller.Folders) {
foreach (NSMenuItem item in FolderMenuItems) {
FolderMenuItems = new NSMenuItem [SparkleShare.Controller.Folders.Count];
Tasks = new EventHandler [SparkleShare.Controller.Folders.Count];
int i = 0;
foreach (string path in SparkleShare.Controller.Folders) {
// if (repo.HasUnsyncedChanges)
// folder_action.IconName = "dialog-error";
NSMenuItem item = new NSMenuItem ();
item.Title = System.IO.Path.GetFileName (path);
item.Image = NSImage.ImageNamed ("NSFolder");
item.Image.Size = new SizeF (16, 16);
Tasks [i] = OpenEventLogDelegate(item.Title);
FolderMenuItems [i] = item;
FolderMenuItems [i].Activated += Tasks [i];
Menu.AddItem (FolderMenuItems [i]);
item.Activated += delegate {
};
item.Activated += OpenEventLogDelegate (item.Title);
Menu.AddItem (item);
i++;
};
// } else {
} else {
// TODO: No Remote Folders Yet
// }
}
Menu.AddItem (NSMenuItem.SeparatorItem);
@ -205,11 +205,11 @@ namespace SparkleShare {
Title = "Add Remote Folder..."
};
// if (SparkleShare.Controller.FirstRun)
// SyncMenuItem.Enabled = false;
if (SparkleShare.Controller.FirstRun)
SyncMenuItem.Enabled = false;
SyncMenuItem.Activated += delegate {
// TODO
SparkleWindow w = new SparkleWindow ();
};
Menu.AddItem (SyncMenuItem);
@ -219,16 +219,21 @@ namespace SparkleShare {
NotificationsMenuItem = new NSMenuItem () {
Title = "Show Notifications",
State = NSCellStateValue.On
Title = "Show Notifications"
};
// if (SparkleShare.Controller.NotificationsEnabled)
// NotificationsMenuItem.State = NSCellStateValue.On;
// else
// NotificationsMenuItem.State = NSCellStateValue.On;
if (SparkleShare.Controller.NotificationsEnabled)
NotificationsMenuItem.State = NSCellStateValue.On;
NotificationsMenuItem.Activated += delegate {
// SparkleShare.Controller.ToggleNotifications ();
SparkleShare.Controller.ToggleNotifications ();
if (SparkleShare.Controller.NotificationsEnabled)
NotificationsMenuItem.State = NSCellStateValue.On;
else
NotificationsMenuItem.State = NSCellStateValue.Off;
};
Menu.AddItem (NotificationsMenuItem);
@ -248,33 +253,30 @@ namespace SparkleShare {
Menu.AddItem (AboutMenuItem);
StatusItem.Menu = Menu;
StatusItem.Menu.Update ();
Console.WriteLine ("MENU UPDATED");
}
public delegate void Task();
EventHandler [] Tasks;
// A method reference that makes sure that opening the
// event log for each repository works correctly
private EventHandler OpenEventLogDelegate (string path)
{
return delegate {
SparkleLog log = null; //SparkleUI.OpenLogs.Find (delegate (SparkleLog l) { return l.LocalPath.Equals (path); });
SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) { return l.LocalPath.Equals (path); });
// Check whether the log is already open, create a new one if
//that's not the case or present it to the user if it is
// that's not the case or present it to the user if it is
if (log == null) {
log = new SparkleLog (path);
/*log.Hidden += delegate {
SparkleUI.OpenLogs.Remove (log);
log.Destroy ();
};
SparkleUI.OpenLogs.Add (log);*/
SparkleUI.OpenLogs.Add (new SparkleLog (path));
}
@ -306,15 +308,15 @@ namespace SparkleShare {
Animation.Stop ();
if (false /* SparkleShare.Controller.Folders.Count == 0 */) {
if (SparkleShare.Controller.Folders.Count == 0) {
StateText = _("Welcome to SparkleShare!");
InvokeOnMainThread (delegate {
StatusItem.Image = NSImage.ImageNamed ("idle.png");
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle.png");
StatusItem.Image.Size = new SizeF (16, 16);
StatusItem.AlternateImage = NSImage.ImageNamed ("idle-active.png");
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle-active.png");
StatusItem.AlternateImage.Size = new SizeF (16, 16);
});
@ -330,13 +332,13 @@ namespace SparkleShare {
} else {
StateText = _("Up to date") + " ("/* + SparkleShare.Controller.FolderSize + ")" */;
StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")";
InvokeOnMainThread (delegate {
StatusItem.Image = NSImage.ImageNamed ("idle.png");
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle.png");
StatusItem.Image.Size = new SizeF (16, 16);
StatusItem.AlternateImage = NSImage.ImageNamed ("idle-active.png");
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle-active.png");
StatusItem.AlternateImage.Size = new SizeF (16, 16);
});

View file

@ -8,164 +8,59 @@
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
using Mono.Unix.Native;
using SparkleLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Drawing;
using System.Timers;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {
public class SparkleUI {
public partial class AppDelegate : NSApplicationDelegate {
// Workaround to be able to work with SparkleUI as the main class
}
public class SparkleUI : AppDelegate
{
public static SparkleStatusIcon StatusIcon;
public static List <SparkleLog> OpenLogs;
// Short alias for the translations
public static string _(string s)
{
return Catalog.GetString (s);
}
public SparkleUI ()
{
// Initialize the application
Application.Init ();
// Create the statusicon
NSApplication.Init ();
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
//NSApplication.SharedApplication.applicationIconImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/sparkeshare.icns");
OpenLogs = new List <SparkleLog> ();
StatusIcon = new SparkleStatusIcon ();
// Keep track of which event logs are open
SparkleUI.OpenLogs = new List <SparkleLog> ();
SparkleShare.Controller.OnFirstRun += delegate {
Application.Invoke (delegate {
SparkleIntro intro = new SparkleIntro ();
intro.ShowAll ();
});
};
SparkleShare.Controller.OnInvitation += delegate (string invitation_file_path) {
Application.Invoke (delegate {
SparkleInvitation invitation = new SparkleInvitation (invitation_file_path);
invitation.Present ();
});
};
// Show a bubble when there are new changes
SparkleShare.Controller.NotificationRaised += delegate (SparkleCommit commit, string repository_path) {
string file_name = "";
string message = null;
if (commit.Added.Count > 0) {
foreach (string added in commit.Added) {
file_name = added;
break;
}
message = String.Format (_("added {0}"), file_name);
}
if (commit.Edited.Count > 0) {
foreach (string modified in commit.Edited) {
file_name = modified;
break;
}
message = String.Format (_("edited {0}"), file_name);
}
if (commit.Deleted.Count > 0) {
foreach (string removed in commit.Deleted) {
file_name = removed;
break;
}
message = String.Format (_("deleted {0}"), file_name);
}
int changes_count = (commit.Added.Count +
commit.Edited.Count +
commit.Deleted.Count);
if (changes_count > 1)
message += " + " + (changes_count - 1);
Application.Invoke (delegate {
SparkleBubble bubble = new SparkleBubble (commit.UserName, message);
string avatar_file_path = SparkleUIHelpers.GetAvatar (commit.UserEmail, 32);
if (avatar_file_path != null)
bubble.Icon = new Gdk.Pixbuf (avatar_file_path);
else
bubble.Icon = SparkleUIHelpers.GetIcon ("avatar-default", 32);
// bubble.AddAction ("", "Show Events", delegate {
// SparkleLog log = new SparkleLog (repository_path);
// log.ShowAll ();
// });
// bubble.Show ();
});
};
// Show a bubble when there was a conflict
SparkleShare.Controller.ConflictNotificationRaised += delegate {
Application.Invoke (delegate {
string title = _("Ouch! Mid-air collision!");
string subtext = _("Don't worry, SparkleShare made a copy of each conflicting file.");
SparkleBubble bubble = new SparkleBubble(title, subtext);
// bubble.Show ();
});
};
}
// Runs the application
public void Run ()
{
Application.Run ();
NSApplication.Main (new string [0]);
}
}
}
}

View file

@ -0,0 +1,73 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit;
namespace SparkleShare {
public class SparkleWindow : NSWindow {
public readonly string LocalPath;
private WebView WebView;
private NSButton CloseButton;
private NSButton OpenFolderButton;
private NSImage SideSplash;
public SparkleWindow () : base ()
{
SetFrame (new RectangleF (0, 0, 640, 480), true);
Center ();
StyleMask = (NSWindowStyle.Closable |
NSWindowStyle.Miniaturizable |
NSWindowStyle.Titled);
MaxSize = new SizeF (640, 480);
MinSize = new SizeF (640, 480);
HasShadow = true;
BackingType = NSBackingStore.Buffered;
SideSplash = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/side-splash.png");
SideSplash.Size = new SizeF (150, 480);
NSText tv = new NSText (new RectangleF (200, 200, 200, 200)) {
Value = "TEST"
};
ContentView.AddSubview (new NSImageView (new RectangleF (0, 0, 150, 480)) { Image = SideSplash});
ContentView.AddSubview (new NSTextField (new RectangleF (200, 100, 128, 31)) { BezelStyle = NSTextFieldBezelStyle.Rounded});
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
MakeKeyAndOrderFront (this);
}
}
}