void PWSTreeCtrl::FinishAddingGroup(wxTreeEvent& evt, wxTreeItemId groupItem) { if (evt.IsEditCancelled()) { // New item, not yet in db. So we could just remove from the tree Delete(groupItem); } else { // Can't call GetItemGroup here since the item doesn't actually have the new label wxString groupName = evt.GetLabel(); for (wxTreeItemId parent = GetItemParent(groupItem); parent != GetRootItem(); parent = GetItemParent(parent)) { groupName = GetItemText(parent) + wxT(".") + groupName; } StringX sxGroup = tostringx(groupName); // The new item we just added above will get removed once the update GUI callback from core happens. DBEmptyGroupsCommand* cmd = DBEmptyGroupsCommand::Create(&m_core, sxGroup, DBEmptyGroupsCommand::EG_ADD); if (cmd) m_core.Execute(cmd); // evt.GetItem() is not valid anymore. A new item has been inserted instead. // We can select it using the full path we computed earlier wxTreeItemId newItem = Find(groupName, GetRootItem()); if (newItem.IsOk()) wxTreeCtrl::SelectItem(newItem); } }
/** * Applique les modifications dans le fichier correspondant au nœud sélectionné * @param event un évènement */ void PreferenceCouleur::EvtTreeModifNomFin(wxTreeEvent &event) { if (!event.IsEditCancelled()) { //renommer le fichier - event.GetLabel(); if (wxFileExists(Parametre::Get()->getCheminCouleur(event.GetLabel()))) { wxLogMessage(_T("Fichier Existant !")); m_treeFiles->EndEditLabel(event.GetItem(), true); m_treeFiles->SetFocus(); } else { if (wxFileExists(Parametre::Get()->getCheminCouleur(m_treeFiles->GetItemText(event.GetItem())))) { ModifierFiltre(event.GetLabel().BeforeLast('.'), m_treeFiles->GetItemText(event.GetItem())); wxRemoveFile(Parametre::Get()->getCheminCouleur(m_treeFiles->GetItemText(event.GetItem()))); m_textNomSet->ChangeValue(event.GetLabel().BeforeLast('.')); m_treeFiles->SortChildren(m_nodeExistant); CallListeners(); } } } m_nomAvantModif.Clear(); }
/////////////////////////////////////////////////////////////////////////////// // GUI callback for when a label is done being edited by the user. Creates a // command to change the name of the dependency node associated with the item. // void SceneOutliner::OnEndLabelEdit( wxTreeEvent& args ) { if ( !args.IsEditCancelled() ) { SceneOutlinerItemData* data = GetTreeItemData( args.GetItem() ); Reflect::Object* object = data->GetObject(); SceneGraph::SceneNode* node = Reflect::SafeCast< SceneGraph::SceneNode >( object ); if ( node ) { const tstring newName = args.GetLabel().c_str(); if ( node->GetName() != newName ) { // Create an undoable command to rename the object m_CurrentScene->Push( new PropertyUndoCommand<tstring>( new Helium::MemberProperty<SceneGraph::SceneNode, tstring> (node, &SceneGraph::SceneNode::GetName, &SceneGraph::SceneNode::SetGivenName), newName) ); m_CurrentScene->Execute( false ); // Sort Sort( m_TreeCtrl->GetItemParent( args.GetItem() ) ); // Keep the item in view if ( !m_TreeCtrl->IsVisible( args.GetItem() ) ) { m_TreeCtrl->EnsureVisible( args.GetItem() ); } } args.Veto(); OnSelectionChanged( (wxTreeEvent)NULL ); } } }
void CollectionsPanel::OnMyCollectionsEndLabelEdit( wxTreeEvent& event ) { // this just makes the code below more generic in case we want to abstract it later SortTreeCtrl* treeCtrl = m_MyCollectionsTreeCtrl; event.Veto(); if( event.IsEditCancelled() ) { return; } wxTreeItemId item = event.GetItem(); if ( !item ) { return; } AssetCollectionItemData* baseData = GetItemData( treeCtrl, item ); if ( !baseData ) { return; } AssetCollection* collection = baseData->GetCollection<AssetCollection>(); if ( !collection || !collection->CanRename() ) { return; } wxString labelValue = event.GetLabel(); labelValue.Trim(true); // trim white-space right labelValue.Trim(false); // trim white-space left if ( labelValue.empty() ) { return; } tstring errors; collection->Freeze(); bool renameResult = m_CollectionManager->RenameCollection( collection, (const wxChar*)labelValue.c_str(), errors ); collection->Thaw(); if ( !renameResult ) { wxMessageBox( errors.c_str(), TXT( "MyCollection Name Already In Use" ), wxCENTER | wxICON_WARNING | wxOK, this ); //treeCtrl->EditLabel( item ); return; } }
void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) { if (event.IsEditCancelled()) return; if ((event.GetLabel().empty()) || (event.GetLabel() == wxT(".")) || (event.GetLabel() == wxT("..")) || (event.GetLabel().Find(wxT('/')) != wxNOT_FOUND) || (event.GetLabel().Find(wxT('\\')) != wxNOT_FOUND) || (event.GetLabel().Find(wxT('|')) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); return; } wxTreeItemId treeid = event.GetItem(); wxDirItemData *data = (wxDirItemData*)m_treeCtrl->GetItemData( treeid ); wxASSERT( data ); wxString new_name( wxPathOnly( data->m_path ) ); new_name += wxString(wxFILE_SEP_PATH); new_name += event.GetLabel(); wxLogNull log; if (wxFileExists(new_name)) { wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } if (wxRenameFile(data->m_path,new_name)) { data->SetNewDirName( new_name ); } else { wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); event.Veto(); } }
void PWSTreeCtrl::FinishRenamingGroup(wxTreeEvent& evt, wxTreeItemId groupItem, const wxString& oldPath) { wxCHECK_RET(ItemIsGroup(groupItem), wxT("Cannot handle renaming of non-group items")); if (evt.IsEditCancelled()) return; // We DON'T need to handle these two as they can only occur while moving items // not removing groups as they become empty // renaming of groups that have only other groups as children MultiCommands* pmcmd = MultiCommands::Create(&m_core); if (!pmcmd) return; // For some reason, Command objects can't handle const references StringX sxOldPath = tostringx(oldPath); StringX sxNewPath = tostringx(GetItemGroup(groupItem)); // This takes care of modifying all the actual items pmcmd->Add(RenameGroupCommand::Create(&m_core, sxOldPath, sxNewPath)); // But we have to do the empty groups ourselves because EG_RENAME is not recursive typedef std::vector<StringX> EmptyGroupsArray; const EmptyGroupsArray& emptyGroups = m_core.GetEmptyGroups(); StringX sxOldPathWithDot = sxOldPath + _T('.'); for( EmptyGroupsArray::const_iterator itr = emptyGroups.begin(); itr != emptyGroups.end(); ++itr) { if (*itr == sxOldPath || itr->find(sxOldPathWithDot) == 0) { StringX sxOld = *itr; StringX sxNew = sxNewPath + itr->substr(sxOldPath.size()); pmcmd->Add(DBEmptyGroupsCommand::Create(&m_core, sxOld, sxNew)); } } if (pmcmd->GetSize()) m_core.Execute(pmcmd); // The old treeItem is gone, since it was renamed. We need to find the new one to select it wxTreeItemId newItem = Find(towxstring(sxNewPath), GetRootItem()); if (newItem.IsOk()) wxTreeCtrl::SelectItem(newItem); }
void CBookmarksDialog::OnEndLabelEdit(wxTreeEvent& event) { if (event.IsEditCancelled()) return; wxTreeItemId item = event.GetItem(); if (item != m_pTree->GetSelection()) { if (!Verify()) { event.Veto(); return; } } if (!item || item == m_bookmarks_global || item == m_bookmarks_site) { event.Veto(); return; } wxString name = event.GetLabel(); wxTreeItemId parent = m_pTree->GetItemParent(item); wxTreeItemIdValue cookie; for (wxTreeItemId child = m_pTree->GetFirstChild(parent, cookie); child.IsOk(); child = m_pTree->GetNextChild(parent, cookie)) { if (child == item) continue; if (!name.CmpNoCase(m_pTree->GetItemText(child))) { wxMessageBoxEx(_("Name already exists"), _("Cannot rename entry"), wxICON_EXCLAMATION, this); event.Veto(); return; } } m_pTree->SortChildren(parent); }
void WatchWindow::OnEndLabelEdit(wxTreeEvent& event) { if (!event.IsEditCancelled()) { wxTreeItemId item = event.GetItem(); wxTreeItemId next = GetNextSibling(item); wxString expression = event.GetLabel(); expression.Trim().Trim(false); if (expression.empty()) { Delete(item); event.Veto(); } else { SetItemText(item, expression); UpdateItem(item); } CreateEmptySlotIfNeeded(); // Select the next item. if (!next.IsOk()) { wxTreeItemIdValue cookie; next = GetLastChild(GetRootItem(), cookie); } SelectItem(next); } m_editing = false; }
void PanelObjectList::OnTreeEndLabelEdit(wxTreeEvent& event) { wxTreeItemId id = event.GetItem(); TreeItemDataGenericObjectInfo* pData = (TreeItemDataGenericObjectInfo*)m_pTree_Objects->GetItemData( id ); if( pData && pData->m_pLabelEditFunction ) { //// end the edit to commit the new name //m_pTree_Objects->EndEditLabel( id ); wxString newlabel = event.GetLabel(); if( event.IsEditCancelled() == false ) { // manually set the item to the new name, so the callback func can query for the name. // the edit process seems to happen later RenameObject( pData->m_pObject, newlabel ); // Call the callback and let game code handle the new name pData->m_pLabelEditFunction( pData->m_pObject_LabelEdit ? pData->m_pObject_LabelEdit : pData->m_pObject, id, newlabel ); } } }
void CRemoteTreeView::OnEndLabelEdit(wxTreeEvent& event) { if (event.IsEditCancelled()) { event.Veto(); return; } if (!m_pState->IsRemoteIdle()) { event.Veto(); return; } CItemData* const pData = (CItemData*)GetItemData(event.GetItem()); if (pData) { event.Veto(); return; } CServerPath old_path = GetPathFromItem(event.GetItem()); CServerPath parent = old_path.GetParent(); const wxString& oldName = GetItemText(event.GetItem()); const wxString& newName = event.GetLabel(); if (oldName == newName) { event.Veto(); return; } m_pState->m_pCommandQueue->ProcessCommand(new CRenameCommand(parent, oldName, parent, newName)); m_pState->ChangeRemoteDir(parent); CServerPath currentPath; const wxTreeItemId selected = GetSelection(); if (selected) currentPath = GetPathFromItem(selected); if (currentPath.empty()) return; if (currentPath == old_path || currentPath.IsSubdirOf(old_path, false)) { // Previously selected path was below renamed one, list the new one std::list<wxString> subdirs; while (currentPath != old_path) { if (!currentPath.HasParent()) { // Abort just in case return; } subdirs.push_front(currentPath.GetLastSegment()); currentPath = currentPath.GetParent(); } currentPath = parent; currentPath.AddSegment(newName); for (std::list<wxString>::const_iterator iter = subdirs.begin(); iter != subdirs.end(); ++iter) currentPath.AddSegment(*iter); m_pState->ChangeRemoteDir(currentPath); } else if (currentPath != parent) m_pState->ChangeRemoteDir(currentPath); }
int bmx_wxtreeevent_iseditcancelled(wxTreeEvent & event) { return static_cast<int>(event.IsEditCancelled()); }
void CLocalTreeView::OnEndLabelEdit(wxTreeEvent& event) { if (event.IsEditCancelled()) { event.Veto(); return; } wxTreeItemId item = event.GetItem(); #ifdef __WXMSW__ if (item == m_desktop || item == m_documents) { wxBell(); event.Veto(); return; } #endif wxString path = GetDirFromItem(item); CLocalPath local_path(path); if (!local_path.HasParent() || !local_path.IsWriteable()) { wxBell(); event.Veto(); return; } if (path.Last() == wxFileName::GetPathSeparator()) path.RemoveLast(); int pos = path.Find(wxFileName::GetPathSeparator(), true); wxASSERT(pos != -1); wxString parent = path.Left(pos + 1); const wxString& oldName = GetItemText(item); const wxString& newName = event.GetLabel(); if (newName == _T("")) { wxBell(); event.Veto(); return; } wxASSERT(parent + oldName == path); if (oldName == newName) return; if (!Rename(this, parent, oldName, newName)) { event.Veto(); return; } // We may call SetLocalDir, item might be deleted by it, so // if we don't rename item now and veto the event, wxWidgets // might access deleted item. event.Veto(); SetItemText(item, newName); wxTreeItemId currentSel = GetSelection(); if (currentSel == wxTreeItemId()) { Refresh(); return; } if (item == currentSel) { m_pState->SetLocalDir(parent + newName); return; } wxString sub; wxTreeItemId tmp = currentSel; while (tmp != GetRootItem() && tmp != item) { sub = wxFileName::GetPathSeparator() + GetItemText(tmp) + sub; tmp = GetItemParent(tmp); } if (tmp == GetRootItem()) { // Rename unrelated to current selection return; } // Current selection below renamed item m_pState->SetLocalDir(parent + newName + sub); }
void SceneBrowser::OnEndLabelEdit(wxTreeEvent& event) { wxTreeItemId item = event.GetItem(); wxASSERT(item.IsOk()); if (event.IsEditCancelled()) return; String newName = AS_STRING(event.GetLabel()); if (mSceneManipulator->getSceneInfo()->isAutoName(newName)) { event.Veto(); wxMessageBox( wxString::Format(_("Cannot rename %s: The name is reserved for auto naming object. Specify a different name."), newName.c_str()), _("Error Renaming Object"), wxOK|wxCENTRE|wxICON_ERROR, this); return; } ObjectItemData* data = static_cast<ObjectItemData*>(mObjectsTree->GetItemData(item)); if (!data) { event.Veto(); return; } ObjectPtr object = data->object.lock(); if (!object) { event.Veto(); return; } if (newName.empty()) { // Always veto event.Veto(); if (mSceneManipulator->getSceneInfo()->isAutoName(object->getName())) return; // Generate auto name and set tree item text manual newName = mSceneManipulator->getSceneInfo()->generateAutoName(object); mObjectsTree->SetItemText(item, AS_STRING(newName)); } else { if (object->getName() == newName) { event.Veto(); return; } ObjectPtr other = mSceneManipulator->getSceneInfo()->findObjectByName(newName); if (other) { wxASSERT(other != object); event.Veto(); wxMessageBox( wxString::Format(_("Cannot rename %s: An object with the name you specified already exists. Specify a different name."), newName.c_str()), _("Error Renaming Object"), wxOK|wxCENTRE|wxICON_ERROR, this); return; } } mSceneManipulator->renameObject(object, newName, this); }
void CLocalTreeView::OnEndLabelEdit(wxTreeEvent& event) { if (event.IsEditCancelled()) { event.Veto(); return; } wxTreeItemId item = event.GetItem(); #ifdef __WXMSW__ if (item == m_desktop || item == m_documents) { wxBell(); event.Veto(); return; } #endif wxString path = GetDirFromItem(item); #ifdef __WXMSW__ if (path.Len() == 3 && path.Mid(1) == _T(":\\")) { wxBell(); event.Veto(); return; } #endif if (!m_pState->LocalDirHasParent(path) || !m_pState->LocalDirIsWriteable(path)) { wxBell(); event.Veto(); return; } if (path.Last() == wxFileName::GetPathSeparator()) path.RemoveLast(); int pos = path.Find(wxFileName::GetPathSeparator(), true); wxASSERT(pos != -1); wxString parent = path.Left(pos + 1); const wxString& oldName = GetItemText(item); const wxString& newName = event.GetLabel(); wxASSERT(parent + oldName == path); if (oldName == newName) return; if (!Rename(this, parent, oldName, newName)) { event.Veto(); return; } wxTreeItemId currentSel = GetSelection(); if (currentSel == wxTreeItemId()) { Refresh(); return; } if (item == currentSel) { m_pState->SetLocalDir(parent + newName); return; } wxString sub; wxTreeItemId tmp = currentSel; while (tmp != GetRootItem() && tmp != item) { sub = wxFileName::GetPathSeparator() + GetItemText(tmp) + sub; tmp = GetItemParent(tmp); } if (tmp == GetRootItem()) { // Rename unrelated to current selection return; } // Current selection below renamed item m_pState->SetLocalDir(parent + newName + sub); }
void MainFrame::OnTreeEndLabel(wxTreeEvent& evt) { if (evt.IsEditCancelled()) return; wxTreeItemId tree_id = m_pTree->GetItemParent(evt.GetItem()); if (!tree_id) { evt.Veto(); return; } TreeItemData* pItem = (TreeItemData*)m_pTree->GetItemData(tree_id); if (!pItem) { evt.Veto(); return; } wxString strOld = m_pTree->GetItemText(evt.GetItem()); SetCursor(*wxHOURGLASS_CURSOR); try { pItem->RenameKey(Omega::string_t(strOld.wc_str(),Omega::string_t::npos),Omega::string_t(evt.GetLabel().wc_str(),Omega::string_t::npos),(TreeItemData*)m_pTree->GetItemData(evt.GetItem())); } catch (Omega::IAlreadyExistsException* pE) { pE->Release(); wxMessageBox(wxString::Format(_("Cannot rename %s: The specified value name already exists. Type another name and try again."),strOld.c_str()),_("Error Renaming Value"),wxOK|wxICON_ERROR,this); evt.Veto(); m_pTree->EditLabel(evt.GetItem()); } catch (Omega::Registry::IBadNameException* pE) { pE->Release(); wxMessageBox(wxString::Format(_("Cannot rename %s: The specified value name is invalid. Type another name and try again."),strOld.c_str()),_("Error Renaming Value"),wxOK|wxICON_ERROR,this); evt.Veto(); m_pTree->EditLabel(evt.GetItem()); } catch (Omega::Registry::IAccessDeniedException* pE) { pE->Release(); wxMessageBox(wxString::Format(_("Cannot rename %s: You do not have permission to edit this part of the registry."),strOld.c_str()),_("Error Renaming Value"),wxOK|wxICON_ERROR,this); evt.Veto(); m_pTree->EditLabel(evt.GetItem()); } catch (Omega::IException* pE) { wxMessageBox(pE->GetDescription().c_wstr(),_("System Error"),wxOK|wxICON_ERROR,this); pE->Release(); SetCursor(*wxSTANDARD_CURSOR); evt.Veto(); m_pTree->EditLabel(evt.GetItem()); } catch(...) { SetCursor(*wxSTANDARD_CURSOR); evt.Veto(); throw; } SetCursor(*wxSTANDARD_CURSOR); pItem = (TreeItemData*)m_pTree->GetItemData(evt.GetItem()); pItem->Refresh(m_pList,m_pTree,evt.GetItem()); }