66import darkdetect
77import ntkutils
88import pygments
9+ import pyperclip
910from tkinterdnd2 import *
1011from tklinenums import TkLineNumbers
1112
@@ -112,35 +113,17 @@ def onscroll(first, last):
112113 menubar .add_cascade (label = "File" , menu = filemenu )
113114 menubar .add_cascade (label = "Settings" , menu = settingsmenu )
114115
115- filemenu .add_command (
116- label = "Save ({})" .format (cfg ["hkey-save" ]),
117- command = tabmanager .save ,
118- foreground = "black" ,
119- )
120- filemenu .add_command (
121- label = "Save As" ,
122- command = lambda : tabmanager .save (saveas = True ),
123- foreground = "black" ,
124- )
125- filemenu .add_command (
126- label = "Open ({})" .format (cfg ["hkey-open" ]),
127- command = tabmanager .openfile ,
128- foreground = "black" ,
129- )
116+ filemenu .add_command (label = "Save ({})" .format (cfg ["hkey-save" ]), command = tabmanager .save , foreground = "black" )
117+ filemenu .add_command (label = "Save As" , command = lambda : tabmanager .save (saveas = True ), foreground = "black" )
118+ filemenu .add_command (label = "Open ({})" .format (cfg ["hkey-open" ]), command = tabmanager .openfile , foreground = "black" )
130119 filemenu .add_command (label = "New" , command = tabmanager .new , foreground = "black" )
131120 filemenu .add_separator ()
132- filemenu .add_command (
133- label = "Change file extension" , command = tabmanager .changetype , foreground = "black"
134- )
121+ filemenu .add_command (label = "Change file extension" , command = tabmanager .changetype , foreground = "black" )
135122 filemenu .add_separator ()
136123 filemenu .add_command (label = "Preview Markdown" , command = md .build , foreground = "black" )
137- filemenu .add_command (
138- label = "Close Preview" , command = closepreview , foreground = "black"
139- )
124+ filemenu .add_command (label = "Close Preview" , command = closepreview , foreground = "black" )
140125
141- settingsmenu .add_command (
142- label = "Open Settings" , command = settingsui .build , foreground = "black"
143- )
126+ settingsmenu .add_command (label = "Open Settings" , command = settingsui .build , foreground = "black" )
144127 settingsmenu .add_command (label = "About" , command = about .build , foreground = "black" )
145128
146129 if cfg ["mica" ]:
@@ -175,6 +158,28 @@ def filedrop(event):
175158 root .drop_target_register (DND_FILES )
176159 root .dnd_bind ("<<Drop>>" , filedrop )
177160
161+ def cut ():
162+ pyperclip .copy (textwidget .selection_get ())
163+ textwidget .delete ("sel.first" , "sel.last" )
164+
165+ def copy ():
166+ pyperclip .copy (textwidget .selection_get ())
167+
168+ def paste ():
169+ textwidget .insert ("insert" , pyperclip .paste ())
170+
171+ def popup (event ):
172+ try :
173+ context .tk_popup (event .x_root , event .y_root , 0 )
174+ finally :
175+ context .grab_release ()
176+
177+ context = tkinter .Menu (root , tearoff = False , bg = "white" )
178+ context .add_command (label = "Cut" , command = cut , foreground = "black" )
179+ context .add_command (label = "Copy" , command = copy , foreground = "black" )
180+ context .add_command (label = "Paste" , command = paste , foreground = "black" )
181+ root .bind ("<Button-3>" , popup )
182+
178183 # Set global variables
179184 v .cfg = cfg
180185 v .root = root
@@ -188,9 +193,6 @@ def filedrop(event):
188193
189194 setimages ()
190195
191- notebook .add (
192- tkinter .Frame (), text = tabmanager .tabs [0 ][0 ], image = closeimg , compound = "right"
193- )
194- notebook .bind (
195- "<ButtonRelease-1>" , tabmanager .click , add = "+"
196- ) # Bind Left mouse button to write content of selected tab into the text widget
196+ notebook .add (tkinter .Frame (), text = tabmanager .tabs [0 ][0 ], image = closeimg , compound = "right" )
197+ # Bind Left mouse button to write content of selected tab into the text widget
198+ notebook .bind ("<ButtonRelease-1>" , tabmanager .click , add = "+" )
0 commit comments