windows statusicon: create animation

This commit is contained in:
Hylke Bons 2012-03-07 01:20:07 +00:00
parent ffb9bee2eb
commit 6fcf98ed83
13 changed files with 77 additions and 122 deletions

View file

@ -159,7 +159,7 @@ namespace SparkleShare {
if (!Program.Controller.FirstRun && TutorialPageNumber == 0) { if (!Program.Controller.FirstRun && TutorialPageNumber == 0) {
if (ChangePageEvent != null) if (ChangePageEvent != null)
ChangePageEvent (page_type, null); ChangePageEvent (page_type, null);
if (ShowWindowEvent != null) if (ShowWindowEvent != null)
ShowWindowEvent (); ShowWindowEvent ();

View file

@ -270,13 +270,6 @@ namespace SparkleShare {
} }
} }
internal static System.Drawing.Bitmap sparkleshare_windows_status {
get {
object obj = ResourceManager.GetObject("sparkleshare_windows_status", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
internal static System.Drawing.Bitmap tutorial_slide_1 { internal static System.Drawing.Bitmap tutorial_slide_1 {
get { get {
object obj = ResourceManager.GetObject("tutorial_slide_1", resourceCulture); object obj = ResourceManager.GetObject("tutorial_slide_1", resourceCulture);

View file

@ -199,9 +199,6 @@
<data name="sparkleshare_syncing_error_24" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="sparkleshare_syncing_error_24" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\data\icons\sparkleshare-syncing-error-24.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\..\data\icons\sparkleshare-syncing-error-24.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="sparkleshare_windows_status" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\data\icons\sparkleshare-windows-status.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="sparkleshare" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="sparkleshare" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\data\icons\sparkleshare.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\..\data\icons\sparkleshare.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>

View file

@ -96,7 +96,7 @@ namespace SparkleShare {
Height = 260 Height = 260
}; };
image.Source = SparkleUIHelpers.GetBitmap ("about"); image.Source = SparkleUIHelpers.GetImageSource ("about");
Label version = new Label () { Label version = new Label () {

View file

@ -30,7 +30,7 @@ namespace SparkleShare {
Controller.ShowBubbleEvent += delegate (string title, Controller.ShowBubbleEvent += delegate (string title,
string subtext, string image_path) { string subtext, string image_path) {
SparkleUI.StatusIcon.ShowBalloon (title, subtext, image_path); // TODO SparkleUI.StatusIcon.ShowBalloon (title, subtext, image_path);
}; };
} }
} }

View file

@ -435,7 +435,7 @@ namespace SparkleShare {
Height = 200 Height = 200
}; };
slide_image.Source = SparkleUIHelpers.GetBitmap ("tutorial-slide-1-windows"); slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-1-windows");
ContentCanvas.Children.Add (slide_image); ContentCanvas.Children.Add (slide_image);
@ -502,7 +502,7 @@ namespace SparkleShare {
Height = 200 Height = 200
}; };
slide_image.Source = SparkleUIHelpers.GetBitmap ("tutorial-slide-3-windows"); slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-3-windows");
ContentCanvas.Children.Add (slide_image); ContentCanvas.Children.Add (slide_image);
@ -534,7 +534,7 @@ namespace SparkleShare {
Height = 64 Height = 64
}; };
slide_image.Source = SparkleUIHelpers.GetBitmap ("tutorial-slide-4"); slide_image.Source = SparkleUIHelpers.GetImageSource ("tutorial-slide-4");
CheckBox check_box = new CheckBox () { CheckBox check_box = new CheckBox () {
Content = "Add SparkleShare to startup items", Content = "Add SparkleShare to startup items",

View file

@ -73,7 +73,7 @@ namespace SparkleShare {
Height = 482 Height = 482
}; };
this.side_splash.Source = SparkleUIHelpers.GetBitmap ("side-splash"); this.side_splash.Source = SparkleUIHelpers.GetImageSource ("side-splash");
ContentCanvas.Children.Add (this.bar); ContentCanvas.Children.Add (this.bar);
@ -159,7 +159,6 @@ namespace SparkleShare {
} }
ElementHost.EnableModelessKeyboardInterop (this); ElementHost.EnableModelessKeyboardInterop (this);
Show ();
} }

View file

@ -226,6 +226,24 @@
<EmbeddedResource Include="..\..\data\tutorial-slide-4.png"> <EmbeddedResource Include="..\..\data\tutorial-slide-4.png">
<Link>Pixmaps\tutorial-slide-4.png</Link> <Link>Pixmaps\tutorial-slide-4.png</Link>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\process-syncing-sparkleshare-windows-i.png">
<Link>Pixmaps\process-syncing-sparkleshare-windows-i.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\process-syncing-sparkleshare-windows-ii.png">
<Link>Pixmaps\process-syncing-sparkleshare-windows-ii.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\process-syncing-sparkleshare-windows-iii.png">
<Link>Pixmaps\process-syncing-sparkleshare-windows-iii.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\process-syncing-sparkleshare-windows-iiii.png">
<Link>Pixmaps\process-syncing-sparkleshare-windows-iiii.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\process-syncing-sparkleshare-windows-iiiii.png">
<Link>Pixmaps\process-syncing-sparkleshare-windows-iiiii.png</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\data\icons\sparkleshare-syncing-error-windows.png">
<Link>Pixmaps\sparkleshare-syncing-error-windows.png</Link>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Icons.tt"> <None Include="Icons.tt">

View file

@ -20,7 +20,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using WinForms = System.Windows.Forms; using Forms = System.Windows.Forms;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows; using System.Windows;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
@ -32,15 +32,16 @@ namespace SparkleShare {
public SparkleStatusIconController Controller = new SparkleStatusIconController(); public SparkleStatusIconController Controller = new SparkleStatusIconController();
private WinForms.Timer Animation; private Forms.Timer Animation;
private Bitmap [] AnimationFrames; private Icon [] AnimationFrames;
private Icon ErrorIcon;
private int FrameNumber; private int FrameNumber;
private string StateText; private string StateText;
private ContextMenu context_menu; private ContextMenu context_menu;
private MenuItem exit_item; private MenuItem exit_item;
private WinForms.NotifyIcon notify_icon = new WinForms.NotifyIcon () { private Forms.NotifyIcon notify_icon = new Forms.NotifyIcon () {
Text = "SparkleShare", Text = "SparkleShare",
Visible = true Visible = true
}; };
@ -60,15 +61,18 @@ namespace SparkleShare {
this.context_menu.IsOpen = false; this.context_menu.IsOpen = false;
}; };
notify_icon.Icon = Icon.FromHandle(Icons.document_added_12.GetHicon());
AnimationFrames = CreateAnimationFrames (); AnimationFrames = CreateAnimationFrames ();
Animation = CreateAnimation (); Animation = CreateAnimation ();
notify_icon.Icon = AnimationFrames [0];
ErrorIcon = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("sparkleshare-syncing-error-windows"));
this.notify_icon.MouseClick +=new WinForms.MouseEventHandler(ShowMenu); this.notify_icon.MouseClick += delegate {
this.context_menu.Placement = PlacementMode.Mouse;
this.context_menu.IsOpen = true;
};
CreateMenu (); CreateMenu ();
SetNormalState (); SetNormalState ();
Controller.UpdateQuitItemEvent += delegate (bool enable) { Controller.UpdateQuitItemEvent += delegate (bool enable) {
@ -108,37 +112,31 @@ namespace SparkleShare {
} }
private void ShowMenu (object sender, WinForms.MouseEventArgs e)
{
this.context_menu.Placement = PlacementMode.Mouse;
this.context_menu.IsOpen = true;
}
[DllImport("user32.dll", EntryPoint = "DestroyIcon")] [DllImport("user32.dll", EntryPoint = "DestroyIcon")]
static extern bool DestroyIcon(IntPtr hIcon); static extern bool DestroyIcon(IntPtr hIcon);
// Slices up the graphic that contains the // Slices up the graphic that contains the
// animation frames. // animation frames.
private Bitmap [] CreateAnimationFrames () private Icon [] CreateAnimationFrames ()
{ {
Bitmap [] animation_frames = new Bitmap [5]; Icon [] animation_frames = new Icon [5];
animation_frames [0] = Icons.process_syncing_sparkleshare_i_24; animation_frames [0] = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("process-syncing-sparkleshare-windows-i"));
animation_frames [1] = Icons.process_syncing_sparkleshare_ii_24; animation_frames [1] = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("process-syncing-sparkleshare-windows-ii"));
animation_frames [2] = Icons.process_syncing_sparkleshare_iii_24; animation_frames [2] = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("process-syncing-sparkleshare-windows-iii"));
animation_frames [3] = Icons.process_syncing_sparkleshare_iiii_24; animation_frames [3] = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("process-syncing-sparkleshare-windows-iiii"));
animation_frames [4] = Icons.process_syncing_sparkleshare_iiiii_24; animation_frames [4] = GetIconFromBitmap (SparkleUIHelpers.GetBitmap ("process-syncing-sparkleshare-windows-iiiii"));
return animation_frames; return animation_frames;
} }
// Creates the Animation that handles the syncing animation // Creates the Animation that handles the syncing animation
private WinForms.Timer CreateAnimation () private Forms.Timer CreateAnimation ()
{ {
FrameNumber = 0; FrameNumber = 0;
WinForms.Timer Animation = new WinForms.Timer () { Forms.Timer Animation = new Forms.Timer () {
Interval = 35 Interval = 35
}; };
@ -149,7 +147,7 @@ namespace SparkleShare {
FrameNumber = 0; FrameNumber = 0;
Dispatcher.Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
this.notify_icon.Icon = GetIconFromBitmap (AnimationFrames [FrameNumber]); this.notify_icon.Icon = AnimationFrames [FrameNumber];
}); });
}; };
@ -174,7 +172,7 @@ namespace SparkleShare {
MenuItem folder_item = new MenuItem () { MenuItem folder_item = new MenuItem () {
Header = " SparkleShare"//, Header = "SparkleShare"//,
,Icon = i ,Icon = i
}; };
@ -183,7 +181,7 @@ namespace SparkleShare {
}; };
MenuItem add_item = new MenuItem () { MenuItem add_item = new MenuItem () {
Header = " Add Hosted Project…", Header = "Add Hosted Project…",
IsEnabled = (!Program.Controller.FirstRun) IsEnabled = (!Program.Controller.FirstRun)
}; };
@ -192,7 +190,7 @@ namespace SparkleShare {
}; };
MenuItem log_item = new MenuItem () { MenuItem log_item = new MenuItem () {
Header = " View Recent Changes…", Header = "View Recent Changes…",
IsEnabled = (Program.Controller.Folders.Count > 0) IsEnabled = (Program.Controller.Folders.Count > 0)
}; };
@ -203,9 +201,9 @@ namespace SparkleShare {
MenuItem notify_item = new MenuItem (); MenuItem notify_item = new MenuItem ();
if (Program.Controller.NotificationsEnabled) if (Program.Controller.NotificationsEnabled)
notify_item = new MenuItem () { Header = " Turn Notifications Off" }; notify_item = new MenuItem () { Header = "Turn Notifications Off" };
else else
notify_item = new MenuItem () { Header = " Turn Notifications On" }; notify_item = new MenuItem () { Header = "Turn Notifications On" };
notify_item.Click += delegate { notify_item.Click += delegate {
Program.Controller.ToggleNotifications (); Program.Controller.ToggleNotifications ();
@ -213,7 +211,7 @@ namespace SparkleShare {
}; };
MenuItem about_item = new MenuItem () { MenuItem about_item = new MenuItem () {
Header = " About SparkleShare" Header = "About SparkleShare"
}; };
about_item.Click += delegate { about_item.Click += delegate {
@ -221,7 +219,7 @@ namespace SparkleShare {
}; };
exit_item = new MenuItem () { exit_item = new MenuItem () {
Header = " Exit" Header = "Exit"
}; };
this.exit_item.Click += delegate { this.exit_item.Click += delegate {
@ -237,18 +235,12 @@ namespace SparkleShare {
if (Program.Controller.Folders.Count > 0) { if (Program.Controller.Folders.Count > 0) {
foreach (string folder_name in Program.Controller.Folders) { foreach (string folder_name in Program.Controller.Folders) {
MenuItem subfolder_item = new MenuItem () { MenuItem subfolder_item = new MenuItem () {
Header = " " + folder_name Header = folder_name
}; };
subfolder_item.Click += OpenFolderDelegate (folder_name); subfolder_item.Click += OpenFolderDelegate (folder_name);
System.Windows.Controls.Image i2 = new System.Windows.Controls.Image(); subfolder_item.Icon = ErrorIcon;
i2.Source =
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Icons.sparkleshare_windows_status.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromWidthAndHeight(16, 16));
subfolder_item.Icon = i2;
/* /*
if (Program.Controller.UnsyncedFolders.Contains (folder_name)) if (Program.Controller.UnsyncedFolders.Contains (folder_name))
subfolder_item.Icon = Icons.dialog_error_16; subfolder_item.Icon = Icons.dialog_error_16;
@ -260,7 +252,7 @@ namespace SparkleShare {
} else { } else {
MenuItem no_folders_item = new MenuItem () { MenuItem no_folders_item = new MenuItem () {
Header = " No projects yet", Header = "No projects yet",
IsEnabled = false IsEnabled = false
}; };
@ -279,17 +271,7 @@ namespace SparkleShare {
} }
public void ShowBalloon (string title, string subtext, string image_path)
{
// TODO: Use the image pointed to by image_path
this.notify_icon.BalloonTipText = title;
this.notify_icon.BalloonTipText = subtext;
this.notify_icon.BalloonTipIcon = WinForms.ToolTipIcon.None;
this.notify_icon.ShowBalloonTip (5 * 1000);
}
public void UpdateMenu () public void UpdateMenu ()
{ {
@ -311,23 +293,24 @@ namespace SparkleShare {
Animation.Stop (); Animation.Stop ();
if (Program.Controller.Folders.Count == 0) { if (Program.Controller.Folders.Count == 0) {
StateText = _(" Welcome to SparkleShare!"); StateText = _("Welcome to SparkleShare!");
Dispatcher.Invoke ((Action)delegate { Dispatcher.Invoke ((Action)delegate {
this.notify_icon.Icon = GetIconFromBitmap (Icons.sparkleshare_windows_status); this.notify_icon.Icon = AnimationFrames [0];
}); });
} else { } else {
if (error) { if (error) {
StateText = _(" Not everything is synced"); StateText = _("Not everything is synced");
Dispatcher.Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
this.notify_icon.Icon = GetIconFromBitmap (Icons.sparkleshare_syncing_error_24); this.notify_icon.Icon = ErrorIcon;
}); });
} else { } else {
StateText = _(" Files up to date") + Controller.FolderSize; StateText = _("Files up to date") + Controller.FolderSize;
Dispatcher.Invoke ((Action)delegate { Dispatcher.Invoke ((Action)delegate {
this.notify_icon.Icon = GetIconFromBitmap (Icons.sparkleshare_windows_status); this.notify_icon.Icon = AnimationFrames [0];
}); });
} }
} }
@ -343,7 +326,7 @@ namespace SparkleShare {
// The state when animating // The state when animating
private void SetAnimationState () private void SetAnimationState ()
{ {
StateText = _(" Syncing…"); StateText = _("Syncing…");
if (!Animation.Enabled) if (!Animation.Enabled)
Animation.Start (); Animation.Start ();
@ -369,47 +352,4 @@ namespace SparkleShare {
return icon; return icon;
} }
} }
// TODO: remove
public static class ControlExtention {
public static void SafeInvoke (this WinForms.Control ui_element,
Action updater, bool force_synchronous)
{
if (ui_element == null)
return;
if (ui_element.InvokeRequired) {
if (force_synchronous) {
ui_element.Invoke ((Action) delegate {
SafeInvoke (ui_element, updater, force_synchronous);
});
} else {
ui_element.BeginInvoke ((Action) delegate {
SafeInvoke (ui_element, updater, force_synchronous);
});
}
} else {
if (ui_element.IsDisposed)
throw new ObjectDisposedException ("Control is already disposed.");
updater ();
}
}
public static void SafeInvoke (this WinForms.Control ui_element, Action updater)
{
ui_element.SafeInvoke (updater, false);
}
}
} }

View file

@ -36,7 +36,7 @@ namespace SparkleShare {
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

@ -31,11 +31,19 @@ namespace SparkleShare {
} }
public static BitmapFrame GetBitmap (string name) public static BitmapFrame GetImageSource (string name)
{ {
Assembly assembly = Assembly.GetExecutingAssembly (); Assembly assembly = Assembly.GetExecutingAssembly ();
Stream image_stream = assembly.GetManifestResourceStream ("SparkleShare.Pixmaps." + name + ".png"); Stream image_stream = assembly.GetManifestResourceStream ("SparkleShare.Pixmaps." + name + ".png");
return BitmapFrame.Create (image_stream); return BitmapFrame.Create (image_stream);
} }
public static Bitmap GetBitmap (string name)
{
Assembly assembly = Assembly.GetExecutingAssembly ();
Stream image_stream = assembly.GetManifestResourceStream ("SparkleShare.Pixmaps." + name + ".png");
return (Bitmap) Bitmap.FromStream (image_stream);
}
} }
} }

View file

Before

Width:  |  Height:  |  Size: 677 B

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 869 B