Differential D3659 Diff 8958 plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/newaction/newaction.py
Changeset View
Changeset View
Standalone View
Standalone View
plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/newaction/newaction.py
- This file was added.
1 | from PyQt5.QtWidgets import QAction, QMessageBox | ||||
---|---|---|---|---|---|
2 | | ||||
3 | | ||||
4 | class NewAction(QAction): | ||||
5 | | ||||
6 | def __init__(self, scripter, parent=None): | ||||
7 | super(NewAction, self).__init__(parent) | ||||
8 | self.scripter = scripter | ||||
9 | | ||||
10 | self.triggered.connect(self.new) | ||||
11 | | ||||
12 | self.setText('New') | ||||
13 | self.setObjectName('new') | ||||
14 | | ||||
15 | @property | ||||
16 | def parent(self): | ||||
17 | return 'File' | ||||
18 | | ||||
19 | def new(self): | ||||
20 | msgBox = QMessageBox(self.scripter.uicontroller.mainWidget) | ||||
21 | | ||||
22 | msgBox.setText("The document has been modified."); | ||||
23 | msgBox.setInformativeText("Do you want to save your changes?"); | ||||
24 | msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel); | ||||
25 | msgBox.setDefaultButton(QMessageBox.Save); | ||||
26 | | ||||
27 | ret = msgBox.exec(); | ||||
28 | | ||||
29 | if ret == QMessageBox.Cancel: | ||||
30 | return | ||||
31 | if ret == QMessageBox.Save: | ||||
32 | self.scripter.uicontroller.invokeAction('save') | ||||
33 | | ||||
34 | self.scripter.documentcontroller.clearActiveDocument() | ||||
35 | self.scripter.uicontroller.setStatusBar() | ||||
36 | self.scripter.uicontroller.clearEditor() |