Skip to content

Commit c0e443b

Browse files
authored
Merge pull request #16 from mrexodia/ux-improvements
UX improvements
2 parents 5dcf3d5 + cbae9ce commit c0e443b

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

QCodeEditor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ def __init__(self, editor):
153153
self.editor = editor
154154
self.editor.blockCountChanged.connect(self.updateWidth)
155155
self.editor.updateRequest.connect(self.updateContents)
156-
self.font = QFont()
156+
self.font = editor.font()
157157
self.numberBarColor = bnstyles["numberBar"]
158+
self.updateWidth()
158159

159160
def paintEvent(self, event):
160161
painter = QPainter(self)

__init__.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class Snippets(QDialog):
153153
def __init__(self, context, parent=None):
154154
super(Snippets, self).__init__(parent)
155155
# Create widgets
156-
self.setWindowModality(Qt.ApplicationModal)
156+
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
157157
self.title = QLabel(self.tr("Snippet Editor"))
158158
self.saveButton = QPushButton(self.tr("&Save"))
159159
self.saveButton.setShortcut(QKeySequence(self.tr("Ctrl+S")))
@@ -315,12 +315,19 @@ def clearSelection(self):
315315
self.tree.clearSelection()
316316
self.currentFile = ""
317317

318+
def askSave(self):
319+
return QMessageBox.question(self, self.tr("Save?"), self.tr("Do you want to save changes to {}?").format(self.currentFileLabel.text()), QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel)
320+
318321
def reject(self):
319322
self.settings.setValue("ui/snippeteditor/geometry", self.saveGeometry())
320323

321324
if self.snippetChanged():
322-
question = QMessageBox.question(self, self.tr("Discard"), self.tr("You have unsaved changes, quit anyway?"))
323-
if question != QMessageBox.StandardButton.Yes:
325+
save = self.askSave()
326+
if save == QMessageBox.Yes:
327+
self.save()
328+
elif save == QMessageBox.No:
329+
pass
330+
elif save == QMessageBox.Cancel:
324331
return
325332
self.accept()
326333

@@ -358,8 +365,12 @@ def selectFile(self, new, old):
358365
if old and old.length() > 0:
359366
oldSelection = self.files.filePath(old.indexes()[0])
360367
if not QFileInfo(oldSelection).isDir() and self.snippetChanged():
361-
question = QMessageBox.question(self, self.tr("Discard"), self.tr("Snippet changed. Discard changes?"))
362-
if question != QMessageBox.StandardButton.Yes:
368+
save = self.askSave()
369+
if save == QMessageBox.Yes:
370+
self.save()
371+
elif save == QMessageBox.No:
372+
pass
373+
elif save == QMessageBox.Cancel:
363374
self.resetting = True
364375
self.tree.selectionModel().select(old, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
365376
return False
@@ -376,7 +387,7 @@ def loadSnippet(self):
376387
self.readOnly(False)
377388

378389
def newFileDialog(self):
379-
(snippetName, ok) = QInputDialog.getText(self, self.tr("Snippet Name"), self.tr("Snippet Name: "))
390+
(snippetName, ok) = QInputDialog.getText(self, self.tr("Snippet Name"), self.tr("Snippet Name: "), flags=self.windowFlags())
380391
if ok and snippetName:
381392
if not snippetName.endswith(".py"):
382393
snippetName += ".py"
@@ -437,11 +448,7 @@ def run(self):
437448
log_warn("Cannot run snippets outside of the UI at this time.")
438449
return
439450
if self.snippetChanged():
440-
question = QMessageBox.question(self, self.tr("Confirm"), self.tr("You have unsaved changes, must save first. Save?"))
441-
if (question == QMessageBox.StandardButton.No):
442-
return
443-
else:
444-
self.save()
451+
self.save()
445452
actionText = actionFromSnippet(self.currentFile, self.snippetDescription.text())
446453
UIActionHandler.globalActions().executeAction(actionText, self.context)
447454

@@ -457,10 +464,13 @@ def clearHotkey(self):
457464
self.keySequenceEdit.clear()
458465

459466

460-
def launchPlugin(context):
461-
snippets = Snippets(context)
462-
snippets.exec_()
467+
snippets = None
463468

469+
def launchPlugin(context):
470+
global snippets
471+
if not snippets:
472+
snippets = Snippets(context)
473+
snippets.show()
464474

465475
if __name__ == '__main__':
466476
app = QApplication(sys.argv)

plugin.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
{"pluginmetadataversion": 2, "name": "Snippet UI Plugin", "type": ["ui"], "api": ["python2", "python3"], "description": "Powerful code-editing plugin for writing and managing python code-snippets with syntax highlightingd, hotkey binding and other features", "longdescription": "The snippet editor started as a simple example UI plugin to demonstrate new features available to UI plugins. It has turned into a functionally useful plugin in its own right. The snippet editor allows you to write small bits of code that might not be big enough to warrant the effort of a full plugin but are longer enough that you don't want to retype them every time in the python-console!\n\nAs an added bonus, all snippets are added to the snippets menu and hot-keys can be associated with them as they make use of the action system. All action-system items are also available through the command-palette (CTL/CMD-p).\n\n![](https://github.com/Vector35/snippets/blob/master/media/snippets.gif?raw=true)\n\n.", "license": {"name": "MIT", "text": "Copyright (c) 2019 Vector 35 Inc\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."}, "platforms": ["Darwin", "Linux", "Windows"], "installinstructions": {"Darwin": "no special instructions, package manager is recommended", "Linux": "no special instructions, package manager is recommended", "Windows": "no special instructions, package manager is recommended"}, "dependencies": {}, "version": "1.10", "author": "Vector 35 Inc", "minimumbinaryninjaversion": 1528}
1+
{
2+
"pluginmetadataversion": 2,
3+
"name": "Snippet UI Plugin",
4+
"type": [
5+
"ui"
6+
],
7+
"api": [
8+
"python2",
9+
"python3"
10+
],
11+
"description": "Powerful code-editing plugin for writing and managing python code-snippets with syntax highlightingd, hotkey binding and other features",
12+
"longdescription": "The snippet editor started as a simple example UI plugin to demonstrate new features available to UI plugins. It has turned into a functionally useful plugin in its own right. The snippet editor allows you to write small bits of code that might not be big enough to warrant the effort of a full plugin but are longer enough that you don't want to retype them every time in the python-console!\n\nAs an added bonus, all snippets are added to the snippets menu and hot-keys can be associated with them as they make use of the action system. All action-system items are also available through the command-palette (CTL/CMD-p).\n\n![](https://github.com/Vector35/snippets/blob/master/media/snippets.gif?raw=true)\n\n.",
13+
"license": {
14+
"name": "MIT",
15+
"text": "Copyright (c) 2019 Vector 35 Inc\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
16+
},
17+
"platforms": [
18+
"Darwin",
19+
"Linux",
20+
"Windows"
21+
],
22+
"installinstructions": {
23+
"Darwin": "no special instructions, package manager is recommended",
24+
"Linux": "no special instructions, package manager is recommended",
25+
"Windows": "no special instructions, package manager is recommended"
26+
},
27+
"dependencies": "pygments>=2.7.0,<2.9.0\n",
28+
"version": "1.11",
29+
"author": "Vector 35 Inc",
30+
"minimumbinaryninjaversion": 1528
31+
}

0 commit comments

Comments
 (0)