Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search entry from list tags #198

Merged
merged 1 commit into from
Dec 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions nvpy/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,34 @@ def hideSuggestions(self, *args):


class TagList(tk.Toplevel):
def __init__(self, parent, taglist):
# search tag callback
def tagsel(self, box, view):
sel = box.curselection()
if len(sel) != 1: return
for idx in sel:
item = box.get(idx)
view.set_search_entry_text("t:%s" % item)
self.destroy()

def __init__(self, parent, taglist, view):
tk.Toplevel.__init__(self, parent)
self.title("List all tags")
self.bind("<Escape>",lambda a : self.destroy())

box = tk.Listbox(self, width=30, selectmode = tk.BROWSE)
if taglist:
alltags = list(set(taglist))
alltags.sort(key=lambda x: x.upper())
tagtxt = '\n'.join(alltags)
for item in alltags:
box.insert(tk.END,item)
# bind double click and Enter (on box)
box.bind("<Double-Button-1>", lambda a : self.tagsel(box,view))
box.bind("<Return>", lambda a : self.tagsel(box,view))
box.focus()
else:
tagtxt = "No tags defined"
box.insert(tk.END, "No tags defined")

msg = tk.Text(self, width=30, wrap=tk.NONE)
msg.insert(tk.END, tagtxt)
msg.config(state=tk.DISABLED)
msg.pack()
box.pack()

button = tk.Button(self, text="Dismiss", command=self.destroy)
button.pack()
Expand All @@ -332,7 +346,6 @@ def __init__(self, parent, taglist):

self.geometry("+%d+%d" % (x, y)) # Put me over root window


#########################################################################
class StatusBar(tk.Frame):
"""Adapted from the tkinterbook.
Expand Down Expand Up @@ -1562,7 +1575,7 @@ def cmd_help_about(self):
parent=self.root)

def cmd_list_tags(self):
l = TagList(self.root, self.taglist)
l = TagList(self.root, self.taglist, self)
self.root.wait_window(l)

def cmd_help_bindings(self):
Expand Down