1919from wx .lib .filebrowsebutton import FileBrowseButton
2020from os .path import relpath , dirname , isdir
2121
22+ from .gridbase import GridEditor
2223from .. import context , utils
2324from ..context import IS_MAC , IS_WINDOWS , IS_WX_410_OR_HIGHER
2425from ..namespace .suggesters import SuggestionSource
@@ -74,6 +75,8 @@ def __init__(self, suggestion_source, language='En', **kw):
7475 @staticmethod
7576 def _get_auto_suggestion_config ():
7677 from robotide .context import APP
78+ if not APP :
79+ return True
7780 settings = APP .settings ['Grid' ]
7881 return settings .get (_AUTO_SUGGESTION_CFG_KEY , False )
7982
@@ -357,7 +360,8 @@ def __init__(self, parent, plugin, controller, language='En'):
357360 """ According to class MRO, super().__init__ in _ContentAssistTextCtrlBase will init ExpandoTextCtrl
358361 instance """
359362
360- _ContentAssistTextCtrlBase .__init__ (self , SuggestionSource (plugin , controller ), language = language ,
363+ self .suggestion_source = SuggestionSource (plugin , controller )
364+ _ContentAssistTextCtrlBase .__init__ (self , self .suggestion_source , language = language ,
361365 parent = parent , size = wx .DefaultSize ,
362366 style = wx .WANTS_CHARS | wx .TE_NOHIDESEL )
363367 self .SetBackgroundColour (context .POPUP_BACKGROUND )
@@ -481,9 +485,9 @@ def _get_choices(self, value, row):
481485 @staticmethod
482486 def _get_duplicate_names (choices ):
483487 results = set ()
484- normalized_names = [utils .normalize (ch .name ) for ch in choices ]
488+ normalized_names = [utils .normalize (ch .name if hasattr ( ch , 'name' ) else ch ) for ch in choices ]
485489 for choice in choices :
486- normalized = utils .normalize (choice .name )
490+ normalized = utils .normalize (choice .name if hasattr ( choice , 'name' ) else choice )
487491 if normalized_names .count (normalized ) > 1 :
488492 results .add (normalized )
489493 return results
@@ -493,17 +497,24 @@ def _format_choices(self, choices, prefix, duplicate_names):
493497 choices ]
494498
495499 def _format (self , choice , prefix , duplicate_names ):
496- return choice .name if self ._matches_unique_shortname (
497- choice , prefix , duplicate_names ) else choice .longname
500+ if hasattr (choice , 'name' ):
501+ return choice .name if self ._matches_unique_shortname (
502+ choice , prefix , duplicate_names ) else choice .longname
503+ elif self ._matches_unique_shortname (choice , prefix , duplicate_names ):
504+ return choice
498505
499506 @staticmethod
500507 def _matches_unique_shortname (choice , prefix , duplicate_names ):
501508 if isinstance (choice , VariableInfo ):
502509 return True
503- if not utils .normalize (choice .name ).startswith (
510+ if hasattr (choice , 'name' ):
511+ name = choice .name
512+ else :
513+ name = choice
514+ if not utils .normalize (name ).startswith (
504515 utils .normalize (prefix )):
505516 return False
506- if utils .normalize (choice . name ) in duplicate_names :
517+ if utils .normalize (name ) in duplicate_names :
507518 return False
508519 return True
509520
@@ -532,8 +543,11 @@ def content_assist_for(self, value, row=None):
532543 self ._choices = self ._suggestions .get_for (value , row = row )
533544 if not self ._choices :
534545 self ._list .ClearAll ()
535- self ._parent .hide ()
546+ if not isinstance (self ._parent , GridEditor ):
547+ self ._parent .hide ()
536548 return False
549+ self ._choices = list (set ([c for c in self ._choices if c is not None ]))
550+ # print(f"DEBUG: contentassist.py ContentAssistPopup content_assist_for CALL POPULATE Choices={self._choices}")
537551 self ._list .populate (self ._choices )
538552 return True
539553
@@ -616,7 +630,7 @@ def on_list_item_activated(self, event):
616630 def on_list_item_selected (self , event ):
617631 self ._selection = event .GetIndex ()
618632 item = self ._suggestions .get_item (event .GetText ())
619- if item .details :
633+ if hasattr ( item , 'details' ) and item .details :
620634 self ._details_popup .Show ()
621635 self ._details_popup .set_content (item .details , item .name )
622636 elif self ._details_popup .IsShown ():
0 commit comments