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)
def onBridgeCmd(self, cmd) -> None: if not self.note: # shutdown return # focus lost or key/button pressed? if cmd.startswith("blur") or cmd.startswith("key"): (type, ord, nid, txt) = cmd.split(":", 3) ord = int(ord) try: nid = int(nid) except ValueError: nid = 0 if nid != self.note.id: print("ignored late blur") return txt = urllib.parse.unquote(txt) txt = unicodedata.normalize("NFC", txt) txt = self.mungeHTML(txt) # misbehaving apps may include a null byte in the text txt = txt.replace("\x00", "") # reverse the url quoting we added to get images to display txt = self.mw.col.media.escapeImages(txt, unescape=True) self.note.fields[ord] = txt if not self.addMode: self.note.flush() self.mw.requireReset() 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.checkValid() else: gui_hooks.editor_did_fire_typing_timer(self.note) self.checkValid() # 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 in self._links: self._links[cmd](self) else: print("uncaught cmd", cmd)
def onBridgeCmd(self, cmd) -> None: if not self.note: # shutdown return # focus lost or key/button pressed? if cmd.startswith("blur") or cmd.startswith("key"): (type, ord, nid, txt) = cmd.split(":", 3) ord = int(ord) try: nid = int(nid) 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.note.flush() self.mw.requireReset(reason=ResetReason.EditorBridgeCmd, context=self) 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.checkValid() else: gui_hooks.editor_did_fire_typing_timer(self.note) self.checkValid() # 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 in self._links: self._links[cmd](self) else: print("uncaught cmd", cmd)
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)
def onFocus(self, num): self.currentField = int(num) gui_hooks.editor_did_focus_field(self.note, self.currentField)