diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2019-09-03 21:43:17 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2019-09-03 21:43:17 -0400 |
| commit | 18c5d6075fe85da373bda0011aa3154b9c602366 (patch) | |
| tree | 26b88f7294304f1f6ca0f1fd58d49c8e245e79e2 /python | |
| parent | 6967f7b6e047425f12658ac282534ba8cafed05c (diff) | |
make snippets dialog modal and also disable edit fields until a new snippet is created
Diffstat (limited to 'python')
| -rw-r--r-- | python/examples/snippets/__init__.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/python/examples/snippets/__init__.py b/python/examples/snippets/__init__.py index c19232a3..15967b25 100644 --- a/python/examples/snippets/__init__.py +++ b/python/examples/snippets/__init__.py @@ -81,7 +81,7 @@ class Snippets(QDialog): def __init__(self, parent=None): super(Snippets, self).__init__(parent) # Create widgets - self.setWindowModality(Qt.NonModal) + self.setWindowModality(Qt.ApplicationModal) self.title = QLabel(self.tr("Snippet Editor")) self.saveButton = QPushButton(self.tr("Save")) self.revertButton = QPushButton(self.tr("Revert")) @@ -182,6 +182,9 @@ class Snippets(QDialog): self.deleteSnippetButton.clicked.connect(self.deleteSnippet) self.newFolderButton.clicked.connect(self.newFolder) + #Read-only until new snippet + self.readOnly(True) + @staticmethod def registerAllSnippets(): for action in list(filter(lambda x: x.startswith("Snippets\\"), UIAction.getAllRegisteredActions())): @@ -239,6 +242,7 @@ class Snippets(QDialog): return newSelection = self.files.filePath(new.indexes()[0]) if QFileInfo(newSelection).isDir(): + self.readOnly(True) self.clearSelection() return @@ -260,6 +264,7 @@ class Snippets(QDialog): self.snippetDescription.setText(snippetDescription) if snippetDescription else self.snippetDescription.setText("") self.keySequenceEdit.setKeySequence(snippetKeys) if snippetKeys else self.keySequenceEdit.setKeySequence(QKeySequence("")) self.edit.setPlainText(snippetCode) if snippetCode else self.edit.setPlainText("") + self.readOnly(False) def newFileDialog(self): (snippetName, ok) = QInputDialog.getText(self, self.tr("Snippet Name"), self.tr("Snippet Name: ")) @@ -272,8 +277,20 @@ class Snippets(QDialog): open(os.path.join(selection, snippetName), "w").close() else: open(os.path.join(snippetPath, snippetName), "w").close() + self.readOnly(False) log_debug("Snippet %s created." % snippetName) + def readOnly(self, flag): + self.keySequenceEdit.setEnabled(not flag) + self.snippetDescription.setReadOnly(flag) + self.edit.setReadOnly(flag) + if flag: + self.snippetDescription.setDisabled(True) + self.edit.setDisabled(True) + else: + self.snippetDescription.setEnabled(True) + self.edit.setEnabled(True) + def deleteSnippet(self): selection = self.tree.selectedIndexes()[::self.columns][0] #treeview returns each selected element in the row snippetName = self.files.fileName(selection) @@ -282,6 +299,7 @@ class Snippets(QDialog): log_debug("Deleting snippet %s." % snippetName) self.clearSelection() self.files.remove(selection) + self.registerAllSnippets() def snippetChanged(self): if (self.currentFile == "" or QFileInfo(self.currentFile).isDir()): |
