comparison dwt/custom/DefaultContent.d @ 212:ab60f3309436

reverted the char[] to String and use the an alias.
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:12:38 +0200
parents a5afe31f5cdd
children fd9c62a2998e
comparison
equal deleted inserted replaced
211:ff59aeb96cac 212:ab60f3309436
27 import dwt.dwthelper.utils; 27 import dwt.dwthelper.utils;
28 28
29 alias tango.text.Text.Text!(char) StringBuffer; 29 alias tango.text.Text.Text!(char) StringBuffer;
30 30
31 class DefaultContent : StyledTextContent { 31 class DefaultContent : StyledTextContent {
32 private final static char[] LineDelimiter = tango.io.FileConst.FileConst.NewlineString; 32 private final static String LineDelimiter = tango.io.FileConst.FileConst.NewlineString;
33 33
34 StyledTextListener[] textListeners; // stores text listeners for event sending 34 StyledTextListener[] textListeners; // stores text listeners for event sending
35 char[] textStore; // stores the actual text 35 String textStore; // stores the actual text
36 int gapStart = -1; // the character position start of the gap 36 int gapStart = -1; // the character position start of the gap
37 int gapEnd = -1; // the character position after the end of the gap 37 int gapEnd = -1; // the character position after the end of the gap
38 int gapLine = -1; // the line on which the gap exists, the gap will always be associated with one line 38 int gapLine = -1; // the line on which the gap exists, the gap will always be associated with one line
39 int highWatermark = 300; 39 int highWatermark = 300;
40 int lowWatermark = 50; 40 int lowWatermark = 50;
185 * @param start start offset of text to replace 185 * @param start start offset of text to replace
186 * @param replaceLength start offset of text to replace 186 * @param replaceLength start offset of text to replace
187 * @param newText start offset of text to replace 187 * @param newText start offset of text to replace
188 * @return a bool specifying whether or not the replace operation is valid 188 * @return a bool specifying whether or not the replace operation is valid
189 */ 189 */
190 protected bool isValidReplace(int start, int replaceLength, char[] newText){ 190 protected bool isValidReplace(int start, int replaceLength, String newText){
191 if (replaceLength is 0) { 191 if (replaceLength is 0) {
192 // inserting text, see if the \r\n line delimiter is being split 192 // inserting text, see if the \r\n line delimiter is being split
193 if (start is 0) return true; 193 if (start is 0) return true;
194 if (start is getCharCount()) return true; 194 if (start is getCharCount()) return true;
195 char before = getTextRange(start - 1, 1)[0]; 195 char before = getTextRange(start - 1, 1)[0];
270 * <p> 270 * <p>
271 * 271 *
272 * @param position the position at which to insert the text 272 * @param position the position at which to insert the text
273 * @param text the text to insert 273 * @param text the text to insert
274 */ 274 */
275 void insert(int position, char[] text) { 275 void insert(int position, String text) {
276 if (text.length is 0) return; 276 if (text.length is 0) return;
277 277
278 int startLine = getLineAtOffset(position); 278 int startLine = getLineAtOffset(position);
279 int change = text.length; 279 int change = text.length;
280 bool endInsert = position is getCharCount(); 280 bool endInsert = position is getCharCount();
452 * <p> 452 * <p>
453 * 453 *
454 * @param text the text to lineate 454 * @param text the text to lineate
455 * @return number of lines in the text 455 * @return number of lines in the text
456 */ 456 */
457 int lineCount(char[] text){ 457 int lineCount(String text){
458 int lineCount_ = 0; 458 int lineCount_ = 0;
459 int length = text.length; 459 int length = text.length;
460 for (int i = 0; i < length; i++) { 460 for (int i = 0; i < length; i++) {
461 char ch = text[i]; 461 char ch = text[i];
462 if (ch is DWT.CR) { 462 if (ch is DWT.CR) {
485 * @return the logical line text (i.e., without the gap) 485 * @return the logical line text (i.e., without the gap)
486 * @exception IllegalArgumentException <ul> 486 * @exception IllegalArgumentException <ul>
487 * <li>ERROR_INVALID_ARGUMENT when index is out of range</li> 487 * <li>ERROR_INVALID_ARGUMENT when index is out of range</li>
488 * </ul> 488 * </ul>
489 */ 489 */
490 public char[] getLine(int index) { 490 public String getLine(int index) {
491 if ((index >= lineCount_) || (index < 0)) error(DWT.ERROR_INVALID_ARGUMENT); 491 if ((index >= lineCount_) || (index < 0)) error(DWT.ERROR_INVALID_ARGUMENT);
492 int start = lines[index][0]; 492 int start = lines[index][0];
493 int length_ = lines[index][1]; 493 int length_ = lines[index][1];
494 int end = start + length_ - 1; 494 int end = start + length_ - 1;
495 if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { 495 if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
518 * <p> 518 * <p>
519 * 519 *
520 * @return the platform line delimiter as specified in the line.separator 520 * @return the platform line delimiter as specified in the line.separator
521 * system property. 521 * system property.
522 */ 522 */
523 public char[] getLineDelimiter() { 523 public String getLineDelimiter() {
524 return LineDelimiter; 524 return LineDelimiter;
525 } 525 }
526 /** 526 /**
527 * Returns the line at the given index with delimiters. 527 * Returns the line at the given index with delimiters.
528 * <p> 528 * <p>
529 * @param index the index of the line to return 529 * @param index the index of the line to return
530 * @return the logical line text (i.e., without the gap) with delimiters 530 * @return the logical line text (i.e., without the gap) with delimiters
531 */ 531 */
532 char[] getFullLine(int index) { 532 String getFullLine(int index) {
533 int start = lines[index][0]; 533 int start = lines[index][0];
534 int length_ = lines[index][1]; 534 int length_ = lines[index][1];
535 int end = start + length_ - 1; 535 int end = start + length_ - 1;
536 if (!gapExists() || (end < gapStart) || (start >= gapEnd)) { 536 if (!gapExists() || (end < gapStart) || (start >= gapEnd)) {
537 // line is before or after the gap 537 // line is before or after the gap
550 * <p> 550 * <p>
551 * 551 *
552 * @param index the line index 552 * @param index the line index
553 * @return the physical line 553 * @return the physical line
554 */ 554 */
555 char[] getPhysicalLine(int index) { 555 String getPhysicalLine(int index) {
556 int start = lines[index][0]; 556 int start = lines[index][0];
557 int length_ = lines[index][1]; 557 int length_ = lines[index][1];
558 return getPhysicalText(start, length_); 558 return getPhysicalText(start, length_);
559 } 559 }
560 /** 560 /**
698 * 698 *
699 * @param start the physical start offset of the text to return 699 * @param start the physical start offset of the text to return
700 * @param length the physical length of the text to return 700 * @param length the physical length of the text to return
701 * @return the text 701 * @return the text
702 */ 702 */
703 char[] getPhysicalText(int start, int length_) { 703 String getPhysicalText(int start, int length_) {
704 return textStore[ start .. start + length_ ].dup; 704 return textStore[ start .. start + length_ ].dup;
705 } 705 }
706 /** 706 /**
707 * Returns a string representing the logical content of 707 * Returns a string representing the logical content of
708 * the text store (i.e., gap stripped out). 708 * the text store (i.e., gap stripped out).
710 * 710 *
711 * @param start the logical start offset of the text to return 711 * @param start the logical start offset of the text to return
712 * @param length the logical length of the text to return 712 * @param length the logical length of the text to return
713 * @return the text 713 * @return the text
714 */ 714 */
715 public char[] getTextRange(int start, int length_) { 715 public String getTextRange(int start, int length_) {
716 if (textStore is null) 716 if (textStore is null)
717 return ""; 717 return "";
718 if (length_ is 0) 718 if (length_ is 0)
719 return ""; 719 return "";
720 int end= start + length_; 720 int end= start + length_;
773 * line delimiter being split or partially deleted. Splitting a line 773 * line delimiter being split or partially deleted. Splitting a line
774 * delimiter by inserting text between the CR and LF characters of the 774 * delimiter by inserting text between the CR and LF characters of the
775 * \r\n delimiter or deleting part of this line delimiter is not supported</li> 775 * \r\n delimiter or deleting part of this line delimiter is not supported</li>
776 * </ul> 776 * </ul>
777 */ 777 */
778 public void replaceTextRange(int start, int replaceLength, char[] newText){ 778 public void replaceTextRange(int start, int replaceLength, String newText){
779 // check for invalid replace operations 779 // check for invalid replace operations
780 if (!isValidReplace(start, replaceLength, newText)) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 780 if (!isValidReplace(start, replaceLength, newText)) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
781 781
782 // inform listeners 782 // inform listeners
783 StyledTextEvent event = new StyledTextEvent(this); 783 StyledTextEvent event = new StyledTextEvent(this);
812 * about where the next change will occur. 812 * about where the next change will occur.
813 * <p> 813 * <p>
814 * 814 *
815 * @param text the text 815 * @param text the text
816 */ 816 */
817 public void setText (char[] text){ 817 public void setText (String text){
818 textStore = text.dup; 818 textStore = text.dup;
819 gapStart = -1; 819 gapStart = -1;
820 gapEnd = -1; 820 gapEnd = -1;
821 expandExp = 1; 821 expandExp = 1;
822 indexLines(); 822 indexLines();
837 837
838 int startLine = getLineAtOffset(position); 838 int startLine = getLineAtOffset(position);
839 int startLineOffset = getOffsetAtLine(startLine); 839 int startLineOffset = getOffsetAtLine(startLine);
840 int endLine = getLineAtOffset(position + length_); 840 int endLine = getLineAtOffset(position + length_);
841 841
842 char[] endText = ""; 842 String endText = "";
843 bool splittingDelimiter = false; 843 bool splittingDelimiter = false;
844 if (position + length_ < getCharCount()) { 844 if (position + length_ < getCharCount()) {
845 endText = getTextRange(position + length_ - 1, 2); 845 endText = getTextRange(position + length_ - 1, 2);
846 if ((endText[0] is DWT.CR) && (endText[1] is DWT.LF)) { 846 if ((endText[0] is DWT.CR) && (endText[1] is DWT.LF)) {
847 splittingDelimiter = true; 847 splittingDelimiter = true;