void wxGxContentView::OnBeginDrag(wxListEvent& event) { //TODO: wxDELETE(pDragData) somethere wxDataObjectComposite *pDragData = new wxDataObjectComposite(); wxGISStringDataObject *pNamesData = new wxGISStringDataObject(wxDataFormat(wxGIS_DND_NAME)); pDragData->Add(pNamesData, true); wxFileDataObject *pFileData = new wxFileDataObject(); pDragData->Add(pFileData, false); //wxGISDecimalDataObject *pIDsData = new wxGISDecimalDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-id"))); //pDragData->Add(pIDsData, false); //TODO: create dataobject for QGIS // wxDataObjectSimple* pDataObjectSimple = new wxDataObjectSimple(wxDataFormat(wxT("application/x-vnd.qgis.qgis.uri"))); // my_data->Add(pDataObjectSimple); // // wxMemoryOutputStream *pstream = new wxMemoryOutputStream(); // wxDataOutputStream dostr(*pstream); // long nItem = wxNOT_FOUND; int nCount(0); for ( ;; ) { nItem = GetNextItem(nItem, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if ( nItem == wxNOT_FOUND ) break; LPITEMDATA pItemData = (LPITEMDATA)GetItemData(nItem); if(pItemData == NULL) continue; wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pItemData->nObjectID); if(pGxObject == NULL) continue; wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); //pIDsData->AddDecimal(pGxObject->GetId()); } wxDropSource dragSource( this ); dragSource.SetData( *pDragData ); wxDragResult result = dragSource.DoDragDrop( wxDrag_DefaultMove ); }
void wxGxTreeView::OnBeginDrag(wxTreeEvent& event) { //event.Skip(); wxTreeItemId item = event.GetItem(); if(!item.IsOk()) return; SelectItem(item); //TODO: wxDELETE(pDragData) somethere 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); //wxGISDecimalDataObject *pIDsData = new wxGISDecimalDataObject(wxDataFormat(wxT("application/x-vnd.wxgis.gxobject-id"))); //pDragData->Add(pIDsData, false); //TODO: create dataobject for QGIS // wxDataObjectSimple* pDataObjectSimple = new wxDataObjectSimple(wxDataFormat(wxT("application/x-vnd.qgis.qgis.uri"))); // my_data->Add(pDataObjectSimple); // // wxMemoryOutputStream *pstream = new wxMemoryOutputStream(); // wxDataOutputStream dostr(*pstream); // wxArrayTreeItemIds treearray; size_t count = GetSelections(treearray); if(count == 0) return; //first is catalog memory address to prevent different app drop //pIDsData->AddDecimal((long)GetGxCatalog()); for(size_t i = 0; i < count; ++i) { wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); if(pData == NULL) continue; wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); if(pGxObject == NULL) continue; wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); pFileData->AddFile(sSystemPath); pNamesData->AddString(pGxObject->GetFullName()); //pIDsData->AddDecimal(pGxObject->GetId()); } wxDropSource dragSource( this ); dragSource.SetData( *pDragData ); wxDragResult result = dragSource.DoDragDrop( wxDrag_DefaultMove ); // IGxObject* pParentGxObject(NULL); // for(size_t i = 0; i < count; ++i) // { // wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); // if(pData == NULL) // continue; // // IGxObjectSPtr pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); // pParentGxObject = pGxObject->GetParent(); // wxString sSystemPath(pGxObject->GetInternalName(), wxConvUTF8); // pFileData->AddFile(sSystemPath); // dostr.WriteString(sSystemPath); // wxStreamBuffer* theBuffer = pstream->GetOutputStreamBuffer(); // // pDataObjectSimple->SetData(theBuffer->GetBufferSize(), theBuffer->GetBufferStart()); // } //// IGxObjectUI* pGxObjectUI = dynamic_cast<IGxObjectUI*>(pGxObject.get()); ////if(pGxObjectUI) ////{ //// wxDataFormat frm = pGxObjectUI->GetDataFormat(); //// if(frm.GetType() != wxDF_INVALID) //// my_data.SetFormat(frm); ////} // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // wxFileDataObject my_data; // wxArrayTreeItemIds treearray; // size_t count = GetSelections(treearray); // if(count == 0) // return; // wxGxObject* pParentGxObject(NULL); // for(size_t i = 0; i < count; ++i) // { // wxGxTreeItemData* pData = (wxGxTreeItemData*)GetItemData(treearray[i]); // if(pData == NULL) // continue; // wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(pData->m_nObjectID); // pParentGxObject = pGxObject->GetParent(); // wxString sSystemPath(pGxObject->GetPath(), wxConvUTF8); // my_data.AddFile(sSystemPath); // } // wxDropSource dragSource( this ); //dragSource.SetData( my_data ); //wxDragResult result = dragSource.DoDragDrop( ); }
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; } }