void wxGxContentView::OnBeginLabelEdit(wxListEvent& event) { LPITEMDATA pItemData = (LPITEMDATA)event.GetData(); if(pItemData == NULL) { event.Veto(); return; } wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pItemData->nObjectID); IGxObjectEdit* pObjEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pObjEdit == NULL) { event.Veto(); return; } if(!pObjEdit->CanRename()) { event.Veto(); return; } //event.Skip(); }
void wxGISCatalogMainCmd::OnClick(void) { wxCHECK_RET(m_pGxApp && m_pApp, wxT("Application pointer is null")); wxGxSelection* pSel = m_pGxApp->GetGxSelection(); wxGxCatalogBase* pCat = GetGxCatalog(); switch(m_subtype) { case 0: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); if(!pGxObject) return; wxGxObject* pParentGxObject = pGxObject->GetParent(); if(pParentGxObject) { pSel->Select(pParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } /* if(wxIsKindOf(pParentGxObject, wxGxObjectContainer)) { pSel->Select(pParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } else { wxGxObject* pGrandParentGxObject = pParentGxObject->GetParent(); pSel->Select(pGrandParentGxObject->GetId(), false, wxGxSelection::INIT_ALL); } */ } break; case 1:// 1 Connect Folder { wxDirDialog dlg(dynamic_cast<wxWindow*>(m_pApp), wxString(_("Choose a folder to connect"))); if(pSel && pCat && dlg.ShowModal() == wxID_OK) { wxGxCatalog* pGxCatalog = wxDynamicCast(pCat, wxGxCatalog); if(pGxCatalog) { wxGxDiscConnections* pGxDiscConnections = wxDynamicCast(pGxCatalog->GetRootItemByType(wxCLASSINFO(wxGxDiscConnections)), wxGxDiscConnections); if(pGxDiscConnections && pGxDiscConnections->ConnectFolder(dlg.GetPath())) return; else wxMessageBox(_("Cannot connect folder"), _("Error"), wxOK | wxICON_ERROR); } } return; } case 2:// 2 Disconnect Folder - duplicate Delete command { if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); wxGxDiscConnection* pGxDiscConnection = wxDynamicCast(pGxObject, wxGxDiscConnection); if(pGxDiscConnection && pGxDiscConnection->Delete()) return; else wxMessageBox(_("Cannot disconnect folder"), _("Error"), wxOK | wxICON_ERROR); } return; } case 8: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); wxGxView* pGxView = dynamic_cast<wxGxView*>(wxWindow::FindFocus()); if(pGxView && pGxObject) pGxView->BeginRename(pGxObject->GetId()); } break; case 4: if(pSel && pCat) { bool bAskToDelete(true); wxGISAppConfig oConfig = GetConfig(); bAskToDelete = oConfig.ReadBool(enumGISHKCU, m_pApp->GetAppName() + wxString(wxT("/catalog/ask_delete")), bAskToDelete); if(bAskToDelete) { //show ask dialog wxWindow* pWnd = dynamic_cast<wxWindow*>(m_pApp); wxRichMessageDialog dlg(pWnd, wxString::Format(_("Do you really want to delete %d item(s)"), pSel->GetCount()), wxString(_("Delete confirm")), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION | wxSTAY_ON_TOP | wxCENTRE); dlg.SetExtendedMessage(wxString(_("The result of operation cannot be undone!\nThe deleted items will remove from disk and will not put to the recycled bin."))); dlg.ShowCheckBox("Use my choice and do not show this dialog in future"); int nRes = dlg.ShowModal(); if(oConfig.IsOk()) oConfig.Write(enumGISHKCU, m_pApp->GetAppName() + wxString(wxT("/catalog/ask_delete")), !dlg.IsCheckBoxChecked()); if(nRes == wxID_NO) return; } for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanDelete()) { if(!pGxObjectEdit->Delete()) { wxWindow* pWnd = dynamic_cast<wxWindow*>(m_pApp); if(i == pSel->GetCount() - 1) { wxMessageBox(wxString::Format(_("Delete '%s'failed"), pGxObject->GetName().c_str()), _("Error"), wxOK | wxICON_ERROR, pWnd); return; } int nRes = wxMessageBox(wxString::Format(_("Cannot delete '%s'\nContinue?"), pGxObject->GetName().c_str()), _("Error"), wxYES_NO | wxICON_QUESTION, pWnd); if(nRes == wxNO) return; } } } } return; case 5: if(pSel && pCat) { long nSelId = wxNOT_FOUND; if(pSel->CanUndo()) { nSelId = pSel->Undo(wxNOT_FOUND); } if(pCat->GetRegisterObject(nSelId)) { pSel->Select(nSelId, false, wxGxSelection::INIT_ALL); } } return; case 6: if(pSel && pCat) { long nSelId = wxNOT_FOUND; if(pSel->CanRedo()) { nSelId = pSel->Redo(wxNOT_FOUND); } if(pCat->GetRegisterObject(nSelId)) { pSel->Select(nSelId, false, wxGxSelection::INIT_ALL); } } return; case 9: if(pSel && pCat) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) pGxObject->Refresh(); } } return; case 10: if(pSel && pCat) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); IGxObjectEditUI* pGxObjectEdit = dynamic_cast<IGxObjectEditUI*>(pGxObject); if(pGxObjectEdit) pGxObjectEdit->EditProperties(dynamic_cast<wxWindow*>(m_pApp)); } return; case 11://copy if(pSel && pCat) { wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) { wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); } } //! Lock clipboard wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { //! Put data to clipboard if(!wxTheClipboard->AddData(pDragData)) wxMessageBox(_("Can't copy file(s) to the clipboard"), _("Error"), wxOK | wxICON_ERROR); } } return; case 12://cut if(pSel && pCat) { wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); pDragData->Add(new wxTextDataObject(wxT("cut"))); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); if(pGxObject) { wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); } } //! Lock clipboard wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { //! Put data to clipboard if(!wxTheClipboard->AddData(pDragData)) wxMessageBox(_("Can't copy file(s) to the clipboard"), _("Error"), wxOK | wxICON_ERROR); } } return; case 13://paste if(pSel && pCat) { IGxDropTarget* pTarget = dynamic_cast<IGxDropTarget*>(pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId())); if(!pTarget) return; wxClipboardLocker locker; if(!locker) wxMessageBox(_("Can't open clipboard"), _("Error"), wxOK | wxICON_ERROR); else { wxTextDataObject data; bool bMove(false); if(wxTheClipboard->GetData( data )) { if(data.GetText() == wxString(wxT("cut"))) bMove = true; } wxGISStringDataObject data_names(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-name"))); if(wxTheClipboard->GetData( data_names )) { pTarget->Drop(data_names.GetStrings(), bMove); return; } wxFileDataObject filedata; if( wxTheClipboard->GetData( filedata ) ) { pTarget->Drop(wxGISDropTarget::PathsToNames(filedata.GetFilenames()), bMove); return; } } } return; case 7: if(pSel && pCat) { //create folder long nSelId = pSel->GetFirstSelectedObjectId(); wxGxObject* pGxObject = pCat->GetRegisterObject(nSelId); wxGxAutoRenamer* pGxFolder = dynamic_cast<wxGxAutoRenamer*>(pGxObject); if(!pGxFolder) return; wxGxView* pGxView = dynamic_cast<wxGxView*>(wxWindow::FindFocus()); CPLString sFolderPath = CheckUniqPath(pGxObject->GetPath(), CPLString(wxString(_("New folder")).mb_str(wxConvUTF8)), true, " "); pGxFolder->BeginRenameOnAdd(pGxView, sFolderPath); if(!CreateDir(sFolderPath)) { wxMessageBox(_("Create folder error!"), _("Error"), wxICON_ERROR | wxOK ); pGxFolder->BeginRenameOnAdd(NULL, ""); return; } } return; case 3: default: return; } }
bool wxGISCatalogMainCmd::GetEnabled(void) { wxCHECK_MSG(m_pGxApp, false, wxT("Application pointer is null")); wxGxSelection* pSel = m_pGxApp->GetGxSelection(); wxGxCatalogBase* pCat = GetGxCatalog(); switch(m_subtype) { case 0://Up One Level if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); return pGxObject != NULL && pGxObject->GetParent(); } return false; case 1: return true; case 2: //check if wxGxDiscConnection if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); return pGxObject != NULL && pGxObject->IsKindOf(wxCLASSINFO(wxGxDiscConnection)); } return false; case 3: return true; case 4://delete if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanDelete()) return true; } } return false; case 5: if(pSel) return pSel->CanUndo(); return false; case 6: if(pSel) return pSel->CanRedo(); return false; case 7: if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetFirstSelectedObjectId()); wxGxObjectContainer* pCont = wxDynamicCast(pGxObject, wxGxObjectContainer); if(pCont) return pCont->CanCreate(enumGISContainer, enumContFolder); } return false; case 8://Rename if(pCat && pSel) { size_t nCounter(0); for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanRename()) nCounter++; } return nCounter == 1 ? true : false; } return false; case 9://Refresh if(pSel) return pSel->GetCount() > 0; return false; case 10://Properties //check if IGxObjectEditUI if(pCat && pSel) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetLastSelectedObjectId()); return dynamic_cast<IGxObjectEditUI*>(pGxObject); } return false; case 11://Copy if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanCopy("")) return true; } } return false; case 12://Cut if(pCat && pSel) { for(size_t i = 0; i < pSel->GetCount(); ++i) { wxGxObject* pGxObject = pCat->GetRegisterObject(pSel->GetSelectedObjectId(i)); IGxObjectEdit* pGxObjectEdit = dynamic_cast<IGxObjectEdit*>(pGxObject); if(pGxObjectEdit && pGxObjectEdit->CanMove("")) return true; } } return false; case 13://Paste { IViewDropTarget* pViewDropTarget = dynamic_cast<IViewDropTarget*>(wxWindow::FindFocus()); if(pViewDropTarget) { if( pViewDropTarget->CanPaste() ) { wxClipboardLocker locker; bool bMove(false); if(!locker) { // } else { wxTextDataObject data; if(wxTheClipboard->GetData( data )) { if(data.GetText() == wxString(wxT("cut"))) bMove = true; } } for(size_t i = 0; i < pSel->GetCount(); ++i) { IGxDropTarget* pGxDropTarget = dynamic_cast<IGxDropTarget*>(pCat->GetRegisterObject(pSel->GetSelectedObjectId(i))); if(pGxDropTarget && wxIsDragResultOk(pGxDropTarget->CanDrop(bMove == true ? wxDragMove : wxDragCopy))) return true; } } } } return false; default: return false; } }