Adding shift+click to example selection

This commit is contained in:
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.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 view import modals
@@ -31,8 +31,8 @@ class ShowVariantsEdit(ClickMessage):
model.modal_set(lambda: modals.edit_variants(model.entry))
class ShowExampleEdit(CtrlClickMessage):
def update_model_noctrl(self, model):
class ShowExampleEdit(KeyPlusClickMessage):
def update_model_default(self, model):
example = self.get_arg(0, Example)
# if some are chosen, then show modal for choosing senses
@@ -49,10 +49,30 @@ class ShowExampleEdit(CtrlClickMessage):
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
return not (self.ctrl or self.shift)
class ShowExampleTranslationEdit(ClickMessage):
def update_model(self, model):