adding of multiword examples, still some cleanup to do.
This commit is contained in:
parent
fcd6f158a1
commit
887eb37d20
|
@ -3,11 +3,11 @@ from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTr
|
|||
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
||||
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
|
||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample
|
||||
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters
|
||||
from message.delete_messages import DeleteComment, DeleteVariants, DeleteRelatedEntries, DeleteEntryLabels
|
||||
from message.ske_messages import ShowSkeModal, SearchInSkeModal, SkeInsert
|
||||
|
||||
from message.message import msg
|
||||
from message.message import msg, delayed_msg
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ from browser import document
|
|||
from message.simple_messages import DataChgClickMessage, ClickMessage, NoReset
|
||||
from message.message import Message
|
||||
from model.example import Example, ComponentLexeme
|
||||
from model.sense import Sense
|
||||
|
||||
|
||||
|
||||
|
@ -48,14 +49,22 @@ class ExampleBin(DataChgClickMessage):
|
|||
class EditExampleText(Message):
|
||||
def update_model(self, model):
|
||||
example = self.get_arg(0, Example)
|
||||
sense = self.get_arg(1, Sense)
|
||||
|
||||
example.overwrite_with_copy()
|
||||
example.edited = True
|
||||
|
||||
# if this was a newly created example, now we can add it to the sense
|
||||
# easier to add here than to add before editing and checking if the user
|
||||
# canceled the operation
|
||||
if example.newly_created:
|
||||
example.newly_created = False
|
||||
sense.examples.append(example)
|
||||
|
||||
idx = 0
|
||||
for txt in document.getElementsByClassName("example-component-text"):
|
||||
example.components[idx].text = txt.value
|
||||
idx += 1
|
||||
|
||||
|
||||
class ExampleRoleChange(NoReset):
|
||||
def update_model(self, model):
|
||||
|
|
|
@ -54,3 +54,7 @@ def msg(message_class, *params):
|
|||
message.on_event(event)
|
||||
update.update_model(message)
|
||||
return callback
|
||||
|
||||
|
||||
def delayed_msg(message_class, event, timeout_ms, *params):
|
||||
window.setTimeout(lambda: msg(message_class, *params)(event), timeout_ms)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from message.simple_messages import DataChgClickMessage
|
||||
from message.message import delayed_msg
|
||||
from message.show_messages import ShowExampleEdit
|
||||
from model import Sense
|
||||
from model import Example
|
||||
|
||||
|
||||
def _get_sense_idx(sense, model):
|
||||
|
@ -38,3 +41,18 @@ class SenseBin(DataChgClickMessage):
|
|||
|
||||
assert(sidx >= 0)
|
||||
model.entry.senses.splice(sidx, 1)
|
||||
|
||||
|
||||
class AddMultiwordExample(DataChgClickMessage):
|
||||
def on_event(self, event):
|
||||
super().on_event(event)
|
||||
self.event_copy = event
|
||||
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
new_example = Example.new_multiword()
|
||||
|
||||
# open up an edit example dialog
|
||||
delayed_msg(ShowExampleEdit, self.event_copy, 0, new_example, sense)
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from browser import window, document
|
||||
from message.message import Message, msg
|
||||
from message.message import Message, msg, delayed_msg
|
||||
|
||||
|
||||
# click messages stuff
|
||||
|
@ -78,8 +78,8 @@ class _ModalResetDelayed(Message):
|
|||
|
||||
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)
|
||||
# modal reset should be called a bit later for shoother transition
|
||||
delayed_msg(_ModalResetDelayed, None, 100)
|
||||
|
||||
def data_change(self):
|
||||
return False
|
||||
|
|
|
@ -8,6 +8,7 @@ from view.utils import show_toggle_cluster_buttons
|
|||
from model.example.component_lexeme import ComponentLexeme
|
||||
from model.example.corpus_example import CorpusExample
|
||||
from model.example.multiword_example import MultiwordExample
|
||||
from model.example_clusters import ExampleClusters
|
||||
|
||||
|
||||
class Example(Data):
|
||||
|
@ -16,12 +17,27 @@ class Example(Data):
|
|||
self.inner = None
|
||||
self.components = []
|
||||
self.edited = False
|
||||
self.newly_created = False
|
||||
|
||||
# removes space from last component if multiword example
|
||||
def check_multiword_components(self):
|
||||
if self.is_multiword():
|
||||
self.components[len(self.components) - 1].no_space = ComponentLexeme.LAST_COMPONENT_SPACE
|
||||
|
||||
@staticmethod
|
||||
def new_multiword():
|
||||
example = Example()
|
||||
example.newly_created = True
|
||||
example.edited = True
|
||||
example.inner = MultiwordExample()
|
||||
example.inner.cluster = ExampleClusters.first_empty_cluster()
|
||||
example.inner.type = "type??"
|
||||
|
||||
empty_component = ComponentLexeme()
|
||||
empty_component.role = "headword"
|
||||
example.components.append(empty_component)
|
||||
|
||||
return example
|
||||
|
||||
def import_xml(self, example_xml):
|
||||
self.translations = from_container_list(example_xml.querySelectorAll("translationContainer"))
|
||||
|
|
|
@ -89,7 +89,8 @@ def edit_example(example, sense):
|
|||
h("div.three-fifth", {}, middle),
|
||||
h("div.one-fifth", {}, list_of_right_buttons(idx, component))]))
|
||||
|
||||
return modal_template(divs, "Edit Example", (message.EditExampleText, example_original))
|
||||
return modal_template(divs, "Edit Example",
|
||||
(message.EditExampleText, example_original, sense))
|
||||
|
||||
|
||||
def edit_variants(entry):
|
||||
|
|
|
@ -92,6 +92,7 @@ class View:
|
|||
return h("span.popup-menu", { "style": style }, [
|
||||
h("button.shyButton", { "on": {"click": msg(SenseMoveUp, sense)}}, "↑"),
|
||||
h("button.shyButton", { "on": {"click": msg(SenseMoveDown, sense)}}, "↓"),
|
||||
h("button.shyButton", { "on": {"click": msg(AddMultiwordExample, sense)}}, "+"),
|
||||
h("button.shyButton", { "on": {"click": msg(SenseBin, sense)}}, "🗑")])
|
||||
|
||||
elif type(menu_target) is Example:
|
||||
|
|
Loading…
Reference in New Issue
Block a user