📄 window.c
字号:
window->lastModTime = 0; StopHighlighting(window); EndSmartIndent(window); UpdateWindowTitle(window); UpdateWindowReadOnly(window); XtSetSensitive(window->closeItem, FALSE); XtSetSensitive(window->readOnlyItem, TRUE); XmToggleButtonSetState(window->readOnlyItem, FALSE, FALSE); ClearUndoList(window); ClearRedoList(window); XmTextSetString(window->statsLine, ""); /* resets scroll pos of stats line from long file names */ UpdateStatsLine(window); DetermineLanguageMode(window, True); return; } /* Free syntax highlighting patterns, if any. w/o redisplaying */ FreeHighlightingData(window); /* remove the buffer modification callbacks so the buffer will be deallocated when the last text widget is destroyed */ BufRemoveModifyCB(window->buffer, modifiedCB, window); BufRemoveModifyCB(window->buffer, SyntaxHighlightModifyCB, window);#ifdef ROWCOLPATCH patchRowCol(window->menuBar);#endif /* free the undo and redo lists */ ClearUndoList(window); ClearRedoList(window); /* remove and deallocate all of the widgets associated with window */ XtFree(window->backlightCharTypes); /* we made a copy earlier on */ XtDestroyWidget(window->shell); /* remove the window from the global window list, update window menus */ removeFromWindowList(window); InvalidateWindowMenus(); /* deallocate the window data structure */ XtFree((char *)window);}/*** Check if there is already a window open for a given file*/WindowInfo *FindWindowWithFile(const char *name, const char *path){ WindowInfo *w; for (w=WindowList; w!=NULL; w=w->next) { if (!strcmp(w->filename, name) && !strcmp(w->path, path)) { return w; } } return NULL;}/*** Add another independently scrollable window pane to the current window,** splitting the pane which currently has keyboard focus.*/void SplitWindow(WindowInfo *window){ short paneHeights[MAX_PANES+1]; int insertPositions[MAX_PANES+1], topLines[MAX_PANES+1]; int horizOffsets[MAX_PANES+1]; int i, focusPane, emTabDist, wrapMargin, lineNumCols, totalHeight=0; char *delimiters; Widget text; textDisp *textD, *newTextD; /* Don't create new panes if we're already at the limit */ if (window->nPanes >= MAX_PANES) return; /* Record the current heights, scroll positions, and insert positions of the existing panes, keyboard focus */ focusPane = 0; for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; insertPositions[i] = TextGetCursorPos(text); XtVaGetValues(containingPane(text),XmNheight,&paneHeights[i],NULL); totalHeight += paneHeights[i]; TextGetScroll(text, &topLines[i], &horizOffsets[i]); if (text == window->lastFocus) focusPane = i; } /* Unmanage & remanage the panedWindow so it recalculates pane heights */ XtUnmanageChild(window->splitPane); /* Create a text widget to add to the pane and set its buffer and highlight data to be the same as the other panes in the window */ XtVaGetValues(window->textArea, textNemulateTabs, &emTabDist, textNwordDelimiters, &delimiters, textNwrapMargin, &wrapMargin, textNlineNumCols, &lineNumCols, NULL); text = createTextArea(window->splitPane, window, 1, 1, emTabDist, delimiters, wrapMargin, lineNumCols); TextSetBuffer(text, window->buffer); if (window->highlightData != NULL) AttachHighlightToWidget(text, window); if (window->backlightChars) { XtVaSetValues(text, textNbacklightCharTypes, window->backlightCharTypes, 0); } XtManageChild(text); window->textPanes[window->nPanes++] = text; /* Fix up the colors */ textD = ((TextWidget)window->textArea)->text.textD; newTextD = ((TextWidget)text)->text.textD; XtVaSetValues(text, XmNforeground, textD->fgPixel, XmNbackground, textD->bgPixel, NULL); TextDSetColors( newTextD, textD->fgPixel, textD->bgPixel, textD->selectFGPixel, textD->selectBGPixel, textD->highlightFGPixel, textD->highlightBGPixel, textD->lineNumFGPixel, textD->cursorFGPixel ); /* Set the minimum pane height in the new pane */ UpdateMinPaneHeights(window); /* adjust the heights, scroll positions, etc., to split the focus pane */ for (i=window->nPanes; i>focusPane; i--) { insertPositions[i] = insertPositions[i-1]; paneHeights[i] = paneHeights[i-1]; topLines[i] = topLines[i-1]; horizOffsets[i] = horizOffsets[i-1]; } paneHeights[focusPane] = paneHeights[focusPane]/2; paneHeights[focusPane+1] = paneHeights[focusPane]; for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; setPaneDesiredHeight(containingPane(text), paneHeights[i]); } /* Re-manage panedWindow to recalculate pane heights & reset selection */ XtManageChild(window->splitPane); /* Reset all of the heights, scroll positions, etc. */ for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; TextSetCursorPos(text, insertPositions[i]); TextSetScroll(text, topLines[i], horizOffsets[i]); setPaneDesiredHeight(containingPane(text), totalHeight/(window->nPanes+1)); } XmProcessTraversal(window->lastFocus, XmTRAVERSE_CURRENT); /* Update the window manager size hints after the sizes of the panes have been set (the widget heights are not yet readable here, but they will be by the time the event loop gets around to running this timer proc) */ XtAppAddTimeOut(XtWidgetToApplicationContext(window->shell), 0, wmSizeUpdateProc, window);}Widget GetPaneByIndex(WindowInfo *window, int paneIndex){ Widget text = NULL; if (paneIndex >= 0 && paneIndex <= window->nPanes) { text = (paneIndex == 0) ? window->textArea : window->textPanes[paneIndex - 1]; } return(text);}int WidgetToPaneIndex(WindowInfo *window, Widget w){ int i; Widget text; int paneIndex = 0; for (i = 0; i <= window->nPanes; ++i) { text = (i == 0) ? window->textArea : window->textPanes[i - 1]; if (text == w) { paneIndex = i; } } return(paneIndex);}/*** Close the window pane that last had the keyboard focus. (Actually, close** the bottom pane and make it look like pane which had focus was closed)*/void ClosePane(WindowInfo *window){ short paneHeights[MAX_PANES+1]; int insertPositions[MAX_PANES+1], topLines[MAX_PANES+1]; int horizOffsets[MAX_PANES+1]; int i, focusPane,totalHeight=0; Widget text; /* Don't delete the last pane */ if (window->nPanes <= 0) return; /* Record the current heights, scroll positions, and insert positions of the existing panes, and the keyboard focus */ focusPane = 0; for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; insertPositions[i] = TextGetCursorPos(text); XtVaGetValues(containingPane(text), XmNheight, &paneHeights[i], NULL); totalHeight += paneHeights[i]; TextGetScroll(text, &topLines[i], &horizOffsets[i]); if (text == window->lastFocus) focusPane = i; } /* Unmanage & remanage the panedWindow so it recalculates pane heights */ XtUnmanageChild(window->splitPane); /* Destroy last pane, and make sure lastFocus points to an existing pane. Workaround for OM 2.1.30: text widget must be unmanaged for xmPanedWindowWidget to calculate the correct pane heights for the remaining panes, simply detroying it didn't seem enough */ window->nPanes--; XtUnmanageChild(containingPane(window->textPanes[window->nPanes])); XtDestroyWidget(containingPane(window->textPanes[window->nPanes])); if (window->nPanes == 0) window->lastFocus = window->textArea; else if (focusPane > window->nPanes) window->lastFocus = window->textPanes[window->nPanes-1]; /* adjust the heights, scroll positions, etc., to make it look like the pane with the input focus was closed */ for (i=focusPane; i<=window->nPanes; i++) { insertPositions[i] = insertPositions[i+1]; paneHeights[i] = paneHeights[i+1]; topLines[i] = topLines[i+1]; horizOffsets[i] = horizOffsets[i+1]; } /* set the desired heights and re-manage the paned window so it will recalculate pane heights */ for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; setPaneDesiredHeight(containingPane(text), paneHeights[i]); } XtManageChild(window->splitPane); /* Reset all of the scroll positions, insert positions, etc. */ for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; TextSetCursorPos(text, insertPositions[i]); TextSetScroll(text, topLines[i], horizOffsets[i]); } XmProcessTraversal(window->lastFocus, XmTRAVERSE_CURRENT); /* Update the window manager size hints after the sizes of the panes have been set (the widget heights are not yet readable here, but they will be by the time the event loop gets around to running this timer proc) */ XtAppAddTimeOut(XtWidgetToApplicationContext(window->shell), 0, wmSizeUpdateProc, window);}/*** Turn on and off the display of line numbers*/void ShowLineNumbers(WindowInfo *window, int state){ Widget text; int i, marginWidth; Dimension windowWidth; textDisp *textD = ((TextWidget)window->textArea)->text.textD; if (window->showLineNumbers == state) return; window->showLineNumbers = state; /* Just setting window->showLineNumbers is sufficient to tell UpdateLineNumDisp to expand the line number areas and the window size for the number of lines required. To hide the line number display, set the width to zero, and contract the window width. */ if (state) { UpdateLineNumDisp(window); } else { XtVaGetValues(window->shell, XmNwidth, &windowWidth, NULL); XtVaGetValues(window->textArea, textNmarginWidth, &marginWidth, NULL); XtVaSetValues(window->shell, XmNwidth, windowWidth - textD->left + marginWidth, NULL); for (i=0; i<=window->nPanes; i++) { text = i==0 ? window->textArea : window->textPanes[i-1]; XtVaSetValues(text, textNlineNumCols, 0, NULL); } } /* Tell WM that the non-expandable part of the window has changed size */ UpdateWMSizeHints(window);}void SetTabDist(WindowInfo *window, int tabDist){ if (window->buffer->tabDist != tabDist) { int saveCursorPositions[MAX_PANES + 1]; int saveVScrollPositions[MAX_PANES + 1]; int saveHScrollPositions[MAX_PANES + 1]; int paneIndex; window->ignoreModify = True; for (paneIndex = 0; paneIndex <= window->nPanes; ++paneIndex) { Widget w = GetPaneByIndex(window, paneIndex); textDisp *textD = ((TextWidget)w)->text.textD; TextGetScroll(w, &saveVScrollPositions[paneIndex], &saveHScrollPositions[paneIndex]); saveCursorPositions[paneIndex] = TextGetCursorPos(w); textD->modifyingTabDist = 1; } BufSetTabDistance(window->buffer, tabDist); for (paneIndex = 0; paneIndex <= window->nPanes; ++paneIndex) { Widget w = GetPaneByIndex(window, paneIndex); textDisp *textD = ((TextWidget)w)->text.textD; textD->modifyingTabDist = 0; TextSetCursorPos(w, saveCursorPositions[paneIndex]); TextSetScroll(w, saveVScrollPositions[paneIndex], saveHScrollPositions[paneIndex]); } window->ignoreModify = False; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -