newer 发表于 2021-1-27 00:42:13

保存和关闭文档后AcApDocManager::disableDocumentActivation() 方法无效的问题

AcApDocManager::disableDocumentActivation() doesn't work after save & close document

By Philippe Leefsma

问题:

AcApDocManager::disableDocumentActivation() should disable switching documents, opening new documents and closing documents. Usually, it does all this. However, if when saving the current document (eg. SAVE from command line), it is possible to directly close (fe. CLOSE from command line) the current document after that. Also opening a new document immediately after a SAVE is doable.

How can to make it work after SAVE?


解答:

A workaround is to use AcEditorReactor and override commandEnded(). In it, you can check if the command is 'qsave' or 'save', if it is, call AcApDocManager::disableDocumentActivation() again (it is first called it in the acrxEntryPoint()).



class CMyEditorReactor : public AcEditorReactor
{
public:
       void commandEnded(const ACHAR *pCmdStr)
       {
         if(_tcsicmp(pCmdStr, _T("qsave")) == 0 ||
            _tcsicmp(pCmdStr, _T("save")) == 0)
                     acDocManagerPtr()->disableDocumentActivation();
       }
};

CMyEditorReactor *gpMyEdReactor = NULL;
//------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CdisableDocumentActivationApp : public AcRxArxApp {

public:
       CdisableDocumentActivationApp () : AcRxArxApp () {}

       virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt)
       {
            AcRx::AppRetCode retCode =
                  AcRxArxApp::On_kInitAppMsg (pkt) ;

            acDocManagerPtr()->disableDocumentActivation();

            gpMyEdReactor = new CMyEditorReactor();
            acedEditor->addReactor(gpMyEdReactor);

            return (retCode) ;
       }

       virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt)
       {
            AcRx::AppRetCode retCode =
                  AcRxArxApp::On_kUnloadAppMsg (pkt) ;

            if(acDocManagerPtr())
                     acDocManagerPtr()->enableDocumentActivation();

            if(gpMyEdReactor)
            {
                     acedEditor->removeReactor(gpMyEdReactor);
                     delete gpMyEdReactor;
            }

            return (retCode) ;
       }

       virtual void RegisterServerComponents () {
       }

} ;

//------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CdisableDocumentActivationApp)



yangjian001 发表于 2021-1-27 11:18:33

一点看不懂
页: [1]
查看完整版本: 保存和关闭文档后AcApDocManager::disableDocumentActivation() 方法无效的问题