Skip to content

Commit

Permalink
Entity Tree: Select first entity initially, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfstr committed Aug 31, 2024
1 parent 26c7457 commit 474bac7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/crystal/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def _create_entity_tree(self, parent: wx.Window, progress_listener: OpenProjectP
"""
self.entity_tree = EntityTree(parent, self.project, progress_listener)
bind(self.entity_tree.peer, wx.EVT_TREE_SEL_CHANGED, self._on_selected_entity_changed)
self._on_selected_entity_changed()

return self.entity_tree.peer

Expand Down Expand Up @@ -829,7 +830,7 @@ def start_server(self) -> 'ProjectServer':

# === Entity Pane: Events ===

def _on_selected_entity_changed(self, event: wx.TreeEvent) -> None:
def _on_selected_entity_changed(self, event: Optional[wx.TreeEvent]=None) -> None:
selected_entity = self.entity_tree.selected_entity # cache

readonly = self._readonly # cache
Expand Down
5 changes: 5 additions & 0 deletions src/crystal/browser/entitytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def __init__(self,
bind(self.peer, wx.EVT_MOTION, self._on_mouse_motion)
# For tests only
bind(self.peer, EVT_TREE_ITEM_GETTOOLTIP, self._on_get_tooltip_event)

# Select first top-level entity initially, if available
root_children = self.root.children
if len(root_children) >= 1:
root_children[0].view.peer.SelectItem()

# === Bulkhead ===

Expand Down
6 changes: 1 addition & 5 deletions src/crystal/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,7 @@ async def test_can_download_and_serve_a_static_site() -> None:
# 1. Test cannot add new root resource in read-only project
# 2. Test cannot add new resource group in read-only project
selected_ti = TreeItem.GetSelection(mw.entity_tree.window)
if is_windows():
# Windows will initialize the selection to the first child of the root
assert selected_ti == feed_group_ti
else:
assert (selected_ti is None) or (selected_ti == root_ti)
assert selected_ti == feed_group_ti
assert False == mw.new_root_url_button.IsEnabled()
assert False == mw.new_group_button.IsEnabled()

Expand Down

0 comments on commit 474bac7

Please sign in to comment.