Ticket #2226: 2226.patch

File 2226.patch, 11.4 KB (added by diana, 15 years ago)
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinkColorHud.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    330330                                oldText.removeAttachment(interval).addAttachment(interval, newLink); 
    331331 
    332332                        LogicR3.fire(frameView.textView().get(), null, null, event,  
    333                                         TextView.EventIds.SET_TEXT,     newText, "Change normal link color"); 
     333                                        TextView.EventIds.SET_TEXT,     newText, "Change normal link color", true); 
    334334                } 
    335335        } 
    336336} 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextView.java

     
    249249                /** 
    250250                 * Set the text to the model. 
    251251                 */ 
    252                 @EventParams({ImmHotText.class, String.class}) 
     252                @EventParams({ImmHotText.class, String.class, Boolean.class}) 
    253253                SET_TEXT, 
    254254                 
    255255                /** 
     
    277277                 * Index of the attribute value in the APPLY_STYLE operation. 
    278278                 */ 
    279279                public static final int ATTR_VALUE_PARAM_INDEX = 1; 
     280                /** 
     281                 * Index for the input text of a SET_TEXT operation 
     282                 */ 
     283                public static final int UNDO_SIGNIFICANCE_INDEX = 2; 
    280284        } 
    281285         
    282286        /** 
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextLinksHud.java

     
    238238                                } 
    239239                                 
    240240                                LogicR3.fire(frameView.textView().get(), null, null, event,  
    241                                                 TextView.EventIds.SET_TEXT,     newText, description); 
     241                                                TextView.EventIds.SET_TEXT,     newText, description, true); 
    242242                                 
    243243                                return true; 
    244244                        } 
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/TextFrameLogic.java

     
    277277                                textRes.getText().removeAttachment(interval).addAttachment(interval, newAtt); 
    278278                         
    279279                        LogicR3.fire(headView.textView().get(), null, null, cause,  
    280                                         TextView.EventIds.SET_TEXT,     newText, "Link visited"); 
     280                                        TextView.EventIds.SET_TEXT,     newText, "Link visited", true); 
    281281                } 
    282282        } 
    283283} 
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/view/HotTextLogic.java

     
    5656         * Note that this will be done even if the text view is not editable. 
    5757         */ 
    5858        ON_SET_TEXT { 
    59                  
     59 
    6060                long lastSignificantTime = 0; 
    6161 
    6262                public void defineFilter(EventFilterBuilder filter) { 
     
    7070                        if (bookView == null) { 
    7171                                return false; 
    7272                        } 
    73                          
     73                        Boolean undoSignificance = event.getEventParam(TextView.EventIds.UNDO_SIGNIFICANCE_INDEX, 
     74                                        Boolean.class); 
    7475                        HotTextResourceH model = view.getModel(); 
    7576                        final ImmHotText text = event.getEventParam(TextView.EventIds.TEXT_PARAM_INDEX, 
    7677                                        ImmHotText.class); 
     78                        boolean significant = false; 
     79                        if(undoSignificance) { 
     80                                long currentTime = System.currentTimeMillis(); 
     81                                if (currentTime - this.lastSignificantTime > 500) { 
     82                                        significant = true; 
     83                                } 
     84                                this.lastSignificantTime = currentTime; 
     85                        } else { 
     86                                //TODO: very dirty fix!!!!!! 
     87                                final ImmHotText oldText = model.getText(); 
     88                                new AutoAction("Set old text", true) { 
    7789 
    78                         boolean significant = false; 
    79                         long currentTime = System.currentTimeMillis(); 
    80                         if (currentTime - this.lastSignificantTime > 500) { 
     90                                        @Override 
     91                                        public void performAuto() { 
     92                                                getChanger().setRaw(HotTextResourceR4.KEY_TEXT, oldText); 
     93                                        } 
     94                                }.register(model.getAccess()); 
    8195                                significant = true; 
    8296                        } 
    83                         this.lastSignificantTime = currentTime; 
    84                          
     97                        //                      System.out.println("significant: "+significant); 
    8598                        new AutoAction("Set text", significant) { 
    8699 
    87100                                @Override 
     
    113126 
    114127                        PageWorkArea pageWorkArea = docView.workArea().get(); 
    115128                        String word = event 
    116                                         .getEventParam(QuickSearchPanel.EventIds.WORD_PARAM_ID, String.class); 
     129                        .getEventParam(QuickSearchPanel.EventIds.WORD_PARAM_ID, String.class); 
    117130                        boolean isNext = event.getEventParam(QuickSearchPanel.EventIds.DIRECTION_PARAM_ID, 
    118131                                        Boolean.class); 
    119132                        findText(word, pageWorkArea, isNext); 
     
    218231                        return false; 
    219232                } 
    220233        }, 
    221          
     234 
    222235        /** 
    223236         * Interaction with the keyboard. 
    224237         * Supports the pasting of the copied text. 
     
    235248 
    236249                        ClipboardManager manager = ClipboardManager.get(); 
    237250                        DndTransferable transferable = manager.getContents(); 
    238                                                  
     251 
    239252                        if (transferable != null) {                              
    240253                                boolean handled = pasteText(event, transferable); 
    241254                                return handled; 
    242255                        } 
    243                          
     256 
    244257                        return false; 
    245258                } 
    246259        }, 
    247          
     260 
    248261        /** 
    249262         *      Handles "copy" regarding text.  
    250263         */ 
     
    268281                                        return LogicR3.fire(textView, null, null, event, TextView.EventIds.COPY); 
    269282                                } 
    270283                        } 
    271                          
     284 
    272285                        return false; 
    273286                } 
    274                  
     287 
    275288        }, 
    276          
     289 
    277290        /** 
    278291         * Handles "Cut" regarding text  
    279292         */ 
     
    297310                                        return LogicR3.fire(textView, null, null, event, TextView.EventIds.CUT); 
    298311                                } 
    299312                        } 
    300                          
     313 
    301314                        return false; 
    302315                } 
    303                  
    304                  
     316 
     317 
    305318        }, 
    306          
     319 
    307320        /** 
    308321         * Handles pasting of text. 
    309322         */ 
     
    323336                                LogicR3.fire(textView, null, null, event, TextView.EventIds.PASTE); 
    324337                                return true; 
    325338                        } 
    326                          
     339 
    327340                        return false; 
    328341                } 
    329                  
    330342 
     343 
    331344        }; 
    332          
     345 
    333346        /** 
    334347         * The color used to higlight search results. 
    335348         */ 
     
    347360         *              Whether the event has been handled. 
    348361         */ 
    349362        private static boolean pasteText(EventR3 event, DndTransferable transferable) { 
    350                  
     363 
    351364                ImmHotText textToInsert = getText(transferable); 
    352365                if (textToInsert == null) { 
    353366                        return false; 
    354367                } 
    355                  
     368 
    356369                TextView source = event.getSource(TextView.class); 
    357370                TextViewFlow flow = source.textFlow().get(); 
    358                  
     371 
    359372                if (flow.isEditable()) { 
    360                          
     373 
    361374                        ImmHotText text = flow.getText(); 
    362375 
    363376                        HotInterval interval = getSelectionEnds(flow); 
    364377                        assert interval != null; 
    365378 
    366                         ImmHotText newText = text.replace(interval, textToInsert); 
     379 
     380                        ImmHotText newText = text.replace(interval, ImmHotText.empty()); 
     381                        newText = newText.replace(new HotInterval(interval.getBegin(), 
     382                                        interval.getBegin()), textToInsert); 
    367383                        boolean handled = LogicR3.fire(TextFlowLogic.createSetTextEvent(newText, 
    368                                         "Insert text", event)); 
     384                                        "Insert text", event, false)); 
    369385 
    370386                        if (handled) { 
    371387                                HotPos newPos = newText.advance(interval.getBegin(), textToInsert.getLength()); 
     
    373389                        } 
    374390                        return handled; 
    375391                } 
    376                  
     392 
    377393                return false; 
    378394        } 
    379          
     395 
    380396        /** 
    381397         * Creates an {@link ImmHotText} instance from the contents of the given 
    382398         * transferable if possible. 
     
    388404         */ 
    389405        private static ImmHotText getText(DndTransferable transferable) { 
    390406                assert transferable != null; 
    391                  
     407 
    392408                if (transferable.getDndData(HotTextData.class) != null) {                                                                
    393409                        return transferable.getDndData(HotTextData.class).getContent(); 
    394410                } 
    395                          
     411 
    396412                if (transferable.getDndData(RtfData.class) != null) {                                    
    397413                        RtfTextImportManager rtfManager = new RtfTextImportManager(); 
    398414                        return rtfManager.getResourceData(transferable);                                 
    399415                } 
    400          
     416 
    401417                if (transferable.getDndData(StringData.class) != null) { 
    402418                        String text = transferable.getDndData(StringData.class).getContent(); 
    403419                        return ImmHotText.createPlain(text); 
    404420                } 
    405                  
     421 
    406422                return null; 
    407423        } 
    408424 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextFlowLogic.java

     
    230230                        } 
    231231                         
    232232                        boolean handled = LogicR3.fire( 
    233                                         createSetTextEvent(newText, "Delete characters", event)); 
     233                                        createSetTextEvent(newText, "Delete characters", event, true)); 
    234234                         
    235235                        if (handled) { 
    236236                                setSelection(flow, new HotInterval(interval.getBegin(),  
     
    298298                                        interval.getBegin(),interval.getEnd()); 
    299299                        ClipboardManager.get().setContents(contents, Operation.CUT); 
    300300                                boolean handled = LogicR3.fire( 
    301                                                 createSetTextEvent(newText, "Delete characters", event)); 
     301                                                createSetTextEvent(newText, "Delete characters", event, true)); 
    302302                                if (handled) { 
    303303                                        flow.markPos().set(flow.caretPos().get()); 
    304304                                } 
     
    338338                        text = text.applyStyle(selection, style); 
    339339                         
    340340                        return LogicR3.fire( 
    341                                         createSetTextEvent(text, "Apply style", event)); 
     341                                        createSetTextEvent(text, "Apply style", event, false)); 
    342342                } 
    343343                 
    344344        }, 
     
    382382                        ImmHotText text = flow.getText(); 
    383383                        text = text.applyStyle(selection, style); 
    384384 
    385                         return LogicR3.fire(createSetTextEvent(text, "Apply paragraph style", event)); 
     385                        return LogicR3.fire(createSetTextEvent(text, "Apply paragraph style", event, false)); 
    386386                } 
    387387        }, 
    388388         
     
    456456 
    457457                HotInterval interval = getSelectionEnds(flow); 
    458458                assert interval != null; 
    459  
    460459                ImmHotText newText = immHotText.replace(interval, ImmHotText 
    461460                                .createPlain(text)); 
    462461 
    463462                boolean handled = LogicR3.fire(createSetTextEvent(newText, 
    464                                 "Insert a character", event)); 
     463                                "Insert a character", event, true)); 
    465464 
    466465                if (handled) { 
    467466                        int offset = text.length(); 
     
    485484         *                      Description of the event. 
    486485         * @param cause 
    487486         *                      The cause of the event. 
     487         * @param undoSignificance  
     488         *          If true - the undo considers the fastness of typing  
     489         *          (when undo all the changes applied in some time interval are undo) 
     490         *          If false - the undo considers only the last change. 
    488491         * @return 
    489492         *                      The newly created event. 
    490493         */ 
    491         public static EventR3 createSetTextEvent(ImmHotText text, String description, EventR3 cause) { 
     494        public static EventR3 createSetTextEvent(ImmHotText text, String description, EventR3 cause,  
     495                        boolean undoSignificance) { 
    492496                List<Object> fields = new ArrayList<Object>(cause.getFields()); 
    493497                 
    494498                fields.set(EventR3.ID_INDEX, TextView.EventIds.SET_TEXT); 
     
    496500                 
    497501                addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.TEXT_PARAM_INDEX, text, fields); 
    498502                addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.DESCRIPTION_PARAM_INDEX, description, fields); 
    499  
     503                addEventParam(EventR3.PARAMS_INDEX + TextView.EventIds.UNDO_SIGNIFICANCE_INDEX, undoSignificance, fields); 
     504                 
    500505                return new EventR3(fields); 
    501506        } 
    502507