当前位置: 首页>>代码示例>>Java>>正文


Java ReadonlyStatusHandler类代码示例

本文整理汇总了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;
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:18,代码来源:LuaFix.java

示例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());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:Change.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:RollbackLineStatusAction.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CodeInsightUtilBase.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CodeInsightUtilBase.java

示例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));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:WrapWithCustomTemplateAction.java

示例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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:QuickEditHandler.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:ReplaceInProjectManager.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:LivePreviewController.java

示例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();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidDesignerEditorPanel.java

示例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();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:AndroidDesignerEditorPanel.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:StringEditorDialog.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GuiEditor.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:MergeAction.java

示例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();
          }
        }
      });
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:AbstractFileProcessor.java


注:本文中的com.intellij.openapi.vfs.ReadonlyStatusHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。