From c1d8dc03788713b7b9d3e759ab5493829597f97f Mon Sep 17 00:00:00 2001 From: Martin Jobst Date: Mon, 18 Aug 2025 21:03:09 +0200 Subject: [PATCH] Allow to distinguish between save and revert in editor callback This adds a new method afterRevert in IXtextEditorCallback to allow implementations to distinguish between save and revert. The default implementation delegates to afterSave, in order to preserve compatibility with existing implementations. --- .../xtext/ui/editor/CompoundXtextEditorCallback.java | 11 +++++++++++ .../eclipse/xtext/ui/editor/IXtextEditorCallback.java | 4 ++++ .../src/org/eclipse/xtext/ui/editor/XtextEditor.java | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/CompoundXtextEditorCallback.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/CompoundXtextEditorCallback.java index b81256ac029..8e4301bad34 100644 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/CompoundXtextEditorCallback.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/CompoundXtextEditorCallback.java @@ -66,6 +66,17 @@ public void afterSave(XtextEditor xtextEditor) { } } + @Override + public void afterRevert(XtextEditor xtextEditor) { + for (IXtextEditorCallback xtextEditorCallback : editorCallbacks) { + try { + xtextEditorCallback.afterRevert(xtextEditor); + } catch (Exception e) { + handle(e); + } + } + } + @Override public void beforeDispose(XtextEditor xtextEditor) { for (IXtextEditorCallback xtextEditorCallback : editorCallbacks) { diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/IXtextEditorCallback.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/IXtextEditorCallback.java index babf48c04a3..19e11c1a934 100644 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/IXtextEditorCallback.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/IXtextEditorCallback.java @@ -29,6 +29,10 @@ public interface IXtextEditorCallback { */ void afterSave(XtextEditor editor); + default void afterRevert(XtextEditor editor) { + afterSave(editor); + } + void beforeDispose(XtextEditor editor); boolean onValidateEditorInputState(XtextEditor editor); diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/XtextEditor.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/XtextEditor.java index 87570d4938e..7449e29067a 100755 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/XtextEditor.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/XtextEditor.java @@ -364,7 +364,7 @@ protected void run() throws Exception { @Override public void doRevertToSaved() { super.doRevertToSaved(); - callback.afterSave(this); + callback.afterRevert(this); } /**