Exemplo n.º 1
0
    Notebook::Ptr NotebookManager::get_or_create_notebook(const std::string & notebookName)
    {
      if (notebookName.empty())
        throw sharp::Exception ("NotebookManager.GetNotebook () called with a null name.");
      
      Notebook::Ptr notebook = get_notebook (notebookName);
      if (notebook) {
        return notebook;
      }
      
      Gtk::TreeIter iter;
//      lock (locker) {
        notebook = get_notebook (notebookName);
        if (notebook)
          return notebook;
        
        try {
          m_adding_notebook = true;
          notebook = Notebook::Ptr(new Notebook (notebookName));
        } 
        catch(...)
        {
          // set flag to fast and rethrow
          m_adding_notebook = false;
          throw;
        }
        m_adding_notebook = false;
        iter = m_notebooks->append ();
        iter->set_value(0, notebook);
        m_notebookMap [notebook->get_normalized_name()] = iter;
        
        // Create the template note so the system tag
        // that represents the notebook actually gets
        // saved to a note (and persisted after Tomboy
        // is shut down).
        Note::Ptr templateNote = notebook->get_template_note ();
        
        // Make sure the template note has the notebook tag.
        // Since it's possible for the template note to already
        // exist, we need to make sure it gets tagged.
        templateNote->add_tag (notebook->get_tag());
        m_note_added_to_notebook (*templateNote, notebook);
//      }

      return notebook;
    }
Exemplo n.º 2
0
     /// <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>
 Notebook::Ptr NotebookManager::get_notebook_from_tag(const Tag::Ptr &tag)
 {
   if (!is_notebook_tag (tag)) {
     return Notebook::Ptr();
   }
   
   // Parse off the system and notebook prefix to get
   // the name of the notebook and then look it up.
   std::string systemNotebookPrefix = std::string(Tag::SYSTEM_TAG_PREFIX)
     + Notebook::NOTEBOOK_TAG_PREFIX;
   std::string notebookName = sharp::string_substring(tag->name(), 
                                                      systemNotebookPrefix.size());
   
   return get_notebook (notebookName);
 }