From 5f26dd603481bf2ca460741e121623e2eec21891 Mon Sep 17 00:00:00 2001 From: matic_t Date: Mon, 5 Oct 2020 06:54:01 -0700 Subject: [PATCH] Should be finished v2 --- src/export.py | 12 +++++++++++- src/message/__init__.py | 2 +- src/message/show_menu.py | 16 ++++++++++++--- src/message/simple_edits.py | 2 +- src/view/modals.py | 39 +++++++++++++++++++++++++++++++++++-- src/view/view.py | 2 +- 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/export.py b/src/export.py index ea70b3f..8308e98 100644 --- a/src/export.py +++ b/src/export.py @@ -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("", "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 \ No newline at end of file diff --git a/src/message/__init__.py b/src/message/__init__.py index 81bafe6..805bc1a 100644 --- a/src/message/__init__.py +++ b/src/message/__init__.py @@ -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 diff --git a/src/message/show_menu.py b/src/message/show_menu.py index a80d0b9..1038dc3 100644 --- a/src/message/show_menu.py +++ b/src/message/show_menu.py @@ -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 diff --git a/src/message/simple_edits.py b/src/message/simple_edits.py index 927c819..6c4a9cc 100644 --- a/src/message/simple_edits.py +++ b/src/message/simple_edits.py @@ -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) diff --git a/src/view/modals.py b/src/view/modals.py index b8cccc6..e3c9850 100644 --- a/src/view/modals.py +++ b/src/view/modals.py @@ -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): diff --git a/src/view/view.py b/src/view/view.py index 083901a..7ebbb4a 100644 --- a/src/view/view.py +++ b/src/view/view.py @@ -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: