/// <summary> /// Construct a new Notebook with the specified notebook system tag. /// </summary> /// <param name="notebookTag"> /// A <see cref="Tag"/>. This must be a system notebook tag. /// </param> public Notebook (Tag notebookTag) { // Parse the notebook name from the tag name string systemNotebookPrefix = Tag.SYSTEM_TAG_PREFIX + NotebookTagPrefix; string notebookName = notebookTag.Name.Substring (systemNotebookPrefix.Length); Name = notebookName; tag = notebookTag; }
public TagButton (Tag tag) { this.tag = tag; this.Label = tag.Name; this.Relief = ReliefStyle.None; this.EnterNotifyEvent += EnterNotifyEventHandler; this.LeaveNotifyEvent += LeaveNotifyEventHandler; image = new Image (); image.Visible = false; image.NoShowAll = true; this.Image = image; }
/// <summary> /// Evaluates the specified tag and returns <value>true</value> /// if it's a tag which represents a notebook. /// </summary> /// <param name="tag"> /// A <see cref="Tag"/> /// </param> /// <returns> /// A <see cref="System.Boolean"/> /// </returns> public static bool IsNotebookTag (Tag tag) { string fullTagName = tag.Name; if (fullTagName.StartsWith (Tag.SYSTEM_TAG_PREFIX + Notebook.NotebookTagPrefix) == true) return true; return false; }
/// <summary> /// Returns the Notebook associated with the specified tag /// or null if the Tag does not represent a notebook. /// </summary> /// <param name="tag"> /// A <see cref="Tag"/> /// </param> /// <returns> /// A <see cref="Notebook"/> /// </returns> public static Notebook GetNotebookFromTag (Tag tag) { if (IsNotebookTag (tag) == false) return null; // Parse off the system and notebook prefix to get // the name of the notebook and then look it up. string systemNotebookPrefix = Tag.SYSTEM_TAG_PREFIX + Notebook.NotebookTagPrefix; string notebookName = tag.Name.Substring (systemNotebookPrefix.Length); return GetNotebook (notebookName); }
// <summary> // Same as GetTag () but will create a new tag if one doesn't already exist. // </summary> public static Tag GetOrCreateTag (string tag_name) { if (tag_name == null) throw new ArgumentNullException ("TagManager.GetOrCreateTag () called with a null tag name."); string normalized_tag_name = tag_name.Trim ().ToLower (); if (normalized_tag_name == String.Empty) throw new ArgumentException ("TagManager.GetOrCreateTag () called with an empty tag name."); if (normalized_tag_name.StartsWith(Tag.SYSTEM_TAG_PREFIX) || normalized_tag_name.Split(':').Length > 2){ lock (locker) { if(internal_tags.ContainsKey(normalized_tag_name)) return internal_tags[normalized_tag_name]; else{ Tag t = new Tag(tag_name); internal_tags [ t.NormalizedName] = t; return t; } } } Gtk.TreeIter iter = Gtk.TreeIter.Zero; bool tag_added = false; Tag tag = GetTag (normalized_tag_name); if (tag == null) { lock (locker) { tag = GetTag (normalized_tag_name); if (tag == null) { tag = new Tag (tag_name.Trim ()); iter = tags.Append (); tags.SetValue (iter, 0, tag); tag_map [tag.NormalizedName] = iter; tag_added = true; } } } if (tag_added && TagAdded != null) TagAdded (tag, iter); return tag; }
// <summary> // This will remove the tag from every note that is currently tagged // and from the main list of tags. // </summary> public static void RemoveTag (Tag tag) { if (tag == null) throw new ArgumentNullException ("TagManager.RemoveTag () called with a null tag"); if(tag.IsProperty || tag.IsSystem){ lock (locker) { internal_tags.Remove(tag.NormalizedName); } } bool tag_removed = false; if (tag_map.ContainsKey (tag.NormalizedName)) { lock (locker) { if (tag_map.ContainsKey (tag.NormalizedName)) { Gtk.TreeIter iter = tag_map [tag.NormalizedName]; if (!tags.Remove (ref iter)) { Logger.Debug ("TagManager: Removed tag: {0}", tag.NormalizedName); } else { // FIXME: For some really weird reason, this block actually gets called sometimes! Logger.Warn ("TagManager: Call to remove tag from ListStore failed: {0}", tag.NormalizedName); } tag_map.Remove (tag.NormalizedName); Logger.Debug ("Removed TreeIter from tag_map: {0}", tag.NormalizedName); tag_removed = true; foreach (Note note in tag.Notes) { note.RemoveTag (tag); } } } } if (tag_removed && TagRemoved != null) { TagRemoved (tag.NormalizedName); } }
void OnTagRemoving (Note note, Tag tag) { Logger.Debug ("Removing tag from {0}: {1}", note.Title, tag.Name); }
void OnTagAdded (Note note, Tag tag) { Logger.Debug ("Tag added to {0}: {1}", note.Title, tag.Name); }
public bool ContainsTag (Tag tag) { if (tag != null && data.Data.Tags.ContainsKey (tag.NormalizedName)) return true; return false; }
public void RemoveTag (Tag tag) { if (tag == null) throw new ArgumentException ("Note.RemoveTag () called with a null tag."); if (!data.Data.Tags.ContainsKey (tag.NormalizedName)) return; if (TagRemoving != null) TagRemoving (this, tag); data.Data.Tags.Remove (tag.NormalizedName); tag.RemoveNote (this); if (TagRemoved != null) TagRemoved (this, tag.NormalizedName); DebugSave ("Tag removed, queueing save"); QueueSave (ChangeType.OtherDataChanged); }
public void AddTag (Tag tag) { if (tag == null) throw new ArgumentNullException ("Note.AddTag () called with a null tag."); tag.AddNote (this); if (!data.Data.Tags.ContainsKey (tag.NormalizedName)) { data.Data.Tags [tag.NormalizedName] = tag; if (TagAdded != null) TagAdded (this, tag); DebugSave ("Tag added, queueing save"); QueueSave (ChangeType.OtherDataChanged); } }
/// <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); }
/// <summary> /// Construct a new Notebook with a given name /// </summary> /// <param name="name"> /// A <see cref="System.String"/>. This is the name that will be used /// to identify the notebook. /// </param> public Notebook (string name) { Name = name; tag = TagManager.GetOrCreateSystemTag (NotebookTagPrefix + name); }