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,10 +621,13 @@ 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));
|
||||
|
||||
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
||||
|
@ -632,8 +639,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
final String f_name = fileChosen.getAbsolutePath();
|
||||
|
||||
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);
|
||||
|
@ -648,30 +658,10 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
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));
|
||||
|
||||
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 {
|
||||
} 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();
|
||||
|
@ -689,16 +679,22 @@ public class Jskad extends JPanel implements DocumentListener {
|
|||
parentFrame.setTitle(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException fnfe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
JOptionPane.showMessageDialog(Jskad.this,
|
||||
"No such file exists.",
|
||||
"Open File Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
JOptionPane.showMessageDialog(Jskad.this,
|
||||
"Error reading file.",
|
||||
"Open File Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (BadLocationException ble) {
|
||||
ThdlDebug.noteIffyCode();
|
||||
}
|
||||
}
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
|
||||
|
@ -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