📄 view.java
字号:
|| inputHandler.isPrefixActive() || getTextArea().hasFocus()) { KeyEventTranslator.Key keyStroke = KeyEventTranslator .translateKeyEvent(evt); if(keyStroke != null) { if(Debug.DUMP_KEY_EVENTS && from != VIEW) { Log.log(Log.DEBUG,this, "Translated: " + keyStroke); } if(inputHandler.handleKey(keyStroke)) evt.consume(); } } // we might have been closed as a result of // the above if(isClosed()) return; // this is a weird hack. // we don't want C+e a to insert 'a' in the // search bar if the search bar has focus... if(inputHandler.isPrefixActive()) { if(getFocusOwner() instanceof JTextComponent) { prefixFocusOwner = getFocusOwner(); getTextArea().requestFocus(); } else if(focusOnTextArea) { getTextArea().requestFocus(); } else { prefixFocusOwner = null; } } else { prefixFocusOwner = null; } break; case KeyEvent.KEY_PRESSED: if(keyEventInterceptor != null) keyEventInterceptor.keyPressed(evt); else { /* boolean */ focusOnTextArea = false; if(prefixFocusOwner != null) { if(prefixFocusOwner.isShowing()) { prefixFocusOwner.requestFocus(); focusOnTextArea = true; } prefixFocusOwner = null; } KeyEventTranslator.Key keyStroke = KeyEventTranslator .translateKeyEvent(evt); if(keyStroke != null) { if(Debug.DUMP_KEY_EVENTS && from != VIEW) { Log.log(Log.DEBUG,this, "Translated: " + keyStroke); } if(inputHandler.handleKey(keyStroke)) evt.consume(); } // we might have been closed as a result of // the above if(isClosed()) return; // this is a weird hack. // we don't want C+e a to insert 'a' in the // search bar if the search bar has focus... if(inputHandler.isPrefixActive()) { if(getFocusOwner() instanceof JTextComponent) { prefixFocusOwner = getFocusOwner(); getTextArea().requestFocus(); } else if(focusOnTextArea) { getTextArea().requestFocus(); } else { prefixFocusOwner = null; } } else { prefixFocusOwner = null; } } break; case KeyEvent.KEY_RELEASED: if(keyEventInterceptor != null) keyEventInterceptor.keyReleased(evt); break; } if(!evt.isConsumed()) super.processKeyEvent(evt); } //}}} //}}} //{{{ Buffers, edit panes, split panes //{{{ splitHorizontally() method /** * Splits the view horizontally. * @since jEdit 4.1pre2 */ public EditPane splitHorizontally() { return split(JSplitPane.VERTICAL_SPLIT); } //}}} //{{{ splitVertically() method /** * Splits the view vertically. * @since jEdit 4.1pre2 */ public EditPane splitVertically() { return split(JSplitPane.HORIZONTAL_SPLIT); } //}}} //{{{ split() method /** * Splits the view. * @since jEdit 4.1pre2 */ public EditPane split(int orientation) { editPane.saveCaretInfo(); EditPane oldEditPane = editPane; setEditPane(createEditPane(oldEditPane.getBuffer())); editPane.loadCaretInfo(); JComponent oldParent = (JComponent)oldEditPane.getParent(); final JSplitPane newSplitPane = new JSplitPane(orientation); newSplitPane.setOneTouchExpandable(true); newSplitPane.setBorder(null); newSplitPane.setMinimumSize(new Dimension(0,0)); int parentSize = (orientation == JSplitPane.VERTICAL_SPLIT ? oldEditPane.getHeight() : oldEditPane.getWidth()); final int dividerPosition = (int)((double)(parentSize - newSplitPane.getDividerSize()) * 0.5); newSplitPane.setDividerLocation(dividerPosition); if(oldParent instanceof JSplitPane) { JSplitPane oldSplitPane = (JSplitPane)oldParent; int dividerPos = oldSplitPane.getDividerLocation(); Component left = oldSplitPane.getLeftComponent(); if(left == oldEditPane) oldSplitPane.setLeftComponent(newSplitPane); else oldSplitPane.setRightComponent(newSplitPane); newSplitPane.setLeftComponent(oldEditPane); newSplitPane.setRightComponent(editPane); oldSplitPane.setDividerLocation(dividerPos); } else { this.splitPane = newSplitPane; newSplitPane.setLeftComponent(oldEditPane); newSplitPane.setRightComponent(editPane); oldParent.add(newSplitPane,0); oldParent.revalidate(); } SwingUtilities.invokeLater(new Runnable() { public void run() { newSplitPane.setDividerLocation(dividerPosition); } }); editPane.focusOnTextArea(); return editPane; } //}}} //{{{ unsplit() method /** * Unsplits the view. * @since jEdit 2.3pre2 */ public void unsplit() { if(splitPane != null) { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane _editPane = editPanes[i]; if(editPane != _editPane) _editPane.close(); } JComponent parent = (JComponent)splitPane.getParent(); parent.remove(splitPane); parent.add(editPane,0); parent.revalidate(); splitPane = null; updateTitle(); editPane.focusOnTextArea(); } else getToolkit().beep(); } //}}} //{{{ unsplitCurrent() method /** * Removes the current split. * @since jEdit 2.3pre2 */ public void unsplitCurrent() { if(splitPane != null) { // find first split pane parenting current edit pane Component comp = editPane; while(!(comp instanceof JSplitPane)) { comp = comp.getParent(); } // get rid of any edit pane that is a child // of the current edit pane's parent splitter EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane _editPane = editPanes[i]; if(GUIUtilities.isAncestorOf(comp,_editPane) && _editPane != editPane) _editPane.close(); } JComponent parent = (JComponent)comp.getParent(); if(parent instanceof JSplitPane) { JSplitPane parentSplit = (JSplitPane)parent; int pos = parentSplit.getDividerLocation(); if(parentSplit.getLeftComponent() == comp) parentSplit.setLeftComponent(editPane); else parentSplit.setRightComponent(editPane); parentSplit.setDividerLocation(pos); } else { parent.remove(comp); parent.add(editPane,0); splitPane = null; } parent.revalidate(); updateTitle(); editPane.focusOnTextArea(); } else getToolkit().beep(); } //}}} //{{{ nextTextArea() method /** * Moves keyboard focus to the next text area. * @since jEdit 2.7pre4 */ public void nextTextArea() { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { if(editPane == editPanes[i]) { if(i == editPanes.length - 1) editPanes[0].focusOnTextArea(); else editPanes[i+1].focusOnTextArea(); break; } } } //}}} //{{{ prevTextArea() method /** * Moves keyboard focus to the previous text area. * @since jEdit 2.7pre4 */ public void prevTextArea() { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { if(editPane == editPanes[i]) { if(i == 0) editPanes[editPanes.length - 1].focusOnTextArea(); else editPanes[i-1].focusOnTextArea(); break; } } } //}}} //{{{ getSplitPane() method /** * Returns the top-level split pane, if any. * @since jEdit 2.3pre2 */ public JSplitPane getSplitPane() { return splitPane; } //}}} //{{{ getBuffer() method /** * Returns the current edit pane's buffer. */ public Buffer getBuffer() { if(editPane == null) return null; else return editPane.getBuffer(); } //}}} //{{{ setBuffer() method /** * Sets the current edit pane's buffer. */ public void setBuffer(Buffer buffer) { editPane.setBuffer(buffer); } //}}} //{{{ goToBuffer() method /** * If this buffer is open in one of the view's edit panes, sets focus * to that edit pane. Otherwise, opens the buffer in the currently * active edit pane. * @param buffer The buffer * @since jEdit 4.2pre1 */ public EditPane goToBuffer(Buffer buffer) { if(editPane.getBuffer() == buffer) { editPane.focusOnTextArea(); return editPane; } EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane ep = editPanes[i]; if(ep.getBuffer() == buffer /* ignore zero-height splits, etc */ && ep.getTextArea().getVisibleLines() > 1) { setEditPane(ep); ep.focusOnTextArea(); return ep; } } setBuffer(buffer); return editPane; } //}}} //{{{ getTextArea() method /** * Returns the current edit pane's text area. */ public JEditTextArea getTextArea() { if(editPane == null) return null; else return editPane.getTextArea(); } //}}} //{{{ getEditPane() method /** * Returns the current edit pane. * @since jEdit 2.5pre2 */ public EditPane getEditPane() { return editPane; } //}}} //{{{ getEditPanes() method /** * Returns all edit panes. * @since jEdit 2.5pre2 */ public EditPane[] getEditPanes() { if(splitPane == null) { EditPane[] ep = { editPane }; return ep; } else { Vector vec = new Vector(); getEditPanes(vec,splitPane); EditPane[] ep = new EditPane[vec.size()]; vec.copyInto(ep); return ep; } } //}}} //{{{ getViewConfig() method /** * @since jEdit 4.2pre1 */ public ViewConfig getViewConfig() { StringBuffer splitConfig = new StringBuffer(); if(splitPane != null) getSplitConfig(splitPane,splitConfig); else { splitConfig.append('"'); splitConfig.append(MiscUtilities.charsToEscapes( getBuffer().getPath())); splitConfig.append("\" buffer"); } ViewConfig config = new ViewConfig(); config.plainView = isPlainView(); config.splitConfig = splitConfig.toString(); config.x = getX(); config.y = getY(); config.width = getWidth(); config.height = getHeight(); config.extState = GUIUtilities.getExtendedState(this); config.top = dockableWindowManager.getTopDockingArea().getCurrent(); config.left = dockableWindowManager.getLeftDockingArea().getCurrent(); config.bottom = dockableWindowManager.getBottomDockingArea().getCurrent(); config.right = dockableWindowManager.getRightDockingArea().getCurrent(); config.topPos = dockableWindowManager.getTopDockingArea().getDimension(); config.leftPos = dockableWindowManager.getLeftDockingArea().getDimension(); config.bottomPos = dockableWindowManager.getBottomDockingArea().getDimension(); config.rightPos = dockableWindowManager.getRightDockingArea().getDimension(); return config; } //}}} //}}} //{{{ isClosed() method /** * Returns true if this view has been closed with * {@link jEdit#closeView(View)}. */ public boolean isClosed() { return closed; } //}}} //{{{ isPlainView() method /** * Returns true if this is an auxilliary view with no dockable windows. * @since jEdit 4.1pre2 */ public boolean isPlainView() { return plainView; } //}}} //{{{ getNext() method /** * Returns the next view in the list. */ public View getNext() { return next; } //}}} //{{{ getPrev() method /** * Returns the previous view in the list. */ public View getPrev() { return prev; } //}}} //{{{ handleMessage() method public void handleMessage(EBMessage msg) { if(msg instanceof PropertiesChanged) propertiesChanged(); else if(msg instanceof SearchSettingsChanged) { if(searchBar != null) searchBar.update(); } else if(msg instanceof BufferUpdate) handleBufferUpdate((BufferUpdate)msg); else if(msg instanceof EditPaneUpdate) handleEditPaneUpdate((EditPaneUpdate)msg); } //}}} //{{{ getMinimumSize() method public Dimension getMinimumSize() { return new Dimension(0,0); } //}}} //{{{ setWaitSocket() method /** * This socket is closed when the buffer is closed. */ public void setWaitSocket(Socket waitSocket) { this.waitSocket = waitSocket; } //}}} //{{{ toString() method public String toString() { return getClass().getName() + "[" + (jEdit.getActiveView() == this ? "active" : "inactive") + "]"; } //}}} //{{{ Package-private members View prev; View next; //{{{ View constructor View(Buffer buffer, ViewConfig config) { this.plainView = config.plainView; enableEvents(AWTEvent.KEY_EVENT_MASK); setIconImage(GUIUtilities.getEditorIcon()); dockableWindowManager = new DockableWindowManager(this,config); topToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1)); bottomToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -