Skip to content

Commit b3f93e5

Browse files
committed
initial testing of qcodeeditor version
1 parent f37906c commit b3f93e5

File tree

3 files changed

+15
-143
lines changed

3 files changed

+15
-143
lines changed

QCodeEditor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/jwiens/dev/QCodeEditor/QCodeEditor.py

__init__.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from binaryninjaui import (getMonospaceFont, UIAction, UIActionHandler, Menu, DockHandler,
1818
getThemeColor, ThemeColor)
1919
import numbers
20-
from .lntextedit import LNTextEdit
20+
from .QCodeEditor import QCodeEditor, PythonHighlighter
2121

2222
snippetPath = os.path.realpath(os.path.join(user_plugin_path(), "..", "snippets"))
2323
try:
@@ -140,9 +140,8 @@ def __init__(self, context, parent=None):
140140
self.browseButton.setIcon(QIcon.fromTheme("edit-undo"))
141141
self.deleteSnippetButton = QPushButton("Delete")
142142
self.newSnippetButton = QPushButton("New Snippet")
143-
self.edit = LNTextEdit()
144-
self.edit.edit.setPlaceholderText("python code")
145-
self.edit.edit.highlight_color = getThemeColor(ThemeColor.SelectionColor)
143+
self.edit = QCodeEditor(HIGHLIGHT_CURRENT_LINE=False, SyntaxHighlighter=PythonHighlighter)
144+
self.edit.setPlaceholderText("python code")
146145
self.resetting = False
147146
self.columns = 3
148147
self.context = context
@@ -157,9 +156,9 @@ def __init__(self, context, parent=None):
157156

158157
#Set Editbox Size
159158
font = getMonospaceFont(self)
160-
self.edit.edit.setFont(font)
159+
self.edit.setFont(font)
161160
font = QFontMetrics(font)
162-
self.edit.edit.setTabStopWidth(4 * font.width(' ')); #TODO, replace with settings API
161+
self.edit.setTabStopWidth(4 * font.width(' ')); #TODO, replace with settings API
163162

164163
#Files
165164
self.files = QFileSystemModel()
@@ -246,9 +245,9 @@ def __init__(self, context, parent=None):
246245
if self.tree.selectionModel().hasSelection():
247246
self.selectFile(self.tree.selectionModel().selection(), None)
248247
self.edit.setFocus()
249-
cursor = self.edit.edit.textCursor()
250-
cursor.setPosition(self.edit.edit.document().characterCount()-1)
251-
self.edit.edit.setTextCursor(cursor)
248+
cursor = self.edit.textCursor()
249+
cursor.setPosition(self.edit.document().characterCount()-1)
250+
self.edit.setTextCursor(cursor)
252251
else:
253252
self.readOnly(True)
254253
else:
@@ -282,7 +281,7 @@ def clearSelection(self):
282281
self.currentHotkeyLabel.setText("")
283282
self.currentFileLabel.setText("")
284283
self.snippetDescription.setText("")
285-
self.edit.edit.setPlainText("")
284+
self.edit.setPlainText("")
286285
self.currentFile = ""
287286

288287
def reject(self):
@@ -337,7 +336,7 @@ def loadSnippet(self):
337336
(snippetDescription, snippetKeys, snippetCode) = loadSnippetFromFile(self.currentFile)
338337
self.snippetDescription.setText(snippetDescription) if snippetDescription else self.snippetDescription.setText("")
339338
self.keySequenceEdit.setKeySequence(snippetKeys) if snippetKeys else self.keySequenceEdit.setKeySequence(QKeySequence(""))
340-
self.edit.edit.setPlainText(snippetCode) if snippetCode else self.edit.edit.setPlainText("")
339+
self.edit.setPlainText(snippetCode) if snippetCode else self.edit.setPlainText("")
341340
self.readOnly(False)
342341

343342
def newFileDialog(self):
@@ -359,7 +358,7 @@ def newFileDialog(self):
359358
def readOnly(self, flag):
360359
self.keySequenceEdit.setEnabled(not flag)
361360
self.snippetDescription.setReadOnly(flag)
362-
self.edit.edit.setReadOnly(flag)
361+
self.edit.setReadOnly(flag)
363362
if flag:
364363
self.snippetDescription.setDisabled(True)
365364
self.edit.setDisabled(True)
@@ -385,15 +384,15 @@ def snippetChanged(self):
385384
return True
386385
if snippetKeys != None and snippetKeys != self.keySequenceEdit.keySequence().toString():
387386
return True
388-
return self.edit.edit.toPlainText() != snippetCode or \
387+
return self.edit.toPlainText() != snippetCode or \
389388
self.snippetDescription.text() != snippetDescription
390389

391390
def save(self):
392391
log_debug("Saving snippet %s" % self.currentFile)
393392
outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
394393
outputSnippet.write("#" + self.snippetDescription.text() + "\n")
395394
outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n")
396-
outputSnippet.write(self.edit.edit.toPlainText())
395+
outputSnippet.write(self.edit.toPlainText())
397396
outputSnippet.close()
398397
self.registerAllSnippets()
399398

@@ -414,7 +413,7 @@ def run(self):
414413
outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
415414
outputSnippet.write("#" + self.snippetDescription.text() + "\n")
416415
outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n")
417-
outputSnippet.write(self.edit.edit.toPlainText())
416+
outputSnippet.write(self.edit.toPlainText())
418417
outputSnippet.close()
419418
self.registerAllSnippets()
420419

lntextedit.py

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)