Ejemplo n.º 1
0
    def onBridgeCmd(self, cmd: str) -> Any:
        if not self.note:
            # shutdown
            return

        # focus lost or key/button pressed?
        if cmd.startswith("blur") or cmd.startswith("key"):
            (type, ord_str, nid_str, txt) = cmd.split(":", 3)
            ord = int(ord_str)
            try:
                nid = int(nid_str)
            except ValueError:
                nid = 0
            if nid != self.note.id:
                print("ignored late blur")
                return

            self.note.fields[ord] = self.mungeHTML(txt)

            if not self.addMode:
                self._save_current_note()
            if type == "blur":
                self.currentField = None
                # run any filters
                if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
                    # something updated the note; update it after a subsequent focus
                    # event has had time to fire
                    self.mw.progress.timer(100, self.loadNoteKeepingFocus,
                                           False)
                else:
                    self._check_and_update_duplicate_display_async()
            else:
                gui_hooks.editor_did_fire_typing_timer(self.note)
                self._check_and_update_duplicate_display_async()

        # focused into field?
        elif cmd.startswith("focus"):
            (type, num) = cmd.split(":", 1)
            self.currentField = int(num)
            gui_hooks.editor_did_focus_field(self.note, self.currentField)

        elif cmd.startswith("toggleSticky"):
            (type, num) = cmd.split(":", 1)
            ord = int(num)

            model = self.note.note_type()
            fld = model["flds"][ord]
            new_state = not fld["sticky"]
            fld["sticky"] = new_state

            update_notetype_legacy(parent=self.mw,
                                   notetype=model).run_in_background()

            return new_state

        elif cmd in self._links:
            self._links[cmd](self)

        else:
            print("uncaught cmd", cmd)
Ejemplo n.º 2
0
    def onRename(self) -> None:
        nt = self.current_notetype()
        text, ok = getText(tr.actions_new_name(), default=nt["name"])
        if ok and text.strip():
            nt["name"] = text

            update_notetype_legacy(parent=self, notetype=nt).success(
                self.refresh_list).run_in_background()
Ejemplo n.º 3
0
    def accept(self) -> None:
        def on_done(changes: OpChanges) -> None:
            tooltip(tr.card_templates_changes_saved(), parent=self.parentWidget())
            self.cleanup()
            gui_hooks.sidebar_should_refresh_notetypes()
            QDialog.accept(self)

        update_notetype_legacy(parent=self, notetype=self.model).success(
            on_done
        ).run_in_background()
Ejemplo n.º 4
0
    def accept(self) -> None:
        self.saveField()

        def on_done(changes: OpChanges) -> None:
            tooltip(tr.card_templates_changes_saved(),
                    parent=self.parentWidget())
            QDialog.accept(self)

        update_notetype_legacy(
            parent=self.mw,
            notetype=self.model).success(on_done).run_in_background()
Ejemplo n.º 5
0
 def onAdvanced(self) -> None:
     nt = self.current_notetype()
     d = QDialog(self)
     disable_help_button(d)
     frm = aqt.forms.modelopts.Ui_Dialog()
     frm.setupUi(d)
     frm.latexsvg.setChecked(nt.get("latexsvg", False))
     frm.latexHeader.setText(nt["latexPre"])
     frm.latexFooter.setText(nt["latexPost"])
     d.setWindowTitle(
         without_unicode_isolation(tr.actions_options_for(val=nt["name"])))
     qconnect(frm.buttonBox.helpRequested, lambda: openHelp(HelpPage.LATEX))
     restoreGeom(d, "modelopts")
     gui_hooks.models_advanced_will_show(d)
     d.exec_()
     saveGeom(d, "modelopts")
     nt["latexsvg"] = frm.latexsvg.isChecked()
     nt["latexPre"] = str(frm.latexHeader.toPlainText())
     nt["latexPost"] = str(frm.latexFooter.toPlainText())
     update_notetype_legacy(parent=self, notetype=nt).success(
         self.refresh_list).run_in_background()
Ejemplo n.º 6
0
    def onBridgeCmd(self, cmd: str) -> Any:
        if not self.note:
            # shutdown
            return

        # focus lost or key/button pressed?
        if cmd.startswith("blur") or cmd.startswith("key"):
            (type, ord_str, nid_str, txt) = cmd.split(":", 3)
            ord = int(ord_str)
            try:
                nid = int(nid_str)
            except ValueError:
                nid = 0
            if nid != self.note.id:
                print("ignored late blur")
                return

            try:
                self.note.fields[ord] = self.mungeHTML(txt)
            except IndexError:
                print("ignored late blur after notetype change")
                return

            if not self.addMode:
                self._save_current_note()
            if type == "blur":
                self.currentField = None
                # run any filters
                if gui_hooks.editor_did_unfocus_field(False, self.note, ord):
                    # something updated the note; update it after a subsequent focus
                    # event has had time to fire
                    self.mw.progress.timer(100, self.loadNoteKeepingFocus,
                                           False)
                else:
                    self._check_and_update_duplicate_display_async()
            else:
                gui_hooks.editor_did_fire_typing_timer(self.note)
                self._check_and_update_duplicate_display_async()

        # focused into field?
        elif cmd.startswith("focus"):
            (type, num) = cmd.split(":", 1)
            self.last_field_index = self.currentField = int(num)
            gui_hooks.editor_did_focus_field(self.note, self.currentField)

        elif cmd.startswith("toggleStickyAll"):
            model = self.note.note_type()
            flds = model["flds"]

            any_sticky = any([fld["sticky"] for fld in flds])
            result = []
            for fld in flds:
                if not any_sticky or fld["sticky"]:
                    fld["sticky"] = not fld["sticky"]

                result.append(fld["sticky"])

            update_notetype_legacy(
                parent=self.mw,
                notetype=model).run_in_background(initiator=self)

            return result

        elif cmd.startswith("toggleSticky"):
            (type, num) = cmd.split(":", 1)
            ord = int(num)

            model = self.note.note_type()
            fld = model["flds"][ord]
            new_state = not fld["sticky"]
            fld["sticky"] = new_state

            update_notetype_legacy(
                parent=self.mw,
                notetype=model).run_in_background(initiator=self)

            return new_state

        elif cmd.startswith("lastTextColor"):
            (_, textColor) = cmd.split(":", 1)
            self.mw.pm.profile["lastTextColor"] = textColor

        elif cmd.startswith("lastHighlightColor"):
            (_, highlightColor) = cmd.split(":", 1)
            self.mw.pm.profile["lastHighlightColor"] = highlightColor

        elif cmd.startswith("saveTags"):
            (type, tagsJson) = cmd.split(":", 1)
            self.note.tags = json.loads(tagsJson)

            gui_hooks.editor_did_update_tags(self.note)
            if not self.addMode:
                self._save_current_note()

        elif cmd in self._links:
            self._links[cmd](self)

        else:
            print("uncaught cmd", cmd)