com.intellij.diff.DiffContentFactory Java Examples
The following examples show how to use
com.intellij.diff.DiffContentFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PatchDiffRequestFactory.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static MergeRequest createBadMergeRequest(@javax.annotation.Nullable Project project, @Nonnull Document document, @Nullable VirtualFile file, @Nonnull String localContent, @Nonnull AppliedTextPatch textPatch, @javax.annotation.Nullable String windowTitle, @Nullable String localTitle, @Nullable String resultTitle, @javax.annotation.Nullable String patchTitle, @Nullable Consumer<MergeResult> callback) throws InvalidDiffRequestException { if (!DiffUtil.canMakeWritable(document)) { throw new InvalidDiffRequestException("Output is read only" + (file != null ? " : '" + file.getPresentableUrl() +"'": "")); } if (windowTitle == null) windowTitle = getBadPatchTitle(file); if (localTitle == null) localTitle = VcsBundle.message("patch.apply.conflict.local.version"); if (resultTitle == null) resultTitle = VcsBundle.message("patch.apply.conflict.patched.somehow.version"); if (patchTitle == null) patchTitle = VcsBundle.message("patch.apply.conflict.patch"); DocumentContent resultContent = DiffContentFactory.getInstance().create(project, document, file); return new ApplyPatchMergeRequest(project, resultContent, textPatch, localContent, windowTitle, localTitle, resultTitle, patchTitle, callback); }
Example #2
Source File: PatchDiffRequestFactory.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static DiffRequest createBadDiffRequest(@Nullable Project project, @Nonnull VirtualFile file, @Nonnull String localContent, @Nonnull AppliedTextPatch textPatch, @Nullable String windowTitle, @Nullable String localTitle, @javax.annotation.Nullable String resultTitle, @Nullable String patchTitle) { if (windowTitle == null) windowTitle = getBadPatchTitle(file); if (localTitle == null) localTitle = VcsBundle.message("patch.apply.conflict.local.version"); if (resultTitle == null) resultTitle = VcsBundle.message("patch.apply.conflict.patched.somehow.version"); if (patchTitle == null) patchTitle = VcsBundle.message("patch.apply.conflict.patch"); DocumentContent resultContent = DiffContentFactory.getInstance().createDocument(project, file); if (resultContent == null) resultContent = DiffContentFactory.getInstance().create(localContent, file); return new ApplyPatchDiffRequest(resultContent, textPatch, localContent, windowTitle, localTitle, resultTitle, patchTitle); }
Example #3
Source File: DiffElement.java From consulo with Apache License 2.0 | 6 votes |
/** * Called in background thread without ReadLock OR in EDT * * @see DiffRequestProducer#process */ @Nonnull public DiffContent createDiffContent(@Nullable Project project, @Nonnull ProgressIndicator indicator) throws DiffRequestProducerException, ProcessCanceledException { try { final T src = getValue(); if (src instanceof VirtualFile) { return DiffContentFactory.getInstance().create(project, (VirtualFile)src); } byte[] content = getContent(); if (content == null) throw new DiffRequestProducerException("Can't get content"); return DiffContentFactory.getInstance().create(new String(content, getCharset()), getFileType()); } catch (IOException e) { throw new DiffRequestProducerException(e); } }
Example #4
Source File: GodClassPreviewResultDialog.java From IntelliJDeodorant with MIT License | 5 votes |
public GodClassPreviewResultDialog(@NotNull Project project, @NotNull MutableDiffRequestChain requestChain, @NotNull DiffDialogHints hints, ExtractClassPreviewProcessor previewProcessor) { super(project, requestChain, hints); this.myChain = requestChain; this.project = project; this.diffContentFactory = DiffContentFactory.getInstance(); this.previewProcessor = previewProcessor; this.javaCodeStyleManager = JavaCodeStyleManager.getInstance(project); this.codeStyleManager = CodeStyleManager.getInstance(project); }
Example #5
Source File: VcsSelectionHistoryDialog.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private DiffContent createDiffContent(int index, @Nonnull BlockData data) { if (index >= myRevisions.size()) return DiffContentFactory.getInstance().createEmpty(); Block block = data.getBlock(index); if (block == null) return null; if (block == EMPTY_BLOCK) return DiffContentFactory.getInstance().createEmpty(); return DiffContentFactory.getInstance().create(block.getBlockContent(), myFile.getFileType()); }
Example #6
Source File: ApplyPatchViewer.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { DocumentContent resultContent = myPatchRequest.getResultContent(); DocumentContent localContent = DiffContentFactory.getInstance().create(myPatchRequest.getLocalContent(), resultContent); SimpleDiffRequest request = new SimpleDiffRequest(myPatchRequest.getTitle(), localContent, resultContent, myPatchRequest.getLocalTitle(), myPatchRequest.getResultTitle()); LogicalPosition currentPosition = DiffUtil.getCaretPosition(myResultEditor); request.putUserData(DiffUserDataKeys.SCROLL_TO_LINE, Pair.create(Side.RIGHT, currentPosition.line)); DiffManager.getInstance().showDiff(myProject, request, new DiffDialogHints(null, myPanel)); }
Example #7
Source File: DiffActionExecutor.java From consulo with Apache License 2.0 | 5 votes |
@Override protected DiffContent createRemote(final VcsRevisionNumber revisionNumber) throws IOException, VcsException { if (myFileStillExists) { return super.createRemote(revisionNumber); } else { return DiffContentFactory.getInstance().createEmpty(); } }
Example #8
Source File: SelectionDifferenceModel.java From consulo with Apache License 2.0 | 5 votes |
@Override protected DiffContent getEditableRightDiffContent(RevisionProcessingProgress p) { Document d = getDocument(); int fromOffset = d.getLineStartOffset(myFrom); int toOffset = d.getLineEndOffset(myTo); DocumentContent documentContent = DiffContentFactory.getInstance().create(myProject, d); return new DocumentFragmentContent(myProject, documentContent, new TextRange(fromOffset, toOffset)); }
Example #9
Source File: TestDiffRequestProcessor.java From consulo with Apache License 2.0 | 5 votes |
private Pair<String, DiffContent> createContentWithTitle(String titleKey, String contentString, String contentFilePath) { String title; DiffContent content; VirtualFile vFile; if (contentFilePath != null && (vFile = LocalFileSystem.getInstance().findFileByPath(contentFilePath)) != null) { title = ExecutionBundle.message(titleKey) + " (" + vFile.getPresentableUrl() + ")"; content = DiffContentFactory.getInstance().create(getProject(), vFile); } else { title = ExecutionBundle.message(titleKey); content = DiffContentFactory.getInstance().create(contentString); } return Pair.create(title, content); }
Example #10
Source File: CompareClipboardWithSelectionAction.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static DocumentContent createContent(@Nonnull Project project, @Nonnull Editor editor, @Nullable FileType type) { DocumentContent content = DiffContentFactory.getInstance().create(project, editor.getDocument(), type); SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); content = DiffContentFactory.getInstance().createFragment(project, content, range); } return content; }
Example #11
Source File: DirDiffPanel.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected DiffRequest loadRequest(@Nonnull ElementWrapper element, @Nonnull ProgressIndicator indicator) throws ProcessCanceledException, DiffRequestProducerException { final Project project = myModel.getProject(); DiffElement sourceElement = element.sourceElement; DiffElement targetElement = element.targetElement; DiffContent sourceContent = sourceElement != null ? sourceElement.createDiffContent(project, indicator) : DiffContentFactory.getInstance().createEmpty(); DiffContent targetContent = targetElement != null ? targetElement.createDiffContent(project, indicator) : DiffContentFactory.getInstance().createEmpty(); return new SimpleDiffRequest(null, sourceContent, targetContent, null, null); }
Example #12
Source File: GodClassUserInputDialog.java From IntelliJDeodorant with MIT License | 5 votes |
@Override protected void doAction() { if (isPreviewUsages()) { godClassPanel.setPreviewUsage(true); DiffContentFactory contentFactory = DiffContentFactory.getInstance(); DiffContent c1 = contentFactory.create(""); DiffContent c2 = contentFactory.create(""); MutableDiffRequestChain chain = new MutableDiffRequestChain(c1, c2); refactoring.setPreviewUsage(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { refactoring.apply(); }); GodClassPreviewResultDialog previewResultDialog = new GodClassPreviewResultDialog(getProject(), chain, DiffDialogHints.DEFAULT, refactoring.getPreviewProcessor()); previewResultDialog.show(); refactoring = abstractRefactoring.renewRefactoring(); setPreviewResults(false); godClassPanel.setPreviewUsage(false); } else { closeOKAction(); refactoring.setExtractedTypeName(extractedClassNameField.getText()); WriteCommandAction.runWriteCommandAction(refactoring.getProject(), refactoring::apply); IntelliJDeodorantCounterCollector.getInstance().extractClassRefactoringApplied(refactoring.getProject(), refactoring.getExtractedFieldFragmentsCount(), refactoring.getExtractedMethodsCount(), refactoring.getSourceClass().getFields().length, refactoring.getSourceClass().getMethods().length); } }
Example #13
Source File: FileDifferenceModel.java From consulo with Apache License 2.0 | 4 votes |
public DiffContent getLeftDiffContent(RevisionProcessingProgress p) { if (!hasLeftEntry()) return DiffContentFactory.getInstance().createEmpty(); if (!isLeftContentAvailable(p)) return DiffContentFactory.getInstance().create("Content not available"); return doGetLeftDiffContent(p); }
Example #14
Source File: FileDifferenceModel.java From consulo with Apache License 2.0 | 4 votes |
public DiffContent getRightDiffContent(RevisionProcessingProgress p) { if (!hasRightEntry()) return DiffContentFactory.getInstance().createEmpty(); if (!isRightContentAvailable(p)) return DiffContentFactory.getInstance().create("Content not available"); if (isRightContentCurrent) return getEditableRightDiffContent(p); return getReadOnlyRightDiffContent(p); }
Example #15
Source File: FileDifferenceModel.java From consulo with Apache License 2.0 | 4 votes |
protected DocumentContent createSimpleDiffContent(String content, Entry e) { return DiffContentFactory.getInstance().create(content, myGateway.getFileType(e.getName())); }
Example #16
Source File: MemoryDiskConflictResolver.java From consulo with Apache License 2.0 | 4 votes |
boolean askReloadFromDisk(VirtualFile file, Document document) { if (myConflictAppeared != null) { Throwable trace = myConflictAppeared; myConflictAppeared = null; throw new IllegalStateException("Unexpected memory-disk conflict in tests for " + file.getPath() + ", please use FileDocumentManager#reloadFromDisk or avoid VFS refresh", trace); } String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl()); DialogBuilder builder = new DialogBuilder(); builder.setCenterPanel(new JLabel(message, Messages.getQuestionIcon(), SwingConstants.CENTER)); builder.addOkAction().setText(UIBundle.message("file.cache.conflict.load.fs.changes.button")); builder.addCancelAction().setText(UIBundle.message("file.cache.conflict.keep.memory.changes.button")); builder.addAction(new AbstractAction(UIBundle.message("file.cache.conflict.show.difference.button")) { @Override public void actionPerformed(ActionEvent e) { Project project = ProjectLocator.getInstance().guessProjectForFile(file); String fsContent = LoadTextUtil.loadText(file).toString(); DocumentContent content1 = DiffContentFactory.getInstance().create(project, fsContent, file.getFileType()); DocumentContent content2 = DiffContentFactory.getInstance().create(project, document, file); String title = UIBundle.message("file.cache.conflict.for.file.dialog.title", file.getPresentableUrl()); String title1 = UIBundle.message("file.cache.conflict.diff.content.file.system.content"); String title2 = UIBundle.message("file.cache.conflict.diff.content.memory.content"); DiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2); request.putUserData(DiffUserDataKeys.GO_TO_SOURCE_DISABLE, true); DialogBuilder diffBuilder = new DialogBuilder(project); DiffRequestPanel diffPanel = DiffManager.getInstance().createRequestPanel(project, diffBuilder, diffBuilder.getWindow()); diffPanel.setRequest(request); diffBuilder.setCenterPanel(diffPanel.getComponent()); diffBuilder.setDimensionServiceKey("FileDocumentManager.FileCacheConflict"); diffBuilder.addOkAction().setText(UIBundle.message("file.cache.conflict.save.changes.button")); diffBuilder.addCancelAction(); diffBuilder.setTitle(title); if (diffBuilder.show() == DialogWrapper.OK_EXIT_CODE) { builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE); } } }); builder.setTitle(UIBundle.message("file.cache.conflict.dialog.title")); builder.setButtonsAlignment(SwingConstants.CENTER); builder.setHelpId("reference.dialogs.fileCacheConflict"); return builder.show() == 0; }
Example #17
Source File: ShowLineStatusRangeDiffAction.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private DiffContent createDiffContent(@Nonnull Document document, @Nonnull TextRange textRange, @Nullable VirtualFile file) { final Project project = myLineStatusTracker.getProject(); DocumentContent content = DiffContentFactory.getInstance().create(project, document, file); return new DocumentFragmentContent(project, content, textRange); }
Example #18
Source File: EntireFileDifferenceModel.java From consulo with Apache License 2.0 | 4 votes |
@Override protected DiffContent getEditableRightDiffContent(RevisionProcessingProgress p) { Document d = getDocument(); return DiffContentFactory.getInstance().create(myProject, d); }
Example #19
Source File: ApplyPatchViewer.java From consulo with Apache License 2.0 | 4 votes |
public ApplyPatchViewer(@Nonnull DiffContext context, @Nonnull ApplyPatchRequest request) { myProject = context.getProject(); myContext = context; myPatchRequest = request; DocumentContent resultContent = request.getResultContent(); DocumentContent patchContent = DiffContentFactory.getInstance().create(new DocumentImpl("", true), resultContent); myResultHolder = TextEditorHolder.create(myProject, resultContent); myPatchHolder = TextEditorHolder.create(myProject, patchContent); myResultEditor = myResultHolder.getEditor(); myPatchEditor = myPatchHolder.getEditor(); if (isReadOnly()) myResultEditor.setViewer(true); myPatchEditor.setViewer(true); DiffUtil.disableBlitting(myResultEditor); DiffUtil.disableBlitting(myPatchEditor); ((EditorMarkupModel)myResultEditor.getMarkupModel()).setErrorStripeVisible(false); myResultEditor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT); myPatchEditor.getGutterComponentEx().setForceShowRightFreePaintersArea(true); ((EditorMarkupModel)myPatchEditor.getMarkupModel()).setErrorStripeVisible(false); List<TextEditorHolder> holders = ContainerUtil.list(myResultHolder, myPatchHolder); List<EditorEx> editors = ContainerUtil.list(myResultEditor, myPatchEditor); JComponent resultTitle = DiffUtil.createTitle(myPatchRequest.getResultTitle()); JComponent patchTitle = DiffUtil.createTitle(myPatchRequest.getPatchTitle()); List<JComponent> titleComponents = DiffUtil.createSyncHeightComponents(ContainerUtil.list(resultTitle, patchTitle)); myContentPanel = new TwosideContentPanel(holders, titleComponents); myPanel = new SimpleDiffPanel(myContentPanel, this, myContext); myModel = new MyModel(myProject, myResultEditor.getDocument()); myFocusTrackerSupport = new FocusTrackerSupport.Twoside(holders); myFocusTrackerSupport.setCurrentSide(Side.LEFT); myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable(); myStatusPanel = new MyStatusPanel(); myFoldingModel = new MyFoldingModel(myResultEditor, this); new MyFocusOppositePaneAction().install(myPanel); new TextDiffViewerUtil.EditorActionsPopup(createEditorPopupActions()).install(editors, myPanel); new TextDiffViewerUtil.EditorFontSizeSynchronizer(editors).install(this); myEditorSettingsAction = new SetEditorSettingsAction(getTextSettings(), editors); myEditorSettingsAction.applyDefaults(); if (!isReadOnly()) { DiffUtil.registerAction(new ApplySelectedChangesAction(true), myPanel); DiffUtil.registerAction(new IgnoreSelectedChangesAction(true), myPanel); } ProxyUndoRedoAction.register(myProject, myResultEditor, myContentPanel); }