📄 editpane.java
字号:
/* * EditPane.java - Text area and buffer switcher * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2000, 2004 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package org.gjt.sp.jedit;//{{{ Importsimport javax.swing.*;import java.awt.event.*;import java.awt.*;import java.lang.reflect.Method;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.io.VFSManager;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.options.GlobalOptions;import org.gjt.sp.jedit.syntax.SyntaxStyle;import org.gjt.sp.jedit.textarea.*;import org.gjt.sp.util.Log;//}}}/** * A panel containing a text area.<p> * * In a BeanShell script, you can obtain the current edit pane from the * <code>editPane</code> variable.<p> * * This class does not have a public constructor. * Edit panes can be created and destroyed using methods in the * {@link View} class.<p> * * Each edit pane can edit one buffer at a time. * * @see View#splitHorizontally() * @see View#splitVertically() * @see View#unsplitCurrent() * @see View#unsplit() * @see View#getEditPane() * @see View#getEditPanes() * * @author Slava Pestov * @version $Id: EditPane.java,v 1.49 2004/01/25 01:38:28 spestov Exp $ */public class EditPane extends JPanel implements EBComponent{ //{{{ getView() method /** * Returns the view containing this edit pane. * @since jEdit 2.5pre2 */ public View getView() { return view; } //}}} //{{{ getBuffer() method /** * Returns the current buffer. * @since jEdit 2.5pre2 */ public Buffer getBuffer() { return buffer; } //}}} //{{{ setBuffer() method /** * Sets the current buffer. * @param buffer The buffer to edit. * @since jEdit 2.5pre2 */ public void setBuffer(final Buffer buffer) { if(buffer == null) throw new NullPointerException(); if(this.buffer == buffer) return; //if(buffer.insideCompoundEdit()) // buffer.endCompoundEdit(); recentBuffer = this.buffer; if(recentBuffer != null) saveCaretInfo(); this.buffer = buffer; textArea.setBuffer(buffer); if(!init) { view.updateTitle(); if(bufferSwitcher != null) { if(bufferSwitcher.getSelectedItem() != buffer) bufferSwitcher.setSelectedItem(buffer); } EditBus.send(new EditPaneUpdate(this,EditPaneUpdate .BUFFER_CHANGED)); } SwingUtilities.invokeLater(new Runnable() { public void run() { // only do this if we are the current edit pane if(view.getEditPane() == EditPane.this && (bufferSwitcher == null || !bufferSwitcher.isPopupVisible())) { textArea.requestFocus(); } } }); // Only do this after all I/O requests are complete Runnable runnable = new Runnable() { public void run() { // avoid a race condition // see bug #834338 if(buffer == getBuffer()) loadCaretInfo(); } }; if(buffer.isPerformingIO()) VFSManager.runInAWTThread(runnable); else runnable.run(); } //}}} //{{{ prevBuffer() method /** * Selects the previous buffer. * @since jEdit 2.7pre2 */ public void prevBuffer() { Buffer buffer = this.buffer.getPrev(); if(buffer == null) setBuffer(jEdit.getLastBuffer()); else setBuffer(buffer); } //}}} //{{{ nextBuffer() method /** * Selects the next buffer. * @since jEdit 2.7pre2 */ public void nextBuffer() { Buffer buffer = this.buffer.getNext(); if(buffer == null) setBuffer(jEdit.getFirstBuffer()); else setBuffer(buffer); } //}}} //{{{ recentBuffer() method /** * Selects the most recently edited buffer. * @since jEdit 2.7pre2 */ public void recentBuffer() { if(recentBuffer != null) setBuffer(recentBuffer); else getToolkit().beep(); } //}}} //{{{ focusOnTextArea() method /** * Sets the focus onto the text area. * @since jEdit 2.5pre2 */ public void focusOnTextArea() { SwingUtilities.invokeLater(new Runnable() { public void run() { textArea.requestFocus(); } }); } //}}} //{{{ getTextArea() method /** * Returns the view's text area. * @since jEdit 2.5pre2 */ public JEditTextArea getTextArea() { return textArea; } //}}} //{{{ getBufferSwitcher() method /** * Returns the buffer switcher combo box instance. * @since jEdit 4.1pre8 */ public BufferSwitcher getBufferSwitcher() { return bufferSwitcher; } //}}} //{{{ showBufferSwitcher() method /** * Shows the buffer switcher combo box. * @since jEdit 4.1pre8 */ public void showBufferSwitcher() { if(bufferSwitcher == null) getToolkit().beep(); else { bufferSwitcher.requestFocus(); bufferSwitcher.showPopup(); } } //}}} //{{{ saveCaretInfo() method /** * Saves the caret information to the current buffer. * @since jEdit 2.5pre2 */ public void saveCaretInfo() { buffer.setIntegerProperty(Buffer.CARET, textArea.getCaretPosition()); /*Selection[] selection = textArea.getSelection(); if(selection != null) buffer.setProperty(Buffer.SELECTION,selection);*/ buffer.setIntegerProperty(Buffer.SCROLL_VERT, textArea.getFirstPhysicalLine()); buffer.setIntegerProperty(Buffer.SCROLL_HORIZ, textArea.getHorizontalOffset()); } //}}} //{{{ loadCaretInfo() method /** * Loads the caret information from the current buffer. * @since jEdit 2.5pre2 */ public void loadCaretInfo() { Integer caret = (Integer)buffer.getProperty(Buffer.CARET); //Selection[] selection = (Selection[])buffer.getProperty(Buffer.SELECTION); Integer firstLine = (Integer)buffer.getProperty(Buffer.SCROLL_VERT); Integer horizontalOffset = (Integer)buffer.getProperty(Buffer.SCROLL_HORIZ); if(caret != null) { textArea.setCaretPosition(Math.min(caret.intValue(), buffer.getLength())); } /*if(selection != null) textArea.setSelection(selection);*/ if(firstLine != null) textArea.setFirstPhysicalLine(firstLine.intValue()); if(horizontalOffset != null) textArea.setHorizontalOffset(horizontalOffset.intValue()); /* Silly bug workaround #8694. If you look at the above code, * note that we restore the saved caret position first, then * scroll to the saved location. However, the caret changing * can itself result in scrolling to a different location than * what was saved; and since moveCaretPosition() calls * updateBracketHighlight(), the bracket highlight's out of * bounds calculation will rely on a different set of physical * first/last lines than what we will end up with eventually. * Instead of confusing the user with status messages that * appear at random when switching buffers, we simply hide the * message altogether. */ view.getStatus().setMessage(null); } //}}} //{{{ handleMessage() method public void handleMessage(EBMessage msg) { if(msg instanceof PropertiesChanged) { propertiesChanged(); loadBufferSwitcher(); } else if(msg instanceof BufferUpdate) handleBufferUpdate((BufferUpdate)msg); } //}}} //{{{ getMinimumSize() method /** * Returns 0,0 for split pane compatibility. */ public final Dimension getMinimumSize() { return new Dimension(0,0); } //}}} //{{{ toString() method public String toString() { return getClass().getName() + "[" + (view.getEditPane() == this ? "active" : "inactive") + "]"; } //}}} //{{{ Package-private members //{{{ EditPane constructor EditPane(View view, Buffer buffer)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -