Example #1
0
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;
	}
}