Adding shift+click to example selection

This commit is contained in:
Ozbolt Menegatti 2020-01-14 22:16:47 +01:00
parent f8bc2f0d22
commit 575345f98f
2 changed files with 36 additions and 9 deletions

View File

@ -1,6 +1,6 @@
from message.message import Message from message.message import Message
from message.translation_edit import AddTranslation, EditTranslation from message.translation_edit import AddTranslation, EditTranslation
from message.simple_messages import ClickMessage, CtrlClickMessage from message.simple_messages import ClickMessage, KeyPlusClickMessage
from model import Example, Sense, Translation from model import Example, Sense, Translation
from view import modals from view import modals
@ -31,8 +31,8 @@ class ShowVariantsEdit(ClickMessage):
model.modal_set(lambda: modals.edit_variants(model.entry)) model.modal_set(lambda: modals.edit_variants(model.entry))
class ShowExampleEdit(CtrlClickMessage): class ShowExampleEdit(KeyPlusClickMessage):
def update_model_noctrl(self, model): def update_model_default(self, model):
example = self.get_arg(0, Example) example = self.get_arg(0, Example)
# if some are chosen, then show modal for choosing senses # if some are chosen, then show modal for choosing senses
@ -50,9 +50,29 @@ class ShowExampleEdit(CtrlClickMessage):
else: else:
model.chosen_examples.append(example) 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): def reset(self):
# special case, when choosing messages dont reset # special case, when choosing messages dont reset
return not self.ctrl return not (self.ctrl or self.shift)
class ShowExampleTranslationEdit(ClickMessage): class ShowExampleTranslationEdit(ClickMessage):
def update_model(self, model): def update_model(self, model):

View File

@ -68,23 +68,30 @@ class ModalNotOkClose(Reset):
return False return False
# Special message to handle ctrl+click and click # Special message to handle ctrl+click, shift+click and click
# overwrite update_model_noctrl and/or update_model_ctrl # overwrite update_model_default/ctrl/shift
class CtrlClickMessage(ClickMessage): class KeyPlusClickMessage(ClickMessage):
def on_event(self, event): def on_event(self, event):
super().on_event(event) super().on_event(event)
self.ctrl = event.ctrlKey self.ctrl = event.ctrlKey
self.shift = event.shiftKey
def update_model(self, model): def update_model(self, model):
if self.ctrl: if self.ctrl:
self.update_model_ctrl(model) self.update_model_ctrl(model)
elif self.shift:
document.getSelection().removeAllRanges()
self.update_model_shift(model)
else: else:
self.update_model_noctrl(model) self.update_model_default(model)
def update_model_ctrl(self, model): def update_model_ctrl(self, model):
pass pass
def update_model_noctrl(self, model): def update_model_shift(self, model):
pass
def update_model_default(self, model):
pass pass