+ wxString name = event.GetLabel();
+
+ TreeNode *pNode = GetNode(event);
+ if ( pNode->IsKey() )
+ {
+ wxRegKey& key = pNode->Key();
+ ok = key.Rename(name);
+ }
+ else
+ {
+ pNode = pNode->Parent();
+ wxRegKey& key = pNode->Key();
+
+ ok = key.RenameValue(m_nameOld, name);
+ }
+
+ if ( !ok ) {
+ wxLogError(_T("Failed to rename '%s' to '%s'."),
+ m_nameOld.c_str(), name.c_str());
+ }
+#if 0 // MSW tree ctrl doesn't like this at all, it hangs
+ else {
+ pNode->Refresh();
+ }
+#endif // 0
+}
+
+void RegTreeCtrl::OnBeginDrag(wxTreeEvent& event)
+{
+ m_copyOnDrop = event.GetEventType() == wxEVT_COMMAND_TREE_BEGIN_DRAG;
+
+ TreeNode *pNode = GetNode(event);
+ if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
+ {
+ wxLogStatus("This registry key can't be %s.",
+ m_copyOnDrop ? "copied" : "moved");
+ }
+ else
+ {
+ wxLogStatus("%s item %s...",
+ m_copyOnDrop ? "Copying" : "Moving",
+ pNode->FullName());
+
+ m_draggedItem = pNode;
+
+ event.Allow();
+ }
+}
+
+void RegTreeCtrl::OnEndDrag(wxTreeEvent& event)
+{
+ wxCHECK_RET( m_draggedItem, "end drag without begin drag?" );
+
+ // clear the pointer anyhow
+ TreeNode *src = m_draggedItem;
+ m_draggedItem = NULL;
+
+ // where are we going to drop it?
+ TreeNode *dst = GetNode(event);
+ if ( dst && !dst->IsKey() ) {
+ // we need a parent key
+ dst = dst->Parent();
+ }
+ if ( !dst || dst->IsRoot() ) {
+ wxLogError("Can't create a key here.");
+
+ return;
+ }
+
+ bool isKey = src->IsKey();
+ if ( (isKey && (src == dst)) ||
+ (!isKey && (dst->Parent() == src)) ) {
+ wxLogStatus("Can't copy something on itself");
+
+ return;
+ }
+
+ // remove the "Registry Root\\" from the full name
+ wxString nameSrc, nameDst;
+ nameSrc << wxString(src->FullName()).AfterFirst('\\');
+ nameDst << wxString(dst->FullName()).AfterFirst('\\') << '\\'
+ << wxString(src->FullName()).AfterLast('\\');
+
+ wxString verb = m_copyOnDrop ? "copy" : "move";
+ wxString what = isKey ? "key" : "value";
+
+ if ( wxMessageBox(wxString::Format
+ (
+ "Do you really want to %s the %s %s to %s?",
+ verb.c_str(),
+ what.c_str(),
+ nameSrc.c_str(),
+ nameDst.c_str()
+ ),
+ "RegTest Confirm",
+ wxICON_QUESTION | wxYES_NO | wxCANCEL, this) != wxYES ) {
+ return;
+ }
+
+ bool ok;
+ if ( isKey ) {
+ wxRegKey& key = src->Key();
+ wxRegKey keyDst(dst->Key(), src->m_strName);
+ ok = keyDst.Create(FALSE);
+ if ( !ok ) {
+ wxLogError("Key '%s' already exists");
+ }
+ else {
+ ok = key.Copy(keyDst);
+ }
+
+ if ( ok && !m_copyOnDrop ) {
+ // delete the old key
+ ok = key.DeleteSelf();
+ if ( ok ) {
+ src->Parent()->Refresh();
+ }
+ }
+ }
+ else { // value
+ wxRegKey& key = src->Parent()->Key();
+ ok = key.CopyValue(src->m_strName, dst->Key());
+ if ( ok && !m_copyOnDrop ) {
+ // we moved it, so delete the old one
+ ok = key.DeleteValue(src->m_strName);
+ }
+ }
+
+ if ( !ok ) {
+ wxLogError("Failed to %s registry %s.", verb.c_str(), what.c_str());
+ }
+ else {
+ dst->Refresh();
+ }