@@ -717,7 +717,73 @@ def _set_shared_doc_lang(self, lang='en'):
717717 def set_editor (self , editor ):
718718 self ._editor = editor
719719
720+
720721 def validate_and_update (self , data , text , lang = 'en' ):
722+
723+ try :
724+ from robot .parsing .parser .parser import get_model # RF > 4.0
725+ except ImportError :
726+ return self ._old_validate_and_update (data , text )
727+ return self ._new_validate_and_update (data , text , lang )
728+
729+ """
730+ Backwards compatible code v1.7.4.2
731+ """
732+
733+ def _old_validate_and_update (self , data , text ):
734+ m_text = text .decode ("utf-8" )
735+ if not self ._old_sanity_check (data , m_text ):
736+ handled = self ._old_handle_sanity_check_failure ()
737+ if not handled :
738+ return False
739+ self ._editor .reset ()
740+ # print("DEBUG: updating text") # %s" % (self._editor.GetCurrentPos()))
741+ data .update_from (m_text )
742+ # print("DEBUG: AFTER updating text")
743+ self ._editor .set_editor_caret_position ()
744+ # %s" % (self._editor.GetCurrentPos()))
745+ return True
746+
747+ def _old_sanity_check (self , data , text ):
748+ formatted_text = data .format_text (text )
749+ # print(f"DEBUG: texteditor old_sanity_check {formatted_text=}")
750+ c = self ._normalize (formatted_text )
751+ e = self ._normalize (text )
752+ return len (c ) == len (e )
753+
754+ @staticmethod
755+ def _normalize (text ):
756+ for item in [' ' , r'\t' , r'\n' , r'\r\n' , '...' , '*' ]:
757+ if item in text :
758+ # print("DEBUG: _normaliz item %s txt %s" % (item, text))
759+ text = text .replace (item , '' )
760+ return text
761+
762+ def _old_handle_sanity_check_failure (self ):
763+ if self ._last_answer == wx .ID_NO and \
764+ time () - self ._last_answer_time <= 0.2 :
765+ self ._editor ._mark_file_dirty ()
766+ return False
767+ # TODO: use widgets.Dialog
768+ id = wx .MessageDialog (self ._editor ,
769+ 'ERROR: Data sanity check failed!\n '
770+ 'Reset changes?' ,
771+ 'Can not apply changes from Txt Editor' ,
772+ style = wx .YES | wx .NO ).ShowModal ()
773+ self ._last_answer = id
774+ self ._last_answer_time = time ()
775+ if id == wx .ID_YES :
776+ self ._editor ._revert ()
777+ return True
778+ else :
779+ self ._editor ._mark_file_dirty ()
780+ return False
781+
782+ """
783+ End Backwards compatible code v1.7.4.2
784+ """
785+
786+ def _new_validate_and_update (self , data , text , lang = 'en' ):
721787 from robotide .lib .robot .errors import DataError
722788 m_text = text .decode ("utf-8" )
723789 # print(f"DEBUG: textedit.py validate_and_update ENTER"
0 commit comments