1 21 22 package org.armedbear.j; 23 24 public final class CheckinBuffer extends Buffer implements Constants 25 { 26 private final int vcType; 27 private final boolean editOnly; 28 29 private int commentIndex = -1; 30 31 public CheckinBuffer(Buffer parentBuffer, int vcType) 32 { 33 this(parentBuffer, vcType, false); 34 } 35 36 public CheckinBuffer(Buffer parentBuffer, int vcType, boolean editOnly) 37 { 38 super(); 39 this.parentBuffer = parentBuffer; 40 this.vcType = vcType; 41 this.editOnly = editOnly; 42 initializeUndo(); 43 type = TYPE_NORMAL; 44 isUntitled = true; 45 mode = CheckinMode.getMode(); 46 try { 47 lockWrite(); 48 } 49 catch (InterruptedException e) { 50 Log.debug(e); 51 return; 52 } 53 try { 54 appendLine(""); 55 renumber(); 56 } 57 finally { 58 unlockWrite(); 59 } 60 setLoaded(true); 61 setInitialized(true); 62 } 63 64 public final File getCurrentDirectory() 65 { 66 if (parentBuffer != null) 67 return parentBuffer.getCurrentDirectory(); 68 return Directories.getUserHomeDirectory(); 69 } 70 71 public final int getVCType() 72 { 73 return vcType; 74 } 75 76 public final boolean isEditOnly() 77 { 78 return editOnly; 79 } 80 81 public String getFileNameForDisplay() 82 { 83 return title != null ? title : ""; 84 } 85 86 public static void previousComment() 87 { 88 final Editor editor = Editor.currentEditor(); 89 final Buffer buffer = editor.getBuffer(); 90 if (buffer instanceof CheckinBuffer) 91 ((CheckinBuffer)buffer).retrieveComment(editor, -1); 92 } 93 94 public static void nextComment() 95 { 96 final Editor editor = Editor.currentEditor(); 97 final Buffer buffer = editor.getBuffer(); 98 if (buffer instanceof CheckinBuffer) 99 ((CheckinBuffer)buffer).retrieveComment(editor, +1); 100 } 101 102 private void retrieveComment(Editor editor, int arg) 103 { 104 final CommentRing commentRing = CommentRing.getInstance(); 105 if (commentIndex < 0) 106 commentIndex = commentRing.size(); 107 int index = commentIndex + arg; 108 if (index > commentRing.size()-1) { 109 index = 0; 111 } else if (index < 0) { 112 index = commentRing.size()-1; 114 } 115 final String comment = commentRing.get(index); 116 if (comment == null) { 117 return; 119 } 120 commentIndex = index; 121 switch (vcType) { 122 case VC_CVS: 123 CVS.replaceComment(editor, comment); 124 break; 125 case VC_P4: 126 P4.replaceComment(editor, comment); 127 break; 128 default: 129 Debug.bug(); 130 break; 131 } 132 } 133 134 public static void finish() 135 { 136 final Editor editor = Editor.currentEditor(); 137 final Buffer buffer = editor.getBuffer(); 138 if (buffer instanceof CheckinBuffer) { 139 CheckinBuffer cb = (CheckinBuffer) buffer; 140 switch (cb.getVCType()) { 141 case VC_CVS: 142 CommentRing.getInstance().appendNew(CVS.extractComment(cb)); 143 CVS.finish(editor, cb); 144 break; 145 case VC_P4: 146 CommentRing.getInstance().appendNew(P4.extractComment(cb)); 147 P4.finish(editor, cb); 148 break; 149 default: 150 break; 151 } 152 } 153 } 154 155 public Expansion getExpansion(Position dot) 156 { 157 Expansion e = 158 new Expansion(dot, Editor.getModeList().getMode(PLAIN_TEXT_MODE)); 159 if (parentBuffer != null && e.getPrefix() != null) { 160 for (BufferIterator it = new BufferIterator(); it.hasNext();) { 162 Buffer b = it.nextBuffer(); 163 if (b instanceof DiffOutputBuffer) { 164 if (((DiffOutputBuffer)b).getParentBuffer() == parentBuffer) { 165 Expansion d = 167 new Expansion(b, e.getPrefix(), e.getCurrent()); 168 e.appendCandidates(d.getCandidates()); 169 break; } 171 } 172 } 173 Expansion p = 175 new Expansion(parentBuffer, e.getPrefix(), e.getCurrent()); 176 e.appendCandidates(p.getCandidates()); 177 } 178 return e; 179 } 180 } 181 | Popular Tags |