// getDocFromFilename() // Passed a filename, it finds the corresponding document pointer // Returns true if successful bool CMDITestDialog::getDocFromFilename(CString csFileName, AcApDocument* &pNewDocument) { // Iterate over the open documents. We will match the filename if: // The filename specified matches the fully qualified path // name, as returned by AcApDocument::filename() // -or- // The filename specified matches the filename portion of the // document name AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator(); AcApDocument* pThisDocument = NULL; CString csThisFilename; CString csThisFilenameShort; csFileName.MakeUpper(); // uppercase comparisons while(!iter->done()) { // Tiptoe through the tulips pThisDocument = iter->document(); csThisFilename = pThisDocument->docTitle(); csThisFilename.MakeUpper(); csThisFilenameShort = csThisFilename.Right(csThisFilename.GetLength() - csThisFilename.ReverseFind('\\') - 1); if(csFileName == csThisFilename || // Full path match csFileName == csThisFilenameShort || // Matches filename only csFileName == csThisFilenameShort.Left( // Filename less extension csThisFilenameShort.GetLength() - 4)) { pNewDocument = pThisDocument; if( iter ) delete iter; return true; } iter->step(); } pNewDocument = NULL; if( iter ) delete iter; // no match found return false; }
void CMDITestDialog::RebuildListBox() { m_docListBox.ResetContent(); // start from an empty list box // at this moment, get all drawing names and add them to the list box. AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator(); AcApDocument* pDoc = NULL; CString csFilename; while(!iter->done()) { pDoc = iter->document(); if(pDoc) { // #### make sure pDoc is not NULL #### csFilename = pDoc->docTitle(); m_docListBox.AddString( csFilename ); } iter->step(); } if( iter ) delete iter; }
// commandStats: Print out current Session and Cumulative Stats void initStats() { cmdr = new AsdkCommandReactor(); statFileName[0] = EOS; // Define dictionary to delete all its entries when it is deleted. sessionStats = initStatDictionary(); acedEditor->addReactor(cmdr); acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS", /*NOXLATE*/"ASDK_CMDSTAT", "CMDSTAT", ACRX_CMD_MODAL, &commandStats); acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS", /*NOXLATE*/"ASDK_CMDCOUNT", "CMDCOUNT", ACRX_CMD_MODAL, &cmdCommandCount); bStatsFileUpdatePending = Adesk::kFalse; // Initialize Global struct array docData.setLogicalLength(0); // Fill array from existing documents AcApDocumentIterator* pDocIter = acDocManager->newAcApDocumentIterator(); for (;!pDocIter->done(); pDocIter->step()) // add an entry for the document, if some other notification hasn't // already done so. lookupDoc(pDocIter->document()); delete pDocIter; // Establish current document, if there is one yet. if ((docData.length() > 0) && (acDocManager->curDocument() != NULL)) curDocGlobals = docData[lookupDoc(acDocManager->curDocument())]; else curDocGlobals.doc = NULL; pDocReactor = new AsdkDocReactor; acDocManager->addReactor(pDocReactor); resbuf tempRes; int i, j; // set the statFileName to be <LOGINNAME>.txt // remove blanks and tabs from LOGINNAME, so we have a more // reasonable statFileName. if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } strcpy(statFileName, tempRes.resval.rstring); acdbFree (tempRes.resval.rstring) ; for (i = 0, j = 0; (statFileName[i] != EOS) && (j < LOGINNAME_LENGTH); i++) { if ((statFileName[i] != ' ') && (statFileName[i] != '\t')) { statFileName[j] = statFileName[i]; j++; } } statFileName[j] = EOS; strcat(statFileName, /*NOXLATE*/".txt"); }