Skip to content

Commit 0761813

Browse files
Fix crashes when editing Tree items.
1 parent 257c699 commit 0761813

File tree

9 files changed

+96
-74
lines changed

9 files changed

+96
-74
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html[Semantic Versioni
99
== https://github.com/robotframework/RIDE[Unreleased]
1010

1111
=== Fixed
12+
- Fixed crash when renaming test cases names on Tree (Project Explorer), by cancelling with Escape or by adding a Space in the end.
1213
- Fixed missing text colorization in suites and test settings on Grid Editor.
1314

1415
== https://github.com/robotframework/RIDE/blob/master/doc/releasenotes/ride-2.1.5.2.rst[2.1.5.2] - 2025-07-30

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Likewise, the current version of wxPython, is 4.2.3, but RIDE is known to work w
4444

4545
`pip install -U robotframework-ride`
4646

47-
(3.8 <= python <= 3.14) Install current development version (**2.2dev40**) with:
47+
(3.8 <= python <= 3.14) Install current development version (**2.2dev41**) with:
4848

4949
`pip install -U https://github.com/robotframework/RIDE/archive/develop.zip`
5050

src/robotide/application/CHANGELOG.html

Lines changed: 65 additions & 61 deletions
Large diffs are not rendered by default.

src/robotide/application/releasenotes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def set_content(self, html_win, content):
175175
</ul>
176176
<p><strong>New Features and Fixes Highlights</strong></p>
177177
<ul class="simple">
178+
<li>Fixed crash when renaming test cases names on Tree (Project Explorer), by cancelling with Escape or by adding a Space
179+
in the end.</li>
178180
<li>Fixed missing text colorization in suites and test settings on Grid Editor.</li>
179181
<li>Restored init and main scripts and texteditor, because some changes in Grid Editor were not being saved in Text
180182
Editor and would be lost.</li>
@@ -241,7 +243,7 @@ def set_content(self, html_win, content):
241243
<pre class="literal-block">python -m robotide.postinstall -install</pre>
242244
<p>or</p>
243245
<pre class="literal-block">ride_postinstall.py -install</pre>
244-
<p>RIDE {VERSION} was released on 14/August/2025.</p>
246+
<p>RIDE {VERSION} was released on 17/August/2025.</p>
245247
<!-- <br/>
246248
<h3>May The Fourth Be With You!</h3>
247249
<h3>Celebrate the bank holiday, 10th June, Day of Portugal, Portuguese Communities and Camões!!</h3>

src/robotide/controller/ctrlcommands.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,15 @@ def _get_undo_command(self):
375375
class RenameTest(_ReversibleCommand):
376376

377377
def __init__(self, new_name):
378-
self._new_name = new_name
378+
self._new_name = new_name.strip()
379379

380380
def _params(self):
381381
return self._new_name
382382

383383
def _execute(self, context):
384384
old_name = context.name
385+
if old_name == self._new_name:
386+
return
385387
context.test_name.rename(self._new_name)
386388
context.test_name._item.notify_name_changed(old_name=old_name, new_name=self._new_name)
387389

@@ -393,7 +395,7 @@ class RenameFile(_Command):
393395

394396
def __init__(self, new_basename):
395397
self._new_basename = new_basename
396-
self._validator = validators.BaseNameValidator(new_basename)
398+
self._validator = validators.BaseNameValidator(new_basename.strip())
397399

398400
def execute(self, context):
399401
validation_result = self._validator.validate(context)
@@ -424,7 +426,7 @@ def execute(self, directory_controller):
424426
class RenameResourceFile(_Command):
425427

426428
def __init__(self, new_basename, get_should_modify_imports):
427-
self._new_basename = new_basename
429+
self._new_basename = new_basename.strip()
428430
self._should_modify_imports = get_should_modify_imports
429431

430432
def execute(self, context):

src/robotide/controller/ui/treecontroller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def _get_bind_keys(self):
140140
(ctrl_or_cmd(), wx.WXK_UP, self._tree.on_move_up),
141141
(ctrl_or_cmd(), wx.WXK_DOWN, self._tree.on_move_down),
142142
(wx.ACCEL_NORMAL, wx.WXK_F2, self._tree.label_editor.on_label_edit),
143+
(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, self._tree.label_editor.on_label_edited),
143144
(wx.ACCEL_NORMAL, wx.WXK_WINDOWS_MENU, self._tree.on_right_click),
144145
(ctrl_or_cmd() | wx.ACCEL_SHIFT, ord('d'), lambda event: self._expanded_handler().on_safe_delete(event)),
145146
(ctrl_or_cmd() | wx.ACCEL_SHIFT, ord('f'),

src/robotide/ui/treenodehandlers.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def on_include(self, event):
198198

199199

200200
class _CanBeRenamed(object):
201+
_node = None
202+
_old_label = None
201203

202204
def on_rename(self, event):
203205
__ = event
@@ -206,13 +208,15 @@ def on_rename(self, event):
206208
def begin_label_edit(self):
207209
def label_edit():
208210
# DEBUG: fixme yep.yep.yep.yep.yep
209-
node = self._tree.controller.find_node_by_controller(self.controller)
210-
if node:
211-
self._tree.EditLabel(node)
211+
self._node = self._tree.controller.find_node_by_controller(self.controller)
212+
if self._node:
213+
self._old_label = self._tree.GetItemText(self._node)
214+
self._tree.EditLabel(self._node)
212215
# Must handle pending events before label edit
213216
# This is a fix for situations where there is a pending action
214217
# that will change this label (Text Editor all changing actions)
215-
wx.CallAfter(label_edit)
218+
# wx.CallAfter(label_edit)
219+
label_edit()
216220
return True
217221

218222
def end_label_edit(self, event):
@@ -221,6 +225,11 @@ def end_label_edit(self, event):
221225
self.rename(event.GetLabel())
222226
else:
223227
event.Veto()
228+
else:
229+
self._set_node_label(self._old_label)
230+
231+
def _set_node_label(self, label):
232+
self._tree.SetItemText(self._node, label)
224233

225234
def _is_valid_rename(self, label):
226235
validation = self.controller.validate_name(label)

src/robotide/ui/treeplugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from wx import Colour, Point
2121
from wx.lib.agw import customtreectrl
2222
from wx.lib.agw.aui import GetManager
23-
from wx.lib.agw.customtreectrl import GenericTreeItem
23+
from wx.lib.agw.customtreectrl import GenericTreeItem, TreeEvent
2424
from wx.lib.mixins import treemixin
2525

2626
from ..context import IS_WINDOWS
@@ -1285,9 +1285,12 @@ def on_label_edit(self, event=None):
12851285
self._editing_label = False
12861286

12871287
def on_label_edited(self, event):
1288+
if not self._editing_label:
1289+
return
12881290
self._editing_label = False
12891291
self._on_label_edit_called = False
1290-
self._tree.controller.get_handler(event.GetItem()).end_label_edit(event)
1292+
if isinstance(event, TreeEvent):
1293+
self._tree.controller.get_handler(event.GetItem()).end_label_edit(event)
12911294

12921295
# Reset edit control as it doesn't seem to reset it in case the focus
12931296
# goes directly away from the tree control
@@ -1300,7 +1303,7 @@ def on_label_edited(self, event):
13001303

13011304
def _stop_editing(self):
13021305
control = self._tree.GetEditControl()
1303-
if control and wx.Window.FindFocus():
1306+
if control: # and wx.Window.FindFocus():
13041307
control.StopEditing()
13051308

13061309
def on_delete(self, event):

src/robotide/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
#
1616
# Automatically generated by `tasks.py`.
1717

18-
VERSION = 'v2.2dev40'
18+
VERSION = 'v2.2dev41'

0 commit comments

Comments
 (0)