diff -urNad nedit-5.7~/source/menu.c nedit-5.7/source/menu.c --- nedit-5.7~/source/menu.c 2017-02-05 03:15:41.000000000 +1100 +++ nedit-5.7/source/menu.c 2022-10-05 23:37:49.408959439 +1100 @@ -102,6 +102,8 @@ extern void _XmDismissTearOff(Widget, XtPointer, XtPointer); +void initialiseSwitchDocumentsListWrapper(); + static void doActionCB(Widget w, XtPointer clientData, XtPointer callData); static void doTabActionCB(Widget w, XtPointer clientData, XtPointer callData); static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData); @@ -317,6 +319,14 @@ Cardinal *nArgs); static void lastDocumentAP(Widget w, XEvent *event, String *args, Cardinal *nArgs); +static void switchDocumentsAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs); +static void switchDocumentsReverseAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs); +static void switchDocumentsEndAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs); +static void switchDocumentsNullAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs); static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs); static void capitalizeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs); @@ -529,6 +539,10 @@ {"next_document", nextDocumentAP}, {"previous_document", prevDocumentAP}, {"last_document", lastDocumentAP}, + {"switch_documents", switchDocumentsAP}, + {"switch_documents_reverse", switchDocumentsReverseAP}, + {"switch_documents_end", switchDocumentsEndAP}, + {"switch_documents_null", switchDocumentsNullAP}, {"uppercase", capitalizeAP}, {"lowercase", lowercaseAP}, {"fill-paragraph", fillAP}, @@ -593,6 +607,11 @@ static WindowInfo *ShortMenuWindow; #endif +void initialiseSwitchDocumentsListWrapper() +{ + initialiseSwitchDocumentsList(); +} + void HidePointerOnKeyedEvent(Widget w, XEvent *event) { if (event && (event->type == KeyPress || event->type == KeyRelease)) { @@ -705,7 +724,7 @@ createMenuItem(menuPane, "print", "Print...", 'P', doActionCB, "print", SHORT); window->printSelItem = createMenuItem(menuPane, "printSelection", - "Print Selection...", 'l', doActionCB, "print_selection", + "Print Selection...", 't', doActionCB, "print_selection", SHORT); XtSetSensitive(window->printSelItem, window->wasSelected); createMenuSeparator(menuPane, "sep4", SHORT); @@ -3549,6 +3568,30 @@ LastDocument(WidgetToWindow(w)); } +static void switchDocumentsAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs) +{ + switchDocuments(WidgetToWindow(w), SWITCH_DOCUMENTS_DIRECTION_NORMAL); +} + +static void switchDocumentsReverseAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs) +{ + switchDocuments(WidgetToWindow(w), SWITCH_DOCUMENTS_DIRECTION_REVERSE); +} + +static void switchDocumentsEndAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs) +{ + switchDocumentsEnd(WidgetToWindow(w)); +} + +static void switchDocumentsNullAP(Widget w, XEvent *event, String *args, + Cardinal *nArgs) +{ + +} + static void capitalizeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs) { WindowInfo *window = WidgetToWindow(w); diff -urNad nedit-5.7~/source/nedit.c nedit-5.7/source/nedit.c --- nedit-5.7~/source/nedit.c 2017-02-05 05:08:57.000000000 +1100 +++ nedit-5.7/source/nedit.c 2022-10-05 23:34:19.754847484 +1100 @@ -430,6 +430,8 @@ /* Save the command which was used to invoke nedit for restart command */ ArgV0 = argv[0]; + initialiseSwitchDocumentsListWrapper(); + /* Set locale for C library, X, and Motif input functions. Reverts to "C" if requested locale not available. */ XtSetLanguageProc(NULL, neditLanguageProc, NULL); diff -urNad nedit-5.7~/source/window.c nedit-5.7/source/window.c --- nedit-5.7~/source/window.c 2017-02-05 03:15:41.000000000 +1100 +++ nedit-5.7/source/window.c 2022-10-05 23:38:08.588786517 +1100 @@ -193,6 +193,145 @@ static WindowInfo *inFocusDocument = NULL; /* where we are now */ static WindowInfo *lastFocusDocument = NULL; /* where we came from */ + +typedef struct SwitchDocumentsListNode +{ + int windowIDdebug; + WindowInfo * focusDocument; + struct SwitchDocumentsListNode* next; + struct SwitchDocumentsListNode* previous; +} SwitchDocumentsList; + +static SwitchDocumentsList* firstNodeInSwitchDocumentsList; +static SwitchDocumentsList* activeNodeInSwitchDocumentsList; +int switchDocumentsListTraverseDisableMarkActiveDocument; +struct timeval switchDocumentsClockLastSave; +int switchingDocumentsAtPresent; + +struct timeval getTimeNow() +{ + struct timeval timenow; + gettimeofday(&timenow, NULL); + return timenow; +} + +void printWindowList() +{ + printf("*****printWindowList:******\n"); + printf("firstNodeInSwitchDocumentsList = %d\n", firstNodeInSwitchDocumentsList->windowIDdebug); + printf("activeNodeInSwitchDocumentsList = %d\n", activeNodeInSwitchDocumentsList->windowIDdebug); + SwitchDocumentsList* currentNode = firstNodeInSwitchDocumentsList; + WindowInfo *win; + + while(currentNode->next != NULL) + { + printf("\tcurrentNode = %d, currentNode pointer = %d\n", currentNode->windowIDdebug, currentNode->focusDocument); + currentNode = currentNode->next; + } +} + +void initialiseSwitchDocumentsList() +{ + switchDocumentsClockLastSave = getTimeNow(); + firstNodeInSwitchDocumentsList = malloc(sizeof(SwitchDocumentsList)); + firstNodeInSwitchDocumentsList->windowIDdebug = 0; + firstNodeInSwitchDocumentsList->focusDocument = NULL; + firstNodeInSwitchDocumentsList->next = NULL; + firstNodeInSwitchDocumentsList->previous = NULL; + activeNodeInSwitchDocumentsList = firstNodeInSwitchDocumentsList; + switchDocumentsListTraverseDisableMarkActiveDocument = 0; + switchingDocumentsAtPresent = 0; +} + +SwitchDocumentsList* switchDocumentsGetLastNodeInList() +{ + SwitchDocumentsList* currentNode = firstNodeInSwitchDocumentsList; + SwitchDocumentsList* lastNodeInList = currentNode; + while(currentNode->next != NULL) + { + lastNodeInList = currentNode; + currentNode = currentNode->next; + } + return lastNodeInList; +} + +SwitchDocumentsList* switchDocumentsListRemoveNode(SwitchDocumentsList* nodeToRemove) +{ + if(nodeToRemove->next != NULL) + { + if(nodeToRemove->previous == NULL) + {/*nodeToRemove is first node in list*/ + + nodeToRemove->next->previous = NULL; + firstNodeInSwitchDocumentsList = nodeToRemove->next; + + } + else + {/*nodeToRemove is not first node in list*/ + nodeToRemove->previous->next = nodeToRemove->next; + nodeToRemove->next->previous = nodeToRemove->previous; + } + free(nodeToRemove); + } + else + { + printf("switchDocumentsListRemoveNode() error: removing dummy node is impossible: (nodeToRemove->next == NULL)\n"); + exit(0); + } + + SwitchDocumentsList* lastNodeInList = switchDocumentsGetLastNodeInList(); + + return lastNodeInList; /*update activeNodeInSwitchDocumentsList (restore to last document in list)*/ +} + +SwitchDocumentsList* switchDocumentsListRemove(WindowInfo * focusDocument) +{ + SwitchDocumentsList* currentNode = firstNodeInSwitchDocumentsList; + SwitchDocumentsList* nodeToRemove = NULL; + int foundNodeToRemove = 0; + while(currentNode->next != NULL) + { + if(currentNode->focusDocument == focusDocument) + { + /*found node to remove*/ + nodeToRemove = currentNode; + foundNodeToRemove = 1; + } + currentNode = currentNode->next; + } + SwitchDocumentsList* lastNodeInList = currentNode; + if(foundNodeToRemove) + { + lastNodeInList = switchDocumentsListRemoveNode(nodeToRemove); + } + else + { + } + return lastNodeInList; +} + +SwitchDocumentsList* switchDocumentsListAdd(WindowInfo * focusDocument) +{ + switchDocumentsListRemove(focusDocument); /*remove previous instance if existent*/ + + SwitchDocumentsList* currentNode = firstNodeInSwitchDocumentsList; + int lastNewWindowIDdebug = 0; + while(currentNode->next != NULL) + { + lastNewWindowIDdebug = currentNode->windowIDdebug; + currentNode = currentNode->next; + } + currentNode->windowIDdebug = lastNewWindowIDdebug+1; + currentNode->focusDocument = focusDocument; + SwitchDocumentsList* newNode = malloc(sizeof(SwitchDocumentsList)); + newNode->focusDocument = NULL; + newNode->next = NULL; + newNode->previous = currentNode; + currentNode->next = newNode; + + return currentNode; +} + static int DoneWithMoveDocumentDialog; static int updateLineNumDisp(WindowInfo* window); static int updateGutterWidth(WindowInfo* window); @@ -800,6 +939,8 @@ } } + activeNodeInSwitchDocumentsList = switchDocumentsListAdd(window); + return window; } @@ -3785,7 +3926,7 @@ if (window) lastFocusDocument = window; - + return prev; } @@ -3799,6 +3940,16 @@ if (window) inFocusDocument = window; + if(switchDocumentsListTraverseDisableMarkActiveDocument == 0) + { + if(switchingDocumentsAtPresent == 1) + {/*in strange case user is switching documents while creating a new window for example?*/ + activeNodeInSwitchDocumentsList = switchDocumentsListAdd(activeNodeInSwitchDocumentsList->focusDocument); + switchingDocumentsAtPresent = 0; + } + activeNodeInSwitchDocumentsList = switchDocumentsListAdd(inFocusDocument); + } + return prev; } @@ -3863,6 +4014,66 @@ } +void switchDocumentsEnd(WindowInfo *window) +{ + if(switchingDocumentsAtPresent == 1) + { + activeNodeInSwitchDocumentsList = switchDocumentsListAdd(activeNodeInSwitchDocumentsList->focusDocument); + switchingDocumentsAtPresent = 0; + } +} +/* +** Switch through last active windows +*/ +void switchDocuments(WindowInfo *window, int direction) +{ + WindowInfo *win; + + if((activeNodeInSwitchDocumentsList->previous != NULL) || (activeNodeInSwitchDocumentsList->next->next != NULL)) + { + if(direction == SWITCH_DOCUMENTS_DIRECTION_NORMAL) + { + if(activeNodeInSwitchDocumentsList->previous != NULL) + { + activeNodeInSwitchDocumentsList = activeNodeInSwitchDocumentsList->previous; + } + else + {/*go around in circles...*/ + activeNodeInSwitchDocumentsList = switchDocumentsGetLastNodeInList(); + } + } + else if(direction != SWITCH_DOCUMENTS_DIRECTION_NORMAL) + { + if(activeNodeInSwitchDocumentsList->next->next != NULL) + { + activeNodeInSwitchDocumentsList = activeNodeInSwitchDocumentsList->next; + } + else + {/*go around in circles...*/ + activeNodeInSwitchDocumentsList = firstNodeInSwitchDocumentsList; + } + } + } + + switchingDocumentsAtPresent = 1; + + for(win = WindowList; win; win=win->next) + if (activeNodeInSwitchDocumentsList->focusDocument == win) + break; + + if (!win) + return; + + switchDocumentsListTraverseDisableMarkActiveDocument = 1; + + if (window->shell == win->shell) + RaiseDocument(win); + else + RaiseDocumentWindow(win); + + switchDocumentsListTraverseDisableMarkActiveDocument = 0; +} + /* ** make sure window is alive is kicking */ @@ -4059,6 +4270,8 @@ return; } + switchDocumentsListRemove(window); + XtDestroyWidget(window->splitPane); } diff -urNad nedit-5.7~/source/window.h nedit-5.7/source/window.h --- nedit-5.7~/source/window.h 2017-02-05 03:15:41.000000000 +1100 +++ nedit-5.7/source/window.h 2022-10-05 23:38:25.376635148 +1100 @@ -83,6 +83,10 @@ void NextDocument(WindowInfo *window); void PreviousDocument(WindowInfo *window); void LastDocument(WindowInfo *window); +#define SWITCH_DOCUMENTS_DIRECTION_NORMAL (1) +#define SWITCH_DOCUMENTS_DIRECTION_REVERSE (2) +void switchDocuments(WindowInfo *window, int direction); +void switchDocumentsEnd(WindowInfo *window); int NDocuments(WindowInfo *window); WindowInfo *MoveDocument(WindowInfo *toWindow, WindowInfo *window); WindowInfo *DetachDocument(WindowInfo *window);