/* Switch_Recent.bsh - a BeanShell macro script for displaying * and switching between open buffers (in most recently viewed order). * This is similar to the functionality provided by Alt+Tab in Windows. * It is assumed that this macro is mapped to the Ctrl-Tab shortcut. *
* Suggested shortcut: A+TAB *
* This Script is a modification of Buffer_Switcher.bsh, written by * Ollie Rutherfurd. * http://web.mit.edu/~jedit/arch/java/versions/4.3pre5/macros/Files/Buffer_Switcher.bsh * Copyright (C) 2001-2004 Ollie Rutherfurd, oliver@rutherfurd.net * * Modified by AhLeung Cheng * v1.0 * * {{{ License * 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 the jEdit program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * }}} */ BufferCellRenderer() { Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Buffer b = (Buffer)value; l = new JLabel("

"+b.getName()+" "+b.getDirectory()+"

"); l.setOpaque(true); l.setIcon(value.getIcon()); // l.setBorder(new javax.swing.border.EmptyBorder(3,3,3,3)); if (isSelected) { l.setBackground(list.getSelectionBackground()); l.setForeground(list.getSelectionForeground()); } else { l.setBackground(list.getBackground()); l.setForeground(list.getForeground()); } return l; } return this; } SwitchRecentDialog(doModal, dialogDimension) { Buffer[] openBuffers = jEdit.getBuffers(); int listLength = openBuffers.length; List history = BufferHistory.getHistory(); Map map = new TreeMap(); // used to sort the list by tree map. key = position; value = buffer; for (int i=0; i1? 1:0); // select the next recent buffer bufferList.setCellRenderer(BufferCellRenderer()); bufferList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bufferList.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, java.util.Collections.EMPTY_SET); // to capture the TAB key dialog = new JDialog(view, "" + listLength + " open buffers", doModal); dialog.setContentPane(new JScrollPane(bufferList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED)); dialog.setMinimumSize(dialogDimension); dialog.setMaximumSize(dialogDimension); dialog.setLocationRelativeTo(view); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); void switchBuffer() { view.getEditPane().setBuffer(bufferList.getSelectedValue()); } void keyPressed(evt) { evt.consume(); int selected = bufferList.getSelectedIndex(); switch (evt.getKeyCode()) { case KeyEvent.VK_BACK_QUOTE: selected = (selected+listLength-1)%listLength; break; case KeyEvent.VK_TAB: selected = (selected+1)%listLength; break; case KeyEvent.VK_ESCAPE: dialog.dispose(); return; } bufferList.setSelectedIndex(selected); bufferList.ensureIndexIsVisible(selected); } void keyReleased(evt) { if (evt.getKeyCode() == KeyEvent.VK_CONTROL) { switchBuffer(); dialog.dispose(); } } void keyTyped(evt) {} void mouseClicked(evt) { if (SwingUtilities.isLeftMouseButton(evt)) { switchBuffer(); dialog.dispose(); } } void mouseEntered(evt){} void mouseExited(evt){} void mousePressed(evt){} void mouseReleased(evt){} } SwitchRecentDialog(false, new Dimension(600, 400));