save cursor position
This commit is contained in:
parent
89a8afbd6a
commit
555397452c
@ -10,8 +10,11 @@ from .db import initialize_db
|
|||||||
# TODO: add footer w/ filter status
|
# TODO: add footer w/ filter status
|
||||||
# TODO: toggle status with 't'
|
# TODO: toggle status with 't'
|
||||||
# TODO: add way to filter on other columns
|
# TODO: add way to filter on other columns
|
||||||
# TODO: nicer editor for some fields
|
# TODO: safe DB mode
|
||||||
# TODO: auto edit on add
|
# Nice to Have
|
||||||
|
# TODO: CLI?
|
||||||
|
# TODO: config- default category, types, colors
|
||||||
|
# TODO: dropdowns for status, type, category
|
||||||
|
|
||||||
column_to_field = {
|
column_to_field = {
|
||||||
1: "text",
|
1: "text",
|
||||||
@ -89,8 +92,7 @@ class TT(App):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.search_query = ""
|
self.search_query = ""
|
||||||
self.edit_row = None
|
self.saved_cursor_pos = (0, 0)
|
||||||
self.edit_column = None
|
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
self.header = Header()
|
self.header = Header()
|
||||||
@ -106,7 +108,7 @@ class TT(App):
|
|||||||
|
|
||||||
def on_mount(self):
|
def on_mount(self):
|
||||||
self.table.add_columns("ID", "Task", "Status", "Type", "Due", "Category")
|
self.table.add_columns("ID", "Task", "Status", "Type", "Due", "Category")
|
||||||
self.refresh_tasks()
|
self.refresh_tasks(restore_cursor=False)
|
||||||
|
|
||||||
def action_cursor_left(self):
|
def action_cursor_left(self):
|
||||||
self.table.move_cursor(column=self.table.cursor_column - 1)
|
self.table.move_cursor(column=self.table.cursor_column - 1)
|
||||||
@ -130,7 +132,7 @@ class TT(App):
|
|||||||
def action_cursor_bottom(self):
|
def action_cursor_bottom(self):
|
||||||
self.table.move_cursor(row=self.table.row_count - 1)
|
self.table.move_cursor(row=self.table.row_count - 1)
|
||||||
|
|
||||||
def refresh_tasks(self):
|
def refresh_tasks(self, *, restore_cursor=True):
|
||||||
self.table.clear()
|
self.table.clear()
|
||||||
|
|
||||||
tasks = get_tasks(self.search_query)
|
tasks = get_tasks(self.search_query)
|
||||||
@ -150,22 +152,42 @@ class TT(App):
|
|||||||
category,
|
category,
|
||||||
key=str(task.id),
|
key=str(task.id),
|
||||||
)
|
)
|
||||||
|
if restore_cursor:
|
||||||
|
self.table.move_cursor(
|
||||||
|
row=self.saved_cursor_pos[0], column=self.saved_cursor_pos[1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.table.move_cursor(row=0, column=1)
|
||||||
|
|
||||||
def action_delete_task(self):
|
def action_delete_task(self):
|
||||||
if self.table.cursor_column == 0:
|
if self.table.cursor_column == 0:
|
||||||
task_id = int(self.table.get_cell_at((self.table.cursor_row, 0)))
|
cur_row = self.table.cursor_row
|
||||||
|
task_id = int(self.table.get_cell_at((cur_row, 0)))
|
||||||
update_task(task_id, deleted=True)
|
update_task(task_id, deleted=True)
|
||||||
|
self._save_cursor()
|
||||||
self.refresh_tasks()
|
self.refresh_tasks()
|
||||||
|
|
||||||
def action_add_task(self):
|
def action_add_task(self):
|
||||||
"""Add a new task with default values."""
|
"""Add a new task with default values."""
|
||||||
add_task(
|
new_task = add_task(
|
||||||
text="New Task",
|
text="New Task",
|
||||||
type="task",
|
type="",
|
||||||
status=TaskStatus.ZERO.value,
|
status=TaskStatus.ZERO.value,
|
||||||
category="main",
|
category="main",
|
||||||
)
|
)
|
||||||
self.refresh_tasks()
|
self.refresh_tasks(restore_cursor=False)
|
||||||
|
self.move_cursor_to_task(new_task.id)
|
||||||
|
self.action_start_edit()
|
||||||
|
|
||||||
|
def move_cursor_to_task(self, task_id):
|
||||||
|
# ick, but only way to search table?
|
||||||
|
for row in range(len(self.table.rows)):
|
||||||
|
data = self.table.get_row_at(row)
|
||||||
|
if data[0] == str(task_id):
|
||||||
|
self.table.move_cursor(row=row, column=1)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise Exception("nope")
|
||||||
|
|
||||||
# Control of edit bar ####################
|
# Control of edit bar ####################
|
||||||
|
|
||||||
@ -189,11 +211,14 @@ class TT(App):
|
|||||||
def action_start_search(self):
|
def action_start_search(self):
|
||||||
self._show_input("search", "")
|
self._show_input("search", "")
|
||||||
|
|
||||||
|
def _save_cursor(self):
|
||||||
|
self.saved_cursor_pos = (self.table.cursor_row, self.table.cursor_column)
|
||||||
|
|
||||||
def action_start_edit(self):
|
def action_start_edit(self):
|
||||||
if self.table.cursor_row is None or self.table.cursor_column == 0:
|
if self.table.cursor_row is None or self.table.cursor_column == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.saved_cursor_pos = (self.table.cursor_row, self.table.cursor_column)
|
self._save_cursor()
|
||||||
current_value = self.table.get_cell_at(
|
current_value = self.table.get_cell_at(
|
||||||
(self.table.cursor_row, self.table.cursor_column)
|
(self.table.cursor_row, self.table.cursor_column)
|
||||||
)
|
)
|
||||||
@ -203,7 +228,7 @@ class TT(App):
|
|||||||
def on_input_submitted(self, event: Input.Submitted):
|
def on_input_submitted(self, event: Input.Submitted):
|
||||||
if self.mode == "search":
|
if self.mode == "search":
|
||||||
self.search_query = event.value
|
self.search_query = event.value
|
||||||
self.refresh_tasks()
|
self.refresh_tasks(restore_cursor=False)
|
||||||
elif self.mode == "edit":
|
elif self.mode == "edit":
|
||||||
self.apply_change(event.value)
|
self.apply_change(event.value)
|
||||||
self._hide_input()
|
self._hide_input()
|
||||||
|
Loading…
Reference in New Issue
Block a user