⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 undo.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 2 页
字号:
	strcpy(undo->oldText, deletedText);    }        /* increment the operation count for the autosave feature */    window->autoSaveOpCount++;    /* if the window is currently unmodified, remove the previous       restoresToSaved marker, and set it on this record */    if (!window->fileChanged) {    	undo->restoresToSaved = True;	for (u=window->undo; u!=NULL; u=u->next)    	    u->restoresToSaved = False;	for (u=window->redo; u!=NULL; u=u->next)    	    u->restoresToSaved = False;    }    	    /* Add the new record to the undo list  unless SaveUndoInfo is       saving information generated by an Undo operation itself, in       which case, add the new record to the redo list. */    if (isUndo)	addRedoItem(window, undo);    else	addUndoItem(window, undo);}/*** ClearUndoList, ClearRedoList**** Functions for clearing all of the information off of the undo or redo** lists and adjusting the edit menu accordingly*/void ClearUndoList(WindowInfo *window){    while (window->undo != NULL)    	removeUndoItem(window);}void ClearRedoList(WindowInfo *window){    while (window->redo != NULL)    	removeRedoItem(window);}/* ** DisableUnmodified** ** Remove the ability of a window to become "Unmodified" through a sequence** of undos.  This can happen if the file the window is editing gets deleted,** for example.*/void DisableUnmodified(WindowInfo *window){    UndoInfo *undo = window->undo;        while (undo != NULL){        undo->restoresToSaved = False;        undo = undo->next;    }}/*** Add an undo record (already allocated by the caller) to the window's undo** list if the item pushes the undo operation or character counts past the** limits, trim the undo list to an acceptable length.*/static void addUndoItem(WindowInfo *window, UndoInfo *undo){        /* Make the undo menu item sensitive now that there's something to undo */    if (window->undo == NULL) {    	XtSetSensitive(window->undoItem, True);	SetBGMenuUndoSensitivity(window, True);    }    /* Add the item to the beginning of the list */    undo->next = window->undo;    window->undo = undo;        /* Increment the operation and memory counts */    window->undoOpCount++;    window->undoMemUsed += undo->oldLen;        /* Trim the list if it exceeds any of the limits */    if (window->undoOpCount > UNDO_OP_LIMIT)    	trimUndoList(window, UNDO_OP_TRIMTO);    if (window->undoMemUsed > UNDO_WORRY_LIMIT)    	trimUndoList(window, UNDO_WORRY_TRIMTO);    if (window->undoMemUsed > UNDO_PURGE_LIMIT)    	trimUndoList(window, UNDO_PURGE_TRIMTO);}/*** Add an item (already allocated by the caller) to the window's redo list.*/static void addRedoItem(WindowInfo *window, UndoInfo *redo){    /* Make the redo menu item sensitive now that there's something to redo */    if (window->redo == NULL) {    	XtSetSensitive(window->redoItem, True);	SetBGMenuRedoSensitivity(window, True);    }        /* Add the item to the beginning of the list */    redo->next = window->redo;    window->redo = redo;}/*** Pop (remove and free) the current (front) undo record from the undo list*/static void removeUndoItem(WindowInfo *window){    UndoInfo *undo = window->undo;        if (undo == NULL)    	return;        /* Decrement the operation and memory counts */    window->undoOpCount--;    window->undoMemUsed -= undo->oldLen;        /* Remove and free the item */    window->undo = undo->next;    freeUndoRecord(undo);        /* if there are no more undo records left, dim the Undo menu item */    if (window->undo == NULL) {    	XtSetSensitive(window->undoItem, False);	SetBGMenuUndoSensitivity(window, False);    }}/*** Pop (remove and free) the current (front) redo record from the redo list*/static void removeRedoItem(WindowInfo *window){    UndoInfo *redo = window->redo;        /* Remove and free the item */    window->redo = redo->next;    freeUndoRecord(redo);        /* if there are no more redo records left, dim the Redo menu item */    if (window->redo == NULL) {    	XtSetSensitive(window->redoItem, False);	SetBGMenuRedoSensitivity(window, False);    }}/*** Add deleted text to the beginning or end** of the text saved for undoing the last operation.  This routine is intended** for continuing of a string of one character deletes or replaces, but will** work with more than one character.*/static void appendDeletedText(WindowInfo *window, const char *deletedText,	int deletedLen, int direction){    UndoInfo *undo = window->undo;    char *comboText;    /* re-allocate, adding space for the new character(s) */    comboText = XtMalloc(undo->oldLen + deletedLen);    /* copy the new character and the already deleted text to the new memory */    if (direction == FORWARD) {    	strcpy(comboText, undo->oldText);    	strcat(comboText, deletedText);    } else {	strcpy(comboText, deletedText);	strcat(comboText, undo->oldText);    }    /* keep track of the additional memory now used by the undo list */    window->undoMemUsed++;    /* free the old saved text and attach the new */    XtFree(undo->oldText);    undo->oldText = comboText;    undo->oldLen += deletedLen;}/*** Trim records off of the END of the undo list to reduce it to length** maxLength*/static void trimUndoList(WindowInfo *window, int maxLength){    int i;    UndoInfo *u, *lastRec;        if (window->undo == NULL)    	return;    /* Find last item on the list to leave intact */    for (i=1, u=window->undo; i<maxLength && u!=NULL; i++, u=u->next);    if (u == NULL)    	return;        /* Trim off all subsequent entries */    lastRec = u;    while (lastRec->next != NULL) {	u = lastRec->next;	lastRec->next = u->next;    	window->undoOpCount--;    	window->undoMemUsed -= u->oldLen;    	freeUndoRecord(u);    }}  static int determineUndoType(int nInserted, int nDeleted){    int textDeleted, textInserted;        textDeleted = (nDeleted > 0);    textInserted = (nInserted > 0);        if (textInserted && !textDeleted) {    	/* Insert */	if (nInserted == 1)	    return ONE_CHAR_INSERT;	else	    return BLOCK_INSERT;    } else if (textInserted && textDeleted) {    	/* Replace */	if (nInserted == 1)	    return ONE_CHAR_REPLACE;	else	    return BLOCK_REPLACE;    } else if (!textInserted && textDeleted) {    	/* Delete */	if (nDeleted == 1)	    return ONE_CHAR_DELETE;	else	    return BLOCK_DELETE;    } else {    	/* Nothing deleted or inserted */	return UNDO_NOOP;    }}static void freeUndoRecord(UndoInfo *undo){    if (undo == NULL)    	return;    	    XtFree(undo->oldText);    XtFree((char *)undo);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -