Changeset 89


Ignore:
Timestamp:
10/10/02 18:43:48 (20 years ago)
Author:
piso
Message:

playback(): added write locking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/Macro.java

    r2 r89  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: Macro.java,v 1.1.1.1 2002-09-24 16:07:43 piso Exp $
     5 * $Id: Macro.java,v 1.2 2002-10-10 18:43:48 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    4545    public synchronized void record(char c)
    4646    {
    47         list.add(new Character(c) );
     47        list.add(new Character(c));
    4848    }
    4949
    5050    public synchronized void playback()
    5151    {
    52         Editor editor = Editor.currentEditor();
    53         CompoundEdit compoundEdit = editor.beginCompoundEdit();
    54         final int size = list.size();
    55         for (int i = 0; i < size; i++) {
    56             Object object = list.get(i);
    57             if (object instanceof String)
    58                 editor.executeCommand((String) object);
    59             else if (object instanceof Character)
    60                 editor.insertNormalChar(((Character) object).charValue());
     52        final Editor editor = Editor.currentEditor();
     53        final Buffer buffer = editor.getBuffer();
     54        try {
     55            buffer.lockWrite();
    6156        }
    62         editor.getBuffer().endCompoundEdit(compoundEdit);
     57        catch (InterruptedException e) {
     58            Log.debug(e);
     59            return;
     60        }
     61        try {
     62            CompoundEdit compoundEdit = buffer.beginCompoundEdit();
     63            final int size = list.size();
     64            for (int i = 0; i < size; i++) {
     65                Object object = list.get(i);
     66                if (object instanceof String)
     67                    editor.executeCommand((String)object);
     68                else if (object instanceof Character)
     69                    editor.insertNormalChar(((Character) object).charValue());
     70            }
     71            buffer.endCompoundEdit(compoundEdit);
     72        }
     73        finally {
     74            buffer.unlockWrite();
     75        }
    6376    }
    6477}
Note: See TracChangeset for help on using the changeset viewer.