Skip to content

Commit

Permalink
Reworking "Move event" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed May 4, 2023
1 parent 7141ec3 commit df1cdc9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 37 deletions.
40 changes: 26 additions & 14 deletions calcure/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,29 @@ def control_monthly_screen(stdscr, screen, user_events, importer):
user_events.rename_item(event_id, new_name)

# Move event:
if screen.key == 'm':
number = input_integer(stdscr, screen.y_max-2, 0, MSG_EVENT_MOVE)
if screen.key in ['m', 'M']:
number = input_integer(stdscr, screen.y_max-2, 0, MSG_EVENT_MV)
if user_events.filter_events_that_month(screen).is_valid_number(number):
event_id = user_events.filter_events_that_month(screen).items[number].item_id
clear_line(stdscr, screen.y_max-2)
question = f'{MSG_EVENT_MOVE_TO} {screen.year}/{screen.month}/'
day = input_day(stdscr, screen.y_max-2, 0, question)
if screen.is_valid_day(day):
user_events.change_day(event_id, day)
if screen.key == 'm':
year, month, day = input_date(stdscr, screen.y_max-2, 0, MSG_EVENT_MV_TO)
if screen.is_valid_date(year, month, day):
user_events.change_date(event_id, year, month, day)

if screen.key == 'M':
question = f'{MSG_EVENT_MV_TO_D} {screen.year}/{screen.month}/'
day = input_day(stdscr, screen.y_max-2, 0, question)
if screen.is_valid_day(day):
user_events.change_day(event_id, day)

# Otherwise, we check for user input:
else:
# Wait for user to press a key:
screen.key = stdscr.getkey()

# If we need to select an event, change to selection mode:
if screen.key in ['h', 'l', 'u', 'i', 'd', 'x', 'e', 'r', 'c', 'm', '.']:
if screen.key in ['h', 'l', 'u', 'i', 'd', 'x', 'e', 'r', 'c', 'm', 'M', '.']:
screen.selection_mode = True

# Navigation:
Expand Down Expand Up @@ -249,23 +255,29 @@ def control_daily_screen(stdscr, screen, user_events, importer):
user_events.rename_item(item_id, new_name)

# Move event:
if screen.key == 'm':
number = input_integer(stdscr, screen.y_max-2, 0, MSG_EVENT_MOVE)
if screen.key in ['m', 'M']:
number = input_integer(stdscr, screen.y_max-2, 0, MSG_EVENT_MV)
if user_events.filter_events_that_day(screen).is_valid_number(number):
item_id = user_events.filter_events_that_day(screen).items[number].item_id
clear_line(stdscr, screen.y_max-2)
question = f'{MSG_EVENT_MOVE_TO}{screen.year}/{screen.month}/'
day = input_day(stdscr, screen.y_max-2, 0, question)
if screen.is_valid_day(day):
user_events.change_day(item_id, day)
if screen.key == 'm':
year, month, day = input_date(stdscr, screen.y_max-2, 0, MSG_EVENT_MV_TO)
if screen.is_valid_date(year, month, day):
user_events.change_date(event_id, year, month, day)

if screen.key == 'M':
question = f'{MSG_EVENT_MV_TO_D}{screen.year}/{screen.month}/'
day = input_day(stdscr, screen.y_max-2, 0, question)
if screen.is_valid_day(day):
user_events.change_day(event_id, day)

# Otherwise, we check for user input:
else:
# Wait for user to press a key:
screen.key = stdscr.getkey()

# If we need to select an event, change to selection mode:
if screen.key in ['h', 'l', 'u', 'i', 'd', 'x', 'e', 'r', 'c', 'm', '.']:
if screen.key in ['h', 'l', 'u', 'i', 'd', 'x', 'e', 'r', 'c', 'm', 'M', '.']:
screen.selection_mode = True

# Navigation:
Expand Down
11 changes: 10 additions & 1 deletion calcure/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,22 @@ def event_exists(self, new_event):
return False

def change_day(self, selected_item_id, new_day):
"""Move an event to another day"""
"""Move an event to another day within this month"""
for item in self.items:
if item.item_id == selected_item_id:
item.day = new_day
self.changed = True
break

def change_date(self, selected_item_id, new_year, new_month, new_day):
"""Move an event to another date"""
for item in self.items:
if item.item_id == selected_item_id:
item.year = new_year
item.month = new_month
item.day = new_day
self.changed = True
break

class Birthdays(Events):
"""List of birthdays imported from abook"""
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/br.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "Mês (dia) anterior",
" x ": "Deletar um evento",
" r ": "Editar um evento",
" m ": "Mover evento",
" m(M) ": "Mover evento",
" v ": "Alternar visualização diária/mensal",
" g(G) ": "Ir para dia específico",
" h ": "Alternar evento como alta prioridade",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Deleta evento número: "
MSG_EVENT_REN = "Renomeia evento número: "
MSG_NEW_TITLE = "Digitar novo título: "
MSG_EVENT_MOVE = "Move evento número: "
MSG_EVENT_MOVE_TO = "Mover evento para: "
MSG_EVENT_MV = "Move evento número: "
MSG_EVENT_MV_TO = "Mover evento para (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Mover evento para: "
MSG_EVENT_DATE = "Digitar data: "
MSG_EVENT_TITLE = "Digitar título: "
MSG_EVENT_REP = "Repetir evento quantas vezes: "
Expand Down
9 changes: 5 additions & 4 deletions calcure/translations/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
" p,🠐 ": "Previous month (day)",
" x ": "Delete an event",
" r ": "Rename an event",
" m ": "Move event",
" g(G) ": "Go to a certain day",
" m(M) ": "Move event (in this month)",
" g(G) ": "Go to a certain day (in this month)",
" v ": "Toggle daily/monthly view",
" h ": "Toggle event as high priority",
" l ": "Toggle event as low priority",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Delete event number: "
MSG_EVENT_REN = "Rename event number: "
MSG_NEW_TITLE = "Enter new title: "
MSG_EVENT_MOVE = "Move event number: "
MSG_EVENT_MOVE_TO = "Move event to: "
MSG_EVENT_MV = "Move event number: "
MSG_EVENT_MV_TO = "Move event to (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Move event to: "
MSG_EVENT_DATE = "Enter date: "
MSG_EVENT_TITLE = "Enter title: "
MSG_EVENT_REP = "How many times repeat the event: "
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "mois (jour) précédent",
" d,x ": "Supprimer un événement",
" r ": "Modifier un événement",
" m ": "Déplacer l'événement",
" m(M) ": "Déplacer l'événement",
" v ": "Basculer la vue quotidienne/mensuelle",
" g(G) ": "Aller à un certain jour",
" h ": "Désactiver l'événement en haute priorité",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Supprimer l'événement numéro: "
MSG_EVENT_REN = "Renommer l'événement numéro: "
MSG_NEW_TITLE = "Entrez un nouveau titre: "
MSG_EVENT_MOVE = "Déplacer l'événement numéro: "
MSG_EVENT_MOVE_TO = "Déplacer l'événement vers: "
MSG_EVENT_MV = "Déplacer l'événement numéro: "
MSG_EVENT_MV_TO = "Déplacer l'événement vers (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Déplacer l'événement vers: "
MSG_EVENT_DATE = "Entrez la date: "
MSG_EVENT_TITLE = "Entrez le titre: "
MSG_EVENT_REP = "Combien de répétitions de l'événement: "
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/it.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "Mese precedente (giorno)",
" x ": "Cancella un evento",
" r ": "Modifica un evento",
" m ": "Sposta un evento",
" m(M) ": "Sposta un evento",
" v ": "Alterna la visualizzazione giornaliera/mensile",
" g(G) ": "Vai ad un determinato giorno",
" h ": "Imposta un evento come ad alta priorità",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Cancella l'evento con numero: "
MSG_EVENT_REN = "Rinomina l'evento con numero: "
MSG_NEW_TITLE = "Inserisci il nuovo titolo: "
MSG_EVENT_MOVE = "Sposta l'evento con numero: "
MSG_EVENT_MOVE_TO = "Postponi l'evento a: "
MSG_EVENT_MV = "Sposta l'evento con numero: "
MSG_EVENT_MV_TO = "Postponi l'evento a (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Postponi l'evento a: "
MSG_EVENT_DATE = "Inserisci una data: "
MSG_EVENT_TITLE = "Inserisci un titolo: "
MSG_EVENT_REP = "Quante volte vuoi ripetere l'evento: "
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "Предыдущий месяц (день)",
" x ": "Удалить событие",
" r ": "Переименовать событие",
" m ": "Переместить событие",
" m(M) ": "Переместить событие",
" v ": "Переключать дневной/месячный вид",
" g(G) ": "Открыть определённый день",
" h ": "Переключать высокий приоритет",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Удалить событие номер: "
MSG_EVENT_REN = "Переименовать событие номер: "
MSG_NEW_TITLE = "Введите новое название: "
MSG_EVENT_MOVE = "Переместить событие номер: "
MSG_EVENT_MOVE_TO = "Переместить событие на: "
MSG_EVENT_MV = "Переместить событие номер: "
MSG_EVENT_MV_TO = "Переместить событие на (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Переместить событие на: "
MSG_EVENT_DATE = "Введите дату: "
MSG_EVENT_TITLE = "Введите название: "
MSG_EVENT_REP = "Сколько раз повторить событие: "
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/tr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "Önceki ay (gün)",
" x ": "Etkinlik silme",
" e,r ": "Etkinlik düzenleme",
" m ": "Etkinlik taşıma",
" m(M) ": "Etkinlik taşıma",
" g(G) ": "Belirli bir güne git",
" v ": "Günlük/aylık görünümü değiştir",
" h ": "Etkinliği yüksek öncelikli olarak değiştir",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "Etkinlik numarasını sil: "
MSG_EVENT_REN = "Etkinlik numarasını yeniden adlandır: "
MSG_NEW_TITLE = "Yeni başlık girin: "
MSG_EVENT_MOVE = "Etkinlik numarasını taşı: "
MSG_EVENT_MOVE_TO = "Etkinliği şuraya taşı: "
MSG_EVENT_MV = "Etkinlik numarasını taşı: "
MSG_EVENT_MV_TO = "Etkinliği şuraya taşı (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "Etkinliği şuraya taşı: "
MSG_EVENT_DATE = "Tarih girin: "
MSG_EVENT_TITLE = "Başlığı girin: "
MSG_EVENT_REP = "Etkinliğin kaç kez tekrarlanacağı: "
Expand Down
7 changes: 4 additions & 3 deletions calcure/translations/zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" p,🠐 ": "上个月 (日)",
" x ": "删除事件",
" r ": "编辑事件",
" m ": "移动事件",
" m(M) ": "移动事件",
" g ": "跳转到指定的一天",
" v ": "切换每天/每月视图模式",
" h ": "切换事件为更高的优先级",
Expand Down Expand Up @@ -64,8 +64,9 @@
MSG_EVENT_DEL = "删除事件的号码: "
MSG_EVENT_REN = "重命名事件的号码: "
MSG_NEW_TITLE = "输入新的标题: "
MSG_EVENT_MOVE = "移动事件的号码: "
MSG_EVENT_MOVE_TO = "移动事件到: "
MSG_EVENT_MV = "移动事件的号码: "
MSG_EVENT_MV_TO = "移动事件到 (YYYY/MM/DD): "
MSG_EVENT_MV_TO_D = "移动事件到: "
MSG_EVENT_DATE = "输入日期: "
MSG_EVENT_TITLE = "输入标题: "
MSG_EVENT_REP = "事件重复多少次: "
Expand Down

0 comments on commit df1cdc9

Please sign in to comment.