001: /*
002: * DirectoryMode.java
003: *
004: * Copyright (C) 1998-2003 Peter Graves
005: * $Id: DirectoryMode.java,v 1.8 2003/10/15 14:53:25 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.event.KeyEvent;
025: import javax.swing.ButtonGroup;
026: import javax.swing.JRadioButtonMenuItem;
027:
028: public final class DirectoryMode extends AbstractMode implements
029: Constants, Mode {
030: private static final DirectoryMode mode = new DirectoryMode();
031:
032: private DirectoryMode() {
033: super (DIRECTORY_MODE, DIRECTORY_MODE_NAME);
034: setProperty(Property.VERTICAL_RULE, 0);
035: setProperty(Property.SHOW_LINE_NUMBERS, false);
036: setProperty(Property.SHOW_CHANGE_MARKS, false);
037: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
038: setProperty(Property.HIGHLIGHT_BRACKETS, false);
039: }
040:
041: public static final DirectoryMode getMode() {
042: return mode;
043: }
044:
045: public NavigationComponent getSidebarComponent(Editor editor) {
046: Debug.assertTrue(editor.getBuffer().getMode() == mode);
047: if (!editor.getBuffer()
048: .getBooleanProperty(Property.ENABLE_TREE))
049: return null;
050: View view = editor.getCurrentView();
051: if (view == null)
052: return null; // Shouldn't happen.
053: if (view.getSidebarComponent() == null)
054: view.setSidebarComponent(DirectoryTree
055: .getDirectoryTree(editor));
056: return view.getSidebarComponent();
057: }
058:
059: public Formatter getFormatter(Buffer buffer) {
060: return new DirectoryFormatter(buffer);
061: }
062:
063: protected void setKeyMapDefaults(KeyMap km) {
064: km.mapKey(KeyEvent.VK_ENTER, 0, "dirOpenFile");
065: km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK, "dirOpenFile");
066: km.mapKey(VK_DOUBLE_MOUSE_1, 0, "dirOpenFile");
067: km.mapKey(VK_MOUSE_2, 0, "dirOpenFile");
068: km.mapKey(KeyEvent.VK_ENTER, CTRL_MASK,
069: "dirOpenFileAndKillDirectory");
070: km.mapKey(KeyEvent.VK_B, CTRL_MASK | SHIFT_MASK,
071: "dirBrowseFile");
072: km.mapKey(KeyEvent.VK_BACK_SPACE, 0, "dirUpDir");
073: km.mapKey('u', "dirUpDir");
074: km.mapKey('l', "dirLimit");
075: km.mapKey('L', "dirUnlimit");
076: km.mapKey(KeyEvent.VK_S, CTRL_MASK, "dirCycleSortBy");
077: km.mapKey(KeyEvent.VK_R, CTRL_MASK, "dirRescan");
078: km.mapKey(KeyEvent.VK_DELETE, 0, "dirDeleteFiles");
079: km.mapKey('c', "dirCopyFile");
080: km.mapKey('g', "dirGetFile");
081: km.mapKey('m', "dirMoveFile");
082: km.mapKey('t', "dirTagFile");
083: km.mapKey('!', "dirDoShellCommand");
084: km.mapKey(KeyEvent.VK_HOME, 0, "dirHome");
085: km.mapKey('b', "dirBack");
086: km.mapKey('f', "dirForward");
087: }
088:
089: public void populateMenu(Editor editor, Menu menu) {
090: final String text = menu.getText();
091: if (text == "File") {
092: menu.add(editor, "New", 'N', "newBuffer");
093: menu.add(editor, "Open...", 'O', "openFile");
094: menu.add(editor, "Recent Files...", 'R', "recentFiles");
095: menu.addSeparator();
096: menu.add(editor, "Save All", 'A', "saveAll");
097: menu.add(editor, "Close", 'C', "killBuffer");
098: menu.add(editor, "Close All", 'L', "closeAll");
099: menu.add(editor, "Close Others", 'H', "closeOthers");
100: menu.addSeparator();
101: menu.add(editor, "Next Buffer", 'T', "nextBuffer");
102: menu.add(editor, "Previous Buffer", 'R', "prevBuffer");
103: menu.addSeparator();
104: menu.add(editor, "New Frame", 'M', "newFrame");
105: menu.add(editor, "Execute Command...", 'D',
106: "executeCommand");
107: menu.addSeparator();
108: menu.add(editor, "Save Session", 'S', "saveSession");
109: menu.add(editor, "Load Session...", 'L', "loadSession");
110: menu.addSeparator();
111: menu.add(editor, "Print...", 'P', "print");
112: menu.addSeparator();
113: menu.add(editor, "Save All/Exit", '/', "saveAllExit");
114: menu.add(editor, "Exit", 'X', "quit");
115: } else if (text == "Edit") {
116: menu.add(editor, "Copy", 'C', "copyRegion");
117: menu.add(editor, "Copy Append", 'D', "copyAppend");
118: } else if (text == "Search") {
119: populateSearchMenu(editor, menu);
120: } else if (text == "Go") {
121: menu.add(editor, "Go Back", 'B', "dirBack");
122: menu.add(editor, "Go Forward", 'F', "dirForward");
123: menu.add(editor, "Go To Parent Directory", 'P', "dirUpDir");
124: } else
125: super .populateMenu(editor, menu);
126: }
127:
128: public void populateModeMenu(Editor editor, Menu menu) {
129: Buffer buffer = editor.getBuffer();
130: Directory dir = buffer instanceof Directory ? (Directory) buffer
131: : null;
132: menu.add(editor, "Copy File...", 'C', "dirCopyFile");
133: menu.add(editor, "Move File...", 'M', "dirMoveFile");
134: menu.add(editor, "Delete File", 'D', "dirDeleteFiles");
135: menu.addSeparator();
136: menu.add(editor, "Limit...", 'L', "dirLimit");
137: MenuItem unlimit = menu.add(editor, "Unlimit", 'U',
138: "dirUnlimit");
139: boolean enabled = (dir != null && dir.getLimitPattern() != null);
140: unlimit.setEnabled(enabled);
141: menu.addSeparator();
142: JRadioButtonMenuItem sortByName = new JRadioButtonMenuItem(
143: "Sort by Name");
144: sortByName.setMnemonic('N');
145: sortByName.setActionCommand("DirectoryMode.dirSortByName");
146: sortByName.addActionListener(editor.getDispatcher());
147: JRadioButtonMenuItem sortByDate = new JRadioButtonMenuItem(
148: "Sort by Date");
149: sortByDate.setMnemonic('T');
150: sortByDate.setActionCommand("DirectoryMode.dirSortByDate");
151: sortByDate.addActionListener(editor.getDispatcher());
152: JRadioButtonMenuItem sortBySize = new JRadioButtonMenuItem(
153: "Sort by Size");
154: sortBySize.setMnemonic('S');
155: sortBySize.setActionCommand("DirectoryMode.dirSortBySize");
156: sortBySize.addActionListener(editor.getDispatcher());
157: ButtonGroup group = new ButtonGroup();
158: group.add(sortByName);
159: group.add(sortByDate);
160: group.add(sortBySize);
161: menu.add(sortByName);
162: menu.add(sortByDate);
163: menu.add(sortBySize);
164: if (dir != null) {
165: int sortBy = dir.getSortBy();
166: if (sortBy == Directory.SORT_BY_NAME)
167: sortByName.setSelected(true);
168: else if (sortBy == Directory.SORT_BY_DATE)
169: sortByDate.setSelected(true);
170: else if (sortBy == Directory.SORT_BY_SIZE)
171: sortBySize.setSelected(true);
172: }
173: menu.addSeparator();
174: menu.add(editor, "Rescan Directory", 'R', "dirRescan");
175: }
176:
177: public static void dirSortByName() {
178: resort(Directory.SORT_BY_NAME);
179: }
180:
181: public static void dirSortByDate() {
182: resort(Directory.SORT_BY_DATE);
183: }
184:
185: public static void dirSortBySize() {
186: resort(Directory.SORT_BY_SIZE);
187: }
188:
189: private static void resort(int sortBy) {
190: final Editor editor = Editor.currentEditor();
191: final Buffer buffer = editor.getBuffer();
192: if (buffer instanceof Directory) {
193: editor.setWaitCursor();
194: ((Directory) buffer).resort(sortBy);
195: editor.setDefaultCursor();
196: }
197: }
198:
199: protected ToolBar getDefaultToolBar(Frame frame) {
200: return new DirectoryModeToolBar(frame);
201: }
202: }
|