Adding data_change to use to signal to Screenful that save button nedds a litle star

pull/1/head
Ozbolt Menegatti 4 years ago
parent 9f16aa999b
commit 1f038e177a

@ -0,0 +1,15 @@
from browser import window
# interface to screenful
class ScreenfulEmptyShell:
def __init__(self):
func = lambda: None
self.Editor = {"changed": func}
def screenful():
return window.Screenful if window.Screenful else ScreenfulEmptyShell()
def changed():
console.log(Screenful, window.Screenful)
screenful().Editor.changed();

@ -25,6 +25,9 @@ class Message:
return result
def data_change(self):
return True
def add_arg(self, arg):
self._args.append(arg)
@ -35,6 +38,9 @@ class Message:
class ClickMessage(Message):
def on_event(self, event):
event.stopPropagation()
def data_change(self):
return False
def msg(message, params):

@ -21,6 +21,9 @@ class AddToGenericList(NoReset):
def update_model(self, model):
list_getter = self.get_arg(0)
list_getter().append("")
def data_change(self):
return False
class AddToLabelList(NoReset):
@ -31,6 +34,9 @@ class AddToLabelList(NoReset):
# just adding to the copy to show in the modal
list_to_add_to.append(thing_to_add)
def data_change(self):
return False
class EditExampleTranslation(Message):

@ -19,11 +19,17 @@ class NoReset(Reset):
class _ModalResetDelayed(Message):
def update_model(self, model):
model.modal_reset()
def data_change(self):
return False
class ModalNotOkClose(Reset):
def update_model(self, model):
# msg just creates a callback, need to actually run it!
window.setTimeout(lambda: msg(_ModalResetDelayed())(None), 100)
def data_change(self):
return False

@ -12,8 +12,13 @@ def get_translation_location(entry, translation):
if search_translation == translation:
return (si, ci, ti), (sense, cluster)
class TranslationEditMessage(ClickMessage):
def data_change(self):
return True
class EditTranslation(ClickMessage):
class EditTranslation(TranslationEditMessage):
def update_model(self, model):
self.translation = self.get_arg(0, Translation)
self.old_cluster_idx = self.get_arg(1, int)
@ -60,7 +65,7 @@ class EditTranslation(ClickMessage):
sense.translations.splice(cidx, 1)
class MoveRight(ClickMessage):
class MoveRight(TranslationEditMessage):
def update_model(self, model):
translation = self.get_arg(0, Translation)
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
@ -69,7 +74,7 @@ class MoveRight(ClickMessage):
model.translation = None
class MoveLeft(ClickMessage):
class MoveLeft(TranslationEditMessage):
def update_model(self, model):
translation = self.get_arg(0, Translation)
(_, _, idx), (_, cluster) = get_translation_location(model.entry, translation)
@ -78,7 +83,7 @@ class MoveLeft(ClickMessage):
model.translation = None
class BinTranslation(ClickMessage):
class BinTranslation(TranslationEditMessage):
def update_model(self, model):
translation = self.get_arg(0, Translation)
(_, cidx, tidx), (sense, cluster) = get_translation_location(model.entry, translation)
@ -90,7 +95,7 @@ class BinTranslation(ClickMessage):
model.translation = None
class AddTranslation(EditTranslation):
class AddTranslation(TranslationEditMessage):
def handle_cluster_change(self, new_cluster_idx, _):
# we need to cheat here
# sense was actually given in constructor in third place

@ -1,3 +1,5 @@
import lib.screenful as screenful
class Update:
def __init__(self):
self.message_queue = []
@ -10,6 +12,10 @@ class Update:
if msg.reset():
self.model.reset()
break
for msg in self.message_queue:
if msg.data_change():
screenful.changed()
for msg in self.message_queue:
msg.update_model(self.model)

Loading…
Cancel
Save