It used to be the case that you could select 'Close', and then when asked
"do you want to save?" you could press yes and then press cancel and Jskad would still exit. That's no longer the case. Added File->Exit to Jskad.
This commit is contained in:
parent
45b87b0fb4
commit
9a41f512d9
2 changed files with 94 additions and 29 deletions
|
@ -209,20 +209,12 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
closeItem.addActionListener(new ThdlActionListener() {
|
closeItem.addActionListener(new ThdlActionListener() {
|
||||||
public void theRealActionPerformed(ActionEvent e) {
|
public void theRealActionPerformed(ActionEvent e) {
|
||||||
if (!hasChanged || hasChanged && checkSave()) {
|
if (!hasChanged || hasChanged && checkSave()) {
|
||||||
numberOfTibsRTFOpen--;
|
Jskad.this.realCloseAction(true);
|
||||||
|
|
||||||
if (numberOfTibsRTFOpen == 0)
|
|
||||||
System.exit(0);
|
|
||||||
else {
|
|
||||||
final JFrame parentFrame = (JFrame)parentObject;
|
|
||||||
parentFrame.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(closeItem);
|
fileMenu.add(closeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
JMenuItem saveItem = new JMenuItem("Save");
|
JMenuItem saveItem = new JMenuItem("Save");
|
||||||
// saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,java.awt.Event.CTRL_MASK)); //Ctrl-s
|
// saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,java.awt.Event.CTRL_MASK)); //Ctrl-s
|
||||||
saveItem.addActionListener(new ThdlActionListener() {
|
saveItem.addActionListener(new ThdlActionListener() {
|
||||||
|
@ -245,6 +237,17 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
});
|
});
|
||||||
fileMenu.add(saveAsItem);
|
fileMenu.add(saveAsItem);
|
||||||
|
|
||||||
|
if (parentObject instanceof JFrame) {
|
||||||
|
JMenuItem exitItem = new JMenuItem("Exit");
|
||||||
|
exitItem.addActionListener(new ThdlActionListener() {
|
||||||
|
public void theRealActionPerformed(ActionEvent e) {
|
||||||
|
exitAction();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.addSeparator();
|
||||||
|
fileMenu.add(exitItem);
|
||||||
|
}
|
||||||
|
|
||||||
menuBar.add(fileMenu);
|
menuBar.add(fileMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,7 +721,9 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
Point point = parentFrame.getLocationOnScreen();
|
Point point = parentFrame.getLocationOnScreen();
|
||||||
newFrame.setSize(parentFrame.getSize().width, parentFrame.getSize().height);
|
newFrame.setSize(parentFrame.getSize().width, parentFrame.getSize().height);
|
||||||
newFrame.setLocation(point.x+50, point.y+50);
|
newFrame.setLocation(point.x+50, point.y+50);
|
||||||
newFrame.getContentPane().add(new Jskad(newFrame));
|
Jskad jskad = new Jskad(newFrame);
|
||||||
|
jskads.add(jskad);
|
||||||
|
newFrame.getContentPane().add(jskad);
|
||||||
newFrame.setVisible(true);
|
newFrame.setVisible(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -765,6 +770,7 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
newFrame.setSize(x_size, y_size);
|
newFrame.setSize(x_size, y_size);
|
||||||
newFrame.setLocation(point.x+50, point.y+50);
|
newFrame.setLocation(point.x+50, point.y+50);
|
||||||
Jskad newRTF = new Jskad(newFrame);
|
Jskad newRTF = new Jskad(newFrame);
|
||||||
|
jskads.add(newRTF);
|
||||||
newFrame.getContentPane().add(newRTF);
|
newFrame.getContentPane().add(newRTF);
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
try {
|
try {
|
||||||
|
@ -838,7 +844,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFile() {
|
/** Returns true iff the save was successful. */
|
||||||
|
private boolean saveFile() {
|
||||||
String s = getSave(fileName);
|
String s = getSave(fileName);
|
||||||
if (null != s) {
|
if (null != s) {
|
||||||
if (parentObject instanceof JFrame) {
|
if (parentObject instanceof JFrame) {
|
||||||
|
@ -851,10 +858,14 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
parentFrame.setTitle("Jskad: " + s);
|
parentFrame.setTitle("Jskad: " + s);
|
||||||
fileName = new String(s);
|
fileName = new String(s);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveAsFile() {
|
/** Returns true iff the save was successful. */
|
||||||
|
private boolean saveAsFile() {
|
||||||
String s = getSaveAs();
|
String s = getSaveAs();
|
||||||
if (null != s) {
|
if (null != s) {
|
||||||
if (parentObject instanceof JFrame) {
|
if (parentObject instanceof JFrame) {
|
||||||
|
@ -867,27 +878,33 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
parentFrame.setTitle("Jskad: " + s);
|
parentFrame.setTitle("Jskad: " + s);
|
||||||
fileName = new String(s);
|
fileName = new String(s);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true iff the user says (possibly after a successful
|
||||||
|
save) that it is OK to destroy this Jskad widget. */
|
||||||
private boolean checkSave() {
|
private boolean checkSave() {
|
||||||
if (ThdlOptions.getBooleanOption("thdl.Jskad.do.not.confirm.quit")) {
|
if (ThdlOptions.getBooleanOption("thdl.Jskad.do.not.confirm.quit")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int saveFirst = JOptionPane.showConfirmDialog(this, "Do you want to save your changes?", "Please select", JOptionPane.YES_NO_CANCEL_OPTION);
|
int saveFirst
|
||||||
|
= JOptionPane.showConfirmDialog(this,
|
||||||
|
"Do you want to save your changes?",
|
||||||
|
"Please select",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||||
|
|
||||||
switch (saveFirst) {
|
switch (saveFirst) {
|
||||||
case JOptionPane.NO_OPTION: //don't save but do continue
|
case JOptionPane.NO_OPTION: //don't save but do continue
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case JOptionPane.YES_OPTION: //save and continue
|
case JOptionPane.YES_OPTION: //save and continue
|
||||||
if (fileName == null) {
|
if (fileName == null)
|
||||||
saveAsFile();
|
return saveAsFile();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
saveFile();
|
return saveFile();
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -1180,6 +1197,54 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Closes this Jskad session without saving. If deleteFromList
|
||||||
|
is true, the jskads vector is updated so that it no longer
|
||||||
|
contains this instance. If this is the last instance open,
|
||||||
|
the program exits. */
|
||||||
|
private void realCloseAction(boolean deleteFromList) {
|
||||||
|
numberOfTibsRTFOpen--;
|
||||||
|
|
||||||
|
// Delete this Jskad from jskads.
|
||||||
|
if (deleteFromList) {
|
||||||
|
int i, sz = jskads.size();
|
||||||
|
for (i = 0; i < sz; i++) {
|
||||||
|
if (jskads.elementAt(i) == this) {
|
||||||
|
jskads.removeElementAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == sz)
|
||||||
|
throw new Error("Couldn't find the Jskad session being closed in our list of open Jskad sessions! This is a bug.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numberOfTibsRTFOpen == 0)
|
||||||
|
System.exit(0);
|
||||||
|
else {
|
||||||
|
final JFrame parentFrame = (JFrame)parentObject;
|
||||||
|
parentFrame.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stores all open Jskad sessions. */
|
||||||
|
private static Vector jskads = new Vector();
|
||||||
|
|
||||||
|
/** Closes all Jskad windows after asking "Do you want to save?"
|
||||||
|
for the modified windows. If you don't cancel for any unsaved
|
||||||
|
session, then all sessions are closed. */
|
||||||
|
private static void exitAction() {
|
||||||
|
int sz = jskads.size();
|
||||||
|
for (int i = 0; i < sz; i++) {
|
||||||
|
Jskad j = (Jskad)jskads.elementAt(i);
|
||||||
|
if (j.hasChanged && !j.checkSave()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < sz; i++) {
|
||||||
|
Jskad j = (Jskad)jskads.elementAt(i);
|
||||||
|
j.realCloseAction(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1205,6 +1270,7 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
f.setSize(x_size, y_size);
|
f.setSize(x_size, y_size);
|
||||||
f.setLocation(d.width/8, d.height/8);
|
f.setLocation(d.width/8, d.height/8);
|
||||||
final Jskad jskad = new Jskad(f);
|
final Jskad jskad = new Jskad(f);
|
||||||
|
jskads.add(jskad);
|
||||||
f.getContentPane().add(jskad);
|
f.getContentPane().add(jskad);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
|
||||||
|
|
|
@ -101,8 +101,9 @@ printing Rich Text Format (RTF) documents. To start a new
|
||||||
document, choose 'New'. To open an already existing document,
|
document, choose 'New'. To open an already existing document,
|
||||||
choose 'Open'. In either case, if there is any text in the
|
choose 'Open'. In either case, if there is any text in the
|
||||||
current Jskad window, a new window will be opened up. To close a
|
current Jskad window, a new window will be opened up. To close a
|
||||||
Jskad window, choose 'Close' or press the 'X' button. You will
|
Jskad window, choose 'Close' or press the 'X' button. To close
|
||||||
be prompted to save if you haven't already done so.
|
all Jskad windows, choose 'Exit'. You will be prompted to save
|
||||||
|
if you haven't already done so.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -393,11 +394,9 @@ Sambhota keyboard //Everything before <?parameters?> is taken to be a comme
|
||||||
<p>
|
<p>
|
||||||
Jskad remembers your preferences for a few things, such as the working
|
Jskad remembers your preferences for a few things, such as the working
|
||||||
directory, the keyboard to use, the font size, etc. Your
|
directory, the keyboard to use, the font size, etc. Your
|
||||||
preferences are saved at program exit. If you want to reset your
|
preferences are saved automatically at program exit. If you want
|
||||||
preferences, you must delete the file
|
to reset your preferences, you must use 'Clear Preferences' from the
|
||||||
<tt>my_thdl_preferences.txt</tt>. See the Edit menu's "Save
|
'Edit' menu.
|
||||||
preferences to ..." item to learn the precise location of this
|
|
||||||
file.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in a new issue