Skip to content

Commit 46aef00

Browse files
committed
Add Comment field for tags section
Closes #2539
1 parent 0d0bda6 commit 46aef00

2 files changed

Lines changed: 75 additions & 33 deletions

File tree

src/robotide/editor/settingeditors.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,58 @@ def _saving(self, message):
422422
_ = message
423423
self._tags_display.saving()
424424

425+
def _create_controls(self):
426+
sizer = wx.BoxSizer(wx.HORIZONTAL)
427+
sizer.Add((5, 0))
428+
width = max(len(self._controller.label), context.SETTING_LABEL_WIDTH)
429+
label = Label(self, label=self._controller.label,
430+
size=(width, context.SETTING_ROW_HEIGHT))
431+
label.SetToolTip(get_english_label(self._language, self._controller.label))
432+
sizer.Add(label)
433+
value_sizer = wx.BoxSizer(wx.VERTICAL)
434+
self._value_display = self._create_value_display()
435+
self._comment_display = self._create_comment_display()
436+
value_sizer.Add(self._value_display, 0, wx.EXPAND)
437+
value_sizer.Add(self._comment_display, 0, wx.EXPAND)
438+
self.update_value()
439+
self._tooltip = self._get_tooltip()
440+
sizer.Add(value_sizer, 1, wx.EXPAND)
441+
self._add_edit(sizer)
442+
sizer.Add(ButtonWithHandler(self, _('Clear'), mk_handler='Clear', handler=self.on_clear, fsize=self.font_size,
443+
color_secondary_foreground=self.color_secondary_foreground,
444+
color_secondary_background=self.color_secondary_background))
445+
sizer.Layout()
446+
self.SetSizer(sizer)
447+
448+
def _create_comment_display(self):
449+
comment_display = CommentDisplay(self, self._controller)
450+
comment_display.Bind(wx.EVT_LEFT_UP, self.on_left_up)
451+
return comment_display
452+
425453
def _value_display_control(self):
426454
self._tags_display = TagsDisplay(self, self._controller)
427455
self._tags_display.Bind(wx.EVT_LEFT_UP, self.on_left_up)
428456
self._tags_display.Bind(wx.EVT_KEY_DOWN, self.on_key)
429457
return self._tags_display
430458

459+
def update_value(self):
460+
if self._controller is None:
461+
return
462+
if self._controller.is_set:
463+
self._value_display.set_value(self._controller, self.plugin)
464+
self._comment_display.set_value(self._controller)
465+
else:
466+
self._value_display.clear_field()
467+
self._comment_display.clear()
468+
self.Refresh()
469+
431470
def contains(self, text):
432471
return False
433472

434473
def highlight(self, text):
435-
""" Just ignoring it """
436474
pass
437475

438476
def clear_highlight(self):
439-
""" Just ignoring it """
440477
pass
441478

442479
def close(self):
@@ -445,6 +482,33 @@ def close(self):
445482
SettingEditor.close(self)
446483

447484

485+
class CommentDisplay(wx.StaticText):
486+
def __init__(self, parent, controller):
487+
self._parent = parent
488+
self._controller = controller
489+
wx.StaticText.__init__(self, parent, label='')
490+
self.SetForegroundColour(Colour(parent.color_secondary_foreground))
491+
self.SetBackgroundColour(Colour(parent.color_background))
492+
self.Hide()
493+
494+
def set_value(self, controller):
495+
self._controller = controller
496+
comment = controller.comment
497+
if comment and len(comment) > 0:
498+
comment_text = comment.as_list()
499+
if comment_text:
500+
comment_str = ' '.join(str(c).lstrip('# ').strip() for c in comment_text if c)
501+
if comment_str:
502+
self.SetLabel('# ' + comment_str)
503+
self.Show()
504+
return
505+
self.clear()
506+
507+
def clear(self):
508+
self.SetLabel('')
509+
self.Hide()
510+
511+
448512
class _AbstractListEditor(ListEditor):
449513
_titles = []
450514

src/robotide/editor/tags.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, parent, controller):
2727
self._controller = controller
2828
self._sizer = wx.BoxSizer()
2929
self._tag_boxes = []
30+
self._comment_display = None
3031
self.SetAutoLayout(1)
3132
self.SetupScrolling(scroll_y=False, scrollIntoView=False)
3233
self.SetSizer(self._sizer)
@@ -63,10 +64,6 @@ def set_value(self, controller, plugin=None):
6364
if not self._tag_boxes:
6465
self._add_tags(list(controller))
6566
else:
66-
# in GTK you can have focus in a dead object
67-
# this causes Segmentation Faults
68-
# Thus instead of clearing old values and adding new ones
69-
# modify the ones that exist
7067
self._modify_values(controller)
7168
self.build()
7269

@@ -118,21 +115,14 @@ def GetSelection():
118115
def get_height(self):
119116
""" Seems that this method is never called """
120117
_, height = self._sizer.GetSize()
121-
# print(f"DEBUG: tags height={height}")
122-
return height # DEBUG return self._sizer.height
118+
return height
123119

124120

125121
class TagBox(wx.TextCtrl):
126122
tb_properties = None
127123

128124
def __init__(self, parent, tproperties):
129125
wx.TextCtrl.__init__(self, parent, wx.ID_ANY, '', style=wx.TE_CENTER | wx.TE_NOHIDESEL)
130-
"""
131-
self.SetBackgroundColour(Colour(200, 222, 40))
132-
self.SetOwnBackgroundColour(Colour(200, 222, 40))
133-
self.SetForegroundColour(Colour(7, 0, 70))
134-
self.SetOwnForegroundColour(Colour(7, 0, 70))
135-
"""
136126
self._bind()
137127
self.set_properties(tproperties)
138128

@@ -159,7 +149,7 @@ def _apply_properties(self):
159149

160150
def _get_size(self):
161151
size = self.GetTextExtent(self.value)
162-
offset = 13 if IS_WINDOWS else 26 # On GTK3 labels are bigger
152+
offset = 13 if IS_WINDOWS else 26
163153
return wx.Size(max(size[0]+offset, 75), max(size[1]+3, 25))
164154

165155
def _colorize(self):
@@ -182,25 +172,19 @@ def on_key_up(self, event):
182172
self.SetValue('')
183173

184174
if event.GetKeyCode() != wx.WXK_RETURN:
185-
# Don't send skip event if enter key is pressed
186-
# On some platforms this event is sent too late and causes crash
187175
event.Skip()
188176

189177
def _cancel_editing(self):
190178
self.SetValue(self.tb_properties.text)
191179
self._colorize()
192180

193181
def on_char(self, event):
194-
# For some reason at least ESC and F<num> keys are considered chars.
195-
# We only special case ESC, though.
196182
if event.GetKeyCode() != wx.WXK_ESCAPE:
197183
self.tb_properties.activate(self)
198184
event.Skip()
199185

200186
def on_kill_focus(self, event):
201187
self._update_value()
202-
# Send skip event only if tagbox is empty and about to be destroyed
203-
# On some platforms this event is sent too late and causes crash
204188
if self and self.value != '':
205189
event.Skip()
206190

@@ -230,9 +214,8 @@ def properties(tag, controller):
230214

231215

232216
class _TagBoxProperties(object):
233-
# DEBUG: Use colours from settings
234-
foreground_color = 'black' # Colour(7, 0, 70) #
235-
background_color = 'gray' # Colour(200, 222, 40) 'white'
217+
foreground_color = 'black'
218+
background_color = 'gray'
236219
enabled = True
237220
add_new = False
238221

@@ -256,7 +239,6 @@ def change_value(self, value):
256239
self._tag.controller.execute(ctrlcommands.ChangeTag(self._tag, value))
257240

258241
def activate(self, tagbox):
259-
""" Just ignore it """
260242
pass
261243

262244

@@ -265,8 +247,7 @@ class TagBoxProperties(_TagBoxProperties):
265247

266248

267249
class AddTagBoxProperties(_TagBoxProperties):
268-
# DEBUG: Use colours from settings
269-
foreground_color = 'gray' # Colour(200, 222, 40)
250+
foreground_color = 'gray'
270251
text = '<Add New>'
271252
tooltip = 'Click to add new tag'
272253
modifiable = False
@@ -282,21 +263,18 @@ def activate(self, tagbox):
282263

283264

284265
class ForcedTagBoxProperties(_TagBoxProperties):
285-
# DEBUG: Use colours from settings
286266
foreground_color = 'red'
287-
background_color = '#D3D3D3' # Colour(200, 222, 40)
267+
background_color = '#D3D3D3'
288268
enabled = False
289269

290270

291271
class DefaultTagBoxProperties(_TagBoxProperties):
292-
# DEBUG: Use colours from settings
293272
foreground_color = '#666666'
294-
background_color = '#D3D3D3' # Colour(200, 222, 40)
273+
background_color = '#D3D3D3'
295274
enabled = False
296275

297276

298277
class TestTagBoxProperties(_TagBoxProperties):
299-
# DEBUG: Use colours from settings
300278
foreground_color = 'orange'
301-
background_color = '#D3D3D3' # Colour(200, 222, 40)
279+
background_color = '#D3D3D3'
302280
enabled = False

0 commit comments

Comments
 (0)