// Get the state of the recording edits flag
final boolean recordingEdits = CodeGemEditor.this.recordingEditStates;
// The following objects will hold the current editor state
final StateEdit stateEdit = new StateEdit(CodeGemEditor.this, GemCutter.getResourceString("UndoText_CodeChange"));
final PartInput[] oldInputs = codeGem.getInputParts();
// We will disable the recording edits flag while the renaming occurs.
// Once renaming completes, we commit an edit if the renaming is
// not canceled, then reenable the recording edits flag.
// Because the editor has a parseTimer checking code every PARSE_TIMER_PERIOD ms,
// we cannot enable recording edits flag before this time (since an edit state may be
// recorded). Thus we will enable the recording edit states flag only after the next
// possible parseTimer tick, by use of the following timer.
final Timer editEnableTimer = new Timer(PARSE_TIMER_PERIOD + 1,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
CodeGemEditor.this.recordingEditStates = recordingEdits;
}
});
editEnableTimer.setRepeats(false);
// Prepare commit/cancel listener for the symbol renamer
AdvancedCALEditor.SymbolRenamerListener renameListener = new AdvancedCALEditor.SymbolRenamerListener() {
public void renameCanceled(String oldName) {
// Abort the state edit
stateEdit.die();
// Enable recording edits after the next parse tick
editEnableTimer.start();
}
public void renameDone(String oldName, String newName) {
// Post the edit to the edit handler.
stateEdit.end();
if (CodeGemEditor.this.editHandler != null) {
CodeGemEditor.this.editHandler.definitionEdited(CodeGemEditor.this, oldInputs, stateEdit);
}
// Enable recording edits after the next parse tick