diff --git a/source/com/intellij/codeInsight/generation/AutoIndentLinesHandler.java b/source/com/intellij/codeInsight/generation/AutoIndentLinesHandler.java index 3e08114a771f..90c23e91f2a6 100644 --- a/source/com/intellij/codeInsight/generation/AutoIndentLinesHandler.java +++ b/source/com/intellij/codeInsight/generation/AutoIndentLinesHandler.java @@ -5,6 +5,7 @@ import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.*; import com.intellij.openapi.project.Project; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.util.IncorrectOperationException; @@ -16,8 +17,9 @@ public class AutoIndentLinesHandler implements CodeInsightActionHandler { PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!file.isWritable()){ - (editor.getDocument()).fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } } Document document = editor.getDocument(); diff --git a/source/com/intellij/codeInsight/generation/CommentByBlockCommentHandler.java b/source/com/intellij/codeInsight/generation/CommentByBlockCommentHandler.java index 3514b3c66987..ea3eb165991b 100644 --- a/source/com/intellij/codeInsight/generation/CommentByBlockCommentHandler.java +++ b/source/com/intellij/codeInsight/generation/CommentByBlockCommentHandler.java @@ -8,6 +8,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.CodeStyleSettings; @@ -281,8 +282,9 @@ public class CommentByBlockCommentHandler implements CodeInsightActionHandler, B myDocument = editor.getDocument(); if (!myFile.isWritable()) { - myDocument.fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(getDocument(), project)){ + return; + } } FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.comment.block"); final SelectionModel selectionModel = myEditor.getSelectionModel(); diff --git a/source/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/source/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index 59167b756b41..fcf0c025ed6b 100644 --- a/source/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/source/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -13,6 +13,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; @@ -90,8 +91,9 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler, Li myDocument = myEditor.getDocument(); if (!myFile.isWritable()) { - myDocument.fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(getDocument(), project)){ + return; + } } FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.comment.line"); diff --git a/source/com/intellij/codeInsight/generation/GenerateDelegateHandler.java b/source/com/intellij/codeInsight/generation/GenerateDelegateHandler.java index 5e83afa5d98a..9b222a809c96 100644 --- a/source/com/intellij/codeInsight/generation/GenerateDelegateHandler.java +++ b/source/com/intellij/codeInsight/generation/GenerateDelegateHandler.java @@ -7,6 +7,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.infos.CandidateInfo; @@ -27,8 +28,9 @@ public class GenerateDelegateHandler implements CodeInsightActionHandler { public void invoke(final Project project, final Editor editor, final PsiFile file) { if (!file.isWritable()) { - (editor.getDocument()).fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } } PsiDocumentManager.getInstance(project).commitAllDocuments(); diff --git a/source/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java b/source/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java index 44a75804a93b..6834448ea4dc 100644 --- a/source/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java +++ b/source/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java @@ -8,6 +8,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.project.Project; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; @@ -30,9 +31,10 @@ abstract class GenerateMembersHandlerBase implements CodeInsightActionHandler { public final void invoke(final Project project, final Editor editor, PsiFile file) { Document document = editor.getDocument(); if (!file.isWritable()){ - document.fireReadOnlyModificationAttempt(); - return; - } + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } + } PsiDocumentManager.getInstance(project).commitAllDocuments(); int offset = editor.getCaretModel().getOffset(); diff --git a/source/com/intellij/codeInsight/generation/ImplementMethodsHandler.java b/source/com/intellij/codeInsight/generation/ImplementMethodsHandler.java index 17b8ca2b3f2f..3e14c0975c2d 100644 --- a/source/com/intellij/codeInsight/generation/ImplementMethodsHandler.java +++ b/source/com/intellij/codeInsight/generation/ImplementMethodsHandler.java @@ -3,6 +3,7 @@ package com.intellij.codeInsight.generation; import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; @@ -11,8 +12,9 @@ public class ImplementMethodsHandler implements CodeInsightActionHandler{ public final void invoke(final Project project, final Editor editor, PsiFile file) { Document document = editor.getDocument(); if (!file.isWritable()){ - document.fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){ + return; + } } PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file); if (aClass != null) { diff --git a/source/com/intellij/codeInsight/generation/OverrideMethodsHandler.java b/source/com/intellij/codeInsight/generation/OverrideMethodsHandler.java index 7ada29e1639a..aac81763f146 100644 --- a/source/com/intellij/codeInsight/generation/OverrideMethodsHandler.java +++ b/source/com/intellij/codeInsight/generation/OverrideMethodsHandler.java @@ -4,6 +4,7 @@ import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; @@ -11,8 +12,9 @@ public class OverrideMethodsHandler implements CodeInsightActionHandler{ public final void invoke(final Project project, final Editor editor, PsiFile file) { Document document = editor.getDocument(); if (!file.isWritable()){ - document.fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){ + return; + } } PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file); if (aClass != null) { diff --git a/source/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java b/source/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java index cda623c275f7..beea7cb6202e 100644 --- a/source/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java +++ b/source/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java @@ -11,6 +11,7 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.ScrollType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiExpression; @@ -87,8 +88,9 @@ public class SurroundWithHandler implements CodeInsightActionHandler{ public void invoke(final Project project, final Editor editor, PsiFile file, Object handler){ if (!file.isWritable()){ - (editor.getDocument()).fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } } if (!editor.getSelectionModel().hasSelection()) { diff --git a/source/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java b/source/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java index 97186ebd4a8e..5b5183133cf0 100644 --- a/source/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java +++ b/source/com/intellij/codeInsight/intention/impl/ImplementAbstractMethodHandler.java @@ -18,6 +18,7 @@ import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.ex.MessagesEx; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiSearchHelper; @@ -104,9 +105,10 @@ public class ImplementAbstractMethodHandler { private void implementInClass(final PsiClass psiClass) { if (!psiClass.isValid()) return; if (!psiClass.isWritable()) { - MessagesEx.fileIsReadOnly(myProject, psiClass.getContainingFile().getVirtualFile()).showNow(); - PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()).fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()), myProject)){ + MessagesEx.fileIsReadOnly(myProject, psiClass.getContainingFile().getVirtualFile()).showNow(); + return; + } } CommandProcessor.getInstance().executeCommand(myProject, new Runnable() { diff --git a/source/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/source/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index e279e96053b4..11460dce2812 100644 --- a/source/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/source/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -11,6 +11,7 @@ import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.event.EditorFactoryAdapter; import com.intellij.openapi.editor.event.EditorFactoryEvent; import com.intellij.openapi.editor.event.EditorFactoryListener; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.StdFileTypes; @@ -175,8 +176,9 @@ public class TemplateManagerImpl extends TemplateManager implements ProjectCompo return false; } if (!editor.getDocument().isWritable()) { - editor.getDocument().fireReadOnlyModificationAttempt(); - return false; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), myProject)){ + return false; + } } final int wordStart0 = wordStart; final TemplateImpl template0 = template; diff --git a/source/com/intellij/find/FindUtil.java b/source/com/intellij/find/FindUtil.java index 4485e9753b8e..c8f919b07c12 100644 --- a/source/com/intellij/find/FindUtil.java +++ b/source/com/intellij/find/FindUtil.java @@ -19,6 +19,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; @@ -317,61 +318,62 @@ public class FindUtil { Document document = editor.getDocument(); int caretOffset = offset; - if (document.isWritable()) { - document.startGuardedBlockChecking(); - try { - FindManager findManager = FindManager.getInstance(project); - boolean toPrompt = model.isPromptOnReplace(); - model = (FindModel)model.clone(); - while (offset >= 0 && offset < editor.getDocument().getTextLength()) { - caretOffset = offset; - FindResult result = doSearch(project, editor, offset, !isReplaced, model, toPrompt); - if (result == null) { - break; - } - int startResultOffset = result.getStartOffset(); - model.setFromCursor(true); - if (toPrompt) { - int promptResult = findManager.showPromptDialog(model, "Replace"); - if (promptResult == PromptResult.SKIP) { - offset = model.isForward() ? result.getEndOffset() : startResultOffset; - continue; - } - if (promptResult == PromptResult.CANCEL) { - break; - } - if (promptResult == PromptResult.ALL) { - toPrompt = false; - } - } - - int startOffset = result.getStartOffset(), endOffset = result.getEndOffset(); - String foundString = document.getCharsSequence().subSequence(startOffset, endOffset).toString(); - String toReplace = findManager.getStringToReplace(foundString, model); - if (model.isForward()) { - offset = doReplace(document, model, result, toReplace).getEndOffset(); - } - else { - offset = doReplace(document, model, result, toReplace).getStartOffset(); - } - - //[SCR 7258] - if (!isReplaced) { - editor.getCaretModel().moveToOffset(0); - } - - isReplaced = true; - } - } - catch (ReadOnlyFragmentModificationException e) { - EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e); - } - finally { - document.stopGuardedBlockChecking(); + if (!document.isWritable()) { + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(document, project)){ + return false; } } - else { - editor.getDocument().fireReadOnlyModificationAttempt(); + + document.startGuardedBlockChecking(); + try { + FindManager findManager = FindManager.getInstance(project); + boolean toPrompt = model.isPromptOnReplace(); + model = (FindModel)model.clone(); + while (offset >= 0 && offset < editor.getDocument().getTextLength()) { + caretOffset = offset; + FindResult result = doSearch(project, editor, offset, !isReplaced, model, toPrompt); + if (result == null) { + break; + } + int startResultOffset = result.getStartOffset(); + model.setFromCursor(true); + if (toPrompt) { + int promptResult = findManager.showPromptDialog(model, "Replace"); + if (promptResult == PromptResult.SKIP) { + offset = model.isForward() ? result.getEndOffset() : startResultOffset; + continue; + } + if (promptResult == PromptResult.CANCEL) { + break; + } + if (promptResult == PromptResult.ALL) { + toPrompt = false; + } + } + + int startOffset = result.getStartOffset(), endOffset = result.getEndOffset(); + String foundString = document.getCharsSequence().subSequence(startOffset, endOffset).toString(); + String toReplace = findManager.getStringToReplace(foundString, model); + if (model.isForward()) { + offset = doReplace(document, model, result, toReplace).getEndOffset(); + } + else { + offset = doReplace(document, model, result, toReplace).getStartOffset(); + } + + //[SCR 7258] + if (!isReplaced) { + editor.getCaretModel().moveToOffset(0); + } + + isReplaced = true; + } + } + catch (ReadOnlyFragmentModificationException e) { + EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e); + } + finally { + document.stopGuardedBlockChecking(); } if (isReplaced) { diff --git a/source/com/intellij/openapi/editor/actions/EmacsStyleIndentAction.java b/source/com/intellij/openapi/editor/actions/EmacsStyleIndentAction.java index a851d4a078dd..56f0061e4c92 100644 --- a/source/com/intellij/openapi/editor/actions/EmacsStyleIndentAction.java +++ b/source/com/intellij/openapi/editor/actions/EmacsStyleIndentAction.java @@ -1,21 +1,20 @@ package com.intellij.openapi.editor.actions; -import com.intellij.aspects.psi.PsiAspectFile; import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.codeInsight.actions.BaseCodeInsightAction; -import com.intellij.codeInsight.generation.AutoIndentLinesHandler; -import com.intellij.openapi.editor.*; -import com.intellij.openapi.project.Project; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaFile; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.ScrollType; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.jsp.JspFile; import com.intellij.psi.xml.XmlFile; import com.intellij.util.IncorrectOperationException; -import com.intellij.ide.util.JavaUtil; public class EmacsStyleIndentAction extends BaseCodeInsightAction{ @@ -40,8 +39,9 @@ public class EmacsStyleIndentAction extends BaseCodeInsightAction{ PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!file.isWritable()){ - (editor.getDocument()).fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } } final Document document = editor.getDocument(); diff --git a/source/com/intellij/openapi/editor/actions/MultiplePasteAction.java b/source/com/intellij/openapi/editor/actions/MultiplePasteAction.java index 4d9b059dd489..92d2c6cf586f 100644 --- a/source/com/intellij/openapi/editor/actions/MultiplePasteAction.java +++ b/source/com/intellij/openapi/editor/actions/MultiplePasteAction.java @@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.ex.DataConstantsEx; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; @@ -59,8 +60,9 @@ public class MultiplePasteAction extends AnAction { if (editor != null) { if (!editor.getDocument().isWritable()) { - editor.getDocument().fireReadOnlyModificationAttempt(); - return; + if (!FileDocumentManager.fileForDocumentCheckedOutSuccessfully(editor.getDocument(), project)){ + return; + } } final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE); diff --git a/source/com/intellij/refactoring/util/RefactoringMessageUtil.java b/source/com/intellij/refactoring/util/RefactoringMessageUtil.java index 3f85f222cf84..ec529c1d7a42 100644 --- a/source/com/intellij/refactoring/util/RefactoringMessageUtil.java +++ b/source/com/intellij/refactoring/util/RefactoringMessageUtil.java @@ -40,7 +40,7 @@ public class RefactoringMessageUtil { return false; } else { - final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWriteable(new VirtualFile[]{vFile}); + final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(new VirtualFile[]{vFile}); if (status.hasReadonlyFiles()) { String message1 = messagePrefix + ".\n Directory " + vFile.getPresentableUrl() + " is read-only."; showErrorMessage("Read-only Directory", message1, null, project); @@ -64,7 +64,7 @@ public class RefactoringMessageUtil { } } } - final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWriteable(readOnlyDirs.toArray(new VirtualFile[readOnlyDirs.size()])); + final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(readOnlyDirs.toArray(new VirtualFile[readOnlyDirs.size()])); failedDirs.addAll(Arrays.asList(status.getReadonlyFiles())); if (failedDirs.size() > 0) { StringBuffer message = new StringBuffer(messagePrefix); @@ -112,7 +112,7 @@ public class RefactoringMessageUtil { return false; } else { - final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWriteable(new VirtualFile[]{vFile}); + final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(new VirtualFile[]{vFile}); if (status.hasReadonlyFiles()) { String message1 = messagePrefix + ".\n File " + vFile.getPresentableUrl() + " is read-only."; showErrorMessage("Read-only File", message1, null, project);