diff --git a/pgadmin/ctl/ctlTree.cpp b/pgadmin/ctl/ctlTree.cpp index 510d58f..dca6c5f 100644 --- a/pgadmin/ctl/ctlTree.cpp +++ b/pgadmin/ctl/ctlTree.cpp @@ -2,7 +2,7 @@ // // pgAdmin III - PostgreSQL Tools // -// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// Copyright (C) 2002 - 2015, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // // ctlTree.cpp - wxTreeCtrl containing pgObjects @@ -316,7 +316,53 @@ pgCollection *ctlTree::FindCollection(pgaFactory &factory, wxTreeItemId parent) return 0; return collection; } - +void ctlTree::NavigateTree(int keyCode) +{ + switch(keyCode) + { + case WXK_LEFT: + { + //If tree item has children and is expanded, collapse it, otherwise select it's parent if has one + wxTreeItemId currItem = GetSelection(); + if (ItemHasChildren(currItem) && IsExpanded(currItem)) + { + Collapse(currItem); + } + else + { + wxTreeItemId parent = GetItemParent( currItem) ; + if (parent.IsOk()) + { + SelectItem(currItem,false); + SelectItem(parent,true); + } + } + } + break; + case WXK_RIGHT: + { + //If tree item do not have any children ignore it, + //otherwise expand it if not expanded, and select first child if already expanded + wxTreeItemId currItem = GetSelection(); + if(ItemHasChildren(currItem)) + { + if (!IsExpanded(currItem)) + { + Expand(currItem); + } + else + { + wxCookieType cookie; + wxTreeItemId firstChild = GetFirstChild(currItem,cookie); + SelectItem(firstChild,true); + } + } + } + break; + default: + wxASSERT_MSG(false,_("Currently handles only right and left arrow key, other keys are working")); + } +} ////////////////////// diff --git a/pgadmin/frm/events.cpp b/pgadmin/frm/events.cpp index 556fc73..b4f7308 100644 --- a/pgadmin/frm/events.cpp +++ b/pgadmin/frm/events.cpp @@ -2,7 +2,7 @@ // // pgAdmin III - PostgreSQL Tools // -// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// Copyright (C) 2002 - 2015, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // // events.cpp - Event handlers for frmMain @@ -130,7 +130,8 @@ void frmMain::OnSize(wxSizeEvent &event) // to reset m_metaDown void frmMain::OnTreeKeyDown(wxTreeEvent &event) { - switch (event.GetKeyCode()) + int keyCode = event.GetKeyCode(); + switch (keyCode) { case WXK_F1: OnHelp(event); @@ -141,6 +142,11 @@ void frmMain::OnTreeKeyDown(wxTreeEvent &event) case WXK_DELETE: OnDelete(event); break; + //Is tempting to write all cases(this handler) in tree control itself + case WXK_LEFT: + case WXK_RIGHT: + browser->NavigateTree(keyCode); + break; default: event.Skip(); break; diff --git a/pgadmin/include/ctl/ctlTree.h b/pgadmin/include/ctl/ctlTree.h index 54a1424..1f76027 100644 --- a/pgadmin/include/ctl/ctlTree.h +++ b/pgadmin/include/ctl/ctlTree.h @@ -2,7 +2,7 @@ // // pgAdmin III - PostgreSQL Tools // -// Copyright (C) 2002 - 2014, The pgAdmin Development Team +// Copyright (C) 2002 - 2015, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // // ctlTree.h - wxTreeCtrl containing pgObjects @@ -40,6 +40,7 @@ public: pgObject *FindObject(pgaFactory &factory, wxTreeItemId parent); pgCollection *FindCollection(pgaFactory &factory, wxTreeItemId parent); wxTreeItemId FindItem(const wxTreeItemId &item, const wxString &str); + void NavigateTree(int keyCode); virtual ~ctlTree(); DECLARE_EVENT_TABLE()