Ticket #2486: 2486.patch
File 2486.patch, 25.0 KB (added by diana, 15 years ago) |
---|
-
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/links/LinkHolder.java
### Eclipse Workspace Patch 1.0 #P sophie
19 19 public interface LinkHolder { 20 20 21 21 /** 22 * Used only for synchronizing the wanted link property in 23 * currentRuleSync - for the text link holders should depend on the 24 * currently selected interval. 25 * 26 * @return 27 * Different numbers if the wanted rule should be set to null, 28 * a constant otherwise. 29 */ 30 int getSync(); 31 /** 22 32 * Gets the link model of this holder. 23 33 * 24 34 * @return -
modules/org.sophie2.base.model.text/src/test/java/org/sophie2/base/model/text/mvc/SelectionProcessorTest.java
60 60 // Just to be sure that the model is updating right. If this passes 61 61 // and the attributes are not correct, then the processing is surely broken. 62 62 assertEquals(markAndCaretPos, model.getSelectionInfo().getCaret()); 63 assertEquals(markAndCaretPos, model.getSelectionInfo().getMark Index());63 assertEquals(markAndCaretPos, model.getSelectionInfo().getMark()); 64 64 65 65 // No unit except the markAndCaretPos one should have value different from the default, 66 66 // the specified one should have value markAndCaretPos. … … 78 78 markAndCaretPos = markAndCaretPos - (getTextLength() / 4) + insertText.getEnd(); 79 79 // Again, to be sure the model is updated. 80 80 assertEquals(markAndCaretPos, model.getSelectionInfo().getCaret()); 81 assertEquals(markAndCaretPos, model.getSelectionInfo().getMark Index());81 assertEquals(markAndCaretPos, model.getSelectionInfo().getMark()); 82 82 83 83 processedText = model.getProcessedText(); 84 84 for (int i = 0; i < processedText.getEnd(); ++i) { … … 107 107 //in another interval different from the current selection interval -- diana 108 108 caretPos = change.updateIndex(caretPos, modelText);//(caretPos + markPos) / 2 + insertText.getEnd(); 109 109 110 assertEquals(markPos, model.getSelectionInfo().getMark Index());110 assertEquals(markPos, model.getSelectionInfo().getMark()); 111 111 assertEquals(caretPos, model.getSelectionInfo().getCaret()); 112 112 113 113 processedText = model.getProcessedText(); … … 160 160 161 161 // All the possible caret-mark positions.. :D 162 162 for (int caret = 0; caret < modelText.getEnd(); ++caret) { 163 model.setSelectionInfo(caret, model.getSelectionInfo().getMark Index());163 model.setSelectionInfo(caret, model.getSelectionInfo().getMark()); 164 164 for (int mark = 0; mark < modelText.getEnd(); ++mark) { 165 165 model.setSelectionInfo(model.getSelectionInfo().getCaret(), mark); 166 166 ImmText processedText = model.getProcessedText(); -
modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/BaseTextModel.java
220 220 CaretOptions caretOpts; 221 221 SelectionInfo caretInfo = getSelectionInfo(); 222 222 223 if (caretInfo.getCaret() != -1 && caretInfo.getMark Index() != -1) {223 if (caretInfo.getCaret() != -1 && caretInfo.getMark() != -1) { 224 224 ImmTextInterval interval = 225 new ImmTextInterval(caretInfo.getCaret(), caretInfo.getMark Index());225 new ImmTextInterval(caretInfo.getCaret(), caretInfo.getMark()); 226 226 227 227 selectionOpts = new SelectionOptions( 228 228 CommonAttr.BACKGROUND_COLOR, selectionColor, interval); … … 257 257 258 258 ImmText rawText = getRawText(); 259 259 int caretIndex = info.getCaret() == - 1 ? 0 : info.getCaret(); 260 int markIndex = info.getMark Index() == - 1 ? 0 : info.getMarkIndex();260 int markIndex = info.getMark() == - 1 ? 0 : info.getMark(); 261 261 ImmTextInterval selectionInterval = new ImmTextInterval(caretIndex, 262 262 markIndex); 263 263 ImmTextInterval damagedInterval = change.getSourceDamage(rawText); … … 266 266 selectionInterval.compareTo(damagedInterval) == 0) { 267 267 int newCaretIndex = Math.max( 268 268 change.updateIndex(info.getCaret(), rawText), 269 change.updateIndex(info.getMark Index(), rawText));269 change.updateIndex(info.getMark(), rawText)); 270 270 caretInfo().set(new SelectionInfo(newCaretIndex, newCaretIndex)); 271 271 } else { 272 272 caretInfo().set(new SelectionInfo( 273 273 change.updateIndex(info.getCaret(), rawText), 274 change.updateIndex(info.getMark Index(), rawText)));274 change.updateIndex(info.getMark(), rawText))); 275 275 } 276 276 updateSelectionOptions(); 277 277 … … 296 296 if (change instanceof TextReplaceChange) { 297 297 int newCaretIndex = Math.max( 298 298 change.updateIndex(info.getCaret(), rawText), 299 change.updateIndex(info.getMark Index(), rawText));299 change.updateIndex(info.getMark(), rawText)); 300 300 caretInfo().set(new SelectionInfo(newCaretIndex, newCaretIndex)); 301 301 updateSelectionOptions(); 302 302 } … … 318 318 int textEnd = getRawText().getEnd(); 319 319 320 320 if (caretInfo.getCaret() > textEnd) { 321 caretInfo = new SelectionInfo(textEnd, caretInfo.getMark Index());321 caretInfo = new SelectionInfo(textEnd, caretInfo.getMark()); 322 322 } 323 323 324 if (caretInfo.getMark Index() > textEnd) {324 if (caretInfo.getMark() > textEnd) { 325 325 caretInfo = new SelectionInfo(caretInfo.getCaret(), textEnd); 326 326 } 327 327 … … 339 339 public ImmTextInterval getSelectionInterval() { 340 340 SelectionInfo caretInfo = getSelectionInfo(); 341 341 342 Integer mark = caretInfo.getMark Index();342 Integer mark = caretInfo.getMark(); 343 343 Integer caret = caretInfo.getCaret(); 344 344 345 if (mark == null || caret == null) {345 if (mark == - 1 || caret == - 1) { 346 346 return null; 347 347 } 348 348 349 ImmTextInterval interval = null; 350 if (mark > caret) { 351 interval = new ImmTextInterval(caret, mark); 352 } else { 353 interval = new ImmTextInterval(mark, caret); 354 } 355 356 return interval; 349 return new ImmTextInterval(caret, mark); 357 350 } 358 351 359 352 public RwProp<Float> wantedX() { -
modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/SelectionInfo.java
50 50 * @return 51 51 * The mark index. 52 52 */ 53 public int getMark Index() {53 public int getMark() { 54 54 return this.markIndex; 55 55 } 56 56 -
modules/org.sophie2.dev/src/test/java/org/sophie2/dev/author/UndoRedoTextTest.java
188 188 189 189 this.selectedFrameView.textView().get().getTextModel().setSelectionInfo( 190 190 13, this.selectedFrameView.textView().get( 191 ).getTextModel().getSelectionInfo().getMark Index());191 ).getTextModel().getSelectionInfo().getMark()); 192 192 193 193 for (int i = 0; i < 7; ++ i) { 194 194 LogicR3.fire(new EventR3(view, … … 230 230 SelectionInfo selectionInfo = 231 231 this.selectedFrameView.textView().get().getTextModel().getSelectionInfo(); 232 232 int caret = selectionInfo.getCaret(); 233 int mark = selectionInfo.getMark Index();233 int mark = selectionInfo.getMark(); 234 234 TextChange change = new TextReplaceChange(new ImmTextInterval(caret, mark), 235 235 new ImmHotText("" + st2.charAt(i), null)); 236 236 LogicR3.fire(new EventR3(view, -
modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/view/StickySceneView.java
57 57 int end = res.getRawText().getEnd(); 58 58 SelectionInfo caretInfo = res.getSelectionInfo(); 59 59 if (caretInfo.getCaret() == -1) { 60 res.setSelectionInfo(end, caretInfo.getMark Index());60 res.setSelectionInfo(end, caretInfo.getMark()); 61 61 } 62 if (caretInfo.getMark Index() == -1) {62 if (caretInfo.getMark() == -1) { 63 63 res.setSelectionInfo(caretInfo.getCaret(), end); 64 64 } 65 65 } -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/links/TextLinksHaloButton.java
51 51 } 52 52 SelectionInfo caretInfo = flow.getSelectionInfo(); 53 53 return (caretInfo.getCaret() != -1 54 && caretInfo.getCaret() != caretInfo.getMark Index());54 && caretInfo.getCaret() != caretInfo.getMark()); 55 55 } 56 56 57 57 @Override -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextFrameLogic.java
76 76 && pos != text.getEnd()) { 77 77 pos = text.getBegin(); 78 78 } 79 79 80 80 TextUnit hitUnit = text.unitAt(pos); 81 81 82 82 if (hitUnit != null) { 83 83 84 84 String hovered = hitUnit.getStyle().getValue(CommonAttr.LINK_ATTRIBUTE); 85 86 if ( CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(hovered)) {87 return false;85 86 if (! CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(hovered)) { 87 fireLinkTriggeredEvent(pos, event, MouseLinkTriggers.MOUSE_ENTER); 88 88 } 89 89 90 90 for (String linkId : headView.hoveredLinks().get()) { 91 91 if (!hovered.equals(linkId)) { 92 ImmTextInterval linkInterval = 93 TextLinkUtil.getFirstInterval(headView.textFlow().get().getRawText(), linkId); 94 if (linkInterval != null) { 95 fireLinkTriggeredEvent(linkInterval.getBegin(), event, MouseLinkTriggers.MOUSE_LEAVE); 96 } 92 97 93 fireLinkTriggeredEvent(pos, event, MouseLinkTriggers.MOUSE_LEAVE); 94 } else { 95 96 fireLinkTriggeredEvent(pos, event, MouseLinkTriggers.MOUSE_ENTER); 97 } 98 } 98 99 } 99 100 100 101 headView.hoveredLinks().get().clear(); 101 headView.hoveredLinks().add(hovered); 102 if (! CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(hovered)) { 103 headView.hoveredLinks().add(hovered); 104 } 102 105 } else { 103 106 headView.hoveredLinks().get().clear(); 104 107 } … … 198 201 ImmText text = headView.textFlow().get().getRawText(); 199 202 200 203 assert ImmTextUtils.isIndexInText(pos, text) 201 204 || pos == text.getEnd(); 202 205 203 206 TextUnit hitUnit = text.unitAt(pos); 204 207 205 208 if (hitUnit != null) { 206 209 207 210 String hovered = hitUnit.getStyle().getValue(CommonAttr.LINK_ATTRIBUTE); 208 211 209 212 if (!CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(hovered)) { 210 213 211 214 fireLinkTriggeredEvent(pos, event, MouseLinkTriggers.MOUSE_PRESSED); 212 215 headView.pressedLinks().add(hovered); 213 216 } … … 284 287 * Used for skinning. 285 288 */ 286 289 public static final String SET_LINK_ATTACHMENT_MAP = "Set Link Attachment Map"; 287 290 288 291 /** 289 292 * Constant created for visiting link. 290 293 * Constant created to be a parameter of a message of an {@link AutoAction}. … … 308 311 || pos == text.getEnd(): "pos: " + pos + " text: " + text; 309 312 310 313 TextUnit hitUnit = text.unitAt(pos); 311 314 312 315 if (hitUnit == null) { 313 316 SophieLog.info("Action outside the text!"); 314 317 return; 315 318 } 316 319 317 320 String hovered = hitUnit.getStyle().getValue(CommonAttr.LINK_ATTRIBUTE); 318 321 319 322 if (CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(hovered)) { 320 323 SophieLog.debug("Action outside a link!"); 321 324 return; 322 325 } 323 326 324 327 ImmTextInterval interval = TextLinkUtil.getLinkInterval(text, pos); 325 328 326 329 LinkAttachment attachment = linksMap.get(hovered); 327 330 328 331 if (attachment == null) { 329 332 SophieLog.warn("Invalid link ID!"); 330 333 return; 331 334 } 332 333 334 335 336 337 335 338 HotTextResourceH textRes = headView.model().get().getTextModel(); 336 339 ResourceAccess access = textRes.getAccess(); 337 340 -
modules/org.sophie2.extra.comment/src/main/java/org/sophie2/extra/comment/view/CommentTextView.java
172 172 int end = res.getRawText().getEnd(); 173 173 SelectionInfo caretInfo = res.getSelectionInfo(); 174 174 if (caretInfo.getCaret() == -1) { 175 res.setSelectionInfo(end, caretInfo.getMark Index());175 res.setSelectionInfo(end, caretInfo.getMark()); 176 176 } 177 if (caretInfo.getMark Index() == -1) {177 if (caretInfo.getMark() == -1) { 178 178 res.setSelectionInfo(caretInfo.getCaret(), end); 179 179 } 180 180 } -
modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/element/ElementView.java
532 532 public List<LinkTrigger> getTriggers() { 533 533 return getLinkTriggers(); 534 534 } 535 536 public int getSync() { 537 return 0; 538 } 535 539 } 536 540 537 541 /** -
modules/org.sophie2.base.model.text/src/test/java/org/sophie2/base/model/text/TextSelectionTest.java
69 69 TextSelectionTest.this.cPos = 70 70 TextSelectionTest.this.textFlow.getSelectionInfo().getCaret(); 71 71 TextSelectionTest.this.mPos = 72 TextSelectionTest.this.textFlow.getSelectionInfo().getMark Index();72 TextSelectionTest.this.textFlow.getSelectionInfo().getMark(); 73 73 74 74 } 75 75 }); … … 91 91 public void testLeftSelection() { 92 92 fireSelectEvent(Place.LEFT); 93 93 94 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark Index());94 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark()); 95 95 assertEquals(ImmTextUtils.advance(this.text, 96 96 this.textFlow.getSelectionInfo().getCaret(), 0), 97 ImmTextUtils.advance(this.text, this.textFlow.getSelectionInfo().getMark Index(), - 1));97 ImmTextUtils.advance(this.text, this.textFlow.getSelectionInfo().getMark(), - 1)); 98 98 } 99 99 100 100 /** … … 104 104 public void testRightSelection() { 105 105 fireSelectEvent(Place.RIGHT); 106 106 107 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark Index());107 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark()); 108 108 assertSame(ImmTextUtils.advance(this.text, this.cPos, 1), 109 109 this.textFlow.getSelectionInfo()); 110 110 } … … 121 121 wordBreak.getNextBreakPos( 122 122 this.text, this.cPos); 123 123 124 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark Index());124 assertSame(this.mPos, this.textFlow.getSelectionInfo().getMark()); 125 125 assertSame(positionsCaret, 126 126 this.textFlow.getSelectionInfo()); 127 127 } -
modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextModelLogic.java
101 101 return false; 102 102 } 103 103 if (eventID == InputEventR3.MOUSE_DRAGGED) { 104 model.setSelectionInfo(pos, model.getSelectionInfo().getMark Index());104 model.setSelectionInfo(pos, model.getSelectionInfo().getMark()); 105 105 return false; 106 106 } 107 107 if (eventID == InputEventR3.MOUSE_CLICKED) { … … 127 127 } else if (clickCount % 3 == 0) { 128 128 SelectionInfo caretInfo = model.getSelectionInfo(); 129 129 int caret = caretInfo.getCaret(); 130 int mark = caretInfo.getMark Index();130 int mark = caretInfo.getMark(); 131 131 List<Character> breaks = CommonChar.getEffectiveBreaks(CommonChar.PARA_BREAK); 132 132 133 133 int first = ((caret <= mark) ? caret : mark); … … 208 208 int areaIndex = point.getAreaIndex(); 209 209 if (newPos != - 1) { 210 210 setSelection(source, 211 textModel.getSelectionInfo().getMark Index(), newPos, false, areaIndex);211 textModel.getSelectionInfo().getMark(), newPos, false, areaIndex); 212 212 } 213 213 } 214 214 … … 260 260 ImmText txtToReplaceWith = new ImmHotText(inputString, styles); 261 261 SelectionInfo caretInfo = textModel.getSelectionInfo(); 262 262 TextChange change = new TextReplaceChange(new 263 ImmTextInterval(caretInfo.getCaret(), caretInfo.getMark Index()), txtToReplaceWith);263 ImmTextInterval(caretInfo.getCaret(), caretInfo.getMark()), txtToReplaceWith); 264 264 265 265 boolean result = fireChangeText(event, change, false, Place.RIGHT); 266 266 … … 406 406 407 407 SelectionInfo caretInfo = textModel.getSelectionInfo(); 408 408 int caretPos = caretInfo.getCaret(); 409 int markPos = caretInfo.getMark Index();409 int markPos = caretInfo.getMark(); 410 410 411 411 Map<HotAttr<?>, Object> styleValues = new HashMap<HotAttr<?>, Object>(); 412 412 styleValues.put(attr, attrValue); … … 460 460 461 461 SelectionInfo selectionInfo = textModel.getSelectionInfo(); 462 462 int caret = selectionInfo.getCaret(); 463 int mark = selectionInfo.getMark Index();463 int mark = selectionInfo.getMark(); 464 464 465 465 int first = (caret <= mark ? caret : mark); 466 466 int second = (caret > mark ? caret : mark); … … 502 502 SelectionInfo caretInfo = textModel.getSelectionInfo(); 503 503 504 504 ImmTextInterval selection = 505 new ImmTextInterval(caretInfo.getMark Index(), caretInfo.getCaret());505 new ImmTextInterval(caretInfo.getMark(), caretInfo.getCaret()); 506 506 507 507 // Handle attributes that can toggle their value between 2 values. 508 508 // Consider only boolean attributes for now. … … 671 671 protected ImmTextInterval getSelectionEnds(TextModel textModel) { 672 672 SelectionInfo caretInfo = textModel.getSelectionInfo(); 673 673 int caret = caretInfo.getCaret(); 674 int mark = caretInfo.getMark Index();674 int mark = caretInfo.getMark(); 675 675 676 676 if (caret == - 1 || mark == - 1) { 677 677 return null; -
modules/org.sophie2.main.func.links/src/main/java/org/sophie2/main/func/links/LinksHud.java
470 470 471 471 @Override 472 472 protected void setup(Object res) { 473 holder().get(); 473 if (holder().get() != null) { 474 holder().get().getSync(); 475 } 474 476 wantedRule().set(null); 475 477 } 476 478 } -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/links/TextLinkHolder.java
10 10 import org.sophie2.base.model.resources.r4.ResourceRefR4; 11 11 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 12 12 import org.sophie2.base.model.text.elements.CommonAttr; 13 import org.sophie2.base.model.text.model.ImmText; 13 14 import org.sophie2.base.model.text.model.ImmTextInterval; 14 import org.sophie2.base.model.text.model.ImmText;15 15 import org.sophie2.base.model.text.model.TextUnit; 16 16 import org.sophie2.base.model.text.mvc.TextModel; 17 17 import org.sophie2.base.model.text.style.HotStyleDef; 18 18 import org.sophie2.main.app.commons.links.LinkAttachment; 19 19 import org.sophie2.main.app.commons.links.LinkHolder; 20 20 import org.sophie2.main.func.text.view.HeadTextFrameView; 21 import org.sophie2.main.func.text.view.TextLinkUtil;22 21 23 22 /** 24 23 * A {@link LinkHolder} implementation for text link attachments. … … 79 78 String linkId = unitStyle.getValue(CommonAttr.LINK_ATTRIBUTE); 80 79 if (!CommonAttr.LINK_ATTRIBUTE.getDefaultValue().equals(linkId)) { 81 80 82 ImmTextInterval linkInterval =83 TextLinkUtil.getLinkInterval(textModel.getRawText(), selectionInterval.getBegin());84 if (linkInterval.equals(selectionInterval)) {81 // ImmTextInterval linkInterval = 82 // TextLinkUtil.getLinkInterval(textModel.getRawText(), selectionInterval.getBegin()); 83 // if (linkInterval.equals(selectionInterval)) { 85 84 LinkAttachment la = attachmentMap.get(linkId); 86 85 if (la != null) { 87 86 return la; 88 87 } 89 }88 // } 90 89 } 91 90 } 92 91 … … 105 104 // TODO Auto-generated method stub 106 105 return null; 107 106 } 107 108 109 public int getSync() { 110 ImmTextInterval selectedInterval = this.frameView.getHeadView(). 111 textFlow().get().getSelectionInterval(); 112 return selectedInterval.hashCode(); 113 } 108 114 } 115 No newline at end of file -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/utils/TextStyleUtils.java
99 99 TextModel flow = contentView.textFlow().get(); 100 100 SelectionInfo caretInfo = flow.getSelectionInfo(); 101 101 int caretPos = caretInfo.getCaret(); 102 int markPos = caretInfo.getMark Index();102 int markPos = caretInfo.getMark(); 103 103 ImmText text = flow.getRawText(); 104 104 if (caretPos == markPos) { 105 105 HotStyleDef style = HotStyleDef.getEmpty(); -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/HeadSceneTextView.java
48 48 int end = res.getRawText().getEnd(); 49 49 SelectionInfo caretInfo = res.getSelectionInfo(); 50 50 if (caretInfo.getCaret() == -1) { 51 res.setSelectionInfo(end, caretInfo.getMark Index());51 res.setSelectionInfo(end, caretInfo.getMark()); 52 52 } 53 if (caretInfo.getMark Index() == -1) {53 if (caretInfo.getMark() == -1) { 54 54 res.setSelectionInfo(caretInfo.getCaret(), end); 55 55 } 56 56 } -
modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/styling/TextFontHaloMenu.java
42 42 if (contentView != null && contentView.textFlow().get() != null) { 43 43 SelectionInfo caretInfo = contentView.textFlow().get().getSelectionInfo(); 44 44 int caretPos = caretInfo.getCaret(); 45 int markPos = caretInfo.getMark Index();45 int markPos = caretInfo.getMark(); 46 46 47 47 int menuPos = (caretPos - markPos) > 0 ? caretPos : markPos; 48 48