Implement Popups, add popup to message delete
This commit is contained in:
parent
201f123c7e
commit
3303494206
@ -79,6 +79,9 @@ class Drawtool():
|
|||||||
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box, self.main_view.colors["error"])
|
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box, self.main_view.colors["error"])
|
||||||
else:
|
else:
|
||||||
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box)
|
self.stdscr.addstr(self.H - 1, 0, "/" + self.main_view.search_box)
|
||||||
|
elif self.main_view.mode == "popup":
|
||||||
|
_, question = self.main_view.popup
|
||||||
|
self.stdscr.addstr(self.H - 1, 0, question)
|
||||||
elif self.main_view.mode == "vimmode":
|
elif self.main_view.mode == "vimmode":
|
||||||
self.stdscr.addstr(self.H - 1, 0, ":" + self.main_view.vimline_box)
|
self.stdscr.addstr(self.H - 1, 0, ":" + self.main_view.vimline_box)
|
||||||
else:
|
else:
|
||||||
|
23
mainview.py
23
mainview.py
@ -30,6 +30,8 @@ class MainView():
|
|||||||
self.inputs = ""
|
self.inputs = ""
|
||||||
self.inputs_cursor = 0
|
self.inputs_cursor = 0
|
||||||
|
|
||||||
|
self.popup = None
|
||||||
|
|
||||||
self.drawtool = drawtool.Drawtool(self)
|
self.drawtool = drawtool.Drawtool(self)
|
||||||
self.fin = False
|
self.fin = False
|
||||||
from config import colors as colorconfig
|
from config import colors as colorconfig
|
||||||
@ -298,6 +300,16 @@ class MainView():
|
|||||||
else:
|
else:
|
||||||
subprocess.Popen(["xdg-open", f"{path}"], stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
|
subprocess.Popen(["xdg-open", f"{path}"], stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
|
||||||
|
|
||||||
|
def popup_message(self, question):
|
||||||
|
self.mode = "popup"
|
||||||
|
async def action_handler(self, key):
|
||||||
|
self.mode = "normal"
|
||||||
|
self.popup = (action_handler, question)
|
||||||
|
|
||||||
|
def spawn_popup(self, action_handler, question):
|
||||||
|
self.mode = "popup"
|
||||||
|
self.popup = (action_handler, question)
|
||||||
|
|
||||||
async def handle_key(self, key):
|
async def handle_key(self, key):
|
||||||
if not self.ready:
|
if not self.ready:
|
||||||
return
|
return
|
||||||
@ -371,11 +383,19 @@ class MainView():
|
|||||||
return
|
return
|
||||||
if n >= len(self.dialogs[self.selected_chat]["messages"]):
|
if n >= len(self.dialogs[self.selected_chat]["messages"]):
|
||||||
#TODO: alert user
|
#TODO: alert user
|
||||||
|
self.popup_message("No message by that id.")
|
||||||
|
await self.drawtool.redraw()
|
||||||
return
|
return
|
||||||
|
async def action_handler(self, key):
|
||||||
|
if key in ["y","Y"]:
|
||||||
to_delete = self.dialogs[self.selected_chat]["messages"][n]
|
to_delete = self.dialogs[self.selected_chat]["messages"][n]
|
||||||
await to_delete.delete()
|
await to_delete.delete()
|
||||||
self.dialogs[self.selected_chat]["messages"].pop(n)
|
self.dialogs[self.selected_chat]["messages"].pop(n)
|
||||||
self.command_box = ""
|
self.command_box = ""
|
||||||
|
self.mode = "normal"
|
||||||
|
question = f"Are you really sure you want to delete message {n}? [y/N]"
|
||||||
|
self.spawn_popup(action_handler, question)
|
||||||
|
|
||||||
await self.drawtool.redraw()
|
await self.drawtool.redraw()
|
||||||
elif key == "r":
|
elif key == "r":
|
||||||
if self.command_box:
|
if self.command_box:
|
||||||
@ -414,6 +434,9 @@ class MainView():
|
|||||||
self.search_box = ""
|
self.search_box = ""
|
||||||
elif key == " ":
|
elif key == " ":
|
||||||
self.drawtool.show_indices ^= True
|
self.drawtool.show_indices ^= True
|
||||||
|
elif self.mode == "popup":
|
||||||
|
action, _ = self.popup
|
||||||
|
await action(self, key)
|
||||||
elif self.mode == "insert":
|
elif self.mode == "insert":
|
||||||
if key == "ESCAPE":
|
if key == "ESCAPE":
|
||||||
self.mode = "normal"
|
self.mode = "normal"
|
||||||
|
Loading…
Reference in New Issue
Block a user