def saveCopyAsAction(self):
        """Save text in editor to a new note but do not load it."""

        p = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)
        searchPath = os.path.abspath(p)
        filePath = QFileDialog.getSaveFileName(self, "Save Copy As", searchPath)
        if filePath[0] != "":
            self.noteEditor.saveCopyAsRequested(filePath[0])

        self.noteManager.model().updateModel()
    def saveAsFileAction(self):
        """Save text in editor to a new note and load it."""

        p = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)     #get the search directory
        searchPath = os.path.abspath(p)                                         #
        filePath = QFileDialog.getSaveFileName(self, "Save As File", searchPath)#prompt the use for the new file path
        if filePath[0] != "":                                                   #do not perform the save if the user pressed the 'cancel' button
            self.noteEditor.saveAsRequested(filePath[0])

        self.noteManager.model().updateModel()                                          #update the note manager
    def openFileAction(self):
        """Open an existing file by getting its path from a dialog."""

        self.saveFileAction()   #save the current note

        p = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)     #get the search directory
        searchPath = os.path.abspath(p)                                         #
        filePath = QFileDialog.getOpenFileName(self, "Open File", searchPath)   #prompt the user for the file path (note: 'filePath' is a tuple)
        if filePath[0] != "":                                                   #if the user did not hit the 'cancel' button
            self.noteEditor.openFileRequest(filePath[0])                        #open the file in the editor
    def newNotebookAction(self):
        """Create a new notebook."""

        notebookName, ok = QInputDialog.getText(self, "Create New Notebook - Quark Note Taker", "Notebook name: ", QLineEdit.Normal, "New Notebook")

        if ok and notebookName is not None and len(notebookName) > 0:
            p = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)
            rootPath = os.path.abspath(p)
            os.makedirs( os.path.join(rootPath, notebookName) )

        self.noteManager.model().updateModel()
    def __init__(self, parent):
        """Initializes the model by gowing through the notes directory tree."""

        super(QuarkNoteManagerModel, self).__init__(parent)

        self._noteList = []     #initialize empty list of notes
        self._notebookList = [] #initialize empty list of notebooks

        notesDir = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir) #get the Quark notes directory from the config file

        # If the notes directory does not exist, ask the user whether Quark
        # should create the directory specified in the settings.py file.
        # If no, crash gracefully.  If yes, create it and ask whether to put in
        # it copies Quark's readme file and documentation.
        if not os.path.exists(notesDir):
            _message = "Your config file (settings.py) specifies\n\n\t{notesdir}\n\n\
as your notes directory.  However, this directory could not be found.  Would you like to create it?\n\n\
If you chose No, then Quark will not be able to proceed and will terminate.  Otherwise, it will proceed as normal.\n\n\
You can also change which directory to use to store your notes by setting the `notes_dir` field in your \
`settings.py` file.".format(notesdir=quarkSettings.notes_dir)

            buttonPressed = QMessageBox.question(parent, "Notes directory not found", _message)
            if buttonPressed == QMessageBox.Yes:
                notesDirPath = os.path.normcase(os.path.expanduser(quarkSettings.notes_dir))
                os.makedirs(notesDirPath)
                print("Created notes directory in: ", notesDirPath)

                _message = "Would you like a copy of Quark's README.md file as a note in your notes directory?"

                buttonPressed = QMessageBox.question(parent, "Copy Quark README file", _message)
                if buttonPressed == QMessageBox.Yes:
                    readmeNotePath = os.path.join(notesDirPath, "README.md")
                    shutil.copyfile("README.md", readmeNotePath)
                    print("Copied README.md to: ", readmeNotePath)

                _message = "Would you like a copy of Quark's documentation files as a notebook in your notes directory?"

                buttonPressed = QMessageBox.question(parent, "Copy Quark documentation files", _message)
                if buttonPressed == QMessageBox.Yes:
                    docsPath = os.path.join(notesDirPath, "Quark_Documentation")
                    shutil.copytree("Quark_Documentation", docsPath)
                    print("Copied Quark_Documentation to: ", docsPath)
            else:
                print(buttonPressed)
                exit(1)

        self.updateModel()  #load data from notes dir
    def newNoteAction(self):
        """Create a new note.  Automatically saves old note."""

        self.saveFileAction()   #save currently open note

        p = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)
        searchPath = os.path.abspath(p)
        filePath = QFileDialog.getSaveFileName(self, "New Note", searchPath)

        if filePath[0] != "":
            noteFile = open(filePath[0], "w+")  #create blank file
            noteFile.write("")                  #
            noteFile.close()                    #

            self.noteEditor.openFileRequest(filePath[0])    #open newly created file

        self.noteManager.model().updateModel()
    def updateModel(self):
        """Updates the model to match the filesystem."""

        notesDir = quarkExtra.makeAbsoluteFromHome(quarkSettings.notes_dir)  #get the Quark notes directory from the config file

        self.beginResetModel()

        self._noteList = []     #clear list of notes
        self._notebookList = [] #clear list of notebooks

         #load all the notes and notebooks from the notes directory
        if os.path.exists(notesDir):
            for item in sorted(os.listdir(notesDir)):                   #for every item in the notes directory

                itemPath = os.path.join(notesDir, item)             #get absolute path to the item

                if os.path.isfile(itemPath):                        #if the item is a file/note
                    self._noteList.append( QuarkNoteModel(itemPath) )           #append a new note to the notes list

                elif os.path.isdir(itemPath):                       #if the item is directory/notebook
                    self._notebookList.append( QuarkNotebookModel(itemPath) )   #append a new note to the notebooks list

        self.endResetModel()