Lines 556-563
Link Here
|
556 |
public void run() { |
556 |
public void run() { |
557 |
try { |
557 |
try { |
558 |
doc.removeDocumentListener(getListener()); |
558 |
doc.removeDocumentListener(getListener()); |
|
|
559 |
doc.putProperty ("beforeModificationListener", null); // NOI18N |
559 |
doc.remove(0, doc.getLength()); // remove all text |
560 |
doc.remove(0, doc.getLength()); // remove all text |
560 |
doc.addDocumentListener(getListener()); |
561 |
doc.addDocumentListener(getListener()); |
|
|
562 |
doc.putProperty ("beforeModificationListener", getListener ()); // NOI18N |
561 |
} catch(BadLocationException ble) { |
563 |
} catch(BadLocationException ble) { |
562 |
ErrorManager.getDefault().notify( |
564 |
ErrorManager.getDefault().notify( |
563 |
ErrorManager.INFORMATIONAL, ble); |
565 |
ErrorManager.INFORMATIONAL, ble); |
Lines 704-715
Link Here
|
704 |
} |
706 |
} |
705 |
|
707 |
|
706 |
final StyledDocument myDoc = getDocument(); |
708 |
final StyledDocument myDoc = getDocument(); |
707 |
final IOException[] holder = new IOException[1]; |
|
|
708 |
|
709 |
|
709 |
// save the document as a reader |
710 |
// save the document as a reader |
710 |
myDoc.render(new Runnable() { |
711 |
class SaveAsReader implements Runnable { |
|
|
712 |
private boolean doMarkAsUnmodified; |
713 |
private IOException ex; |
714 |
|
711 |
public void run() { |
715 |
public void run() { |
712 |
try { |
716 |
try { |
713 |
OutputStream os = null; |
717 |
OutputStream os = null; |
714 |
|
718 |
|
715 |
// write the document |
719 |
// write the document |
Lines 725-731
Link Here
|
725 |
// remember time of last save |
729 |
// remember time of last save |
726 |
lastSaveTime = System.currentTimeMillis(); |
730 |
lastSaveTime = System.currentTimeMillis(); |
727 |
|
731 |
|
728 |
notifyUnmodified (); |
732 |
doMarkAsUnmodified = true; |
729 |
|
733 |
|
730 |
} catch (BadLocationException ex) { |
734 |
} catch (BadLocationException ex) { |
731 |
ErrorManager.getDefault().notify(ex); |
735 |
ErrorManager.getDefault().notify(ex); |
Lines 744-757
Link Here
|
744 |
// update cached info about lines |
748 |
// update cached info about lines |
745 |
updateLineSet (true); |
749 |
updateLineSet (true); |
746 |
updateTitles (); |
750 |
updateTitles (); |
747 |
} catch (IOException e) { |
751 |
} catch (IOException e) { |
748 |
holder[0] = e; |
752 |
this.ex = e; |
749 |
} |
753 |
} |
750 |
} |
754 |
} |
751 |
}); |
755 |
|
752 |
|
756 |
public void after () throws IOException { |
753 |
// refire the exception |
757 |
if (doMarkAsUnmodified) { |
754 |
if (holder[0] != null) throw holder[0]; |
758 |
notifyUnmodified (); |
|
|
759 |
} |
760 |
|
761 |
if (ex != null) { |
762 |
throw ex; |
763 |
} |
764 |
} |
765 |
} |
766 |
|
767 |
SaveAsReader saveAsReader = new SaveAsReader (); |
768 |
myDoc.render (saveAsReader); |
769 |
saveAsReader.after (); |
755 |
} |
770 |
} |
756 |
|
771 |
|
757 |
/** |
772 |
/** |
Lines 1323-1337
Link Here
|
1323 |
} |
1338 |
} |
1324 |
|
1339 |
|
1325 |
/** Conditionally calls notifyModified |
1340 |
/** Conditionally calls notifyModified |
|
|
1341 |
* @return true if the modification was allowed, false if it should be prohibited |
1326 |
*/ |
1342 |
*/ |
1327 |
private final void callNotifyModified () { |
1343 |
private final boolean callNotifyModified () { |
1328 |
if (!alreadyModified) { |
1344 |
if (!alreadyModified) { |
1329 |
alreadyModified = true; |
1345 |
alreadyModified = true; |
1330 |
if (!notifyModified ()) { |
1346 |
if (!notifyModified ()) { |
1331 |
revertUpcomingUndo (); |
1347 |
revertUpcomingUndo (); |
1332 |
alreadyModified = false; |
1348 |
alreadyModified = false; |
|
|
1349 |
return false; |
1333 |
} |
1350 |
} |
1334 |
} |
1351 |
} |
|
|
1352 |
return true; |
1335 |
} |
1353 |
} |
1336 |
|
1354 |
|
1337 |
/** Called when the document is being modified. |
1355 |
/** Called when the document is being modified. |
Lines 1425-1430
Link Here
|
1425 |
} |
1443 |
} |
1426 |
UndoRedo ur = getUndoRedo(); |
1444 |
UndoRedo ur = getUndoRedo(); |
1427 |
sd.removeDocumentListener(getListener()); |
1445 |
sd.removeDocumentListener(getListener()); |
|
|
1446 |
sd.putProperty ("beforeModificationListener", null); // NOI18N |
1428 |
try { |
1447 |
try { |
1429 |
if(ur.canUndo()) { |
1448 |
if(ur.canUndo()) { |
1430 |
Toolkit.getDefaultToolkit().beep(); |
1449 |
Toolkit.getDefaultToolkit().beep(); |
Lines 1435-1440
Link Here
|
1435 |
ErrorManager.INFORMATIONAL, cne); |
1454 |
ErrorManager.INFORMATIONAL, cne); |
1436 |
} finally { |
1455 |
} finally { |
1437 |
sd.addDocumentListener(getListener()); |
1456 |
sd.addDocumentListener(getListener()); |
|
|
1457 |
sd.putProperty ("beforeModificationListener", getListener ()); // NOI18N |
1438 |
} |
1458 |
} |
1439 |
} |
1459 |
} |
1440 |
}; |
1460 |
}; |
Lines 1494-1531
Link Here
|
1494 |
} |
1514 |
} |
1495 |
|
1515 |
|
1496 |
|
1516 |
|
1497 |
// other public methods ................................................................ |
|
|
1498 |
|
1499 |
|
1500 |
/* JST: Commented out |
1501 |
* Set actions for toolbar. |
1502 |
* @param actions list of actions |
1503 |
* |
1504 |
public void setActions (SystemAction[] actions) { |
1505 |
this.actions = actions; |
1506 |
} |
1507 |
|
1508 |
/** Utility method which enables or disables listening to modifications |
1509 |
* on asociated document. |
1510 |
* <P> |
1511 |
* Could be useful if we have to modify document, but do not want the |
1512 |
* Save and Save All actions to be enabled/disabled automatically. |
1513 |
* Initially modifications are listened to. |
1514 |
* @param listenToModifs whether to listen to modifications |
1515 |
* |
1516 |
public void setModificationListening (final boolean listenToModifs) { |
1517 |
if (this.listenToModifs == listenToModifs) return; |
1518 |
this.listenToModifs = listenToModifs; |
1519 |
if (doc == null) return; |
1520 |
if (listenToModifs) |
1521 |
doc.addi(getModifL()); |
1522 |
else |
1523 |
doc.removeDocumentListener(getModifL()); |
1524 |
} |
1525 |
*/ |
1526 |
|
1527 |
|
1528 |
|
1529 |
/** Loads the document for this object. |
1517 |
/** Loads the document for this object. |
1530 |
* @param kit kit to use |
1518 |
* @param kit kit to use |
1531 |
* @param d original document to load data into |
1519 |
* @param d original document to load data into |
Lines 1617-1622
Link Here
|
1617 |
if (doc != null) { |
1605 |
if (doc != null) { |
1618 |
doc.removeUndoableEditListener (getUndoRedo ()); |
1606 |
doc.removeUndoableEditListener (getUndoRedo ()); |
1619 |
doc.removeDocumentListener(getListener()); |
1607 |
doc.removeDocumentListener(getListener()); |
|
|
1608 |
doc.putProperty ("beforeModificationListener", null); |
1620 |
} |
1609 |
} |
1621 |
|
1610 |
|
1622 |
if (positionManager != null) { |
1611 |
if (positionManager != null) { |
Lines 1949-1957
Link Here
|
1949 |
* document, environment and also temporarilly on undoredo. |
1938 |
* document, environment and also temporarilly on undoredo. |
1950 |
*/ |
1939 |
*/ |
1951 |
private final class Listener extends Object |
1940 |
private final class Listener extends Object |
1952 |
implements ChangeListener, DocumentListener, PropertyChangeListener, Runnable { |
1941 |
implements ChangeListener, DocumentListener, PropertyChangeListener, |
|
|
1942 |
Runnable, java.beans.VetoableChangeListener { |
1953 |
|
1943 |
|
1954 |
Listener() {} |
1944 |
Listener() {} |
1955 |
|
1945 |
|
1956 |
/** Stores exception from loadDocument, can be set in run method */ |
1946 |
/** Stores exception from loadDocument, can be set in run method */ |
1957 |
private IOException loadExc; |
1947 |
private IOException loadExc; |
Lines 1993-1998
Link Here
|
1993 |
//modified(); (bugfix #1492) |
1983 |
//modified(); (bugfix #1492) |
1994 |
} |
1984 |
} |
1995 |
|
1985 |
|
|
|
1986 |
public void vetoableChange (PropertyChangeEvent evt) throws java.beans.PropertyVetoException { |
1987 |
if ("modified".equals (evt.getPropertyName ())) { // NOI18N |
1988 |
if (Boolean.TRUE.equals (evt.getNewValue ())) { |
1989 |
if (!callNotifyModified ()) { |
1990 |
throw new java.beans.PropertyVetoException ("Not allowed", evt); // NOI18N |
1991 |
} |
1992 |
} else { |
1993 |
notifyUnmodified (); |
1994 |
} |
1995 |
} |
1996 |
} |
1997 |
|
1996 |
/** Gives notification that there was an insert into the document. |
1998 |
/** Gives notification that there was an insert into the document. |
1997 |
* @param ev event describing the action |
1999 |
* @param ev event describing the action |
1998 |
*/ |
2000 |
*/ |
Lines 2054-2059
Link Here
|
2054 |
* which can prevent dedloks that sometimes occured during file reload. |
2056 |
* which can prevent dedloks that sometimes occured during file reload. |
2055 |
*/ |
2057 |
*/ |
2056 |
doc.removeDocumentListener(getListener()); |
2058 |
doc.removeDocumentListener(getListener()); |
|
|
2059 |
doc.putProperty ("beforeModificationListener", null); // NOI18N |
2057 |
try { |
2060 |
try { |
2058 |
loadExc = null; |
2061 |
loadExc = null; |
2059 |
LOCAL_LOAD_TASK.set(Boolean.TRUE); |
2062 |
LOCAL_LOAD_TASK.set(Boolean.TRUE); |
Lines 2079-2085
Link Here
|
2079 |
|
2082 |
|
2080 |
// Start listening on changes in document |
2083 |
// Start listening on changes in document |
2081 |
doc.addDocumentListener(getListener()); |
2084 |
doc.addDocumentListener(getListener()); |
|
|
2085 |
doc.putProperty ("beforeModificationListener", getListener ()); // NOI18N // NOI18N |
2082 |
} |
2086 |
} |
|
|
2087 |
|
2083 |
// } |
2088 |
// } |
2084 |
} |
2089 |
} |
2085 |
|
2090 |
|
Lines 2286-2292
Link Here
|
2286 |
public void undo() { |
2291 |
public void undo() { |
2287 |
super.undo(); |
2292 |
super.undo(); |
2288 |
|
2293 |
|
2289 |
if (saveTime == lastSaveTime) { |
2294 |
if (saveTime == lastSaveTime && alreadyModified) { |
2290 |
notifyUnmodified(); |
2295 |
notifyUnmodified(); |
2291 |
} |
2296 |
} |
2292 |
} |
2297 |
} |