mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
per document readonly fragment modification exception handler
This commit is contained in:
@@ -93,7 +93,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
doPaste(editor, project, file, fileType, document);
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
|
||||
}
|
||||
finally {
|
||||
document.stopGuardedBlockChecking();
|
||||
|
||||
@@ -399,7 +399,7 @@ public class FindUtil {
|
||||
toPrompt = doReplace(project, editor, model, document, offset, toPrompt);
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
|
||||
}
|
||||
finally {
|
||||
if (!toPrompt) {
|
||||
|
||||
@@ -289,7 +289,7 @@ public class EditorModificationUtil {
|
||||
if (guard != null) {
|
||||
DocumentEvent evt = new MockDocumentEvent(doc, editor.getCaretModel().getOffset());
|
||||
ReadOnlyFragmentModificationException e = new ReadOnlyFragmentModificationException(evt, guard);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
else {
|
||||
final LogicalPosition start = selectionModel.getBlockStart();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.editor.actionSystem;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -63,7 +64,7 @@ public abstract class EditorActionManager {
|
||||
public abstract TypedAction getTypedAction();
|
||||
|
||||
/**
|
||||
* Gets the handler which is invoked on attempt to modify a read-only fragment in the editor.
|
||||
* Gets the default handler which is invoked on attempt to modify a read-only fragment in the editor.
|
||||
*
|
||||
* @return the handler instance.
|
||||
* @see com.intellij.openapi.editor.Document#createGuardedBlock(int, int)
|
||||
@@ -78,5 +79,24 @@ public abstract class EditorActionManager {
|
||||
* @see com.intellij.openapi.editor.Document#createGuardedBlock(int, int)
|
||||
*/
|
||||
public abstract ReadonlyFragmentModificationHandler setReadonlyFragmentModificationHandler(@NotNull ReadonlyFragmentModificationHandler handler);
|
||||
|
||||
/**
|
||||
* Gets the handler which is invoked on attempt to modify a read-only fragment for the document.
|
||||
*
|
||||
* @param document target document
|
||||
* @return the handler instance.
|
||||
* @see com.intellij.openapi.editor.Document#createGuardedBlock(int, int)
|
||||
*/
|
||||
public abstract ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler(@NotNull Document document);
|
||||
|
||||
/**
|
||||
* Sets the handler which is invoked on attempt to modify a read-only fragment for the document.
|
||||
*
|
||||
* @param document target document
|
||||
* @param handler new handler
|
||||
* @see com.intellij.openapi.editor.Document#createGuardedBlock(int, int)
|
||||
*/
|
||||
public abstract void setReadonlyFragmentModificationHandler(@NotNull Document document, ReadonlyFragmentModificationHandler handler);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -34,24 +34,24 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler {
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
|
||||
public void run() {
|
||||
final Document doc = editor.getDocument();
|
||||
final SelectionModel selectionModel = editor.getSelectionModel();
|
||||
if (selectionModel.hasBlockSelection()) {
|
||||
RangeMarker guard = selectionModel.getBlockSelectionGuard();
|
||||
if (guard != null) {
|
||||
DocumentEvent evt = new MockDocumentEvent(editor.getDocument(), editor.getCaretModel().getOffset());
|
||||
ReadOnlyFragmentModificationException e = new ReadOnlyFragmentModificationException(evt, guard);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Document doc = editor.getDocument();
|
||||
doc.startGuardedBlockChecking();
|
||||
try {
|
||||
executeWriteAction(editor, dataContext);
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
finally {
|
||||
doc.stopGuardedBlockChecking();
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TypedAction {
|
||||
EditorModificationUtil.typeInStringAtCaretHonorBlockSelection(editor, str, true);
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
finally {
|
||||
doc.stopGuardedBlockChecking();
|
||||
@@ -109,7 +109,7 @@ public class TypedAction {
|
||||
getHandler().execute(editor, charTyped, dataContext);
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
finally {
|
||||
doc.stopGuardedBlockChecking();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class TabAction extends EditorAction {
|
||||
}
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
finally {
|
||||
doc.stopGuardedBlockChecking();
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actionSystem.ReadonlyFragmentModificationHandler;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.editor.ex.*;
|
||||
@@ -36,6 +37,7 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
private final List<DocumentListener> myDocumentListeners = new ArrayList<DocumentListener>();
|
||||
private final WeakHashMap<RangeMarkerEx,String> myRangeMarkers = new WeakHashMap<RangeMarkerEx, String>();
|
||||
private final List<RangeMarker> myGuardedBlocks = new ArrayList<RangeMarker>();
|
||||
private ReadonlyFragmentModificationHandler myReadonlyFragmentModificationHandler;
|
||||
|
||||
private final LineSet myLineSet = new LineSet();
|
||||
private final CharArray myText = new CharArray(0) {
|
||||
@@ -185,6 +187,14 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx {
|
||||
}
|
||||
}
|
||||
|
||||
public ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler() {
|
||||
return myReadonlyFragmentModificationHandler;
|
||||
}
|
||||
|
||||
public void setReadonlyFragmentModificationHandler(final ReadonlyFragmentModificationHandler readonlyFragmentModificationHandler) {
|
||||
myReadonlyFragmentModificationHandler = readonlyFragmentModificationHandler;
|
||||
}
|
||||
|
||||
public boolean isWritable() {
|
||||
return !myIsReadOnly;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.intellij.openapi.editor.impl;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.editor.EditorBundle;
|
||||
import com.intellij.openapi.editor.ReadOnlyFragmentModificationException;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.actionSystem.*;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.injected.editor.DocumentWindow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EditorActionManagerImpl extends EditorActionManager {
|
||||
@@ -34,6 +36,22 @@ public class EditorActionManagerImpl extends EditorActionManager {
|
||||
return myReadonlyFragmentsHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadonlyFragmentModificationHandler getReadonlyFragmentModificationHandler(@NotNull final Document document) {
|
||||
final Document doc = document instanceof DocumentWindow ? ((DocumentWindow)document).getDelegate() : document;
|
||||
final ReadonlyFragmentModificationHandler docHandler =
|
||||
doc instanceof DocumentImpl ? ((DocumentImpl)doc).getReadonlyFragmentModificationHandler() : null;
|
||||
return docHandler == null ? myReadonlyFragmentsHandler : docHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadonlyFragmentModificationHandler(@NotNull final Document document, final ReadonlyFragmentModificationHandler handler) {
|
||||
final Document doc = document instanceof DocumentWindow ? ((DocumentWindow)document).getDelegate() : document;
|
||||
if (doc instanceof DocumentImpl) {
|
||||
((DocumentImpl)document).setReadonlyFragmentModificationHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
public ReadonlyFragmentModificationHandler setReadonlyFragmentModificationHandler(@NotNull ReadonlyFragmentModificationHandler handler) {
|
||||
ReadonlyFragmentModificationHandler oldHandler = myReadonlyFragmentsHandler;
|
||||
myReadonlyFragmentsHandler = handler;
|
||||
|
||||
@@ -4022,7 +4022,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
doc.deleteString(myDraggedRange.getStartOffset(), myDraggedRange.getEndOffset());
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(doc).handle(e);
|
||||
}
|
||||
finally {
|
||||
doc.stopGuardedBlockChecking();
|
||||
|
||||
Reference in New Issue
Block a user