Notebook::Ptr NotebookManager::prompt_create_new_notebook(Gtk::Window *parent, const Note::List & notesToAdd) { // Prompt the user for the name of a new notebook CreateNotebookDialog dialog(parent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT)); int response = dialog.run (); std::string notebookName = dialog.get_notebook_name(); if (response != Gtk::RESPONSE_OK) return Notebook::Ptr(); Notebook::Ptr notebook = obj().get_or_create_notebook (notebookName); if (!notebook) { DBG_OUT ("Could not create notebook: %s", notebookName.c_str()); } else { DBG_OUT ("Created the notebook: %s (%s)", notebook->get_name().c_str(), notebook->get_normalized_name().c_str()); if (!notesToAdd.empty()) { // Move all the specified notesToAdd into the new notebook for(Note::List::const_iterator iter = notesToAdd.begin(); iter != notesToAdd.end(); ++iter) { obj().move_note_to_notebook (*iter, notebook); } } } return notebook; }
/// <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> bool NotebookManager::move_note_to_notebook (const Note::Ptr & note, const Notebook::Ptr & notebook) { if (!note) { 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::Ptr currentNotebook = get_notebook_from_note (note); if (currentNotebook == notebook) return true; // It's already there. if(currentNotebook) { note->remove_tag (currentNotebook->get_tag()); m_note_removed_from_notebook(*note, currentNotebook); } // Only attempt to add the notebook tag when this // menu item is not the "No notebook" menu item. if(notebook) { note->add_tag(notebook->get_tag()); m_note_added_to_notebook(*note, notebook); } return true; }
void NotebookManager::delete_notebook(const Notebook::Ptr & notebook) { if (!notebook) throw sharp::Exception ("NotebookManager::delete_notebook () called with a null argument."); std::string normalized_name = notebook->get_normalized_name(); std::map<std::string, Gtk::TreeIter>::iterator map_iter = m_notebookMap.find (normalized_name); if (map_iter == m_notebookMap.end()) return; // lock (locker) { map_iter = m_notebookMap.find (normalized_name); if (map_iter == m_notebookMap.end()) { return; } Gtk::TreeIter iter = map_iter->second;; m_notebooks->erase (iter); m_notebookMap.erase (map_iter); // Remove the notebook tag from every note that's in the notebook std::list<Note *> notes; notebook->get_tag()->get_notes(notes); for(std::list<Note *>::const_iterator note_iter = notes.begin(); note_iter != notes.end(); ++note_iter) { Note * note = *note_iter; note->remove_tag (notebook->get_tag()); m_note_removed_from_notebook (*note, notebook); } // } }
void NotebookNoteAddin::update_notebook_button_label(const Notebook::Ptr & notebook) { std::string labelText = (notebook ? notebook->get_name() : _("Notebook")); m_label_widget->set_text(labelText); m_toolButton->show_all(); }
/// <summary> /// Prompt the user and delete the notebok (if they say so). /// </summary> /// <param name="parent"> /// A <see cref="Gtk.Window"/> /// </param> /// <param name="notebook"> /// A <see cref="Notebook"/> /// </param> void NotebookManager::prompt_delete_notebook(Gtk::Window * parent, const Notebook::Ptr & notebook) { // Confirmation Dialog utils::HIGMessageDialog dialog(parent, GTK_DIALOG_MODAL, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, _("Really delete this notebook?"), _("The notes that belong to this notebook will not be " "deleted, but they will no longer be associated with " "this notebook. This action cannot be undone.")); dialog.set_default_response(Gtk::RESPONSE_NO); int response = dialog.run (); if (response != Gtk::RESPONSE_YES) { return; } // Grab the template note before removing all the notebook tags Note::Ptr templateNote = notebook->get_template_note (); obj().delete_notebook (notebook); // Delete the template note if (templateNote) { obj().note_manager().delete_note(templateNote); } }
NotebookNewNoteMenuItem::NotebookNewNoteMenuItem(const Notebook::Ptr & notebook) // TRANSLATORS: %1%: boost format placeholder for the notebook name : Gtk::ImageMenuItem(str(boost::format(_("New \"%1%\" Note")) % notebook->get_name())) , m_notebook(notebook) { set_image(*manage(new Gtk::Image(IconManager::obj().get_icon(IconManager::NOTE_NEW, 16)))); signal_activate().connect(sigc::mem_fun(*this, &NotebookNewNoteMenuItem::on_activated)); }
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; }
void NotebooksTreeView::on_drag_data_received( const Glib::RefPtr<Gdk::DragContext> & context, int x, int y, const Gtk::SelectionData & selectionData, guint , guint time_) { utils::UriList uriList(selectionData); if (uriList.size() == 0) { context->drag_finish (false, false, time_); return; } Gtk::TreePath treepath; Gtk::TreeViewDropPosition pos; if (get_dest_row_at_pos (x, y, treepath, pos) == false) { context->drag_finish (false, false, time_); return; } Gtk::TreeIter iter = get_model()->get_iter(treepath); if (!iter) { context->drag_finish (false, false, time_); return; } Notebook::Ptr destNotebook; iter->get_value(0, destNotebook); if(std::dynamic_pointer_cast<AllNotesNotebook>(destNotebook)) { context->drag_finish (false, false, time_); return; } for(utils::UriList::const_iterator uri_iter = uriList.begin(); uri_iter != uriList.end(); ++uri_iter) { const sharp::Uri & uri(*uri_iter); NoteBase::Ptr note = m_note_manager.find_by_uri(uri.to_string()); if (!note) continue; DBG_OUT ("Dropped into notebook: %s", note->get_title().c_str()); destNotebook->add_note(std::static_pointer_cast<Note>(note)); } context->drag_finish (true, false, time_); }