<commit_before>using System;
using Eto.Forms;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
using Eto.Platform.GtkSharp.Drawing;
using Eto.Drawing;

namespace Eto.Platform.GtkSharp
{
	public class ApplicationHandler : WidgetHandler<object, Application>, IApplication
	{
		Gtk.StatusIcon statusIcon;

		public static int MainThreadID { get; set; }
		
		public void RunIteration ()
		{
			Gtk.Application.RunIteration ();
		}

		public void Restart ()
		{
			Gtk.Application.Quit ();

			// TODO: restart!
		}

		string badgeLabel;

		public string BadgeLabel
		{
			get { return badgeLabel; }
			set
			{
				badgeLabel = value;
				if (!string.IsNullOrEmpty (badgeLabel))
				{
					if (statusIcon == null)
						statusIcon = new Gtk.StatusIcon ();
					var bmp = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 32, 32);
					using (var graphics = new Graphics(new Bitmap (Widget.Generator, new BitmapHandler (bmp)))) {
						DrawBadgeLabel (graphics, new Size (bmp.Width, bmp.Height), badgeLabel);
					}
					statusIcon.Pixbuf = bmp;
					statusIcon.Visible = true;
				}
				else if (statusIcon != null)
					statusIcon.Visible = false;
			}
		}

		protected virtual void DrawBadgeLabel (Graphics graphics, Size size, string badgeLabel)
		{
			graphics.FillEllipse (Brushes.Red (), new Rectangle (size));
			graphics.DrawEllipse (Pens.White (), new Rectangle (size));
			var font = new Font(SystemFont.Bold, 10);
			var labelSize = graphics.MeasureString (font, badgeLabel);
			graphics.DrawText (font, Colors.White, new Point ((int)((size.Width - labelSize.Width) / 2), (int)((size.Height - labelSize.Height) / 2)), badgeLabel);
			graphics.Flush ();
		}

		public void Invoke (System.Action action)
		{<commit_msg>Gtk: Improvements for badge label status icon, clicking on it will activate the main form<commit_after>using System;
using Eto.Forms;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
using Eto.Platform.GtkSharp.Drawing;
using Eto.Drawing;

namespace Eto.Platform.GtkSharp
{
	public class ApplicationHandler : WidgetHandler<object, Application>, IApplication
	{
		Gtk.StatusIcon statusIcon;

		public static int MainThreadID { get; set; }
		
		public void RunIteration ()
		{
			Gtk.Application.RunIteration ();
		}

		public void Restart ()
		{
			Gtk.Application.Quit ();

			// TODO: restart!
		}

		string badgeLabel;

		public string BadgeLabel
		{
			get { return badgeLabel; }
			set
			{
				badgeLabel = value;
				if (!string.IsNullOrEmpty (badgeLabel))
				{
					if (statusIcon == null) {
						statusIcon = new Gtk.StatusIcon ();
						statusIcon.Activate += delegate {
							var form = Application.Instance.MainForm;
							if (form != null)
								form.BringToFront ();
						};
					}
					var bmp = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 32, 32);
					using (var graphics = new Graphics(new Bitmap (Widget.Generator, new BitmapHandler (bmp)))) {
						graphics.Clear ();
						DrawBadgeLabel (graphics, new Size (bmp.Width, bmp.Height), badgeLabel);
					}
					statusIcon.Pixbuf = bmp;
					statusIcon.Visible = true;
				}
				else if (statusIcon != null)
					statusIcon.Visible = false;
			}
		}

		protected virtual void DrawBadgeLabel (Graphics graphics, Size size, string badgeLabel)
		{
			var rect = new Rectangle (size);
			rect.Inflate (-2, -2);
			graphics.FillEllipse (Brushes.Red (Generator), rect);
			graphics.DrawEllipse (new Pen(Colors.White, 2, Generator), rect);
			var font = new Font(SystemFont.Bold, 10);
			var labelSize = graphics.MeasureString (font, badgeLabel);
			var labelPosition = ((PointF)(rect.Size - labelSize) / 2) + rect.Location;
			graphics.DrawText (font, Colors.White, labelPosition, badgeLabel);
			graphics.Flush ();
		}

		public void Invoke (System.Action action)
		{
{'fraction_non_alphanumeric': 0.11460792027275112, 'fraction_numerical': 0.005245213742460005, 'mean_word_length': 3.373853211009174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5101805', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1192, 'n_words': 317}