@@ -717,7 +717,72 @@ def _set_shared_doc_lang(self, lang='en'):
717717 def set_editor (self , editor ):
718718 self ._editor = editor
719719
720- def validate_and_update (self , data , text , lang = 'en' ):
720+
721+ def validate_and_update (self , data , text ):
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 )
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+ c = self ._normalize (formatted_text )
750+ e = self ._normalize (text )
751+ return len (c ) == len (e )
752+
753+ @staticmethod
754+ def _normalize (self , text ):
755+ for item in [' ' , r'\t' , r'\n' , r'\r\n' , '...' , '*' ]:
756+ if item in text :
757+ # print("DEBUG: _normaliz item %s txt %s" % (item, text))
758+ text = text .replace (item , '' )
759+ return text
760+
761+ def _old_handle_sanity_check_failure (self ):
762+ if self ._last_answer == wx .ID_NO and \
763+ time () - self ._last_answer_time <= 0.2 :
764+ self ._editor ._mark_file_dirty ()
765+ return False
766+ # TODO: use widgets.Dialog
767+ id = wx .MessageDialog (self ._editor ,
768+ 'ERROR: Data sanity check failed!\n '
769+ 'Reset changes?' ,
770+ 'Can not apply changes from Txt Editor' ,
771+ style = wx .YES | wx .NO ).ShowModal ()
772+ self ._last_answer = id
773+ self ._last_answer_time = time ()
774+ if id == wx .ID_YES :
775+ self ._editor ._revert ()
776+ return True
777+ else :
778+ self ._editor ._mark_file_dirty ()
779+ return False
780+
781+ """
782+ End Backwards compatible code v1.7.4.2
783+ """
784+
785+ def _new_validate_and_update (self , data , text , lang = 'en' ):
721786 from robotide .lib .robot .errors import DataError
722787 m_text = text .decode ("utf-8" )
723788 # print(f"DEBUG: textedit.py validate_and_update ENTER"
0 commit comments