using System;

using Mono.Unix;

using Gtk;
using Tomboy;

[PluginInfo(
	"Insert Date/Time", Defines.VERSION,
	PluginInfoAttribute.OFFICIAL_AUTHOR,
	"Inserts current date and time at the cursor position.",
	WebSite = "http://www.gnome.org/projects/tomboy/"
	)]
public class InsertDateTimePlugin : NotePlugin
{
	Gtk.MenuItem itemDT;
	Gtk.MenuItem itemD;
	Gtk.MenuItem itemT;
	
	protected override void Initialize ()
	{
		itemDT = new Gtk.MenuItem (Catalog.GetString ("Date & Time"));
		itemDT.Activated += DateAndTime;
		itemDT.Show ();
		AddPluginMenuItem (itemDT);

		itemD = new Gtk.MenuItem (Catalog.GetString ("Date"));
		itemD.Activated += Date;
		itemD.Show ();
		AddPluginMenuItem (itemD);

		itemT = new Gtk.MenuItem (Catalog.GetString ("Time"));
		itemT.Activated += Time;
		itemT.Show ();
		AddPluginMenuItem (itemT);
	}
	
	protected override void Shutdown ()
	{
		itemDT.Activated -= DateAndTime;
		itemD.Activated -= Date;
		itemT.Activated -= Time;
	}
	
	protected override void OnNoteOpened ()
	{
	}
	
	void DateAndTime (object sender, EventArgs args)
	{
		string format = Catalog.GetString ("dddd, MMMM dd yyyy, hh:mm tt");
		string text = DateTime.Now.ToString (format);
		
		NoteBuffer buffer = Note.Buffer;
		Gtk.TextIter cursor = buffer.GetIterAtMark (buffer.InsertMark);
		buffer.InsertWithTagsByName (ref cursor, text, "monospace", "italic");
	}
	
	void Date (object sender, EventArgs args)
	{
		string format = Catalog.GetString ("dddd, MMMM dd yyyy");
		string text = DateTime.Now.ToString (format);
		
		NoteBuffer buffer = Note.Buffer;
		Gtk.TextIter cursor = buffer.GetIterAtMark (buffer.InsertMark);
		buffer.InsertWithTagsByName (ref cursor, text, "monospace", "italic");
	}

	void Time (object sender, EventArgs args)
	{
		string format = Catalog.GetString ("hh:mm tt");
		string text = DateTime.Now.ToString (format);
		
		NoteBuffer buffer = Note.Buffer;
		Gtk.TextIter cursor = buffer.GetIterAtMark (buffer.InsertMark);
		buffer.InsertWithTagsByName (ref cursor, text, "monospace", "italic");
	}
}
