001: /*
002: * AutosaveBackupOptionPane.java - Autosave & backup options
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2003 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.options;
024:
025: //{{{ Imports
026: import javax.swing.*;
027: import java.awt.event.*;
028: import java.awt.*;
029: import org.gjt.sp.jedit.*;
030: import org.gjt.sp.jedit.browser.VFSBrowser;
031:
032: //}}}
033:
034: /**
035: * The Save and Backup option panel.
036: *
037: * @author Slava Pestov
038: * @author $Id: SaveBackupOptionPane.java 11123 2007-11-23 15:51:02Z k_satoda $
039: */
040: public class SaveBackupOptionPane extends AbstractOptionPane {
041: //{{{ SaveBackupOptionPane constructor
042: public SaveBackupOptionPane() {
043: super ("save-back");
044: } //}}}
045:
046: //{{{ _init() method
047: protected void _init() {
048: /* Two-stage save */
049: twoStageSave = new JCheckBox(jEdit
050: .getProperty("options.save-back.twoStageSave"));
051: twoStageSave.setSelected(jEdit
052: .getBooleanProperty("twoStageSave"));
053: addComponent(twoStageSave);
054:
055: /* Confirm save all */
056: confirmSaveAll = new JCheckBox(jEdit
057: .getProperty("options.save-back.confirmSaveAll"));
058: confirmSaveAll.setSelected(jEdit
059: .getBooleanProperty("confirmSaveAll"));
060: addComponent(confirmSaveAll);
061:
062: /* Autosave interval */
063: autosave = new JTextField(jEdit.getProperty("autosave"));
064: addComponent(jEdit.getProperty("options.save-back.autosave"),
065: autosave);
066:
067: /* Autosave untitled buffers */
068: autosaveUntitled = new JCheckBox(jEdit
069: .getProperty("options.save-back.autosaveUntitled"));
070: autosaveUntitled.setSelected(jEdit
071: .getBooleanProperty("autosaveUntitled"));
072: addComponent(autosaveUntitled);
073:
074: /* Backup count */
075: backups = new JTextField(jEdit.getProperty("backups"));
076: addComponent(jEdit.getProperty("options.save-back.backups"),
077: backups);
078:
079: /* Backup directory */
080: backupDirectory = new JTextField(jEdit
081: .getProperty("backup.directory"));
082: JButton browseBackupDirectory = new JButton("...");
083: browseBackupDirectory.addActionListener(new MyActionListener());
084: JPanel panel = new JPanel(new BorderLayout());
085: panel.add(backupDirectory);
086: panel.add(browseBackupDirectory, BorderLayout.EAST);
087: addComponent(jEdit
088: .getProperty("options.save-back.backupDirectory"),
089: panel);
090:
091: /* Backup filename prefix */
092: backupPrefix = new JTextField(jEdit
093: .getProperty("backup.prefix"));
094: addComponent(jEdit
095: .getProperty("options.save-back.backupPrefix"),
096: backupPrefix);
097:
098: /* Backup suffix */
099: backupSuffix = new JTextField(jEdit
100: .getProperty("backup.suffix"));
101: addComponent(jEdit
102: .getProperty("options.save-back.backupSuffix"),
103: backupSuffix);
104:
105: /* Backup on every save */
106: backupEverySave = new JCheckBox(jEdit
107: .getProperty("options.save-back.backupEverySave"));
108: backupEverySave.setSelected(jEdit
109: .getBooleanProperty("backupEverySave"));
110: addComponent(backupEverySave);
111: } //}}}
112:
113: //{{{ _save() method
114: protected void _save() {
115: jEdit.setBooleanProperty("twoStageSave", twoStageSave
116: .isSelected());
117: jEdit.setBooleanProperty("confirmSaveAll", confirmSaveAll
118: .isSelected());
119: jEdit.setProperty("autosave", this .autosave.getText());
120: jEdit.setProperty("backups", backups.getText());
121: jEdit
122: .setProperty("backup.directory", backupDirectory
123: .getText());
124: jEdit.setProperty("backup.prefix", backupPrefix.getText());
125: jEdit.setProperty("backup.suffix", backupSuffix.getText());
126: jEdit.setBooleanProperty("backupEverySave", backupEverySave
127: .isSelected());
128: boolean newAutosave = autosaveUntitled.isSelected();
129: boolean oldAutosave = jEdit
130: .getBooleanProperty("autosaveUntitled");
131: jEdit.setBooleanProperty("autosaveUntitled", newAutosave);
132:
133: if ((!newAutosave || jEdit.getIntegerProperty("autosave", 0) == 0)
134: && oldAutosave) {
135: Buffer[] buffers = jEdit.getBuffers();
136: for (Buffer buffer : buffers) {
137: if (buffer.isUntitled()) {
138: buffer.removeAutosaveFile();
139: }
140: }
141: }
142: } //}}}
143:
144: //{{{ Private members
145: private JCheckBox twoStageSave;
146: private JCheckBox confirmSaveAll;
147: private JTextField autosave;
148: private JCheckBox autosaveUntitled;
149: private JTextField backups;
150: private JTextField backupDirectory;
151: private JTextField backupPrefix;
152: private JTextField backupSuffix;
153: private JCheckBox backupEverySave;
154:
155: //}}}
156:
157: //{{{ MyActionListener class
158: private class MyActionListener implements ActionListener {
159: public void actionPerformed(ActionEvent e) {
160: String[] choosenFolder = GUIUtilities.showVFSFileDialog(
161: null, backupDirectory.getText(),
162: VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false);
163: if (choosenFolder != null)
164: backupDirectory.setText(choosenFolder[0]);
165: }
166: } //}}}
167:
168: }
|