Tomboy.Note.AddTag C# (CSharp) Method

AddTag() public method

public AddTag ( Tag tag ) : void
tag Tag
return void
		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);
			}
		}

Usage Example

Esempio n. 1
0
		/// <summary>
		/// Place the specified note into the specified notebook.  If the
		/// note already belongs to a notebook, it will be removed from that
		/// notebook first.
		/// </summary>
		/// <param name="note">
		/// A <see cref="Note"/>
		/// </param>
		/// <param name="notebook">
		/// A <see cref="Notebook"/>.  If Notebook is null, the note will
		/// be removed from its current notebook.
		/// </param>
		/// <returns>True if the note was successfully moved.</returns>
		public static bool MoveNoteToNotebook (Note note, Notebook notebook)
		{
			if (note == null)
				return false;
			
			// NOTE: In the future we may want to allow notes
			// to exist in multiple notebooks.  For now, to
			// alleviate the confusion, only allow a note to
			// exist in one notebook at a time.
			
			Notebook currentNotebook = GetNotebookFromNote (note);
			if (currentNotebook == notebook)
				return true; // It's already there.
			
			if (currentNotebook != null) {
				note.RemoveTag (currentNotebook.Tag);
				if (NoteRemovedFromNotebook != null)
					NoteRemovedFromNotebook (note, currentNotebook);
			}
			
			// Only attempt to add the notebook tag when this
			// menu item is not the "No notebook" menu item.
			if (notebook != null && (notebook is SpecialNotebook) == false) {
				note.AddTag (notebook.Tag);
				if (NoteAddedToNotebook != null)
					NoteAddedToNotebook (note, notebook);
			}
			
			return true;
		}