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.
|
# system-specific.
|
||||||
thdl.user.options.directory =
|
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
|
# 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
|
# this to true if you can get away with it and want your THDL tools to load
|
||||||
# faster.
|
# faster.
|
||||||
|
|
|
@ -147,7 +147,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
if (parentObject instanceof JFrame || parentObject instanceof JInternalFrame) {
|
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();
|
rtfFilter = new RTFFilter();
|
||||||
txtFilter = new TXTFilter();
|
txtFilter = new TXTFilter();
|
||||||
fileChooser.addChoosableFileFilter(rtfFilter);
|
fileChooser.addChoosableFileFilter(rtfFilter);
|
||||||
|
@ -617,89 +621,81 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFile() {
|
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);
|
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) {
|
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File fileChosen = fileChooser.getSelectedFile();
|
final File fileChosen = fileChooser.getSelectedFile();
|
||||||
final String f_name = fileChosen.getAbsolutePath();
|
final String f_name = fileChosen.getAbsolutePath();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JFrame parentFrame = (JFrame)parentObject;
|
if (dp.getDocument().getLength()>0 && parentObject instanceof JFrame) {
|
||||||
InputStream in = new FileInputStream(fileChosen);
|
JFrame parentFrame = (JFrame)parentObject;
|
||||||
JFrame newFrame = new JFrame(f_name);
|
InputStream in = new FileInputStream(fileChosen);
|
||||||
Point point = parentFrame.getLocationOnScreen();
|
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||||
newFrame.setSize(x_size, y_size);
|
fileChosen.getParentFile().getAbsolutePath());
|
||||||
newFrame.setLocation(point.x+50, point.y+50);
|
JFrame newFrame = new JFrame(f_name);
|
||||||
Jskad newRTF = new Jskad(newFrame);
|
Point point = parentFrame.getLocationOnScreen();
|
||||||
newFrame.getContentPane().add(newRTF);
|
newFrame.setSize(x_size, y_size);
|
||||||
newRTF.dp.rtfEd.read(in, newRTF.dp.getDocument(), 0);
|
newFrame.setLocation(point.x+50, point.y+50);
|
||||||
newRTF.dp.getDocument().addDocumentListener(newRTF);
|
Jskad newRTF = new Jskad(newFrame);
|
||||||
in.close();
|
newFrame.getContentPane().add(newRTF);
|
||||||
newFrame.setTitle(f_name);
|
newRTF.dp.rtfEd.read(in, newRTF.dp.getDocument(), 0);
|
||||||
newRTF.fileName = new String(f_name);
|
newRTF.dp.getDocument().addDocumentListener(newRTF);
|
||||||
newRTF.hasChanged = false;
|
in.close();
|
||||||
newRTF.dp.getCaret().setDot(0);
|
newFrame.setTitle(f_name);
|
||||||
newFrame.setVisible(true);
|
newRTF.fileName = new String(f_name);
|
||||||
}
|
newRTF.hasChanged = false;
|
||||||
catch (FileNotFoundException fnfe) {
|
newRTF.dp.getCaret().setDot(0);
|
||||||
ThdlDebug.noteIffyCode();
|
newFrame.setVisible(true);
|
||||||
}
|
} else {
|
||||||
catch (IOException ioe) {
|
InputStream in = new FileInputStream(fileChosen);
|
||||||
ThdlDebug.noteIffyCode();
|
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||||
}
|
fileChosen.getParentFile().getAbsolutePath());
|
||||||
catch (BadLocationException ble) {
|
dp.newDocument();
|
||||||
ThdlDebug.noteIffyCode();
|
dp.rtfEd.read(in, dp.getDocument(), 0);
|
||||||
}
|
in.close();
|
||||||
}
|
dp.getCaret().setDot(0);
|
||||||
else {
|
dp.getDocument().addDocumentListener(Jskad.this);
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
hasChanged = false;
|
||||||
|
fileName = new String(f_name);
|
||||||
|
|
||||||
if (fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
|
if (parentObject instanceof JFrame) {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
JFrame parentFrame = (JFrame)parentObject;
|
||||||
return;
|
parentFrame.setTitle(fileName);
|
||||||
}
|
}
|
||||||
|
else if (parentObject instanceof JInternalFrame) {
|
||||||
final File fileChosen = fileChooser.getSelectedFile();
|
JInternalFrame parentFrame = (JInternalFrame)parentObject;
|
||||||
final String f_name = fileChosen.getAbsolutePath();
|
parentFrame.setTitle(fileName);
|
||||||
|
}
|
||||||
try {
|
}
|
||||||
InputStream in = new FileInputStream(fileChosen);
|
}
|
||||||
dp.newDocument();
|
catch (FileNotFoundException fnfe) {
|
||||||
dp.rtfEd.read(in, dp.getDocument(), 0);
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
in.close();
|
"No such file exists.",
|
||||||
dp.getCaret().setDot(0);
|
"Open File Error",
|
||||||
dp.getDocument().addDocumentListener(Jskad.this);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
hasChanged = false;
|
}
|
||||||
fileName = new String(f_name);
|
catch (IOException ioe) {
|
||||||
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
if (parentObject instanceof JFrame) {
|
"Error reading file.",
|
||||||
JFrame parentFrame = (JFrame)parentObject;
|
"Open File Error",
|
||||||
parentFrame.setTitle(fileName);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
else if (parentObject instanceof JInternalFrame) {
|
catch (BadLocationException ble) {
|
||||||
JInternalFrame parentFrame = (JInternalFrame)parentObject;
|
ThdlDebug.noteIffyCode();
|
||||||
parentFrame.setTitle(fileName);
|
}
|
||||||
}
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
}
|
|
||||||
catch (FileNotFoundException fnfe) {
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
|
||||||
catch (IOException ioe) {
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
|
||||||
catch (BadLocationException ble) {
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFile() {
|
private void saveFile() {
|
||||||
|
@ -768,8 +764,11 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
out.close();
|
out.close();
|
||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
exception.printStackTrace();
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
ThdlDebug.noteIffyCode();
|
"Cannot save to that file.",
|
||||||
|
"Save As Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (BadLocationException ble) {
|
} catch (BadLocationException ble) {
|
||||||
ble.printStackTrace();
|
ble.printStackTrace();
|
||||||
|
@ -792,6 +791,8 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
File fileChosen = fileChooser.getSelectedFile();
|
File fileChosen = fileChooser.getSelectedFile();
|
||||||
|
ThdlOptions.setUserPreference("thdl.Jskad.working.directory",
|
||||||
|
fileChosen.getParentFile().getAbsolutePath());
|
||||||
String fileName = fileChosen.getAbsolutePath();
|
String fileName = fileChosen.getAbsolutePath();
|
||||||
int i = fileName.lastIndexOf('.');
|
int i = fileName.lastIndexOf('.');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue