7
7
import getpass
8
8
from collections import namedtuple
9
9
from datetime import datetime
10
+ from pathlib import Path
11
+
10
12
import binaryninjaui
11
13
from binaryninjaui import (getMonospaceFont , UIAction , UIActionHandler , Menu , UIContext )
12
14
if "qt_major_version" in binaryninjaui .__dict__ and binaryninjaui .qt_major_version == 6 :
54
56
try :
55
57
if not os .path .exists (snippetPath ):
56
58
os .mkdir (snippetPath )
57
- dst_examples = os .path .join (snippetPath , "update_example_snippets.py" )
58
- src_examples = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "update_example_snippets.py" )
59
- if not os .path .exists (dst_examples ):
59
+ example_name = "update_example_snippets.py"
60
+ dst_examples = os .path .join (snippetPath , example_name )
61
+ rm_dst_examples = os .path .join (snippetPath , "." + example_name )
62
+ src_examples = os .path .join (os .path .dirname (os .path .realpath (__file__ )), example_name )
63
+ if not os .path .exists (rm_dst_examples ) and not os .path .exists (dst_examples ):
60
64
shutil .copy (src_examples , dst_examples )
61
65
except IOError :
62
66
log_error ("Unable to create %s or unable to add example updater, please report this bug" % snippetPath )
@@ -488,6 +492,10 @@ def deleteSnippet(self):
488
492
if (question == QMessageBox .StandardButton .Yes ):
489
493
log_debug ("Snippets: Deleting snippet %s." % snippetName )
490
494
self .clearSelection ()
495
+ if snippetName == example_name :
496
+ question = QMessageBox .question (self , self .tr ("Confirm" ), self .tr ("Should snippets prevent this file from being recreated?" ))
497
+ if (question == QMessageBox .StandardButton .Yes ):
498
+ Path (rm_dst_examples ).touch ()
491
499
self .files .remove (selection )
492
500
self .registerAllSnippets ()
493
501
@@ -692,6 +700,9 @@ def clearHotkey(self):
692
700
693
701
snippets = None
694
702
703
+ def reloadActions (context ):
704
+ Snippets .registerAllSnippets ()
705
+
695
706
def launchPlugin (context ):
696
707
global snippets
697
708
if not snippets :
@@ -708,6 +719,6 @@ def launchPlugin(context):
708
719
UIAction .registerAction ("Snippets\\ Snippet Editor..." )
709
720
UIAction .registerAction ("Snippets\\ Reload All Snippets" )
710
721
UIActionHandler .globalActions ().bindAction ("Snippets\\ Snippet Editor..." , UIAction (launchPlugin ))
711
- UIActionHandler .globalActions ().bindAction ("Snippets\\ Reload All Snippets" , UIAction (Snippets . registerAllSnippets ))
722
+ UIActionHandler .globalActions ().bindAction ("Snippets\\ Reload All Snippets" , UIAction (reloadActions ))
712
723
Menu .mainMenu ("Tools" ).addAction ("Snippets\\ Snippet Editor..." , "Snippet" )
713
724
Menu .mainMenu ("Tools" ).addAction ("Snippets\\ Reload All Snippets" , "Snippet" )
0 commit comments