Skip to content

Commit

Permalink
Merge pull request #288 from topic2k/add_expand_collapse_items
Browse files Browse the repository at this point in the history
Add expand/collapse to toolbar, menu and context menu (config tree).
  • Loading branch information
topic2k committed Jun 3, 2018
2 parents 3270c21 + 5bc287a commit ba8443f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 9 deletions.
55 changes: 48 additions & 7 deletions eg/Classes/MainFrame/TreeCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,32 @@ def ClearInsertMark(self):
SendMessageTimeout(self.hwnd, 4378, 0, long(0), 1, 100, None)
self.insertionMark = None

@eg.AssertInMainThread
def CollapseAllChildren(self, item_id):
"""
Collapses all children of the selected item.
"""
if not item_id.IsOk():
return
if not self.ItemHasChildren(item_id):
return

def collaps(item):
child, cookie = self.GetFirstChild(item)
while child.IsOk():
if self.ItemHasChildren(child):
collaps(child)
if self.IsExpanded(child):
self.Collapse(child)
child, cookie = self.GetNextChild(item, cookie)
self.Freeze()
try:
collaps(item_id)
finally:
if not self.IsVisible(item_id):
self.EnsureVisible(item_id)
self.Thaw()

@eg.AssertInMainThread
def CollapseAll(self):
"""
Expand All @@ -392,7 +418,8 @@ def CollapseAll(self):
self.visibleNodes = mainNodes
self.expandedNodes.clear()
self.expandedNodes.add(self.root)
self.EnsureVisible(self.GetSelection())
if not self.IsVisible(self.GetSelection()):
self.EnsureVisible(self.GetSelection())
self.Thaw()

@eg.AssertInMainThread
Expand Down Expand Up @@ -462,27 +489,41 @@ def EditNodeLabel(self, node):
self.EditLabel(self.visibleNodes[node])

@eg.AssertInMainThread
def ExpandAll(self):
def ExpandAllChildren(self, item_id):
"""
Expands all items in the tree.
"""
if not item_id.IsOk():
return
self.Freeze()

def Exp(item):
def _expand(item):
child, cookie = self.GetFirstChild(item)
while child.IsOk():
if not self.IsExpanded(child):
self.Expand(child)
Exp(child)
_expand(child)
child, cookie = self.GetNextChild(child, cookie)

if not self.IsExpanded(item_id):
self.Expand(item_id)

try:
item = self.GetRootItem()
Exp(item)
_expand(item_id)
finally:
self.EnsureVisible(self.GetSelection())
if not self.IsVisible(item_id):
self.EnsureVisible(item_id)
self.Thaw()

@eg.AssertInMainThread
def ExpandAll(self):
"""
Expands all items in the tree.
"""
self.ExpandAllChildren(self.GetRootItem())
if not self.IsVisible(self.GetSelection()):
self.EnsureVisible(self.GetSelection())

@eg.AssertInMainThread
def GetEditCmdState(self):
node = self.GetSelectedNode()
Expand Down
38 changes: 36 additions & 2 deletions eg/Classes/MainFrame/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ def FuncWrapper(dummyEvent):
menuBar.Append(menu, text.ViewMenu)
Append("HideShowToolbar", kind=wx.ITEM_CHECK).Check(Config.showToolbar)
menu.AppendSeparator()
Append("ExpandAll")
Append("CollapseAll")
Append("Expand", image=GetInternalBitmap("expand"))
Append("Collapse", image=GetInternalBitmap("collapse"))
Append("ExpandChilds", image=GetInternalBitmap("expand_children"))
Append("CollapseChilds", image=GetInternalBitmap("collapse_children"))
Append("ExpandAll", image=GetInternalBitmap("expand_all"))
Append("CollapseAll", image=GetInternalBitmap("collapse_all"))
menu.AppendSeparator()
item = Append("ExpandOnEvents", kind=wx.ITEM_CHECK)
item.Check(Config.expandOnEvents)
Expand Down Expand Up @@ -406,6 +410,13 @@ def Append(ident, image):
GetInternalBitmap("Execute"),
getattr(text, "Execute")
)
toolBar.AddSeparator()
Append("Expand", GetInternalBitmap("expand"))
Append("Collapse", GetInternalBitmap("collapse"))
Append("ExpandChilds", GetInternalBitmap("expand_children"))
Append("CollapseChilds", GetInternalBitmap("collapse_children"))
Append("ExpandAll", GetInternalBitmap("expand_all"))
Append("CollapseAll", GetInternalBitmap("collapse_all"))

toolBar.EnableTool(wx.ID_SAVE, self.document.isDirty)
toolBar.Realize()
Expand Down Expand Up @@ -446,6 +457,15 @@ def Append(ident, kind=wx.ITEM_NORMAL, image=wx.NullBitmap):
menu.AppendItem(item)
return item

Append("Expand", image=GetInternalBitmap("expand"))
Append("Collapse", image=GetInternalBitmap("collapse"))
Append("ExpandChilds", image=GetInternalBitmap("expand_children"))
Append("CollapseChilds", image=GetInternalBitmap("collapse_children"))
Append("ExpandAll", image=GetInternalBitmap("expand_all"))
Append("CollapseAll", image=GetInternalBitmap("collapse_all"))
subm = menu
menu = wx.Menu()

Append("Undo")
Append("Redo")
menu.AppendSeparator()
Expand All @@ -455,6 +475,8 @@ def Append(ident, kind=wx.ITEM_NORMAL, image=wx.NullBitmap):
Append("Paste")
Append("Delete")
menu.AppendSeparator()
menu.AppendMenu(wx.ID_ANY, text=text.ExpandCollapseMenu, submenu=subm)
menu.AppendSeparator()
Append("AddPlugin", image=ADD_PLUGIN_ICON)
Append("AddFolder", image=ADD_FOLDER_ICON)
Append("AddMacro", image=ADD_MACRO_ICON)
Expand Down Expand Up @@ -901,6 +923,18 @@ def OnCmdHideShowToolbar(self):
self.Layout()
self.SendSizeEvent()

def OnCmdExpand(self):
self.treeCtrl.Expand(self.treeCtrl.GetSelection())

def OnCmdCollapse(self):
self.treeCtrl.Collapse(self.treeCtrl.GetSelection())

def OnCmdExpandChilds(self):
self.treeCtrl.ExpandAllChildren(self.treeCtrl.GetSelection())

def OnCmdCollapseChilds(self):
self.treeCtrl.CollapseAllChildren(self.treeCtrl.GetSelection())

def OnCmdExpandAll(self):
self.treeCtrl.ExpandAll()

Expand Down
5 changes: 5 additions & 0 deletions eg/Classes/Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class Menu:

ViewMenu = "&View"
HideShowToolbar = "&Toolbar"
ExpandCollapseMenu = "Expand/Collapse"
Expand = "Expand"
Collapse = "Collapse"
ExpandChilds = "Expand all children"
CollapseChilds = "Collapse all children"
ExpandAll = "&Expand All"
CollapseAll = "&Collapse All"
ExpandOnEvents = "Select on E&xecution"
Expand Down
Binary file added images/collapse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/collapse_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/collapse_children.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/expand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/expand_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/expand_children.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba8443f

Please sign in to comment.