mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
requestWriting method
This commit is contained in:
@@ -32,10 +32,8 @@ public class GenerateDelegateHandler implements CodeInsightActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.generation.GenerateDelegateHandler");
|
||||
|
||||
public void invoke(final Project project, final Editor editor, final PsiFile file) {
|
||||
if (!file.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
if (!file.isWritable() && !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
|
||||
+2
-4
@@ -44,10 +44,8 @@ public abstract class GenerateMembersHandlerBase implements CodeInsightActionHan
|
||||
}
|
||||
|
||||
public final void invoke(final Project project, final Editor editor, PsiFile file) {
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
if (!file.isWritable() && !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
|
||||
if (aClass == null || aClass.isInterface()) return; //?
|
||||
|
||||
+3
-5
@@ -100,11 +100,9 @@ public class ImplementAbstractMethodHandler {
|
||||
|
||||
private void implementInClass(final PsiClass psiClass) {
|
||||
if (!psiClass.isValid()) return;
|
||||
if (!psiClass.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()), myProject)){
|
||||
MessagesEx.fileIsReadOnly(myProject, psiClass.getContainingFile().getVirtualFile()).showNow();
|
||||
return;
|
||||
}
|
||||
if (!psiClass.isWritable() && !FileDocumentManager.getInstance().requestWriting(PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()), myProject)) {
|
||||
MessagesEx.fileIsReadOnly(myProject, psiClass.getContainingFile().getVirtualFile()).showNow();
|
||||
return;
|
||||
}
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CodeInsightUtilBase {
|
||||
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file.getVirtualFile()), true);
|
||||
|
||||
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)) {
|
||||
if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (editor != null && editor.getComponent().isDisplayable()) {
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ public abstract class AbstractLayoutCodeProcessor {
|
||||
}
|
||||
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, myProject)) {
|
||||
if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) {
|
||||
Messages.showMessageDialog(myProject, PsiBundle.message("cannot.modify.a.read.only.file", file.getName()),
|
||||
CodeInsightBundle.message("error.dialog.readonly.file.title"),
|
||||
Messages.getErrorIcon()
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
document.fireReadOnlyModificationAttempt();
|
||||
return;
|
||||
}
|
||||
if (!psiFile.isWritable() && !FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)) {
|
||||
if (!psiFile.isWritable() && !FileDocumentManager.getInstance().requestWriting(document, project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -36,10 +36,8 @@ public class EmacsStyleIndentAction extends BaseCodeInsightAction implements Dum
|
||||
public void invoke(final Project project, final Editor editor, final PsiFile file) {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
if (!file.isWritable() && !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Document document = editor.getDocument();
|
||||
|
||||
@@ -68,7 +68,7 @@ public class EndHandler extends EditorActionHandler {
|
||||
caretModel.moveToLogicalPosition(new LogicalPosition(line, col));
|
||||
|
||||
if (caretModel.getLogicalPosition().column != col){
|
||||
if (!document.isWritable() && !FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)) {
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
if (editor.isViewer()) return;
|
||||
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), PlatformDataKeys.PROJECT.getData(dataContext))){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), PlatformDataKeys.PROJECT.getData(dataContext))){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,10 +114,8 @@ public class TypedHandler implements TypedActionHandler {
|
||||
|
||||
if (editor.isViewer()) return;
|
||||
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Editor injectedEditor = injectedEditorIfCharTypedIsSignificant(charTyped, editor, file);
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class AutoIndentLinesHandler implements CodeInsightActionHandler {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class CommentByBlockCommentHandler implements CodeInsightActionHandler {
|
||||
myDocument = editor.getDocument();
|
||||
|
||||
if (!myFile.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(myDocument, project)) {
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler {
|
||||
myEditor = editor;
|
||||
|
||||
if (!myFile.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(myDocument, project)) {
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -4,7 +4,6 @@ import com.intellij.codeInsight.CodeInsightActionHandler;
|
||||
import com.intellij.lang.CodeInsightActions;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageCodeInsightActionHandler;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -13,9 +12,8 @@ import com.intellij.psi.util.PsiUtilBase;
|
||||
|
||||
public class ImplementMethodsHandler implements CodeInsightActionHandler{
|
||||
public final void invoke(final Project project, final Editor editor, PsiFile file) {
|
||||
Document document = editor.getDocument();
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -4,7 +4,6 @@ import com.intellij.codeInsight.CodeInsightActionHandler;
|
||||
import com.intellij.lang.CodeInsightActions;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageCodeInsightActionHandler;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -13,9 +12,8 @@ import com.intellij.psi.util.PsiUtilBase;
|
||||
|
||||
public class OverrideMethodsHandler implements CodeInsightActionHandler{
|
||||
public final void invoke(final Project project, final Editor editor, PsiFile file) {
|
||||
Document document = editor.getDocument();
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ public class SurroundWithHandler implements CodeInsightActionHandler{
|
||||
static void doSurround(final Project project, final Editor editor, final Surrounder surrounder, final PsiElement[] elements) {
|
||||
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
|
||||
if (!file.isWritable()){
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -207,10 +207,8 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo
|
||||
if (!isApplicable(file, caretOffset - template.getKey().length(), template)) {
|
||||
return false;
|
||||
}
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), myProject)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), myProject)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final int wordStart0 = wordStart;
|
||||
final TemplateImpl template0 = template;
|
||||
|
||||
@@ -383,10 +383,8 @@ public class FindUtil {
|
||||
private static boolean replace(Project project, Editor editor, int offset, FindModel model) {
|
||||
Document document = editor.getDocument();
|
||||
|
||||
if (!document.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(document, project)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
document.startGuardedBlockChecking();
|
||||
|
||||
+1
-3
@@ -27,10 +27,8 @@ public abstract class EditorWriteActionHandler extends EditorActionHandler {
|
||||
public final void execute(final Editor editor, final DataContext dataContext) {
|
||||
if (editor.isViewer()) return;
|
||||
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), PlatformDataKeys.PROJECT.getData(dataContext)))
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), PlatformDataKeys.PROJECT.getData(dataContext)))
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
|
||||
public void run() {
|
||||
|
||||
@@ -51,10 +51,8 @@ public class TypedAction {
|
||||
if (editor.isViewer()) return;
|
||||
|
||||
Document doc = editor.getDocument();
|
||||
if (!doc.isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(doc, PlatformDataKeys.PROJECT.getData(dataContext))) {
|
||||
return;
|
||||
}
|
||||
if (!FileDocumentManager.getInstance().requestWriting(doc, PlatformDataKeys.PROJECT.getData(dataContext))) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc.startGuardedBlockChecking();
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.intellij.openapi.fileEditor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -61,17 +60,14 @@ public abstract class FileDocumentManager {
|
||||
@NotNull
|
||||
public abstract String getLineSeparator(@Nullable VirtualFile file, @Nullable Project project);
|
||||
|
||||
public static boolean fileForDocumentCheckedOutSuccessfully(@NotNull Document document, Project project) {
|
||||
if (project != null) {
|
||||
final VirtualFile file = getInstance().getFile(document);
|
||||
if (file != null && file.isValid()) {
|
||||
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file);
|
||||
return !operationStatus.hasReadonlyFiles();
|
||||
}
|
||||
}
|
||||
document.fireReadOnlyModificationAttempt();
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Requests writing access on given document
|
||||
*
|
||||
* @param document document
|
||||
* @param project project
|
||||
* @return true if writing access allowed
|
||||
*/
|
||||
public abstract boolean requestWriting(@NotNull Document document, Project project);
|
||||
|
||||
public abstract void reloadFiles(VirtualFile... files);
|
||||
}
|
||||
|
||||
+1
-3
@@ -72,11 +72,9 @@ public class MultiplePasteAction extends AnAction implements DumbAware {
|
||||
((CopyPasteManagerEx)CopyPasteManager.getInstance()).moveContentTopStackTop(chooser.getAllContents().get(selectedIndex));
|
||||
|
||||
if (editor != null) {
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
|
||||
AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(),
|
||||
|
||||
@@ -3983,10 +3983,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
final Editor editor = getEditor(source);
|
||||
if (action == MOVE && !editor.isViewer()) {
|
||||
if (!editor.getDocument().isWritable()) {
|
||||
if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), editor.getProject())){
|
||||
if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), editor.getProject())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
CommandProcessor.getInstance().executeCommand(((EditorImpl)editor).myProject, new Runnable() {
|
||||
public void run() {
|
||||
|
||||
+16
@@ -300,6 +300,22 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestWriting(@NotNull Document document, Project project) {
|
||||
if (document.isWritable()) {
|
||||
return true;
|
||||
}
|
||||
if (project != null) {
|
||||
final VirtualFile file = getInstance().getFile(document);
|
||||
if (file != null && file.isValid()) {
|
||||
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(file);
|
||||
return !operationStatus.hasReadonlyFiles();
|
||||
}
|
||||
}
|
||||
document.fireReadOnlyModificationAttempt();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reloadFiles(final VirtualFile... files) {
|
||||
for (VirtualFile file : files) {
|
||||
if (file.exists()) {
|
||||
|
||||
+1
-1
@@ -422,7 +422,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
|
||||
documentManager.commitDocument(propertiesFileDocument);
|
||||
|
||||
if (!propertiesFile.isWritable() &&
|
||||
!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(propertiesFileDocument, project)) {
|
||||
!FileDocumentManager.getInstance().requestWriting(document, project)) {
|
||||
uninstallDocumentListeners();
|
||||
try {
|
||||
document.replaceString(0, document.getTextLength(), oldText);
|
||||
|
||||
Reference in New Issue
Block a user