resync from TJIDE
[nikiroo-utils.git] / src / jexer / teditor / Document.java
index 2abfef6635f3c1877fc733ee36ea8c67d01160b6..e94950371af02507ad1abaad4f305983e8260274 100644 (file)
@@ -89,7 +89,8 @@ public class Document {
     public Document(final String str, final CellAttributes defaultColor) {
         this.defaultColor = defaultColor;
 
-        // TODO: set different colors based on file extension
+        // Set colors to resemble the Borland IDE colors, but for Java
+        // language keywords.
         highlighter.setJavaColors();
 
         String [] rawLines = str.split("\n");
@@ -120,6 +121,13 @@ public class Document {
         return dirty;
     }
 
+    /**
+     * Unset the dirty flag.
+     */
+    public void setNotDirty() {
+        dirty = false;
+    }
+
     /**
      * Save contents to file.
      *
@@ -362,7 +370,7 @@ public class Document {
         // If at the beginning of a word already, push past it.
         if ((getChar() != -1)
             && (getRawLine().length() > 0)
-            && !Character.isSpace((char) getChar())
+            && !Character.isWhitespace((char) getChar())
         ) {
             left();
         }
@@ -370,7 +378,7 @@ public class Document {
         // int line = lineNumber;
         while ((getChar() == -1)
             || (getRawLine().length() == 0)
-            || Character.isSpace((char) getChar())
+            || Character.isWhitespace((char) getChar())
         ) {
             if (left() == false) {
                 return;
@@ -380,12 +388,12 @@ public class Document {
 
         assert (getChar() != -1);
 
-        if (!Character.isSpace((char) getChar())
+        if (!Character.isWhitespace((char) getChar())
             && (getRawLine().length() > 0)
         ) {
             // Advance until at the beginning of the document or a whitespace
             // is encountered.
-            while (!Character.isSpace((char) getChar())) {
+            while (!Character.isWhitespace((char) getChar())) {
                 int line = lineNumber;
                 if (left() == false) {
                     // End of document, bail out.
@@ -418,7 +426,7 @@ public class Document {
             }
             if (lineNumber != line) {
                 // We wrapped a line.  Here that counts as whitespace.
-                if (!Character.isSpace((char) getChar())) {
+                if (!Character.isWhitespace((char) getChar())) {
                     // We found a character immediately after the line.
                     // Done!
                     return;
@@ -429,12 +437,12 @@ public class Document {
         }
         assert (getChar() != -1);
 
-        if (!Character.isSpace((char) getChar())
+        if (!Character.isWhitespace((char) getChar())
             && (getRawLine().length() > 0)
         ) {
             // Advance until at the end of the document or a whitespace is
             // encountered.
-            while (!Character.isSpace((char) getChar())) {
+            while (!Character.isWhitespace((char) getChar())) {
                 line = lineNumber;
                 if (right() == false) {
                     // End of document, bail out.
@@ -442,7 +450,7 @@ public class Document {
                 }
                 if (lineNumber != line) {
                     // We wrapped a line.  Here that counts as whitespace.
-                    if (!Character.isSpace((char) getChar())
+                    if (!Character.isWhitespace((char) getChar())
                         && (getRawLine().length() > 0)
                     ) {
                         // We found a character immediately after the line.
@@ -462,7 +470,7 @@ public class Document {
             }
             if (lineNumber != line) {
                 // We wrapped a line.  Here that counts as whitespace.
-                if (!Character.isSpace((char) getChar())) {
+                if (!Character.isWhitespace((char) getChar())) {
                     // We found a character immediately after the line.
                     // Done!
                     return;
@@ -473,10 +481,10 @@ public class Document {
         }
         assert (getChar() != -1);
 
-        if (Character.isSpace((char) getChar())) {
+        if (Character.isWhitespace((char) getChar())) {
             // Advance until at the end of the document or a non-whitespace
             // is encountered.
-            while (Character.isSpace((char) getChar())) {
+            while (Character.isWhitespace((char) getChar())) {
                 if (right() == false) {
                     // End of document, bail out.
                     return;
@@ -637,4 +645,18 @@ public class Document {
         return lines.get(lineNumber).getDisplayLength();
     }
 
+    /**
+     * Get the entire contents of the document as one string.
+     *
+     * @return the document contents
+     */
+    public String getText() {
+        StringBuilder sb = new StringBuilder();
+        for (Line line: getLines()) {
+            sb.append(line.getRawString());
+            sb.append("\n");
+        }
+        return sb.toString();
+    }
+
 }