Skip to content

Commit 283fa5c

Browse files
committed
context menu
1 parent dab1a67 commit 283fa5c

File tree

4 files changed

+39
-47
lines changed

4 files changed

+39
-47
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tkinterdnd2
99
tklinenums >= 1.5
1010
requests; sys_platform != 'linux'
1111
pygments
12+
pyperclip

src/editor.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import darkdetect
77
import ntkutils
88
import pygments
9+
import pyperclip
910
from tkinterdnd2 import *
1011
from 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="+")

src/main.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,11 @@ def openfile(path):
5050
tabmanager.openfile(path=path)
5151

5252

53-
title = tkinter.Label(root, text="Onyx Editor", font=("Segoe UI", 20, "bold")).pack(
54-
anchor="nw", padx=20, pady=20
55-
)
56-
btncreatenew = ttk.Button(root, text="Create New File", command=preparewindow).pack(
57-
anchor="nw", padx=20
58-
)
59-
btnopenfile = ttk.Button(
60-
root, text="Open File", command=lambda: openfile(path="")
61-
).pack(anchor="nw", pady=10, padx=20)
62-
btnopendir = ttk.Button(root, text="Open Directory", state="disabled").pack(
63-
anchor="nw", padx=20
64-
)
65-
btnopenlast = ttk.Button(
66-
root, text="Open last file", command=lambda: openfile(path=content)
67-
)
53+
title = tkinter.Label(root, text="Onyx Editor", font=("Segoe UI", 20, "bold")).pack(anchor="nw", padx=20, pady=20)
54+
btncreatenew = ttk.Button(root, text="Create New File", command=preparewindow).pack(anchor="nw", padx=20)
55+
btnopenfile = ttk.Button(root, text="Open File", command=lambda: openfile(path="")).pack(anchor="nw", pady=10, padx=20)
56+
btnopendir = ttk.Button(root, text="Open Directory", state="disabled").pack(anchor="nw", padx=20)
57+
btnopenlast = ttk.Button(root, text="Open last file", command=lambda: openfile(path=content))
6858
btnopenlast.pack(anchor="nw", padx=20, pady=20)
6959

7060
if os.path.isfile("lastfile.txt"):

src/pages/about.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import tkinter
2-
from tkinter import messagebox
32
import webbrowser
4-
from tkinter import ttk
3+
from tkinter import messagebox, ttk
54

65
import darkdetect
76

0 commit comments

Comments
 (0)