From 46aef006616528fce27a4391be17316d68d67b94 Mon Sep 17 00:00:00 2001 From: ChelSlava Date: Mon, 30 Mar 2026 10:27:06 +0300 Subject: [PATCH] Add Comment field for tags section Closes #2539 --- src/robotide/editor/settingeditors.py | 68 ++++++++++++++++++++++++++- src/robotide/editor/tags.py | 40 ++++------------ 2 files changed, 75 insertions(+), 33 deletions(-) diff --git a/src/robotide/editor/settingeditors.py b/src/robotide/editor/settingeditors.py index 55e3d996e..2c5a2eb40 100755 --- a/src/robotide/editor/settingeditors.py +++ b/src/robotide/editor/settingeditors.py @@ -422,21 +422,58 @@ def _saving(self, message): _ = message self._tags_display.saving() + def _create_controls(self): + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add((5, 0)) + width = max(len(self._controller.label), context.SETTING_LABEL_WIDTH) + label = Label(self, label=self._controller.label, + size=(width, context.SETTING_ROW_HEIGHT)) + label.SetToolTip(get_english_label(self._language, self._controller.label)) + sizer.Add(label) + value_sizer = wx.BoxSizer(wx.VERTICAL) + self._value_display = self._create_value_display() + self._comment_display = self._create_comment_display() + value_sizer.Add(self._value_display, 0, wx.EXPAND) + value_sizer.Add(self._comment_display, 0, wx.EXPAND) + self.update_value() + self._tooltip = self._get_tooltip() + sizer.Add(value_sizer, 1, wx.EXPAND) + self._add_edit(sizer) + sizer.Add(ButtonWithHandler(self, _('Clear'), mk_handler='Clear', handler=self.on_clear, fsize=self.font_size, + color_secondary_foreground=self.color_secondary_foreground, + color_secondary_background=self.color_secondary_background)) + sizer.Layout() + self.SetSizer(sizer) + + def _create_comment_display(self): + comment_display = CommentDisplay(self, self._controller) + comment_display.Bind(wx.EVT_LEFT_UP, self.on_left_up) + return comment_display + def _value_display_control(self): self._tags_display = TagsDisplay(self, self._controller) self._tags_display.Bind(wx.EVT_LEFT_UP, self.on_left_up) self._tags_display.Bind(wx.EVT_KEY_DOWN, self.on_key) return self._tags_display + def update_value(self): + if self._controller is None: + return + if self._controller.is_set: + self._value_display.set_value(self._controller, self.plugin) + self._comment_display.set_value(self._controller) + else: + self._value_display.clear_field() + self._comment_display.clear() + self.Refresh() + def contains(self, text): return False def highlight(self, text): - """ Just ignoring it """ pass def clear_highlight(self): - """ Just ignoring it """ pass def close(self): @@ -445,6 +482,33 @@ def close(self): SettingEditor.close(self) +class CommentDisplay(wx.StaticText): + def __init__(self, parent, controller): + self._parent = parent + self._controller = controller + wx.StaticText.__init__(self, parent, label='') + self.SetForegroundColour(Colour(parent.color_secondary_foreground)) + self.SetBackgroundColour(Colour(parent.color_background)) + self.Hide() + + def set_value(self, controller): + self._controller = controller + comment = controller.comment + if comment and len(comment) > 0: + comment_text = comment.as_list() + if comment_text: + comment_str = ' '.join(str(c).lstrip('# ').strip() for c in comment_text if c) + if comment_str: + self.SetLabel('# ' + comment_str) + self.Show() + return + self.clear() + + def clear(self): + self.SetLabel('') + self.Hide() + + class _AbstractListEditor(ListEditor): _titles = [] diff --git a/src/robotide/editor/tags.py b/src/robotide/editor/tags.py index 599dba539..6651ad822 100644 --- a/src/robotide/editor/tags.py +++ b/src/robotide/editor/tags.py @@ -27,6 +27,7 @@ def __init__(self, parent, controller): self._controller = controller self._sizer = wx.BoxSizer() self._tag_boxes = [] + self._comment_display = None self.SetAutoLayout(1) self.SetupScrolling(scroll_y=False, scrollIntoView=False) self.SetSizer(self._sizer) @@ -63,10 +64,6 @@ def set_value(self, controller, plugin=None): if not self._tag_boxes: self._add_tags(list(controller)) else: - # in GTK you can have focus in a dead object - # this causes Segmentation Faults - # Thus instead of clearing old values and adding new ones - # modify the ones that exist self._modify_values(controller) self.build() @@ -118,8 +115,7 @@ def GetSelection(): def get_height(self): """ Seems that this method is never called """ _, height = self._sizer.GetSize() - # print(f"DEBUG: tags height={height}") - return height # DEBUG return self._sizer.height + return height class TagBox(wx.TextCtrl): @@ -127,12 +123,6 @@ class TagBox(wx.TextCtrl): def __init__(self, parent, tproperties): wx.TextCtrl.__init__(self, parent, wx.ID_ANY, '', style=wx.TE_CENTER | wx.TE_NOHIDESEL) - """ - self.SetBackgroundColour(Colour(200, 222, 40)) - self.SetOwnBackgroundColour(Colour(200, 222, 40)) - self.SetForegroundColour(Colour(7, 0, 70)) - self.SetOwnForegroundColour(Colour(7, 0, 70)) - """ self._bind() self.set_properties(tproperties) @@ -159,7 +149,7 @@ def _apply_properties(self): def _get_size(self): size = self.GetTextExtent(self.value) - offset = 13 if IS_WINDOWS else 26 # On GTK3 labels are bigger + offset = 13 if IS_WINDOWS else 26 return wx.Size(max(size[0]+offset, 75), max(size[1]+3, 25)) def _colorize(self): @@ -182,8 +172,6 @@ def on_key_up(self, event): self.SetValue('') if event.GetKeyCode() != wx.WXK_RETURN: - # Don't send skip event if enter key is pressed - # On some platforms this event is sent too late and causes crash event.Skip() def _cancel_editing(self): @@ -191,16 +179,12 @@ def _cancel_editing(self): self._colorize() def on_char(self, event): - # For some reason at least ESC and F keys are considered chars. - # We only special case ESC, though. if event.GetKeyCode() != wx.WXK_ESCAPE: self.tb_properties.activate(self) event.Skip() def on_kill_focus(self, event): self._update_value() - # Send skip event only if tagbox is empty and about to be destroyed - # On some platforms this event is sent too late and causes crash if self and self.value != '': event.Skip() @@ -230,9 +214,8 @@ def properties(tag, controller): class _TagBoxProperties(object): - # DEBUG: Use colours from settings - foreground_color = 'black' # Colour(7, 0, 70) # - background_color = 'gray' # Colour(200, 222, 40) 'white' + foreground_color = 'black' + background_color = 'gray' enabled = True add_new = False @@ -256,7 +239,6 @@ def change_value(self, value): self._tag.controller.execute(ctrlcommands.ChangeTag(self._tag, value)) def activate(self, tagbox): - """ Just ignore it """ pass @@ -265,8 +247,7 @@ class TagBoxProperties(_TagBoxProperties): class AddTagBoxProperties(_TagBoxProperties): - # DEBUG: Use colours from settings - foreground_color = 'gray' # Colour(200, 222, 40) + foreground_color = 'gray' text = '' tooltip = 'Click to add new tag' modifiable = False @@ -282,21 +263,18 @@ def activate(self, tagbox): class ForcedTagBoxProperties(_TagBoxProperties): - # DEBUG: Use colours from settings foreground_color = 'red' - background_color = '#D3D3D3' # Colour(200, 222, 40) + background_color = '#D3D3D3' enabled = False class DefaultTagBoxProperties(_TagBoxProperties): - # DEBUG: Use colours from settings foreground_color = '#666666' - background_color = '#D3D3D3' # Colour(200, 222, 40) + background_color = '#D3D3D3' enabled = False class TestTagBoxProperties(_TagBoxProperties): - # DEBUG: Use colours from settings foreground_color = 'orange' - background_color = '#D3D3D3' # Colour(200, 222, 40) + background_color = '#D3D3D3' enabled = False