| 727 | } |
| 728 | |
| 729 | LRESULT CRegistryManagerView::OnTreeEndEdit(int /*idCtrl*/, LPNMHDR hdr, BOOL& /*bHandled*/) { |
| 730 | auto& item = ((NMTVDISPINFO*)hdr)->item; |
| 731 | if (item.pszText == nullptr) { |
| 732 | // cancelled |
| 733 | if (m_CurrentOperation == Operation::CreateKey) |
| 734 | m_Tree.DeleteItem(item.hItem); |
| 735 | return FALSE; |
| 736 | } |
| 737 | |
| 738 | switch (m_CurrentOperation) |
| 739 | { |
| 740 | case CRegistryManagerView::Operation::RenameKey: |
| 741 | { |
| 742 | CString name; |
| 743 | m_Tree.GetItemText(item.hItem, name); |
| 744 | auto cb = [this](auto& cmd, bool) { |
| 745 | auto hParent = FindItemByPath(cmd.GetPath()); |
| 746 | ATLASSERT(hParent); |
| 747 | TreeHelper th(m_Tree); |
| 748 | auto hItem = th.FindChild(hParent, cmd.GetName()); |
| 749 | ATLASSERT(hItem); |
| 750 | m_Tree.SetItemText(hItem, cmd.GetNewName()); |
| 751 | return true; |
| 752 | }; |
| 753 | auto hParent = m_Tree.GetParentItem(item.hItem); |
| 754 | auto cmd = std::make_shared<RenameKeyCommand>(GetFullNodePath(hParent), name, item.pszText); |
| 755 | if (!m_CmdMgr.AddCommand(cmd)) { |
| 756 | DisplayError(L"Failed to rename key"); |
| 757 | return FALSE; |
| 758 | } |
| 759 | cmd->SetCallback(cb); |
| 760 | return TRUE; |
| 761 | } |
| 762 | case CRegistryManagerView::Operation::CreateKey: |
| 763 | { |
| 764 | auto hItem = item.hItem; |
| 765 | auto hParent = m_Tree.GetParentItem(hItem); |
| 766 | auto cmd = std::make_shared<CreateKeyCommand>(GetFullNodePath(hParent), item.pszText); |
| 767 | if (!m_CmdMgr.AddCommand(cmd)) { |
| 768 | m_Tree.DeleteItem(hItem); |
| 769 | DisplayError(L"Failed to create key"); |
| 770 | return FALSE; |
| 771 | } |
| 772 | auto cb = [this](auto& cmd, bool execute) { |
| 773 | if (execute) { |
| 774 | auto hParent = FindItemByPath(cmd.GetPath()); |
| 775 | ATLASSERT(hParent); |
| 776 | auto hItem = InsertKeyItem(hParent, cmd.GetName()); |
| 777 | m_Tree.EnsureVisible(hItem); |
| 778 | } |
| 779 | else { |
| 780 | auto hItem = FindItemByPath(cmd.GetPath() + L"\\" + cmd.GetName()); |
| 781 | ATLASSERT(hItem); |
| 782 | m_Tree.DeleteItem(hItem); |
| 783 | } |
| 784 | return true; |
| 785 | }; |
| 786 | cmd->SetCallback(cb); |
nothing calls this directly
no test coverage detected