This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 56963
Collapse All | Expand All

(-)libsrc/org/netbeans/editor/BaseDocument.java (-38 / +59 lines)
Lines 559-579 Link Here
559
        text = Analyzer.convertLSToLF(text);
559
        text = Analyzer.convertLSToLF(text);
560
560
561
        // Perform the insert
561
        // Perform the insert
562
        boolean notifyMod = false;
562
        boolean notifyMod = notifyModifyCheckStart(offset, "insertString() vetoed"); // NOI18N
563
        
564
        NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get();
565
        if (notifyModifyStatus == null) { // not in atomic lock
566
            notifyModifyStatus = new NotifyModifyStatus (this);
567
            STATUS.set (notifyModifyStatus);
568
            notifyModify(notifyModifyStatus);
569
            notifyMod = true;
570
        }
571
        if (notifyModifyStatus.isModificationVetoed()) {
572
            if (notifyMod) {
573
                STATUS.set (null);
574
            }
575
            throw new BadLocationException("insertString() vetoed.", offset);
576
        }
577
        boolean modFinished = false; // Whether modification succeeded
563
        boolean modFinished = false; // Whether modification succeeded
578
        extWriteLock();
564
        extWriteLock();
579
        try {
565
        try {
Lines 635-644 Link Here
635
            extWriteUnlock();
621
            extWriteUnlock();
636
            // Notify no mod done if notified mod but mod did not succeeded
622
            // Notify no mod done if notified mod but mod did not succeeded
637
            if (notifyMod) {
623
            if (notifyMod) {
638
                STATUS.set (null);
624
                notifyModifyCheckEnd(modFinished);
639
                if (!modFinished) {
640
                    notifyUnmodify(notifyModifyStatus);
641
                }
642
            }
625
            }
643
        }
626
        }
644
    }
627
    }
Lines 646-665 Link Here
646
    /** Removes portion of a document */
629
    /** Removes portion of a document */
647
    public void remove(int offset, int len) throws BadLocationException {
630
    public void remove(int offset, int len) throws BadLocationException {
648
        if (len > 0) {
631
        if (len > 0) {
649
            boolean notifyMod = false;
632
            boolean notifyMod = notifyModifyCheckStart(offset, "remove() vetoed"); // NOI18N
650
            NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get();
651
            if (notifyModifyStatus == null) { // not in atomic lock
652
                notifyModifyStatus = new NotifyModifyStatus (this);
653
                STATUS.set (notifyModifyStatus);
654
                notifyModify(notifyModifyStatus);
655
                notifyMod = true;
656
            }
657
            if (notifyModifyStatus.isModificationVetoed()) {
658
                if (notifyMod) {
659
                    STATUS.set (null);
660
                }
661
                throw new BadLocationException("remove() vetoed.", offset);
662
            }
663
            boolean modFinished = false; // Whether modification succeeded
633
            boolean modFinished = false; // Whether modification succeeded
664
            extWriteLock();
634
            extWriteLock();
665
            try {
635
            try {
Lines 716-730 Link Here
716
                extWriteUnlock();
686
                extWriteUnlock();
717
                // Notify no mod done if notified mod but mod did not succeeded
687
                // Notify no mod done if notified mod but mod did not succeeded
718
                if (notifyMod) {
688
                if (notifyMod) {
719
                    STATUS.set (null);
689
                    notifyModifyCheckEnd(modFinished);
720
                    if (!modFinished) {
721
                        notifyUnmodify(notifyModifyStatus);
722
                    }
723
                }
690
                }
724
            }
691
            }
725
        }
692
        }
726
    }
693
    }
727
694
695
    /**
696
     * Check notify modify status and initialize it if necessary
697
     * before the actual modification is going to be done.
698
     * <br>
699
     * This method is invoked internally by this document implementation
700
     * and from the document event implementation as well during undo/redo.
701
     *
702
     * @param offset &gt;=0 offset at which the modification has been done.
703
     * @param vetoExceptionText text to be used for exception in case
704
     *  the modification has been vetoed.
705
     * @return whether the modification had to be notified or not.
706
     *  In case it had to be notified the {@link #notifyModifyCheckEnd(boolean)}
707
     *  has to be called.
708
     */
709
    boolean notifyModifyCheckStart(int offset, String vetoExceptionText) throws BadLocationException {
710
        NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get();
711
        boolean notifyMod;
712
        if (notifyModifyStatus == null) { // not in atomic lock
713
            notifyModifyStatus = new NotifyModifyStatus (this);
714
            STATUS.set (notifyModifyStatus);
715
            notifyModify(notifyModifyStatus);
716
            notifyMod = true;
717
        } else {
718
            notifyMod = false;
719
        }
720
721
        if (notifyModifyStatus.isModificationVetoed()) {
722
            if (notifyMod) {
723
                STATUS.set (null);
724
            }
725
            throw new BadLocationException(vetoExceptionText, offset);
726
        }
727
        return notifyMod;
728
    }
729
    
730
    /**
731
     * Check notify modify status after the modification has been done.
732
     * <br>
733
     * This method is invoked internally by this document implementation
734
     * and from the document event implementation as well during undo/redo.
735
     * <br>
736
     * It should only be called if the {@link #notifyModifyCheckStart(int, String)}
737
     * has returned <code>true</code>.
738
     *
739
     * @param modFinished whether the actual modification of the document succeeded.
740
     */
741
    void notifyModifyCheckEnd(boolean modFinished) {
742
        NotifyModifyStatus notifyModifyStatus = (NotifyModifyStatus)STATUS.get();
743
        STATUS.set (null);
744
        if (!modFinished) {
745
            notifyUnmodify(notifyModifyStatus);
746
        }
747
    }
748
    
728
    /** This method is called automatically before the document
749
    /** This method is called automatically before the document
729
    * insertion occurs and can be used to revoke the insertion before it occurs
750
    * insertion occurs and can be used to revoke the insertion before it occurs
730
    * by throwing the <tt>BadLocationException</tt>.
751
    * by throwing the <tt>BadLocationException</tt>.
Lines 1245-1251 Link Here
1245
        atomicUnlockImpl(false);
1266
        atomicUnlockImpl(false);
1246
    }
1267
    }
1247
1268
1248
    public final void atomicUnlockImpl(boolean inUndoOrRedo) {
1269
    private final void atomicUnlockImpl(boolean inUndoOrRedo) {
1249
        boolean modsDone = false;
1270
        boolean modsDone = false;
1250
        boolean lastAtomic = false;
1271
        boolean lastAtomic = false;
1251
        synchronized (this) {
1272
        synchronized (this) {
(-)libsrc/org/netbeans/editor/BaseDocumentEvent.java (-1 / +23 lines)
Lines 223-228 Link Here
223
223
224
        inUndo = true;
224
        inUndo = true;
225
225
226
        boolean notifyMod;
227
        try {
228
            notifyMod = doc.notifyModifyCheckStart(0, "undo() vetoed");
229
        } catch (BadLocationException ex) {
230
            throw new CannotUndoException();
231
        }
232
        boolean modFinished = false;
233
226
        // Super of undo()
234
        // Super of undo()
227
        doc.extWriteLock(); // call this extWriteLock() instead of writeLock()
235
        doc.extWriteLock(); // call this extWriteLock() instead of writeLock()
228
        try {
236
        try {
Lines 249-254 Link Here
249
            }
257
            }
250
        } finally {
258
        } finally {
251
            doc.extWriteUnlock(); // call this extWriteUnlock() instead of writeUnlock()
259
            doc.extWriteUnlock(); // call this extWriteUnlock() instead of writeUnlock()
260
            if (notifyMod) {
261
                doc.notifyModifyCheckEnd(modFinished);
262
            }
252
        }
263
        }
253
        // End super of undo()
264
        // End super of undo()
254
265
Lines 260-271 Link Here
260
    }
271
    }
261
272
262
    public void redo() throws CannotRedoException {
273
    public void redo() throws CannotRedoException {
274
        BaseDocument doc = (BaseDocument)getDocument();
275
        boolean notifyMod;
276
        try {
277
            notifyMod = doc.notifyModifyCheckStart(0, "redo() vetoed"); // NOI18N
278
        } catch (BadLocationException ex) {
279
            throw new CannotRedoException();
280
        }
281
263
        inRedo = true;
282
        inRedo = true;
264
        if (previous != null) {
283
        if (previous != null) {
265
            previous.redo();
284
            previous.redo();
266
        }
285
        }
267
286
268
        BaseDocument doc = (BaseDocument)getDocument();
287
        boolean modFinished = false; // Whether modification succeeded
269
288
270
        // Super of redo()
289
        // Super of redo()
271
        doc.extWriteLock(); // call this extWriteLock() instead of writeLock()
290
        doc.extWriteLock(); // call this extWriteLock() instead of writeLock()
Lines 291-296 Link Here
291
            }
310
            }
292
        } finally {
311
        } finally {
293
            doc.extWriteUnlock(); // call this extWriteUnlock() instead of writeUnlock()
312
            doc.extWriteUnlock(); // call this extWriteUnlock() instead of writeUnlock()
313
            if (notifyMod) {
314
                doc.notifyModifyCheckEnd(modFinished);
315
            }
294
        }
316
        }
295
        // End super of redo()
317
        // End super of redo()
296
318

Return to bug 56963