Example #1
0
 def deleteNote(self):
     """
     Remove the note file from the disk and create a git commit.
     """
     # FIXME: Maybe notes should just be marked as deleted, but still
     #  exist so that any old links to them would still work?
     misc.gitRemove(self.notebook.getDirectory(),
                    self.filename,
                    "remove " + self.name)
     self.notebook.setUnpushed()
Example #2
0
    def moveNote(self, new_notebook):
        """
        Notebooks are just directories, so update the filename accordingly.

        new_notebook is a NotebookStandardItem.
        """

        # Load all versions of the note in the old notebook
        # and all of the (unique) attachments.
        attachments = {}
        note_contents = []
        for version in self.versions:
            note_content = self.loadNoteContent(version)
            note_contents.append(note_content)
            for fullname in note_content.getAttachments():
                attachments[fullname] = True

        # Move attachments.
        old_dir = self.notebook.getDirectory()
        new_dir = new_notebook.getDirectory()
        for fullname in attachments.keys():
            filename = os.path.basename(fullname)
            os.makedirs(new_dir + os.path.dirname(fullname))
            shutil.copy(old_dir + fullname, new_dir + fullname)
            misc.gitRemove(old_dir,
                           fullname,
                           "remove attachment " + filename)
            misc.gitAddCommit(new_dir,
                              fullname,
                              "attachment " + filename)

        # Delete old note.
        self.deleteNote()
        
        # Move to new notebook.
        # FIXME: If this gets move to a new notebook, then back to the old
        #  notebook it will appear as completely new note. However if we
        #  don't do this then the version history of the note will get all
        #  messed up.
        self.notebook = new_notebook
        self.filename = "note_" + str(uuid.uuid1()) + ".xml"
        self.fullname = self.notebook.getDirectory() + self.filename
        self.versions = []
            
        # Replay history in the new notebook.
        for content in note_contents:
            self.saveNote(content, use_current_time = False)
            
        self.notebook.setUnpushed()