mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
merge: fix NPE if UndoManager not found
This commit is contained in:
@@ -200,6 +200,7 @@ public class TextMergeTool implements MergeTool {
|
||||
|
||||
public class MyThreesideViewer extends ThreesideTextDiffViewerEx {
|
||||
@NotNull private final ModifierProvider myModifierProvider;
|
||||
@Nullable private final UndoManager myUndoManager;
|
||||
|
||||
// all changes - both applied and unapplied ones
|
||||
@NotNull private final List<TextMergeChange> myAllMergeChanges = new ArrayList<TextMergeChange>();
|
||||
@@ -217,14 +218,17 @@ public class TextMergeTool implements MergeTool {
|
||||
super(context, request);
|
||||
|
||||
myModifierProvider = new ModifierProvider();
|
||||
myUndoManager = getProject() != null ? UndoManager.getInstance(getProject()) : UndoManager.getGlobalInstance();
|
||||
|
||||
DiffUtil.registerAction(new ApplySelectedChangesAction(Side.LEFT, true), myPanel);
|
||||
DiffUtil.registerAction(new ApplySelectedChangesAction(Side.RIGHT, true), myPanel);
|
||||
DiffUtil.registerAction(new IgnoreSelectedChangesAction(Side.LEFT, true), myPanel);
|
||||
DiffUtil.registerAction(new IgnoreSelectedChangesAction(Side.RIGHT, true), myPanel);
|
||||
|
||||
new UndoRedoAction(true).register();
|
||||
new UndoRedoAction(false).register();
|
||||
if (myUndoManager != null) {
|
||||
new UndoRedoAction(true).register();
|
||||
new UndoRedoAction(false).register();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,10 +337,9 @@ public class TextMergeTool implements MergeTool {
|
||||
@Override
|
||||
public void run() {
|
||||
outputDocument.setText(baseDocument.getCharsSequence());
|
||||
UndoManager undoManager = getProject() != null ? UndoManager.getInstance(getProject()) : UndoManager.getGlobalInstance();
|
||||
if (undoManager != null) {
|
||||
if (myUndoManager != null) {
|
||||
DocumentReference ref = DocumentReferenceManager.getInstance().create(outputDocument);
|
||||
undoManager.nonundoableActionPerformed(ref, false);
|
||||
myUndoManager.nonundoableActionPerformed(ref, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -513,10 +516,10 @@ public class TextMergeTool implements MergeTool {
|
||||
}
|
||||
}
|
||||
|
||||
if (!corruptedStates.isEmpty()) {
|
||||
if (!corruptedStates.isEmpty() && myUndoManager != null) {
|
||||
// document undo is registered inside onDocumentChange, so our undo() will be called after its undo().
|
||||
// thus thus we can avoid checks for isUndoInProgress() (to avoid modification of the same TextMergeChange by this listener)
|
||||
UndoManager.getInstance(getProject()).undoableActionPerformed(new BasicUndoableAction(getEditor(ThreeSide.BASE).getDocument()) {
|
||||
myUndoManager.undoableActionPerformed(new BasicUndoableAction(getEditor(ThreeSide.BASE).getDocument()) {
|
||||
@Override
|
||||
public void undo() throws UnexpectedUndoException {
|
||||
enterBulkChangeUpdateBlock();
|
||||
@@ -701,10 +704,7 @@ public class TextMergeTool implements MergeTool {
|
||||
}
|
||||
|
||||
private void registerUndoRedo(final boolean undo) {
|
||||
Project project = getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
if (myUndoManager == null) return;
|
||||
|
||||
List<TextMergeChange> affectedChanges = getAffectedChanges();
|
||||
final List<TextMergeChange.State> states = new ArrayList<TextMergeChange.State>(affectedChanges.size());
|
||||
@@ -712,7 +712,7 @@ public class TextMergeTool implements MergeTool {
|
||||
states.add(change.storeState());
|
||||
}
|
||||
|
||||
UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction(myDocument) {
|
||||
myUndoManager.undoableActionPerformed(new BasicUndoableAction(myDocument) {
|
||||
@Override
|
||||
public void undo() throws UnexpectedUndoException {
|
||||
if (undo) restoreStates(states);
|
||||
@@ -1185,22 +1185,20 @@ public class TextMergeTool implements MergeTool {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
UndoManager undoManager = getUndoManager();
|
||||
assert myUndoManager != null;
|
||||
TextEditor textEditor = getTextEditor();
|
||||
|
||||
e.getPresentation().setEnabled(myUndo ? undoManager.isUndoAvailable(textEditor) : undoManager.isRedoAvailable(textEditor));
|
||||
e.getPresentation().setEnabled(myUndo ? myUndoManager.isUndoAvailable(textEditor) : myUndoManager.isRedoAvailable(textEditor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
UndoManager undoManager = getUndoManager();
|
||||
assert myUndoManager != null;
|
||||
TextEditor textEditor = getTextEditor();
|
||||
|
||||
if (myUndo) {
|
||||
undoManager.undo(textEditor);
|
||||
myUndoManager.undo(textEditor);
|
||||
}
|
||||
else {
|
||||
undoManager.redo(textEditor);
|
||||
myUndoManager.redo(textEditor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1209,12 +1207,6 @@ public class TextMergeTool implements MergeTool {
|
||||
EditorEx editor = getEditor(ThreeSide.BASE);
|
||||
return TextEditorProvider.getInstance().getTextEditor(editor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private UndoManager getUndoManager() {
|
||||
Project project = getProject();
|
||||
return project != null ? UndoManager.getInstance(project) : UndoManager.getGlobalInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyDividerPaintable implements DiffDividerDrawUtil.DividerPaintable {
|
||||
|
||||
Reference in New Issue
Block a user