ctrl+click now on different message.
Will have to change these stuff, probably composition over inheritance
This commit is contained in:
parent
7e3fa499f8
commit
20ffe570f4
|
@ -1,5 +1,7 @@
|
|||
from model import Translation, Sense, Example
|
||||
from message.simple_messages import ClickMessage
|
||||
from view import modals
|
||||
from browser import document
|
||||
|
||||
|
||||
class ShowMenu(ClickMessage):
|
||||
|
@ -10,6 +12,34 @@ class ShowMenu(ClickMessage):
|
|||
super().on_event(event)
|
||||
|
||||
|
||||
# Special message to handle ctrl+click, shift+click and click
|
||||
# overwrite update_model_default/ctrl/shift
|
||||
class KeyPlusClickMessage(ShowMenu):
|
||||
def on_event(self, event):
|
||||
super().on_event(event)
|
||||
self.ctrl = event.ctrlKey
|
||||
self.shift = event.shiftKey
|
||||
|
||||
def update_model(self, model):
|
||||
if self.ctrl:
|
||||
self.update_model_ctrl(model)
|
||||
elif self.shift:
|
||||
document.getSelection().removeAllRanges()
|
||||
self.update_model_shift(model)
|
||||
else:
|
||||
self.update_model_default(model)
|
||||
|
||||
def update_model_ctrl(self, model):
|
||||
pass
|
||||
|
||||
def update_model_shift(self, model):
|
||||
pass
|
||||
|
||||
def update_model_default(self, model):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ShowTranslationMenu(ShowMenu):
|
||||
def update_model(self, model):
|
||||
model.menu_location = self.menu_location
|
||||
|
@ -24,8 +54,46 @@ class ShowSenseMenu(ShowMenu):
|
|||
model.menu_target = sense
|
||||
|
||||
|
||||
class ShowExampleMenu(ShowMenu):
|
||||
def update_model(self, model):
|
||||
model.menu_location = self.menu_location
|
||||
class ShowExampleMenu(KeyPlusClickMessage):
|
||||
def update_model_default(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
model.menu_target = example
|
||||
|
||||
# if some are chosen, then show modal for choosing senses
|
||||
if len(model.chosen_examples) > 0 and example in model.chosen_examples:
|
||||
chosen_examples = model.chosen_examples
|
||||
model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model.entry))
|
||||
else:
|
||||
model.menu_location = self.menu_location
|
||||
model.menu_target = example
|
||||
|
||||
def update_model_ctrl(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
|
||||
if example in model.chosen_examples:
|
||||
model.chosen_examples.remove(example)
|
||||
else:
|
||||
model.chosen_examples.append(example)
|
||||
|
||||
def update_model_shift(self, model):
|
||||
first_example = self.get_arg(0, Example)
|
||||
last_example = model.chosen_examples[model.chosen_examples.length - 1]
|
||||
adding = False
|
||||
|
||||
# logic to add all senses between these two
|
||||
for sense in model.entry.senses:
|
||||
for example in sense.examples:
|
||||
match = example in (first_example, last_example)
|
||||
|
||||
if adding and match:
|
||||
adding = False
|
||||
elif match:
|
||||
adding = True
|
||||
elif not adding:
|
||||
continue
|
||||
|
||||
if example not in model.chosen_examples:
|
||||
model.chosen_examples.append(example)
|
||||
|
||||
def reset(self):
|
||||
# special case, when choosing messages dont reset
|
||||
return not (self.ctrl or self.shift)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from message.message import Message
|
||||
from message.translation_edit import AddTranslation, EditTranslation
|
||||
from message.simple_messages import ClickMessage, KeyPlusClickMessage
|
||||
from message.simple_messages import ClickMessage
|
||||
|
||||
from model import Example, Sense, Translation
|
||||
from view import modals
|
||||
|
@ -37,49 +37,11 @@ class ShowRelatedEntriesEdit(ClickMessage):
|
|||
model.modal_set(lambda: modals.edit_related_entries(model.entry))
|
||||
|
||||
|
||||
class ShowExampleEdit(KeyPlusClickMessage):
|
||||
class ShowExampleEdit(ClickMessage):
|
||||
def update_model_default(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
example.make_copy()
|
||||
|
||||
# if some are chosen, then show modal for choosing senses
|
||||
if len(model.chosen_examples) > 0 and example in model.chosen_examples:
|
||||
chosen_examples = model.chosen_examples
|
||||
model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model.entry))
|
||||
else:
|
||||
model.modal_set(lambda: modals.edit_example(example))
|
||||
|
||||
def update_model_ctrl(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
|
||||
if example in model.chosen_examples:
|
||||
model.chosen_examples.remove(example)
|
||||
else:
|
||||
model.chosen_examples.append(example)
|
||||
|
||||
def update_model_shift(self, model):
|
||||
first_example = self.get_arg(0, Example)
|
||||
last_example = model.chosen_examples[model.chosen_examples.length - 1]
|
||||
adding = False
|
||||
|
||||
# logic to add all senses between these two
|
||||
for sense in model.entry.senses:
|
||||
for example in sense.examples:
|
||||
match = example in (first_example, last_example)
|
||||
|
||||
if adding and match:
|
||||
adding = False
|
||||
elif match:
|
||||
adding = True
|
||||
elif not adding:
|
||||
continue
|
||||
|
||||
if example not in model.chosen_examples:
|
||||
model.chosen_examples.append(example)
|
||||
|
||||
def reset(self):
|
||||
# special case, when choosing messages dont reset
|
||||
return not (self.ctrl or self.shift)
|
||||
model.modal_set(lambda: modals.edit_example(example))
|
||||
|
||||
|
||||
class ShowEditTranslation(ClickMessage):
|
||||
|
|
|
@ -68,30 +68,4 @@ class ModalNotOkClose(Reset):
|
|||
return False
|
||||
|
||||
|
||||
# Special message to handle ctrl+click, shift+click and click
|
||||
# overwrite update_model_default/ctrl/shift
|
||||
class KeyPlusClickMessage(ClickMessage):
|
||||
def on_event(self, event):
|
||||
super().on_event(event)
|
||||
self.ctrl = event.ctrlKey
|
||||
self.shift = event.shiftKey
|
||||
|
||||
def update_model(self, model):
|
||||
if self.ctrl:
|
||||
self.update_model_ctrl(model)
|
||||
elif self.shift:
|
||||
document.getSelection().removeAllRanges()
|
||||
self.update_model_shift(model)
|
||||
else:
|
||||
self.update_model_default(model)
|
||||
|
||||
def update_model_ctrl(self, model):
|
||||
pass
|
||||
|
||||
def update_model_shift(self, model):
|
||||
pass
|
||||
|
||||
def update_model_default(self, model):
|
||||
pass
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user