All pastes #904553 Raw Edit

tomboy-tasky-addin

public text v1 · immutable
·published 2008-02-15 01:05 UTC
rendered paste body
Index: configure.in
===================================================================
--- configure.in	(revision 1852)
+++ configure.in	(working copy)
@@ -238,16 +238,17 @@
 Tomboy/Addins/Bugzilla/Makefile
 Tomboy/Addins/ExportToHtml/Makefile
 Tomboy/Addins/Evolution/Makefile
+Tomboy/Addins/FileSystemSyncService/Makefile
 Tomboy/Addins/FixedWidth/Makefile
 Tomboy/Addins/GalagoPresence/Makefile
-Tomboy/Addins/Sketching/Makefile
 Tomboy/Addins/InsertTimestamp/Makefile
 Tomboy/Addins/NoteOfTheDay/Makefile
 Tomboy/Addins/PrintNotes/Makefile
+Tomboy/Addins/Sketching/Makefile
+Tomboy/Addins/SshSyncService/Makefile
 Tomboy/Addins/StickyNoteImport/Makefile
-Tomboy/Addins/FileSystemSyncService/Makefile
+Tomboy/Addins/Tasky/Makefile
 Tomboy/Addins/WebDavSyncService/Makefile
-Tomboy/Addins/SshSyncService/Makefile
 test/Makefile
 po/Makefile.in
 ])
Index: Tomboy.mdp
===================================================================
--- Tomboy.mdp	(revision 1852)
+++ Tomboy.mdp	(working copy)
@@ -222,6 +222,7 @@
     <File name="Tomboy/Addins/InsertTimestamp/InsertTimestampNoteAddin.cs" subtype="Code" buildaction="Compile" />
     <File name="Tomboy/Addins/InsertTimestamp/InsertTimestampPreferences.cs" subtype="Code" buildaction="Compile" />
     <File name="Tomboy/Addins/InsertTimestamp/InsertTimestampPreferencesFactory.cs" subtype="Code" buildaction="Compile" />
+    <File name="Tomboy/Addins/Tasky/TaskyNoteAddin.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="gdk-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Index: Tomboy/Addins/Tasky/TaskyNoteAddin.cs
===================================================================
--- Tomboy/Addins/Tasky/TaskyNoteAddin.cs	(revision 0)
+++ Tomboy/Addins/Tasky/TaskyNoteAddin.cs	(revision 0)
@@ -0,0 +1,147 @@
+
+using System;
+using System.Collections;
+
+using Mono.Unix;
+
+using Tomboy;
+
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+namespace Tomboy.TaskyAddin
+{
+	public class TaskyNoteAddin : NoteAddin
+	{
+		static ObjectPath TaskyPath =
+			new ObjectPath ("/org/gnome/Tasky/RemoteControl");
+		static string TaskyNamespace = "org.gnome.Tasky";
+		
+		private org.freedesktop.DBus.IBus sessionBus;
+		
+		Gtk.ImageMenuItem menu_item;
+		Gtk.Menu menu;
+		bool submenu_built;
+
+		public override void Initialize ()
+		{
+			submenu_built = false;
+
+			menu = new Gtk.Menu ();
+			menu.Hidden += OnMenuHidden;
+			menu.ShowAll ();
+			menu_item = new Gtk.ImageMenuItem (
+			        Catalog.GetString ("Create task in ..."));
+			menu_item.Image = new Gtk.Image (Gtk.Stock.Add, Gtk.IconSize.Menu);
+			menu_item.Submenu = menu;
+			menu_item.Activated += OnMenuItemActivated;
+			menu_item.Show ();
+			AddPluginMenuItem (menu_item);
+		}
+
+		public override void Shutdown ()
+		{
+			// The following two lines are required to prevent the plugin
+			// from leaking references when the plugin is disabled.
+			menu.Hidden -= OnMenuHidden;
+			menu_item.Activated -= OnMenuItemActivated;
+		}
+
+		public override void OnNoteOpened ()
+		{
+		}
+
+		void OnMenuItemActivated (object sender, EventArgs args)
+		{
+			if (submenu_built == true)
+				return; // submenu already built.  do nothing.
+
+			UpdateMenu ();
+		}
+
+		void OnMenuHidden (object sender, EventArgs args)
+		{
+			// FIXME: Figure out how to have this function be called only when
+			// the whole Tools menu is collapsed so that if a user keeps
+			// toggling over the "What links here?" menu item, it doesn't
+			// keep forcing the submenu to rebuild.
+
+			// Force the submenu to rebuild next time it's supposed to show
+			submenu_built = false;
+		}
+
+		void UpdateMenu ()
+		{
+			//
+			// Clear out the old list
+			//
+			foreach (Gtk.MenuItem old_item in menu.Children) {
+				menu.Remove (old_item);
+			}
+			
+			Tasky.RemoteControl tasky = GetTaskyRemoteControl ();
+			
+			string [] taskCategories = null;
+			
+			try {
+				taskCategories = tasky.GetCategoryNames ();
+			} catch (Exception e) {
+				Logger.Debug ("Exception calling Tasky.GetCategoryNames (): {0}",
+							  e.Message);
+			}
+			
+			//
+			// Build a new list
+			//
+			foreach (string category in taskCategories) {
+				Gtk.MenuItem item = new Gtk.MenuItem (category);
+				item.Activated += OnCategoryActivated;
+				item.ShowAll ();
+				menu.Append (item);
+			}
+
+			// If nothing was found, add in a "dummy" item
+			if (menu.Children.Length == 0) {
+				Gtk.MenuItem blankItem =
+					new Gtk.MenuItem (Catalog.GetString ("--- Tasky is not running ---"));
+				blankItem.Sensitive = false;
+				blankItem.ShowAll ();
+				menu.Append (blankItem);
+			}
+
+			submenu_built = true;
+		}
+		
+		void OnCategoryActivated (object sender, EventArgs args)
+		{
+			string categoryName = sender as string;
+			if (categoryName == null)
+				return;
+			
+			Tasky.RemoteControl tasky = GetTaskyRemoteControl ();
+			if (tasky == null)
+				return;
+			
+			string taskName = GetTaskName ();
+			
+			try {
+				tasky.CreateTask (categoryName, taskName, true);
+			} catch (Exception e) {
+				Logger.Debug ("Exception calling Tasky.CreateTask ()", e.Message);
+			}
+		}
+		
+		Tasky.RemoteControl GetTaskyRemoteControl ()
+		{
+			return Bus.Session.GetObject<Tasky.RemoteControl> (
+						TaskyNamespace,
+						TaskyPath);
+		}
+		
+		string GetTaskName ()
+		{
+			// TODO: Get the current line of text that the cursor is on and pass that in as the task name
+			return "Create a task remotely from Tomboy";
+		}
+	}
+}
Index: Tomboy/Addins/Tasky/Tasky.addin.xml
===================================================================
--- Tomboy/Addins/Tasky/Tasky.addin.xml	(revision 0)
+++ Tomboy/Addins/Tasky/Tasky.addin.xml	(revision 0)
@@ -0,0 +1,21 @@
+<Addin id="TaskyAddin"
+	namespace="Tomboy"
+	name="Tasky"
+	author="Tomboy Project"
+	description="Create a task from the current line of text in Tasky."
+	category="Tools"
+	defaultEnabled="true"
+	version="0.1">
+
+	<Runtime>
+		<Import assembly="Tasky.dll" />
+	</Runtime>
+
+	<Dependencies>
+		<Addin id="Tomboy" version="0.7" />
+	</Dependencies>
+
+	<Extension path="/Tomboy/NoteAddins">
+		<NoteAddin type="Tomboy.TaskyAddin.TaskyNoteAddin" />
+	</Extension>
+</Addin>
Index: Tomboy/Addins/Tasky/Makefile.am
===================================================================
--- Tomboy/Addins/Tasky/Makefile.am	(revision 0)
+++ Tomboy/Addins/Tasky/Makefile.am	(revision 0)
@@ -0,0 +1,38 @@
+include $(top_srcdir)/Makefile.include
+
+CSFLAGS = 		\
+	-debug 		\
+	-define:DEBUG 	\
+	-target:library
+
+ASSEMBLIES = 					\
+	$(LINK_TOMBOY_EXE)			\
+	$(TOMBOY_LIBS) 				\
+	$(LINK_MONO_ADDINS)			\
+	$(DBUS_LIBS)				\
+	-r:Mono.Posix				\
+	-r:/home/boyd/stage/tasky/lib/tasky/Tasky.exe
+
+ADDIN_NAME = Tasky
+TARGET = $(ADDIN_NAME).dll
+CSFILES = \
+	$(srcdir)/TaskyNoteAddin.cs
+RESOURCES = \
+	-resource:$(srcdir)/$(ADDIN_NAME).addin.xml
+
+$(TARGET): $(CSFILES) $(top_builddir)/Tomboy/Tomboy.exe
+	$(CSC) -out:$@ $(CSFLAGS) $(ASSEMBLIES) $(CSFILES) $(RESOURCES)
+
+
+addinsdir = $(pkglibdir)/addins
+addins_DATA = 			\
+	$(TARGET)
+
+EXTRA_DIST =            	\
+	$(CSFILES) \
+	$(srcdir)/$(ADDIN_NAME).addin.xml
+
+CLEANFILES =				\
+	$(TARGET).mdb \
+	$(TARGET)
+
Index: Tomboy/Addins/Makefile.am
===================================================================
--- Tomboy/Addins/Makefile.am	(revision 1852)
+++ Tomboy/Addins/Makefile.am	(working copy)
@@ -3,14 +3,15 @@
 	Bugzilla			\
 	ExportToHtml			\
 	Evolution		\
+	FileSystemSyncService	\
 	FixedWidth			\
 	GalagoPresence		\
-	Sketching			\
 	InsertTimestamp		\
 	NoteOfTheDay		\
 	PrintNotes			\
+	Sketching			\
+	SshSyncService		\
 	StickyNoteImport	\
-	FileSystemSyncService	\
-	WebDavSyncService	\
-	SshSyncService
+	Tasky			\
+	WebDavSyncService