Esempio n. 1
0
 def saveDocumentAs(self, doc):
     """ Saves the document, always asking for a name.
     
     Returns True if saving succeeded.
     
     """
     filename = doc.url().toLocalFile()
     if filename:
         filetypes = app.filetypes(os.path.splitext(filename)[1])
     else:
         filename = app.basedir() # default directory to save to
         import documentinfo
         import ly.lex
         filetypes = app.filetypes(ly.lex.extensions[documentinfo.mode(doc)])
     caption = app.caption(_("dialog title", "Save File"))
     filename = QFileDialog.getSaveFileName(self, caption, filename, filetypes)
     if not filename:
         return False # cancelled
     if not util.iswritable(filename):
         QMessageBox.warning(self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
         return False
     url = QUrl.fromLocalFile(filename)
     doc.setUrl(url)
     recentfiles.add(url)
     return self.saveDocument(doc)
Esempio n. 2
0
 def saveDocumentAs(self, doc):
     """ Saves the document, always asking for a name.
     
     Returns True if saving succeeded.
     
     """
     filename = doc.url().toLocalFile()
     if filename:
         filetypes = app.filetypes(os.path.splitext(filename)[1])
     else:
         filename = app.basedir()  # default directory to save to
         import documentinfo
         import ly.lex
         filetypes = app.filetypes(
             ly.lex.extensions[documentinfo.mode(doc)])
     caption = app.caption(_("dialog title", "Save File"))
     filename = QFileDialog.getSaveFileName(self, caption, filename,
                                            filetypes)
     if not filename:
         return False  # cancelled
     if not util.iswritable(filename):
         QMessageBox.warning(
             self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
         return False
     url = QUrl.fromLocalFile(filename)
     doc.setUrl(url)
     recentfiles.add(url)
     return self.saveDocument(doc)
Esempio n. 3
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(
             self, app.caption(_("Error")), _("Can't write to destination:\n\n{url}").format(url=dest)
         )
         return False
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(
             self, app.caption(_("Error")), _("Can't write to destination:\n\n{url}").format(url=filename)
         )
     elif b:
         backup.removeBackup(filename)
     return success
Esempio n. 4
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(
             self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=dest))
         return False
     if QSettings().value("strip_trailing_whitespace", False, bool):
         import reformat
         reformat.remove_trailing_whitespace(QTextCursor(doc))
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(
             self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
     elif b:
         backup.removeBackup(filename)
     return success
Esempio n. 5
0
 def saveDocument(self, doc):
     """ Saves the document, asking for a name if necessary.
     
     Returns True if saving succeeded.
     
     """
     if doc.url().isEmpty():
         return self.saveDocumentAs(doc)
     filename = dest = doc.url().toLocalFile()
     if not filename:
         dest = doc.url().toString()
     if not util.iswritable(filename):
         QMessageBox.warning(self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=dest))
         return False
     if QSettings().value("strip_trailing_whitespace", False, bool):
         import reformat
         reformat.remove_trailing_whitespace(QTextCursor(doc))
     b = backup.backup(filename)
     success = doc.save()
     if not success:
         QMessageBox.warning(self, app.caption(_("Error")),
             _("Can't write to destination:\n\n{url}").format(url=filename))
     elif b:
         backup.removeBackup(filename)
     return success