File indexing completed on 2025-03-09 04:10:20

0001 """
0002 SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 """
0006 from PyQt5.QtWidgets import QAction, QFileDialog
0007 from PyQt5.QtGui import QKeySequence
0008 from PyQt5.QtCore import Qt
0009 import krita
0010 
0011 
0012 class SaveAsAction(QAction):
0013 
0014     def __init__(self, scripter, parent=None):
0015         super(SaveAsAction, self).__init__(parent)
0016         self.scripter = scripter
0017         self.editor = self.scripter.uicontroller.editor
0018 
0019         self.triggered.connect(self.save)
0020 
0021         self.setText(i18n("Save As"))
0022         self.setObjectName('saveas')
0023         self.setShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_S))
0024 
0025     @property
0026     def parent(self):
0027         return 'File',
0028 
0029     def save(self):
0030         text = self.editor.toPlainText()
0031 
0032         fileName = QFileDialog.getSaveFileName(self.scripter.uicontroller.mainWidget,
0033                                                i18n("Save Python File"), '',
0034                                                i18n("Python File (*.py)"))[0]
0035         if not fileName:
0036             return
0037 
0038         # don't validate file name - trust user to specify the extension they want
0039         # getSaveFileName will add ".py" if there is no extension.
0040         # It will strip a trailing period and, in each case,  test for file collisions
0041 
0042         document = self.scripter.documentcontroller.saveDocument(text, fileName, save_as=True)
0043         if document:
0044             self.scripter.uicontroller.setStatusBar(document.filePath)
0045         else:
0046             self.scripter.uicontroller.setStatusBar('untitled')
0047         self.editor._documentModified = False
0048         self.scripter.uicontroller.setStatusModified()
0049         return document