diff --git a/editor.lib/src/org/netbeans/editor/BaseDocument.java b/editor.lib/src/org/netbeans/editor/BaseDocument.java --- a/editor.lib/src/org/netbeans/editor/BaseDocument.java +++ b/editor.lib/src/org/netbeans/editor/BaseDocument.java @@ -139,6 +139,9 @@ /** This document's version. It's accessed by DocumentUtilities.getDocumentVersion(). */ private static final String VERSION_PROP = "version"; //NOI18N + /** Timestamp when this document was last modified. It's accessed by DocumentUtilities.getDocumentVersion(). */ + private static final String LAST_MODIFICATION_TIMESTAMP_PROP = "last-modification-timestamp"; //NOI18N + /** Line separator property for reading files in */ public static final String READ_LINE_SEPARATOR_PROP = DefaultEditorKit.EndOfLineStringProperty; @@ -2128,6 +2131,7 @@ /* package */ void incrementDocVersion() { ((AtomicLong) getProperty(VERSION_PROP)).incrementAndGet(); + ((AtomicLong) getProperty(LAST_MODIFICATION_TIMESTAMP_PROP)).set(System.currentTimeMillis()); } /** Compound edit that write-locks the document for the whole processing diff --git a/editor.util/apichanges.xml b/editor.util/apichanges.xml --- a/editor.util/apichanges.xml +++ b/editor.util/apichanges.xml @@ -104,6 +104,20 @@ + + Added DocumentUtilities.getDocumentTimestamp(Document) + + + + + +

+ Adding DocumentUtilities.getDocumentTimestamp(Document) to provide access + to documents' timestamp property. +

+
+
+ Added DocumentUtilities.getDocumentVersion(Document) diff --git a/editor.util/manifest.mf b/editor.util/manifest.mf --- a/editor.util/manifest.mf +++ b/editor.util/manifest.mf @@ -2,4 +2,4 @@ OpenIDE-Module: org.netbeans.modules.editor.util/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/lib/editor/util/Bundle.properties AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 1.33 +OpenIDE-Module-Specification-Version: 1.34 diff --git a/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java b/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java --- a/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java +++ b/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java @@ -73,6 +73,7 @@ /** BaseDocument's version. */ private static final String VERSION_PROP = "version"; //NOI18N + private static final String LAST_MODIFICATION_TIMESTAMP_PROP = "last-modification-timestamp"; //NOI18N private static final Object TYPING_MODIFICATION_DOCUMENT_PROPERTY = new Object(); @@ -878,4 +879,23 @@ Object version = doc.getProperty(VERSION_PROP); return version instanceof AtomicLong ? ((AtomicLong) version).get() : 0; } + + /** + * Attempts to get the timestamp of a Document. Netbeans editor + * documents are versioned and timestamped whenever they are modified. + * This method can be used to read the timestamp of the most recent modification. + * The timestamp is a number of milliseconds returned from System.currentTimeMillis() + * at the document modification. + * + * @param doc The document to get the timestamp for. + * + * @return The document's timestamp or 0 if the document does not + * support timestamps (ie. is not a netbeans editor document). + * + * @since 1.34 + */ + public static long getDocumentTimestamp(Document doc) { + Object version = doc.getProperty(LAST_MODIFICATION_TIMESTAMP_PROP); + return version instanceof AtomicLong ? ((AtomicLong) version).get() : 0; + } }