tomboy r1917 - in trunk: . Tomboy/Notebooks
- From: sharm svn gnome org
- To: svn-commits-list gnome org
- Subject: tomboy r1917 - in trunk: . Tomboy/Notebooks
- Date: Sun, 2 Mar 2008 01:30:17 +0000 (GMT)
Author: sharm
Date: Sun Mar 2 01:30:16 2008
New Revision: 1917
URL: http://svn.gnome.org/viewvc/tomboy?rev=1917&view=rev
Log:
* Tomboy/Notebooks/NotebookManager.cs,
Tomboy/Notebooks/NotebookApplicationAddin.cs: Listen for events
fired when a tag is added or removed from a note. Sync or a dbus
client may be adding or removing a notebook tag. Fixes bug
#518870.
Modified:
trunk/ChangeLog
trunk/Tomboy/Notebooks/NotebookApplicationAddin.cs
trunk/Tomboy/Notebooks/NotebookManager.cs
Modified: trunk/Tomboy/Notebooks/NotebookApplicationAddin.cs
==============================================================================
--- trunk/Tomboy/Notebooks/NotebookApplicationAddin.cs (original)
+++ trunk/Tomboy/Notebooks/NotebookApplicationAddin.cs Sun Mar 2 01:30:16 2008
@@ -126,6 +126,15 @@
(imageItem.Image as Gtk.Image).Pixbuf = ActionManager.newNote;
}
}
+
+ foreach (Note note in Tomboy.DefaultNoteManager.Notes) {
+ note.TagAdded += OnTagAdded;
+ note.TagRemoved += OnTagRemoved;
+ }
+
+ Tomboy.DefaultNoteManager.NoteAdded += OnNoteAdded;
+ Tomboy.DefaultNoteManager.NoteDeleted += OnNoteDeleted;
+
initialized = true;
}
@@ -222,5 +231,60 @@
{
NotebookManager.PromptCreateNewNotebook (null);
}
+
+ /// <summary>
+ /// Handle the addition of note tags through programmatic means,
+ /// such as note sync or the dbus remote control.
+ /// </summary>
+ private void OnTagAdded (Note note, Tag tag)
+ {
+ if (NotebookManager.AddingNotebook)
+ return;
+
+ string megaPrefix =
+ Tag.SYSTEM_TAG_PREFIX + Notebook.NotebookTagPrefix;
+ if (tag.IsSystem == false
+ || tag.Name.StartsWith (megaPrefix) == false) {
+ return;
+ }
+
+ string notebookName =
+ tag.Name.Substring (megaPrefix.Length);
+
+ Notebook notebook =
+ NotebookManager.GetOrCreateNotebook (notebookName);
+
+ NotebookManager.FireNoteAddedToNoteBook (note, notebook);
+ }
+
+ private void OnTagRemoved (Note note, string normalizedTagName)
+ {
+ string megaPrefix =
+ Tag.SYSTEM_TAG_PREFIX + Notebook.NotebookTagPrefix;
+ if (normalizedTagName.StartsWith (megaPrefix) == false)
+ return;
+
+ string normalizedNotebookName =
+ normalizedTagName.Substring (megaPrefix.Length);
+
+ Notebook notebook =
+ NotebookManager.GetNotebook (normalizedNotebookName);
+ if (notebook == null)
+ return;
+
+ NotebookManager.FireNoteRemovedFromNoteBook (note, notebook);
+ }
+
+ private void OnNoteAdded (object sender, Note note)
+ {
+ note.TagAdded += OnTagAdded;
+ note.TagRemoved += OnTagRemoved;
+ }
+
+ private void OnNoteDeleted (object sender, Note note)
+ {
+ note.TagAdded -= OnTagAdded;
+ note.TagRemoved -= OnTagRemoved;
+ }
}
}
Modified: trunk/Tomboy/Notebooks/NotebookManager.cs
==============================================================================
--- trunk/Tomboy/Notebooks/NotebookManager.cs (original)
+++ trunk/Tomboy/Notebooks/NotebookManager.cs Sun Mar 2 01:30:16 2008
@@ -15,7 +15,8 @@
static Gtk.TreeModelSort sortedNotebooks;
static Gtk.TreeModelFilter filteredNotebooks;
static Dictionary<string, Gtk.TreeIter> notebookMap;
- static object locker = new object ();
+ static object locker = new object ();
+ public static bool AddingNotebook = false;
#endregion // Fields
public delegate void NotebookEventHandler (Note note, Notebook notebook);
@@ -123,7 +124,12 @@
if (notebook != null)
return notebook;
- notebook = new Notebook (notebookName);
+ try {
+ AddingNotebook = true;
+ notebook = new Notebook (notebookName);
+ } finally {
+ AddingNotebook = false;
+ }
iter = notebooks.Append ();
notebooks.SetValue (iter, 0, notebook);
notebookMap [notebook.NormalizedName] = iter;
@@ -384,6 +390,19 @@
return true;
}
+
+ public static void FireNoteAddedToNoteBook (Note note, Notebook notebook)
+ {
+ if (NoteAddedToNotebook != null)
+ NoteAddedToNotebook (note, notebook);
+ }
+
+ public static void FireNoteRemovedFromNoteBook (Note note, Notebook notebook)
+ {
+ if (NoteRemovedFromNotebook != null)
+ NoteRemovedFromNotebook (note, notebook);
+ }
+
#endregion // Public Methods
#region Private Methods
@@ -429,17 +448,17 @@
}
}
- /// <summary>
- /// Filter out SpecialNotebooks from the model
- /// </summary>
- static bool FilterNotebooks (Gtk.TreeModel model, Gtk.TreeIter iter)
- {
- Notebook notebook = model.GetValue (iter, 0) as Notebook;
- if (notebook == null || notebook is SpecialNotebook)
- return false;
-
- return true;
- }
+ /// <summary>
+ /// Filter out SpecialNotebooks from the model
+ /// </summary>
+ static bool FilterNotebooks (Gtk.TreeModel model, Gtk.TreeIter iter)
+ {
+ Notebook notebook = model.GetValue (iter, 0) as Notebook;
+ if (notebook == null || notebook is SpecialNotebook)
+ return false;
+
+ return true;
+ }
#endregion // Private Methods
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]