Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions mae/brow/Fide.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Fide extends JPanel implements mae.util.Editor {
String TAB; //replaces TAB key
File file, prevF;
int prevS, prevE;
long lastModified;
JMenu recent, trans;
JFrame frm;
final JTextArea src = new JTextArea();
Expand All @@ -56,7 +57,7 @@ public class Fide extends JPanel implements mae.util.Editor {
final Ear ear = new Ear();
String filter;
//final Map filters = new HashMap();

public final static int
GAP = Scaler.scaledInt(4), //used in BorderLayout
MAX_ITEMS = 15, //items in recent 10->15 V1.65
Expand Down Expand Up @@ -107,7 +108,8 @@ public class Fide extends JPanel implements mae.util.Editor {
add(msg, "South");

frm = new JFrame("Fide");
frm.addWindowListener(ear);
frm.addWindowListener(ear);
frm.addWindowFocusListener(ear);
frm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frm.setJMenuBar(setupMenus());
frm.setContentPane(this);
Expand Down Expand Up @@ -205,6 +207,7 @@ void setSource(String t, File f) {
prevF = file;
text = t;
file = f;
if( f != null )lastModified = f.lastModified();
prevS = src.getSelectionStart();
prevE = src.getSelectionEnd();
String s = (f == null)? "[new file]" : f.getName();
Expand All @@ -231,7 +234,7 @@ void setSource(String t, File f) {
}
void confirmedSave() {
String s = src.getText();
if (text == null || s.equals(text)) return;
if (text == null || s.equals(text)) return;
String title = "Text is modified";
String msg = "Do you want to save";
if (file != null) msg += "\n"+file;
Expand All @@ -250,6 +253,28 @@ void confirmedSave() {
else if (reply != but[1]) //cancel
throw new RuntimeException("action cancelled");
}
void modifiedAnother(){
if(file.lastModified() == lastModified) return;
lastModified = file.lastModified();
String title,msg;
if(file.exists()){
title = "Reload";
msg = file+"\n\nText is modified by another program\nDo you want to reload?";
}else{
title = "Keep";
msg = file+"\n\nThe file doesn't exsist anymore\nDo you want to keep it in editor?";
}
int typ = JOptionPane.QUESTION_MESSAGE;
int opt = JOptionPane.YES_NO_OPTION;
String[] but = {"Yes", "No"};
JOptionPane pane = new JOptionPane(msg, typ, opt, null, but);
JDialog dialog = pane.createDialog(this,title);
dialog.setVisible(true);
dialog.dispose();
Object reply = pane.getValue();
if (reply == but[0]) open(file);
else if(reply == but[1] && !file.exists()) openPrev();
}
public void save() {
String s = src.getText();
if (text == null || s.equals(text)) return;
Expand Down Expand Up @@ -467,6 +492,9 @@ public void windowClosing(WindowEvent e) {
setMessage(x);
}
}
public void windowGainedFocus(WindowEvent e){
modifiedAnother(); //modified by another program
}
}
///==============================================================
JMenu newMenu(String s, char c) {
Expand Down