17
17
from binaryninjaui import (getMonospaceFont , UIAction , UIActionHandler , Menu , DockHandler ,
18
18
getThemeColor , ThemeColor )
19
19
import numbers
20
- from .lntextedit import LNTextEdit
20
+ from .QCodeEditor import QCodeEditor , PythonHighlighter
21
21
22
22
snippetPath = os .path .realpath (os .path .join (user_plugin_path (), ".." , "snippets" ))
23
23
try :
@@ -140,9 +140,8 @@ def __init__(self, context, parent=None):
140
140
self .browseButton .setIcon (QIcon .fromTheme ("edit-undo" ))
141
141
self .deleteSnippetButton = QPushButton ("Delete" )
142
142
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" )
146
145
self .resetting = False
147
146
self .columns = 3
148
147
self .context = context
@@ -157,9 +156,9 @@ def __init__(self, context, parent=None):
157
156
158
157
#Set Editbox Size
159
158
font = getMonospaceFont (self )
160
- self .edit .edit . setFont (font )
159
+ self .edit .setFont (font )
161
160
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
163
162
164
163
#Files
165
164
self .files = QFileSystemModel ()
@@ -246,9 +245,9 @@ def __init__(self, context, parent=None):
246
245
if self .tree .selectionModel ().hasSelection ():
247
246
self .selectFile (self .tree .selectionModel ().selection (), None )
248
247
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 )
252
251
else :
253
252
self .readOnly (True )
254
253
else :
@@ -282,7 +281,7 @@ def clearSelection(self):
282
281
self .currentHotkeyLabel .setText ("" )
283
282
self .currentFileLabel .setText ("" )
284
283
self .snippetDescription .setText ("" )
285
- self .edit .edit . setPlainText ("" )
284
+ self .edit .setPlainText ("" )
286
285
self .currentFile = ""
287
286
288
287
def reject (self ):
@@ -337,7 +336,7 @@ def loadSnippet(self):
337
336
(snippetDescription , snippetKeys , snippetCode ) = loadSnippetFromFile (self .currentFile )
338
337
self .snippetDescription .setText (snippetDescription ) if snippetDescription else self .snippetDescription .setText ("" )
339
338
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 ("" )
341
340
self .readOnly (False )
342
341
343
342
def newFileDialog (self ):
@@ -359,7 +358,7 @@ def newFileDialog(self):
359
358
def readOnly (self , flag ):
360
359
self .keySequenceEdit .setEnabled (not flag )
361
360
self .snippetDescription .setReadOnly (flag )
362
- self .edit .edit . setReadOnly (flag )
361
+ self .edit .setReadOnly (flag )
363
362
if flag :
364
363
self .snippetDescription .setDisabled (True )
365
364
self .edit .setDisabled (True )
@@ -385,15 +384,15 @@ def snippetChanged(self):
385
384
return True
386
385
if snippetKeys != None and snippetKeys != self .keySequenceEdit .keySequence ().toString ():
387
386
return True
388
- return self .edit .edit . toPlainText () != snippetCode or \
387
+ return self .edit .toPlainText () != snippetCode or \
389
388
self .snippetDescription .text () != snippetDescription
390
389
391
390
def save (self ):
392
391
log_debug ("Saving snippet %s" % self .currentFile )
393
392
outputSnippet = codecs .open (self .currentFile , "w" , "utf-8" )
394
393
outputSnippet .write ("#" + self .snippetDescription .text () + "\n " )
395
394
outputSnippet .write ("#" + self .keySequenceEdit .keySequence ().toString () + "\n " )
396
- outputSnippet .write (self .edit .edit . toPlainText ())
395
+ outputSnippet .write (self .edit .toPlainText ())
397
396
outputSnippet .close ()
398
397
self .registerAllSnippets ()
399
398
@@ -414,7 +413,7 @@ def run(self):
414
413
outputSnippet = codecs .open (self .currentFile , "w" , "utf-8" )
415
414
outputSnippet .write ("#" + self .snippetDescription .text () + "\n " )
416
415
outputSnippet .write ("#" + self .keySequenceEdit .keySequence ().toString () + "\n " )
417
- outputSnippet .write (self .edit .edit . toPlainText ())
416
+ outputSnippet .write (self .edit .toPlainText ())
418
417
outputSnippet .close ()
419
418
self .registerAllSnippets ()
420
419
0 commit comments