1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16- from os .path import relpath , dirname , isdir
17- from sys import platform
18-
1916import wx
2017from wx import Colour
2118from wx .lib .expando import ExpandoTextCtrl
2219from wx .lib .filebrowsebutton import FileBrowseButton
20+ from os .path import relpath , dirname , isdir
2321
2422from .. import context , utils
25- from ..context import IS_MAC , IS_WX_410_OR_HIGHER
23+ from ..context import IS_MAC , IS_WINDOWS , IS_WX_410_OR_HIGHER
2624from ..namespace .suggesters import SuggestionSource
2725from ..spec .iteminfo import VariableInfo
2826from .popupwindow import RidePopupWindow , HtmlPopupWindow
3129
3230
3331_PREFERRED_POPUP_SIZE = (400 , 200 )
34- _AUTO_SUGGESTION_CFG_KEY = "disable auto suggestions"
32+ _AUTO_SUGGESTION_CFG_KEY = "enable auto suggestions"
3533
3634
3735class _ContentAssistTextCtrlBase (wx .TextCtrl ):
@@ -62,7 +60,7 @@ def __init__(self, suggestion_source, **kw):
6260 # later after search is performed
6361 if IS_MAC and IS_WX_410_OR_HIGHER :
6462 self .OSXDisableAllSmartSubstitutions ()
65- self ._is_auto_suggestion_disabled = self ._get_auto_suggestion_config ()
63+ self ._is_auto_suggestion_enabled = self ._get_auto_suggestion_config ()
6664 PUBLISHER .subscribe (self .OnSettingsChanged , RideSettingsChanged )
6765
6866 @staticmethod
@@ -75,7 +73,7 @@ def OnSettingsChanged(self, message):
7573 """Update auto suggestion settings from PUBLISHER message"""
7674 section , setting = message .keys
7775 if section == 'Grid' and _AUTO_SUGGESTION_CFG_KEY in setting :
78- self ._is_auto_suggestion_disabled = message .new
76+ self ._is_auto_suggestion_enabled = message .new
7977
8078 def set_row (self , row ):
8179 self ._row = row
@@ -125,7 +123,7 @@ def OnKeyDown(self, event):
125123 event .Skip ()
126124
127125 def _show_auto_suggestions_when_enabled (self ):
128- if not self ._is_auto_suggestion_disabled or self .is_shown ():
126+ if self ._is_auto_suggestion_enabled or self .is_shown ():
129127 self .show_content_assist ()
130128
131129 def OnChar (self , event ):
@@ -162,7 +160,7 @@ def _variable_creator_value(value, symbol, from_, to_):
162160 def execute_enclose_text (self , key_code ):
163161 # DEBUG: move this code to kweditor
164162 from_ , to_ = self .GetSelection ()
165- if not self ._selection :
163+ if not self ._selection or IS_WINDOWS : # On windows selection is not deleted
166164 content = self ._enclose_text (self .Value , key_code , from_ , to_ )
167165 else :
168166 enclosed = self ._enclose_text (self ._selection , key_code , 0 , len (self ._selection ))
@@ -238,54 +236,6 @@ def _remove_text(value, remove_text, on_the_left, on_the_right, from_, to_):
238236 return value [:from_ ]+ value [from_ :to_ ].rstrip (remove_text )+ value [to_ :]
239237 return value
240238
241- def execute_sharp_comment (self ):
242- # Todo: Will only comment the left top cell for a multi cell select block!
243- from_ , to_ = self .GetSelection ()
244- #print(f"DEBUG: value from/to: " + str(from_) + " " + str(to_))
245- #print(f"DEBUG: value selected: " + self.Value)
246- add_text = '# '
247- self .SetValue (self ._add_text (self .Value , add_text , True , False , from_ , to_ ))
248- lenadd = len (add_text )
249- elem = self
250- elem .SetInsertionPoint (from_ + lenadd )
251- if from_ != to_ :
252- elem .SetInsertionPoint (to_ + lenadd )
253- elem .SetSelection (from_ + lenadd , to_ + lenadd )
254- return
255-
256- @staticmethod
257- def _add_text (value , add_text , on_the_left , on_the_right , from_ , to_ ):
258- if on_the_left and on_the_right :
259- return value [:from_ ]+ add_text + value [from_ :to_ ]+ add_text + value [to_ :]
260- if on_the_left :
261- return value [:from_ ]+ add_text + value [from_ :to_ ]+ value [to_ :]
262- if on_the_right :
263- return value [:from_ ]+ value [from_ :to_ ]+ add_text + value [to_ :]
264- return value
265-
266- def execute_sharp_uncomment (self ):
267- # Todo: Will only uncomment the left top cell for a multi cell select block!
268- from_ , to_ = self .GetSelection ()
269- lenold = len (self .Value )
270- self .SetValue (self ._remove_text (self .Value , '# ' , True , False , from_ , to_ ))
271- lenone = len (self .Value )
272- diffone = lenold - lenone
273- elem = self
274- if from_ == to_ :
275- elem .SetInsertionPoint (from_ - diffone )
276- else :
277- elem .SetInsertionPoint (to_ - diffone )
278- elem .SetSelection (from_ - diffone , to_ - diffone )
279-
280- def _remove_text (self , value , remove_text , on_the_left , on_the_right , from_ , to_ ):
281- if on_the_left and on_the_right :
282- return value [:from_ ]+ value [from_ :to_ ].strip (remove_text )+ remove_text + value [to_ :]
283- if on_the_left :
284- return value [:from_ ]+ value [from_ :to_ ].lstrip (remove_text )+ value [to_ :]
285- if on_the_right :
286- return value [:from_ ]+ value [from_ :to_ ].rstrip (remove_text )+ value [to_ :]
287- return value
288-
289239 def OnFocusLost (self , event , set_value = True ):
290240 event .Skip ()
291241 if not self ._popup .is_shown ():
@@ -306,15 +256,13 @@ def fill_suggestion(self):
306256 value = self .gherkin_prefix + self ._popup .get_value () or self .GetValue ()
307257 else :
308258 value = self ._popup .get_value () or self .GetValue ()
309-
310259 if value :
311260 wrapper_view = self .GetParent ().GetParent ()
312261 if hasattr (wrapper_view , 'open_cell_editor' ):
313262 # in grid cell, need to make sure cell editor is open
314263 wrapper_view .open_cell_editor ()
315264 self .SetValue (value )
316265 self .SetInsertionPoint (len (value ))
317-
318266 self .hide ()
319267
320268 def pop_event_handlers (self , event ):
@@ -326,6 +274,7 @@ def pop_event_handlers(self, event):
326274 self .PopEventHandler ()
327275
328276 def OnDestroy (self , event ):
277+ _ = event
329278 # all pushed eventHandlers need to be popped before close
330279 # the last event handler is window object itself - do not pop itself
331280 while self .GetEventHandler () is not self :
@@ -338,11 +287,12 @@ def reset(self):
338287 def show_content_assist (self ):
339288 if self ._showing_content_assist :
340289 return
341- self ._showing_content_assist = True
342290 if self ._populate_content_assist ():
291+ self ._showing_content_assist = True
343292 self ._show_content_assist ()
344293
345294 def _populate_content_assist (self ):
295+ # DEBUG: Get partial content if not found in full
346296 value = self .GetValue ()
347297 (self .gherkin_prefix , value ) = self ._remove_bdd_prefix (value )
348298 return self ._popup .content_assist_for (value , row = self ._row )
@@ -417,8 +367,7 @@ def __init__(self, parent, suggestion_source, pos, size=wx.DefaultSize):
417367 self .SetOwnForegroundColour (Colour (self .color_foreground_text ))
418368
419369
420- class ContentAssistFileButton (FileBrowseButton , _ContentAssistTextCtrlBase ):
421-
370+ class ContentAssistFileButton (FileBrowseButton ):
422371 def __init__ (self , parent , suggestion_source , label , controller , size = wx .DefaultSize ):
423372 self .suggestion_source = suggestion_source
424373 FileBrowseButton .__init__ (self , parent , labelText = label ,
@@ -428,7 +377,6 @@ def __init__(self, parent, suggestion_source, label, controller, size=wx.Default
428377 self ._controller = controller
429378 self ._browsed = False
430379
431- _ContentAssistTextCtrlBase .__init__ (self , suggestion_source )
432380 self .SetBackgroundColour (Colour (context .POPUP_BACKGROUND ))
433381 self .SetOwnBackgroundColour (Colour (context .POPUP_BACKGROUND ))
434382 self .SetForegroundColour (Colour (context .POPUP_FOREGROUND ))
@@ -455,6 +403,7 @@ def OnBrowse(self, evt=None):
455403 self ._browsed = False
456404
457405 def OnDestroy (self , event ):
406+ _ = event
458407 # all pushed eventHandlers need to be popped before close
459408 # the last event handler is window object itself - do not pop itself
460409 try :
@@ -608,26 +557,17 @@ def is_shown(self):
608557
609558 def select_and_scroll (self , key_code ):
610559 sel = self ._list .GetFirstSelected ()
560+ count = self ._list .GetItemCount ()
561+ pos = 0
611562 if key_code == wx .WXK_DOWN :
612- if sel < (self ._list .GetItemCount () - 1 ):
613- self ._select_and_scroll (sel + 1 )
614- else :
615- self ._select_and_scroll (0 )
563+ pos = sel + 1 if sel < count - 1 else 0
616564 elif key_code == wx .WXK_UP :
617- if sel > 0 :
618- self ._select_and_scroll (sel - 1 )
619- else :
620- self ._select_and_scroll (self ._list .GetItemCount () - 1 )
565+ pos = sel - 1 if sel > 0 else count - 1
621566 elif key_code == wx .WXK_PAGEDOWN :
622- if self ._list .GetItemCount () - self ._selection > 14 :
623- self ._select_and_scroll (self ._selection + 14 )
624- else :
625- self ._select_and_scroll (self ._list .GetItemCount () - 1 )
567+ pos = self ._selection + 14 if count - self ._selection > 14 else count - 1
626568 elif key_code == wx .WXK_PAGEUP :
627- if self ._selection > 14 :
628- self ._select_and_scroll (self ._selection - 14 )
629- else :
630- self ._select_and_scroll (0 )
569+ pos = self ._selection - 14 if self ._selection > 14 else 0
570+ self ._select_and_scroll (pos )
631571
632572 def _select_and_scroll (self , selection ):
633573 self ._selection = selection
0 commit comments