MStatus cgfxShaderCmd::undoIt() { #ifdef KH_DEBUG MString ss = " .. Undo "; ss += fArgString; ss += "\n"; ::OutputDebugString( ss.asChar() ); #endif MStatus stat; try { stat = undoCmd(); } catch ( cgfxShaderCommon::InternalError* e ) { reportInternalError( __FILE__, (size_t)e ); stat = MS::kFailure; } catch ( ... ) { reportInternalError( __FILE__, __LINE__ ); stat = MS::kFailure; } #ifdef KH_DEBUG ss = " .. undone\n"; ::OutputDebugString( ss.asChar() ); #endif return stat; } // MStatus cgfxShaderCmd::undoIt
void TextUI::processCommand() { string choice; cin >> choice; switch(atoi(choice.c_str())) { case Load: loadERDiagram(); displayMenu(); break; case Save: saveERDiagram(); displayMenu(); break; case Add: addNewNode(); displayMenu(); break; case Connect: addConnection(); displayMenu(); break; case GetTable: displayComponentTable(); displayConnectionTable(); displayMenu(); break; case SetPK: setPrimaryKey(); displayMenu(); break; case GetERTable: displayERDiagramTable(); displayMenu(); break; case Delete: deleteComponent(); displayMenu(); break; case Undo: undoCmd(); displayMenu(); break; case Redo: redoCmd(); displayMenu(); break; case Exit: exitERDiagram(); break; default: cout << TEXT_MENU_ERRORCHOICE; displayMenu(); break; } }
// TextUI的undo並回傳對應字串 string PresentationModel::undo_TextUI() { string result; if (undoCmd()) { result += TEXT_UNDO_SUCCESS; result += TEXT_ENDLINE; result += displayComponentTable_TextUI(); result += TEXT_ENDLINE; result += displayConnectionTable_TextUI(); } else { result += TEXT_UNDO_FAILED; result += TEXT_ENDLINE; } return result; }
bool pt_PieceTable::_realInsertSpan(PT_DocPosition dpos, const UT_UCSChar * p, UT_uint32 length, const gchar ** attributes, const gchar ** properties, fd_Field * pField, bool bAddChangeRec) { // insert character data into the document at the given position. UT_return_val_if_fail (m_pts==PTS_Editing, false); // get the fragment at the given document position. pf_Frag * pf = NULL; PT_BlockOffset fragOffset = 0; bool bFound = getFragFromPosition(dpos,&pf,&fragOffset); UT_return_val_if_fail (bFound,false); // append the text data to the end of the current buffer. PT_BufIndex bi; if (!m_varset.appendBuf(p,length,&bi)) return false; pf_Frag_Strux * pfs = NULL; bool bFoundStrux = _getStruxFromFrag(pf,&pfs); UT_return_val_if_fail (bFoundStrux,false); if(isEndFootnote((pf_Frag *)pfs)) { bFoundStrux = _getStruxFromFragSkip((pf_Frag *) pfs,&pfs); } UT_return_val_if_fail (pfs,false); if(pfs->getStruxType() == PTX_EndFrame) { bFoundStrux = _getStruxFromFragSkip((pf_Frag *) pfs,&pfs); } // we just did a getFragFromPosition() which gives us the // the thing *starting* at that position. if we have a // fragment boundary at that position, it's sort of arbitrary // whether we treat this insert as a prepend to the one we just found // or an append to the previous one (when it's a text frag). // in the normal case, we want the Attr/Prop of a character // insertion to take the AP of the thing to the immediate // left (seems to be what MS-Word and MS-WordPad do). It's also // useful when the user hits the BOLD button (without a) // selection) and then starts typing -- ideally you'd like // all of the text to have bold not just the first. therefore, // we will see if we are on a text-text boundary and backup // (and thus appending) to the previous. bool bNeedGlob = false; PT_AttrPropIndex indexAP = 0; if ( (fragOffset==0) && (pf->getPrev()) ) { bool bRightOfFmtMark = (pf->getPrev()->getType() == pf_Frag::PFT_FmtMark); if (bRightOfFmtMark) { // if we're just to the right of a _FmtMark, we want to replace // it with a _Text frag with the same attr/prop (we // only used the _FmtMark to remember a toggle format // before we had text for it). pf_Frag_FmtMark * pfPrevFmtMark = static_cast<pf_Frag_FmtMark *>(pf->getPrev()); indexAP = pfPrevFmtMark->getIndexAP(); if (_lastUndoIsThisFmtMark(dpos)) { // if the last thing in the undo history is the insertion of this // _FmtMark, then let's remember the indexAP, do an undo, and then // insert the text. this way the only thing remaining in the undo // is the insertion of this text (with no globbing around it). then // a user-undo will undo all of the coalesced text back to this point // and leave the insertion point as if the original InsertFmtMark // had never happened. // // we don't allow consecutive FmtMarks, but the undo may be a // changeFmtMark and thus just re-change the mark frag rather // than actually deleting it. so we loop here to get back to // the original insertFmtMark (this is the case if the user hit // BOLD then ITALIC then UNDERLINE then typed a character). do { undoCmd(); } while (_lastUndoIsThisFmtMark(dpos)); } else { // for some reason, something else has happened to the document // since this _FmtMark was inserted (perhaps it was one that we // inserted when we did a paragraph break and inserted several // to remember the current inline formatting). // // here we have to do it the hard way and use a glob and an // explicit deleteFmtMark. note that this messes up the undo // coalescing. that is, if the user starts typing at this // position and then hits UNDO, we will erase all of the typing // except for the first character. the second UNDO, will erase // the first character and restores the current FmtMark. if the // user BACKSPACES instead of doing the second UNDO, both the // first character and the FmtMark would be gone. // // TODO decide if we like this... // NOTE this causes BUG#431.... :-) bNeedGlob = true; beginMultiStepGlob(); _deleteFmtMarkWithNotify(dpos,pfPrevFmtMark,pfs,&pf,&fragOffset); } // we now need to consider pf invalid, since the fragment list may have // been coalesced as the FmtMarks were deleted. let's recompute them // but with a few shortcuts. bFound = getFragFromPosition(dpos,&pf,&fragOffset); UT_return_val_if_fail (bFound, false); bFoundStrux = _getStruxFromFrag(pf,&pfs); UT_return_val_if_fail (bFoundStrux,false); if(isEndFootnote((pf_Frag *)pfs)) { bFoundStrux = _getStruxFromFragSkip((pf_Frag *)pfs,&pfs); } UT_return_val_if_fail (bFoundStrux, false); xxx_UT_DEBUGMSG(("Got FragStrux at Pos %d \n",pfs->getPos())); // with the FmtMark now gone, we make a minor adjustment so that we // try to append text to the previous rather than prepend to the current. // this makes us consistent with other places in the code. if ( (fragOffset==0) && (pf->getPrev()) && (pf->getPrev()->getType() == pf_Frag::PFT_Text) && pf->getPrev()->getField()== NULL ) { // append to the end of the previous frag rather than prepend to the current one. pf = pf->getPrev(); fragOffset = pf->getLength(); } } else if (pf->getPrev()->getType() == pf_Frag::PFT_Text && pf->getPrev()->getField()==NULL) { pf_Frag_Text * pfPrevText = static_cast<pf_Frag_Text *>(pf->getPrev()); indexAP = pfPrevText->getIndexAP(); // append to the end of the previous frag rather than prepend to the current one. pf = pf->getPrev(); fragOffset = pf->getLength(); } else { indexAP = _chooseIndexAP(pf,fragOffset); // PLAM: This is the list of field attrs that should not inherit // PLAM: to the span following a field. const gchar * pFieldAttrs[12]; pFieldAttrs[0] = "type"; pFieldAttrs[1] = NULL; pFieldAttrs[2] = "param"; pFieldAttrs[3] = NULL; pFieldAttrs[4] = "name"; pFieldAttrs[5] = NULL; pFieldAttrs[6] = "endnote-id"; pFieldAttrs[7] = NULL; pFieldAttrs[8] = NULL; pFieldAttrs[9] = NULL; pFieldAttrs[10] = NULL; pFieldAttrs[11] = NULL; const PP_AttrProp * pAP = NULL; if (!getAttrProp(indexAP, &pAP)) return false; if (pAP->areAnyOfTheseNamesPresent(pFieldAttrs, NULL)) { // We do not want to inherit a char style from a field. pFieldAttrs[8] = "style"; PP_AttrProp * pAPNew = pAP->cloneWithElimination(pFieldAttrs, NULL); if (!pAPNew) return false; pAPNew->markReadOnly(); if (!m_varset.addIfUniqueAP(pAPNew, &indexAP)) return false; } } } else { // is existing fragment a field? If so do nothing // Or should we display a message to the user? if(pf->getField() != NULL) { return false; } indexAP = _chooseIndexAP(pf,fragOffset); } PT_BlockOffset blockOffset = _computeBlockOffset(pfs,pf) + fragOffset; PX_ChangeRecord_Span * pcr = NULL; if(attributes || properties) { // we need to add the attrs and props passed to us ... PT_AttrPropIndex indexNewAP; bool bMerged; bMerged = m_varset.mergeAP(PTC_AddFmt,indexAP,attributes,properties,&indexNewAP,getDocument()); UT_ASSERT_HARMLESS( bMerged ); if(bMerged) indexAP = indexNewAP; } if (!_insertSpan(pf,bi,fragOffset,length,indexAP,pField)) { if (bNeedGlob) endMultiStepGlob(); return false; } // note: because of coalescing, pf should be considered invalid at this point. // create a change record, add it to the history, and notify // anyone listening. pcr = new PX_ChangeRecord_Span(PX_ChangeRecord::PXT_InsertSpan, dpos,indexAP,bi,length, blockOffset, pField); UT_return_val_if_fail (pcr, false); pcr->setDocument(m_pDocument); bool canCoalesce = _canCoalesceInsertSpan(pcr); if (!bAddChangeRec || (canCoalesce && !m_pDocument->isCoalescingMasked())) { if (canCoalesce) m_history.coalesceHistory(pcr); m_pDocument->notifyListeners(pfs,pcr); delete pcr; } else { m_history.addChangeRecord(pcr); m_pDocument->notifyListeners(pfs,pcr); } if (bNeedGlob) endMultiStepGlob(); return true; }