Feature Request 697358 is done. The working directory for Jskad is
now a preference. In addition, Jskad now raises an error dialog when you try to "Save As" to a bad place or open a file that doesn't exist or isn't readable.
This commit is contained in:
parent
b49c441e6e
commit
9e0dc68d12
2 changed files with 85 additions and 80 deletions
|
@ -24,6 +24,10 @@
|
|||
# system-specific.
|
||||
thdl.user.options.directory =
|
||||
|
||||
# Set this to the full path of Jskad's working directory. When you go
|
||||
# to open a file or to save a file, this is the path you'll see first.
|
||||
thdl.Jskad.working.directory =
|
||||
|
||||
# Should the TibetanMachineWeb fonts not be loaded from within the JAR? Set
|
||||
# this to true if you can get away with it and want your THDL tools to load
|
||||
# faster.
|
||||
|
|
|
@ -147,7 +147,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
if (parentObject instanceof JFrame || parentObject instanceof JInternalFrame) {
|
||||
fileChooser = new JFileChooser();
|
||||
String whereToStart
|
||||
= ThdlOptions.getStringOption("thdl.Jskad.working.directory",
|
||||
null);
|
||||
fileChooser
|
||||
= new JFileChooser(whereToStart.equals("") ? null : whereToStart);
|
||||
rtfFilter = new RTFFilter();
|
||||
txtFilter = new TXTFilter();
|
||||
fileChooser.addChoosableFileFilter(rtfFilter);
|
||||
|
@ -617,89 +621,81 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
}
|
||||
|
||||
private void openFile() {
|
||||
fileChooser = new JFileChooser();
|
||||
String whereToStart
|
||||
= ThdlOptions.getStringOption("thdl.Jskad.working.directory",
|
||||
null);
|
||||
fileChooser
|
||||
= new JFileChooser(whereToStart.equals("") ? null : whereToStart);
|
||||
fileChooser.addChoosableFileFilter(rtfFilter);
|
||||
|
||||
if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
|
||||
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
return;
|
||||
}
|
||||
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
return;
|
||||
}
|
||||
|
||||
final File fileChosen = fileChooser.getSelectedFile();
|
||||
final String f_name = fileChosen.getAbsolutePath();
|
||||
final File fileChosen = fileChooser.getSelectedFile();
|
||||
final String f_name = fileChosen.getAbsolutePath();
|
||||
|
||||
try {
|
||||
JFrame parentFrame = (JFrame)parentObject;
|
||||
InputStream in = new FileInputStream(fileChosen);
|
||||
JFrame newFrame = new JFrame(f_name);
|
||||
Point point = parentFrame.getLocationOnScreen();
|
||||
newFrame.setSize(x_size, y_size);
|
||||
newFrame.setLocation(point.x+50, point.y+50);
|
||||
Jskad newRTF = new Jskad(newFrame);
|
||||
newFrame.getContentPane().add(newRTF);
|
||||
newRTF.dp.rtfEd.read(in, newRTF.dp.getDocument(), 0);
|
||||
newRTF.dp.getDocument().addDocumentListener(newRTF);
|
||||
in.close();
|
||||
newFrame.setTitle(f_name);
|
||||
newRTF.fileName = new String(f_name);
|
||||
newRTF.hasChanged = false;
|
||||
newRTF.dp.getCaret().setDot(0);
|
||||
newFrame.setVisible(true);
|
||||
}
|
||||
catch (FileNotFoundException fnfe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
catch (BadLocationException ble) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
}
|
||||
else {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
try {
|
||||
if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) {
|
||||
JFrame parentFrame = (JFrame)parentObject;
|
||||
InputStream in = new FileInputStream(fileChosen);
|
||||
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||
fileChosen.getParentFile().getAbsolutePath());
|
||||
JFrame newFrame = new JFrame(f_name);
|
||||
Point point = parentFrame.getLocationOnScreen();
|
||||
newFrame.setSize(x_size, y_size);
|
||||
newFrame.setLocation(point.x+50, point.y+50);
|
||||
Jskad newRTF = new Jskad(newFrame);
|
||||
newFrame.getContentPane().add(newRTF);
|
||||
newRTF.dp.rtfEd.read(in, newRTF.dp.getDocument(), 0);
|
||||
newRTF.dp.getDocument().addDocumentListener(newRTF);
|
||||
in.close();
|
||||
newFrame.setTitle(f_name);
|
||||
newRTF.fileName = new String(f_name);
|
||||
newRTF.hasChanged = false;
|
||||
newRTF.dp.getCaret().setDot(0);
|
||||
newFrame.setVisible(true);
|
||||
} else {
|
||||
InputStream in = new FileInputStream(fileChosen);
|
||||
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||
fileChosen.getParentFile().getAbsolutePath());
|
||||
dp.newDocument();
|
||||
dp.rtfEd.read(in, dp.getDocument(), 0);
|
||||
in.close();
|
||||
dp.getCaret().setDot(0);
|
||||
dp.getDocument().addDocumentListener(Jskad.this);
|
||||
hasChanged = false;
|
||||
fileName = new String(f_name);
|
||||
|
||||
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
return;
|
||||
}
|
||||
|
||||
final File fileChosen = fileChooser.getSelectedFile();
|
||||
final String f_name = fileChosen.getAbsolutePath();
|
||||
|
||||
try {
|
||||
InputStream in = new FileInputStream(fileChosen);
|
||||
dp.newDocument();
|
||||
dp.rtfEd.read(in, dp.getDocument(), 0);
|
||||
in.close();
|
||||
dp.getCaret().setDot(0);
|
||||
dp.getDocument().addDocumentListener(Jskad.this);
|
||||
hasChanged = false;
|
||||
fileName = new String(f_name);
|
||||
|
||||
if (parentObject instanceof JFrame) {
|
||||
JFrame parentFrame = (JFrame)parentObject;
|
||||
parentFrame.setTitle(fileName);
|
||||
}
|
||||
else if (parentObject instanceof JInternalFrame) {
|
||||
JInternalFrame parentFrame = (JInternalFrame)parentObject;
|
||||
parentFrame.setTitle(fileName);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException fnfe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
catch (BadLocationException ble) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
}
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
if (parentObject instanceof JFrame) {
|
||||
JFrame parentFrame = (JFrame)parentObject;
|
||||
parentFrame.setTitle(fileName);
|
||||
}
|
||||
else if (parentObject instanceof JInternalFrame) {
|
||||
JInternalFrame parentFrame = (JInternalFrame)parentObject;
|
||||
parentFrame.setTitle(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException fnfe) {
|
||||
JOptionPane.showMessageDialog(Jskad.this,
|
||||
"No such file exists.",
|
||||
"Open File Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
JOptionPane.showMessageDialog(Jskad.this,
|
||||
"Error reading file.",
|
||||
"Open File Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (BadLocationException ble) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
|
||||
private void saveFile() {
|
||||
|
@ -768,8 +764,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
out.close();
|
||||
hasChanged = false;
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
ThdlDebug.noteIffyCode();
|
||||
JOptionPane.showMessageDialog(Jskad.this,
|
||||
"Cannot save to that file.",
|
||||
"Save As Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
return null;
|
||||
} catch (BadLocationException ble) {
|
||||
ble.printStackTrace();
|
||||
|
@ -792,6 +791,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
}
|
||||
|
||||
File fileChosen = fileChooser.getSelectedFile();
|
||||
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||
fileChosen.getParentFile().getAbsolutePath());
|
||||
String fileName = fileChosen.getAbsolutePath();
|
||||
int i = fileName.lastIndexOf('.');
|
||||
|
||||
|
|
Loading…
Reference in a new issue