本文整理汇总了Java中com.intellij.openapi.vfs.ReadonlyStatusHandler类的典型用法代码示例。如果您正苦于以下问题:Java ReadonlyStatusHandler类的具体用法?Java ReadonlyStatusHandler怎么用?Java ReadonlyStatusHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadonlyStatusHandler类属于com.intellij.openapi.vfs包,在下文中一共展示了ReadonlyStatusHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isQuickFixOnReadOnlyFile
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
private static boolean isQuickFixOnReadOnlyFile(PsiElement problemElement) {
final PsiFile containingPsiFile = problemElement.getContainingFile();
if (containingPsiFile == null) {
return false;
}
final VirtualFile virtualFile = containingPsiFile.getVirtualFile();
final Project project = problemElement.getProject();
final ReadonlyStatusHandler handler = ReadonlyStatusHandler.getInstance(project);
final ReadonlyStatusHandler.OperationStatus status;
if (virtualFile != null) {
status = handler.ensureFilesWritable(virtualFile);
return status.hasReadonlyFiles();
}
return false;
}
示例2: modifyDocument
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
/**
* Applies the text from the original marker to the target marker.
* @return the resulting TextRange from the target document, or null if the document if not writable.
*/
@Nullable
private static TextRange modifyDocument(@Nullable Project project, @NotNull RangeMarker original, @NotNull RangeMarker target) {
Document document = target.getDocument();
if (project != null && !ReadonlyStatusHandler.ensureDocumentWritable(project, document)) {
return null;
}
if (DocumentUtil.isEmpty(original)) {
int offset = target.getStartOffset();
document.deleteString(offset, target.getEndOffset());
}
CharSequence text = original.getDocument().getImmutableCharSequence().subSequence(original.getStartOffset(), original.getEndOffset());
int startOffset = target.getStartOffset();
if (DocumentUtil.isEmpty(target)) {
document.insertString(startOffset, text);
} else {
document.replaceString(startOffset, target.getEndOffset(), text);
}
return new TextRange(startOffset, startOffset + text.length());
}
示例3: execute
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
private static void execute(@NotNull final LineStatusTracker tracker, @NotNull final Runnable task) {
CommandProcessor.getInstance().executeCommand(tracker.getProject(), new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
if (!tracker.getDocument().isWritable()) {
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler
.getInstance(tracker.getProject()).ensureFilesWritable(tracker.getVirtualFile());
if (operationStatus.hasReadonlyFiles()) return;
}
task.run();
}
});
}
}, VcsBundle.message("command.name.rollback.change"), null);
}
示例4: prepareFileForWrite
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
@Override
public boolean prepareFileForWrite(@Nullable final PsiFile psiFile) {
if (psiFile == null) return false;
final VirtualFile file = psiFile.getVirtualFile();
final Project project = psiFile.getProject();
if (ReadonlyStatusHandler.ensureFilesWritable(project, file)) {
return true;
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, file), true);
if (editor != null && editor.getComponent().isDisplayable()) {
HintManager.getInstance().showErrorHint(editor, CodeInsightBundle.message("error.hint.file.is.readonly", file.getPresentableUrl()));
}
}
}, project.getDisposed());
return false;
}
示例5: preparePsiElementsForWrite
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
@Override
public boolean preparePsiElementsForWrite(@NotNull Collection<? extends PsiElement> elements) {
if (elements.isEmpty()) return true;
Set<VirtualFile> files = new THashSet<VirtualFile>();
Project project = null;
for (PsiElement element : elements) {
if (element == null) continue;
PsiFile file = element.getContainingFile();
if (file == null || !file.isPhysical()) continue;
project = file.getProject();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) continue;
files.add(virtualFile);
}
if (!files.isEmpty()) {
VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(virtualFiles);
return !status.hasReadonlyFiles();
}
return true;
}
示例6: actionPerformed
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Document document = myEditor.getDocument();
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null) {
ReadonlyStatusHandler.getInstance(myFile.getProject()).ensureFilesWritable(file);
}
String selection = myEditor.getSelectionModel().getSelectedText(true);
if (selection != null) {
selection = selection.trim();
PsiDocumentManager.getInstance(myFile.getProject()).commitAllDocuments();
myTemplate.wrap(selection, new CustomTemplateCallback(myEditor, myFile));
}
}
示例7: commitToOriginal
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
private void commitToOriginal(final DocumentEvent e) {
VirtualFile origVirtualFile = PsiUtilCore.getVirtualFile(myNewFile.getContext());
myCommittingToOriginal = true;
try {
if (origVirtualFile == null || !ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(origVirtualFile).hasReadonlyFiles()) {
PostprocessReformattingAspect.getInstance(myProject).disablePostprocessFormattingInside(new Runnable() {
@Override
public void run() {
if (myAltFullRange != null) {
altCommitToOriginal(e);
return;
}
commitToOriginalInner();
}
});
PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myOrigDocument);
}
}
finally {
myCommittingToOriginal = false;
}
}
示例8: ensureUsagesWritable
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
private boolean ensureUsagesWritable(ReplaceContext replaceContext, Collection<Usage> selectedUsages) {
Set<VirtualFile> readOnlyFiles = null;
for (final Usage usage : selectedUsages) {
final VirtualFile file = ((UsageInFile)usage).getFile();
if (file != null && !file.isWritable()) {
if (readOnlyFiles == null) readOnlyFiles = new HashSet<VirtualFile>();
readOnlyFiles.add(file);
}
}
if (readOnlyFiles != null) {
ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(readOnlyFiles));
}
if (hasReadOnlyUsages(selectedUsages)) {
int result = Messages.showOkCancelDialog(replaceContext.getUsageView().getComponent(),
FindBundle.message("find.replace.occurrences.in.read.only.files.prompt"),
FindBundle.message("find.replace.occurrences.in.read.only.files.title"),
Messages.getWarningIcon());
if (result != Messages.OK) {
return false;
}
}
return true;
}
示例9: performReplaceAll
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
public void performReplaceAll(Editor e) {
if (!ReadonlyStatusHandler.ensureDocumentWritable(e.getProject(), e.getDocument())) return;
if (mySearchResults.getFindModel() != null) {
final FindModel copy = new FindModel();
copy.copyFrom(mySearchResults.getFindModel());
final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
final int offset;
if (!selectionModel.hasSelection() || copy.isGlobal()) {
copy.setGlobal(true);
offset = 0;
} else {
offset = selectionModel.getBlockSelectionStarts()[0];
}
FindUtil.replace(e.getProject(), e, offset, copy, this);
}
}
示例10: executeWithReparse
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
@Override
protected void executeWithReparse(ThrowableRunnable<Exception> operation) {
if (!ReadonlyStatusHandler.ensureFilesWritable(getProject(), myFile)) {
return;
}
try {
myPsiChangeListener.stop();
operation.run();
myPsiChangeListener.start();
reparseFile();
}
catch (Throwable e) {
showError("Execute command", e);
myPsiChangeListener.start();
}
}
示例11: execute
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
@Override
protected void execute(List<EditOperation> operations) {
if (!ReadonlyStatusHandler.ensureFilesWritable(getProject(), myFile)) {
return;
}
try {
myPsiChangeListener.stop();
for (EditOperation operation : operations) {
operation.execute();
}
updateRenderer(true);
}
catch (Throwable e) {
showError("Execute command", e);
}
finally {
myPsiChangeListener.start();
}
}
示例12: saveCreatedProperty
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
public static boolean saveCreatedProperty(final PropertiesFile bundle, final String name, final String value,
final PsiFile formFile) {
final ReadonlyStatusHandler.OperationStatus operationStatus =
ReadonlyStatusHandler.getInstance(bundle.getProject()).ensureFilesWritable(bundle.getVirtualFile());
if (operationStatus.hasReadonlyFiles()) {
return false;
}
CommandProcessor.getInstance().executeCommand(
bundle.getProject(),
new Runnable() {
public void run() {
UndoUtil.markPsiFileForUndo(formFile);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
try {
bundle.addProperty(name, value);
}
catch (IncorrectOperationException e1) {
LOG.error(e1);
}
}
});
}
}, UIDesignerBundle.message("command.create.property"), null);
return true;
}
示例13: ensureEditable
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
public boolean ensureEditable() {
if (isEditable()) {
return true;
}
VirtualFile sourceFileToCheckOut = null;
if (!GuiDesignerConfiguration.getInstance(getProject()).INSTRUMENT_CLASSES) {
final String classToBind = myRootContainer.getClassToBind();
if (classToBind != null && classToBind.length() > 0) {
PsiClass psiClass = FormEditingUtil.findClassToBind(getModule(), classToBind);
if (psiClass != null) {
sourceFileToCheckOut = psiClass.getContainingFile().getVirtualFile();
}
}
}
final ReadonlyStatusHandler.OperationStatus status;
if (sourceFileToCheckOut != null) {
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(myFile, sourceFileToCheckOut);
}
else {
status = ReadonlyStatusHandler.getInstance(getProject()).ensureFilesWritable(myFile);
}
return !status.hasReadonlyFiles();
}
示例14: actionPerformed
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
try {
final VcsContext context = CvsContextWrapper.createCachedInstance(e);
final VirtualFile[] files = context.getSelectedFiles();
if (files.length == 0) return;
final Project project = context.getProject();
final ReadonlyStatusHandler.OperationStatus operationStatus =
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
if (operationStatus.hasReadonlyFiles()) {
return;
}
AbstractVcsHelper.getInstance(project).showMergeDialog(Arrays.asList(files), new CvsMergeProvider());
}
catch (Exception e1) {
LOG.error(e1);
}
}
示例15: handleFiles
import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入依赖的package包/类
private void handleFiles(final List<PsiFile> files) {
final List<VirtualFile> vFiles = new ArrayList<VirtualFile>();
for (PsiFile psiFile : files) {
vFiles.add(psiFile.getVirtualFile());
}
if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtil.toVirtualFileArray(vFiles))
.hasReadonlyFiles()) {
if (!files.isEmpty()) {
final Runnable[] resultRunnable = new Runnable[1];
execute(new Runnable() {
@Override
public void run() {
resultRunnable[0] = prepareFiles(files);
}
}, new Runnable() {
@Override
public void run() {
if (resultRunnable[0] != null) {
resultRunnable[0].run();
}
}
});
}
}
}