Should be finished v2
This commit is contained in:
parent
5e741343c3
commit
5f26dd6034
|
@ -201,7 +201,7 @@ def _original_xml_query_selector(selector, entry, doc, parent_selector = selecto
|
|||
entry.original_xml.querySelector(parent_selector).appendChild(query)
|
||||
return query
|
||||
|
||||
def export_example_to_entry_xml(example):
|
||||
def export_example_to_entry_xml(example, other_examples = None):
|
||||
parser = __new__(DOMParser())
|
||||
doc = parser.parseFromString("<entry />", "text/xml")
|
||||
entry_xml = doc.firstChild
|
||||
|
@ -321,5 +321,15 @@ def export_example_to_entry_xml(example):
|
|||
|
||||
example.translations[0] = example.translations[0][1:] if len(example.translations) > 0 and len(example.translations[0]) > 0 else example.translations[0]
|
||||
export_translation_list(doc, example, translation_container_list)
|
||||
if other_examples is not None:
|
||||
example_container_list = doc.createElement("exampleContainerList")
|
||||
sense.appendChild(example_container_list)
|
||||
|
||||
for example in other_examples:
|
||||
example_container = example.export(doc)
|
||||
translation_container_list = doc.createElement("translationContainerList")
|
||||
export_translation_list(doc, example, translation_container_list)
|
||||
example_container.appendChild(translation_container_list)
|
||||
example_container_list.appendChild(example_container)
|
||||
|
||||
return doc
|
|
@ -1,7 +1,7 @@
|
|||
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress, NoAction
|
||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowHomonymyEdit, ShowRelatedEntriesEdit
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, MoveExamplesToSense, AddToLabelList, AddToGenericList, EditVariants, EditHomonymy, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit, ExampleClusterAdd
|
||||
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
|
||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin, AddMultiwordExample
|
||||
from message.example_edit import ExampleAsNewEntry, ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentSpace, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples, ToggleClusters
|
||||
|
|
|
@ -57,11 +57,21 @@ class ShowSenseMenu(ShowMenu):
|
|||
class ShowExampleMenu(KeyPlusClickMessage):
|
||||
def update_model_default(self, model):
|
||||
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 actions
|
||||
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))
|
||||
multiword_example = False
|
||||
|
||||
for chosen_example in chosen_examples:
|
||||
if chosen_example.is_multiword():
|
||||
if multiword_example is False:
|
||||
multiword_example = chosen_example
|
||||
else:
|
||||
multiword_example = False
|
||||
break
|
||||
|
||||
model.modal_set(lambda: modals.do_chosen_examples(chosen_examples, model, multiword_example))
|
||||
else:
|
||||
model.menu_location = self.menu_location
|
||||
model.menu_target = example
|
||||
|
|
|
@ -58,7 +58,7 @@ class EditComment(QuestionMessage):
|
|||
model.entry.comment = self.new_text
|
||||
|
||||
|
||||
class DoChosenExamples(Message):
|
||||
class MoveExamplesToSense(Message):
|
||||
def update_model(self, model):
|
||||
chosen_examples = self.get_arg(0, list)
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@ from lib.snabbdom import h
|
|||
import message
|
||||
from view.modal_templates import *
|
||||
from view.utils import show_toggle_cluster_buttons
|
||||
from export import export_to_xml, export_example_to_entry_xml
|
||||
from update import update
|
||||
from model.entry import Entry
|
||||
import lib.screenful as screenful
|
||||
from model.model import Model
|
||||
import model
|
||||
|
||||
|
||||
|
@ -127,7 +132,37 @@ def edit_comment(comment):
|
|||
return modal_template(big_question("Edit comment", comment), "Comment", (message.EditComment,), (message.DeleteComment,))
|
||||
|
||||
|
||||
def do_chosen_examples(example_list, entry):
|
||||
def do_chosen_examples(example_list, model, multiword_example):
|
||||
if multiword_example is False:
|
||||
return move_examples_to_sense(example_list, model.entry)
|
||||
else:
|
||||
return modal_template([
|
||||
h("button.shyButton", {"on": {"click": (lambda: move_to_view(example_list, model))}}, "Premakni v pomen"),
|
||||
h("button.shyButton", {"on": {"click": (lambda: export_to_new_entry())}},
|
||||
"Izvozi v novo geslo")], "Izberite željeno akcijo", None)
|
||||
|
||||
|
||||
def move_to_view(example_list, model):
|
||||
model.modal_reset()
|
||||
model.modal_set(lambda: move_examples_to_sense(example_list, model.entry))
|
||||
update.view.view(model, True)
|
||||
|
||||
|
||||
def export_to_new_entry(multiword_example, example_list):
|
||||
other_examples = []
|
||||
for example in example_list:
|
||||
if example.is_multiword() is False:
|
||||
other_examples.append(example)
|
||||
entry_xml = export_example_to_entry_xml(multiword_example, other_examples if len(example_list) > 0 else None)
|
||||
new_entry = Entry()
|
||||
new_entry.import_xml(entry_xml)
|
||||
|
||||
new_model = Model()
|
||||
new_model.entry = new_entry
|
||||
screenful.screenful().Editor['new'](None, export_to_xml(new_model))
|
||||
|
||||
|
||||
def move_examples_to_sense(example_list, entry):
|
||||
example_senses = []
|
||||
for idx, sense in enumerate(entry.senses):
|
||||
for ex in sense.examples:
|
||||
|
@ -150,7 +185,7 @@ def do_chosen_examples(example_list, entry):
|
|||
options.append(h("label.checkable", {"attrs": {"for": id_}}, text))
|
||||
options.append(h("br", {}, []))
|
||||
|
||||
return modal_template(options, "Examples picker", (message.DoChosenExamples, example_list))
|
||||
return modal_template(options, "Examples picker", (message.MoveExamplesToSense, example_list))
|
||||
|
||||
|
||||
def ske_list(search_term, data, page_num, senses, ske_kinds):
|
||||
|
|
|
@ -105,7 +105,7 @@ class View:
|
|||
h("button.shyButton", { "on": {"click": msg(ExampleBin, example)}}, "🗑")]
|
||||
|
||||
if example.is_multiword():
|
||||
dom_children.insert(1, h("button.shyButton", { "on": {"click": msg(ExampleAsNewEntry, example, sense)}}, "As new Entry"))
|
||||
dom_children.insert(1, h("button.shyButton", { "on": {"click": msg(ExampleAsNewEntry, example, sense)}}, "Izvozi v novo geslo"))
|
||||
|
||||
return h("span.popup-menu", { "style": style }, dom_children)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user