Skip to content

Commit 92c012f

Browse files
Autocomplete (#2578)
* Fix auto-complete in Windows. WIP fix condition to not use shortcuts * Fix switch for Enable auto suggestions
1 parent 93dafba commit 92c012f

File tree

7 files changed

+41
-101
lines changed

7 files changed

+41
-101
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni
1010

1111
=== Changed
1212

13-
- Keywords auto-suggestion in grid editor does not need shortcut anymore, if you want to disable this feature you can config in `Preferences -> Grid Editor -> Only trigger auto suggestions from shortcuts`
13+
- Allow to do auto-suggestions of keywords in grid editor without a shortcut, if you want to enable or disable this feature you can config in `Preferences -> Grid Editor -> Enable auto suggestions`
1414

1515
- Made ``\n`` visible when editing cells in Grid Editor (problematic in Windows)
1616

src/robotide/editor/contentassist.py

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
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-
1916
import wx
2017
from wx import Colour
2118
from wx.lib.expando import ExpandoTextCtrl
2219
from wx.lib.filebrowsebutton import FileBrowseButton
20+
from os.path import relpath, dirname, isdir
2321

2422
from .. 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
2624
from ..namespace.suggesters import SuggestionSource
2725
from ..spec.iteminfo import VariableInfo
2826
from .popupwindow import RidePopupWindow, HtmlPopupWindow
@@ -31,7 +29,7 @@
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

3735
class _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

src/robotide/editor/fieldeditors.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@ class FileNameEditor(ValueEditor):
124124
_sizer_flags_for_editor = 0
125125
_sizer_flags_for_label = wx.TOP | wx.BOTTOM | wx.LEFT
126126

127-
def __init__(self, parent, value, label, controller, validator=None,
128-
settings=None, suggestion_source=None):
129-
self._suggestion_source = suggestion_source or SuggestionSource(
130-
parent.plugin, None)
127+
def __init__(self, parent, value, label, controller, validator=None, settings=None, suggestion_source=None):
128+
self._suggestion_source = suggestion_source or SuggestionSource(parent.plugin, None)
131129
self._controller = controller
132130
self._label = label
133131
self._parent = parent
@@ -137,8 +135,7 @@ def setFocusToOK(self):
137135
self._parent.setFocusToOK()
138136

139137
def _get_text_ctrl(self):
140-
filename_ctrl = ContentAssistFileButton(self, self._suggestion_source, '',
141-
self._controller, (500, -1))
138+
filename_ctrl = ContentAssistFileButton(self, self._suggestion_source, '', self._controller, (500, -1))
142139
filename_ctrl.SetBackgroundColour(Colour(self.color_secondary_background))
143140
filename_ctrl.SetForegroundColour(Colour(self.color_secondary_foreground))
144141
return filename_ctrl

src/robotide/editor/kweditor.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def OnMoveCursorDown(self, event=None):
321321
def OnInsertRows(self, event):
322322
self._execute(AddRows(self.selection.rows()))
323323
self.ClearSelection()
324-
self._resize_grid(self)
324+
self._resize_grid()
325325
self._skip_except_on_mac(event)
326326

327327
@staticmethod
@@ -345,7 +345,7 @@ def OnInsertCells(self, event=None):
345345
self.selection.bottomright)
346346
self._execute(InsertCells(self.selection.topleft,
347347
self.selection.bottomright))
348-
self._resize_grid(self)
348+
self._resize_grid()
349349
self._skip_except_on_mac(event)
350350

351351
def OnDeleteCells(self, event=None):
@@ -361,19 +361,19 @@ def OnDeleteCells(self, event=None):
361361

362362
self._dcells = (self.selection.topleft, self.selection.bottomright)
363363
self._execute(DeleteCells(self.selection.topleft, self.selection.bottomright))
364-
self._resize_grid(self)
364+
self._resize_grid()
365365
self._skip_except_on_mac(event)
366366

367367
# DEBUG @requires_focus
368368
def OnCommentRows(self, event=None):
369369
self._execute(CommentRows(self.selection.rows()))
370-
self._resize_grid(self)
370+
self._resize_grid()
371371
self._skip_except_on_mac(event)
372372

373373
# DEBUG @requires_focus
374374
def OnUncommentRows(self, event=None):
375375
self._execute(UncommentRows(self.selection.rows()))
376-
self._resize_grid(self)
376+
self._resize_grid()
377377
self._skip_except_on_mac(event)
378378

379379
def OnMoveRowsUp(self, event=None):
@@ -510,7 +510,7 @@ def OnDelete(self, event=None):
510510
if not self.IsCellEditControlShown():
511511
self._execute(ClearArea(self.selection.topleft,
512512
self.selection.bottomright))
513-
self._resize_grid(self)
513+
self._resize_grid()
514514

515515
# DEBUG @requires_focus
516516
def OnPaste(self, event=None):
@@ -519,7 +519,7 @@ def OnPaste(self, event=None):
519519
self.paste()
520520
else:
521521
self._execute_clipboard_command(PasteArea)
522-
self._resize_grid(self)
522+
self._resize_grid()
523523

524524
def _execute_clipboard_command(self, command_class):
525525
if not self.IsCellEditControlShown():
@@ -532,12 +532,12 @@ def _execute_clipboard_command(self, command_class):
532532
def OnInsert(self, event=None):
533533
_ = event
534534
self._execute_clipboard_command(InsertArea)
535-
self._resize_grid(self)
535+
self._resize_grid()
536536

537537
def OnDeleteRows(self, event):
538538
self._execute(DeleteRows(self.selection.rows()))
539539
self.ClearSelection()
540-
self._resize_grid(self)
540+
self._resize_grid()
541541
self._skip_except_on_mac(event)
542542

543543
# DEBUG @requires_focus
@@ -547,13 +547,13 @@ def OnUndo(self, event=None):
547547
self._execute(Undo())
548548
else:
549549
self.GetCellEditor(*self.selection.cell).Reset()
550-
self._resize_grid(self)
550+
self._resize_grid()
551551

552552
# DEBUG @requires_focus
553553
def OnRedo(self, event=None):
554554
_ = event
555555
self._execute(Redo())
556-
self._resize_grid(self)
556+
self._resize_grid()
557557

558558
def close(self):
559559
self._colorizer.close()
@@ -887,7 +887,7 @@ def OnExtractVariable(self, event):
887887
self._extract_scalar(cells[0])
888888
elif min(row for row, _ in cells) == max(row for row, _ in cells):
889889
self._extract_list(cells)
890-
self._resize_grid(self)
890+
self._resize_grid()
891891

892892
def OnFindWhereUsed(self, event):
893893
_ = event

src/robotide/editor/macroeditors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ def _create_header(self, text, readonly=False):
108108
def cb(event):
109109
_ = event
110110
Usages(self.controller, self._tree.highlight).show()
111-
return FindUsagesHeader(self, name, cb, color_foreground=self.color_secondary_foreground,
111+
return FindUsagesHeader(self, 'Find Usages', cb, color_foreground=self.color_secondary_foreground,
112112
color_background=self.color_secondary_background)

src/robotide/preferences/editors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ def _create_grid_config_editor(self):
253253
if IS_WINDOWS:
254254
set_colors(l_word_wrap, background_color, foreground_color)
255255
sizer.AddMany([l_word_wrap, editor])
256-
l_auto_suggest, editor = boolean_editor(self, settings, 'disable auto suggestions',
257-
'Only trigger auto suggestions from shortcuts')
256+
l_auto_suggest, editor = boolean_editor(self, settings, 'enable auto suggestions',
257+
'Enable auto suggestions')
258+
if IS_WINDOWS:
259+
set_colors(l_auto_suggest, background_color, foreground_color)
258260
sizer.AddMany([l_auto_suggest, editor])
259261
return sizer
260262

src/robotide/preferences/settings.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ background unknown = '#FFFFFF'
7474
background error = '#FF9385'
7575
background highlight = '#FFFF77'
7676
word wrap = True
77+
enable auto suggestions = False
7778

7879
[Plugins]
7980
[[Test Runner]]

0 commit comments

Comments
 (0)