Example move up, down, bin via menu.
This commit is contained in:
parent
513cffbbd9
commit
420f48634d
|
@ -163,7 +163,7 @@
|
|||
margin-right: 1em;
|
||||
}
|
||||
|
||||
.example-dot, .example-text {
|
||||
.example-text {
|
||||
._hoverable();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, Show
|
|||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels
|
||||
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
|
||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
||||
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin
|
||||
from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels
|
||||
|
||||
from message.message import msg
|
||||
|
|
44
src/message/example_edit.py
Normal file
44
src/message/example_edit.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
from message.simple_messages import DataChgClickMessage
|
||||
from model import Example
|
||||
|
||||
|
||||
def _get_example_idx(example, model):
|
||||
for sense in model.entry.senses:
|
||||
for eidx, e in enumerate(sense.examples):
|
||||
if e == example:
|
||||
return (sense, eidx)
|
||||
|
||||
|
||||
class ExampleMoveUp(DataChgClickMessage):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
sense, idx = _get_example_idx(example, model)
|
||||
|
||||
assert(idx >= 0)
|
||||
if idx == 0:
|
||||
return
|
||||
|
||||
sense.examples[idx], sense.examples[idx - 1] = sense.examples[idx - 1], sense.examples[idx]
|
||||
|
||||
|
||||
class ExampleMoveDown(DataChgClickMessage):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
sense, idx = _get_example_idx(example, model)
|
||||
|
||||
assert(idx >= 0)
|
||||
if idx == len(sense.examples) - 1:
|
||||
return
|
||||
|
||||
sense.examples[idx], sense.examples[idx + 1] = sense.examples[idx + 1], sense.examples[idx]
|
||||
|
||||
|
||||
class ExampleBin(DataChgClickMessage):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
sense, idx = _get_example_idx(example, model)
|
||||
|
||||
assert(idx >= 0)
|
||||
sense.examples.splice(idx, 1)
|
||||
|
|
@ -42,7 +42,6 @@ class AddToLabelList(NoReset):
|
|||
class EditExampleTranslation(QuestionMessage):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
example.translations = common_accessors.generic_list_getter()
|
||||
example.text = self.new_text
|
||||
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ def edit_sense_label(sense):
|
|||
|
||||
def edit_example(example):
|
||||
content = question("Edit example", example.text)
|
||||
etl_getter = lambda: example.copy().translations
|
||||
content.extend(generic_list_editor("Edit example translations", etl_getter))
|
||||
|
||||
return modal_template(content, "Edit Example", message.EditExampleTranslation(example))
|
||||
|
||||
|
||||
|
|
|
@ -106,9 +106,9 @@ class View:
|
|||
example_tag += ".example-chosen"
|
||||
|
||||
return h("div.example", {}, [
|
||||
h("div.example-dot", {"on": {"click": msg(ShowExampleMenu(example))} }, "▣"),
|
||||
h("div.example-dot", {}, "▣"),
|
||||
h(example_tag, {}, [
|
||||
h("span.example-text", {"on": {"click": msg(ShowExampleEdit(example))}}, example.text),
|
||||
h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example.text),
|
||||
h("div.example-translation-list", {}, [
|
||||
h("div.example-translation", {}, [
|
||||
h("span.example-arrow", {}, "↪"),
|
||||
|
@ -171,10 +171,12 @@ class View:
|
|||
h("button.shyButton", { "on": {"click": msg(SenseBin(sense))}}, "🗑")])
|
||||
|
||||
elif type(menu_target) is Example:
|
||||
example = menu_target
|
||||
return h("span.popup-menu", { "style": style }, [
|
||||
h("button.shyButton", {}, "a"),
|
||||
h("button.shyButton", {}, "b"),
|
||||
h("button.shyButton", {}, "🗑")])
|
||||
h("button.shyButton", { "on": {"click": msg(ShowExampleEdit(example))}}, "✎"),
|
||||
h("button.shyButton", { "on": {"click": msg(ExampleMoveUp(example))}}, "↑"),
|
||||
h("button.shyButton", { "on": {"click": msg(ExampleMoveDown(example))}}, "↓"),
|
||||
h("button.shyButton", { "on": {"click": msg(ExampleBin(example))}}, "🗑")])
|
||||
else:
|
||||
console.log("Should not be heree!!")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user