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


Java ReadonlyStatusHandler.ensureDocumentWritable方法代码示例

本文整理汇总了Java中com.intellij.openapi.vfs.ReadonlyStatusHandler.ensureDocumentWritable方法的典型用法代码示例。如果您正苦于以下问题:Java ReadonlyStatusHandler.ensureDocumentWritable方法的具体用法?Java ReadonlyStatusHandler.ensureDocumentWritable怎么用?Java ReadonlyStatusHandler.ensureDocumentWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.vfs.ReadonlyStatusHandler的用法示例。


在下文中一共展示了ReadonlyStatusHandler.ensureDocumentWritable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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(@NotNull Project project, @NotNull RangeMarker original, @NotNull RangeMarker target) {
  Document document = target.getDocument();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) { return null; }
  if (DocumentUtil.isEmpty(original)) {
    int offset = target.getStartOffset();
    document.deleteString(offset, target.getEndOffset());
  }
  String text = DocumentUtil.getText(original);
  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:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:Change.java

示例4: 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() && !selectionModel.hasBlockSelection()) || copy.isGlobal()) {
      copy.setGlobal(true);
      offset = 0;
    } else {
      offset = selectionModel.getBlockSelectionStarts()[0];
    }
    FindUtil.replace(e.getProject(), e, offset, copy, this);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:LivePreviewController.java

示例5: save

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
@Override
public void save() {
    if (context.project == null) {
        Flog.info("Document: %s can not be saved.", document);
        return;
    }
    if (!ReadonlyStatusHandler.ensureDocumentWritable(context.project, document)) {
        Flog.info("Document: %s is not writable, can not save.", document);
        return;
    }
    setReadOnly(false);
    try {
        FileDocumentManager.getInstance().saveDocument(document);
    } catch (Throwable e) {
        Flog.error(e);
    }
}
 
开发者ID:Floobits,项目名称:floobits-intellij,代码行数:18,代码来源:DocImpl.java

示例6: 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(@Nonnull Project project, @Nonnull RangeMarker original, @Nonnull RangeMarker target) {
  Document document = target.getDocument();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) { return null; }
  if (DocumentUtil.isEmpty(original)) {
    int offset = target.getStartOffset();
    document.deleteString(offset, target.getEndOffset());
  }
  String text = DocumentUtil.getText(original);
  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:consulo,项目名称:consulo,代码行数:22,代码来源:Change.java

示例7: performReplace

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
@Nullable
public TextRange performReplace(final FindResult occurrence, final String replacement, final Editor editor) {
  Project project = mySearchResults.getProject();
  if (myReplaceDenied || !ReadonlyStatusHandler.ensureDocumentWritable(project, editor.getDocument())) return null;
  FindModel findModel = mySearchResults.getFindModel();
  TextRange result = FindUtil.doReplace(project,
                                        editor.getDocument(),
                                        findModel,
                                        new FindResultImpl(occurrence.getStartOffset(), occurrence.getEndOffset()),
                                        replacement,
                                        true,
                                        new ArrayList<>());
  myLivePreview.inSmartUpdate();
  mySearchResults.updateThreadSafe(findModel, true, result, mySearchResults.getStamp());
  return result;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:LivePreviewController.java

示例8: performReplaceAll

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
public void performReplaceAll(Editor e) {
  Project project = mySearchResults.getProject();
  if (!ReadonlyStatusHandler.ensureDocumentWritable(project, 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(project, e, offset, copy, this);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:LivePreviewController.java

示例9: performReplace

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
@Nullable
public TextRange performReplace(final FindResult occurrence, final String replacement, final Editor editor) {
  if (myReplaceDenied || !ReadonlyStatusHandler.ensureDocumentWritable(editor.getProject(), editor.getDocument())) return null;
  FindModel findModel = mySearchResults.getFindModel();
  TextRange result = FindUtil.doReplace(editor.getProject(),
                                        editor.getDocument(),
                                        findModel,
                                        new FindResultImpl(occurrence.getStartOffset(), occurrence.getEndOffset()),
                                        replacement,
                                        true,
                                        new ArrayList<Pair<TextRange, String>>());
  myLivePreview.inSmartUpdate();
  mySearchResults.updateThreadSafe(findModel, true, result, mySearchResults.getStamp());
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:LivePreviewController.java

示例10: makeWritable

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
@Override
public boolean makeWritable() {
    if (!document.isWritable()) {
        document.setReadOnly(false);
    }

    try {
        return ReadonlyStatusHandler.ensureDocumentWritable(context.project, document);
    } catch (Throwable e) {
        Flog.error(e);
    }
    return false;
}
 
开发者ID:Floobits,项目名称:floobits-intellij,代码行数:14,代码来源:DocImpl.java

示例11: restoreState

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
protected void restoreState(@NotNull final V psiField) {
  if (!ReadonlyStatusHandler.ensureDocumentWritable(myProject, InjectedLanguageUtil.getTopLevelEditor(myEditor).getDocument())) return;
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final PsiFile containingFile = psiField.getContainingFile();
      final RangeMarker exprMarker = getExprMarker();
      if (exprMarker != null) {
        myExpr = restoreExpression(containingFile, psiField, exprMarker, myExprText);
      }

      if (myLocalMarker != null) {
        final PsiElement refVariableElement = containingFile.findElementAt(myLocalMarker.getStartOffset());
        if (refVariableElement != null) {
          final PsiElement parent = refVariableElement.getParent();
          if (parent instanceof PsiNamedElement) {
            ((PsiNamedElement)parent).setName(myLocalName);
          }
        }

        final V localVariable = getLocalVariable();
        if (localVariable != null && localVariable.isPhysical()) {
          myLocalVariable = localVariable;
          final PsiElement nameIdentifier = localVariable.getNameIdentifier();
          if (nameIdentifier != null) {
            myLocalMarker = createMarker(nameIdentifier);
          }
        }
      }
      final List<RangeMarker> occurrenceMarkers = getOccurrenceMarkers();
      for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) {
        RangeMarker marker = occurrenceMarkers.get(i);
        if (getExprMarker() != null && marker.getStartOffset() == getExprMarker().getStartOffset() && myExpr != null) {
          myOccurrences[i] = myExpr;
          continue;
        }
        final E psiExpression =
           restoreExpression(containingFile, psiField, marker, getLocalVariable() != null ? myLocalName : myExprText);
        if (psiExpression != null) {
          myOccurrences[i] = psiExpression;
        }
      }

      if (myExpr != null && myExpr.isPhysical()) {
        myExprMarker = createMarker(myExpr);
      }
      myOccurrenceMarkers = null;
      deleteTemplateField(psiField);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:52,代码来源:AbstractInplaceIntroducer.java

示例12: restoreState

import com.intellij.openapi.vfs.ReadonlyStatusHandler; //导入方法依赖的package包/类
protected void restoreState(final V psiField) {
  if (!ReadonlyStatusHandler.ensureDocumentWritable(myProject, InjectedLanguageUtil.getTopLevelEditor(myEditor).getDocument())) return;
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final PsiFile containingFile = psiField.getContainingFile();
      final RangeMarker exprMarker = getExprMarker();
      if (exprMarker != null) {
        myExpr = restoreExpression(containingFile, psiField, exprMarker, myExprText);
        if (myExpr != null && myExpr.isPhysical()) {
          myExprMarker = createMarker(myExpr);
        }
      }
      if (myLocalMarker != null) {
        final PsiElement refVariableElement = containingFile.findElementAt(myLocalMarker.getStartOffset());
        if (refVariableElement != null) {
          final PsiElement parent = refVariableElement.getParent();
          if (parent instanceof PsiNamedElement) {
            ((PsiNamedElement)parent).setName(myLocalName);
          }
        }

        final V localVariable = getLocalVariable();
        if (localVariable != null && localVariable.isPhysical()) {
          myLocalVariable = localVariable;
          final PsiElement nameIdentifier = localVariable.getNameIdentifier();
          if (nameIdentifier != null) {
            myLocalMarker = createMarker(nameIdentifier);
          }
        }
      }
      final List<RangeMarker> occurrenceMarkers = getOccurrenceMarkers();
      for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) {
        RangeMarker marker = occurrenceMarkers.get(i);
        if (getExprMarker() != null && marker.getStartOffset() == getExprMarker().getStartOffset() && myExpr != null) {
          myOccurrences[i] = myExpr;
          continue;
        }
        final E psiExpression =
           restoreExpression(containingFile, psiField, marker, getLocalVariable() != null ? myLocalName : myExprText);
        if (psiExpression != null) {
          myOccurrences[i] = psiExpression;
        }
      }

      myOccurrenceMarkers = null;
      deleteTemplateField(psiField);
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:51,代码来源:AbstractInplaceIntroducer.java


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