Search in sources :

Example 16 with DocumentContent

use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.

the class CompareClipboardWithSelectionAction method createContent.

@NotNull
private static DocumentContent createContent(@NotNull Project project, @NotNull 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;
}
Also used : DocumentContent(com.intellij.diff.contents.DocumentContent) SelectionModel(com.intellij.openapi.editor.SelectionModel) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with DocumentContent

use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.

the class CompareClipboardWithSelectionAction method getDiffRequest.

@Nullable
@Override
protected DiffRequest getDiffRequest(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    Editor editor = getEditor(e);
    FileType editorFileType = getEditorFileType(e);
    assert editor != null;
    DocumentContent content2 = createContent(project, editor, editorFileType);
    DocumentContent content1 = DiffContentFactory.getInstance().createClipboardContent(project, content2);
    String title1 = DiffBundle.message("diff.content.clipboard.content.title");
    String title2 = createContentTitle(editor);
    String title = DiffBundle.message("diff.clipboard.vs.editor.dialog.title");
    SimpleDiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
    if (editor.isViewer()) {
        request.putUserData(DiffUserDataKeys.FORCE_READ_ONLY_CONTENTS, new boolean[] { false, true });
    }
    return request;
}
Also used : Project(com.intellij.openapi.project.Project) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) FileType(com.intellij.openapi.fileTypes.FileType) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) DocumentContent(com.intellij.diff.contents.DocumentContent) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with DocumentContent

use of com.intellij.diff.contents.DocumentContent in project intellij-community by JetBrains.

the class MemoryDiskConflictResolver method askReloadFromDisk.

boolean askReloadFromDisk(VirtualFile file, Document document) {
    String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl());
    final 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) {
            final ProjectEx project = (ProjectEx) ProjectLocator.getInstance().guessProjectForFile(file);
            FileType fileType = file.getFileType();
            String fsContent = LoadTextUtil.loadText(file).toString();
            DocumentContent content1 = DiffContentFactory.getInstance().create(project, fsContent, fileType);
            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;
}
Also used : ProjectEx(com.intellij.openapi.project.ex.ProjectEx) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequestPanel(com.intellij.diff.DiffRequestPanel) FileType(com.intellij.openapi.fileTypes.FileType) ActionEvent(java.awt.event.ActionEvent) DocumentContent(com.intellij.diff.contents.DocumentContent) DiffRequest(com.intellij.diff.requests.DiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DialogBuilder(com.intellij.openapi.ui.DialogBuilder)

Aggregations

DocumentContent (com.intellij.diff.contents.DocumentContent)18 NotNull (org.jetbrains.annotations.NotNull)6 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)5 FileType (com.intellij.openapi.fileTypes.FileType)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 DiffContent (com.intellij.diff.contents.DiffContent)3 Editor (com.intellij.openapi.editor.Editor)3 DiffContentFactory (com.intellij.diff.DiffContentFactory)2 DiffRequest (com.intellij.diff.requests.DiffRequest)2 TextMergeRequestImpl (com.intellij.diff.requests.TextMergeRequestImpl)2 Document (com.intellij.openapi.editor.Document)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ArrayList (java.util.ArrayList)2 DiffRequestPanel (com.intellij.diff.DiffRequestPanel)1 DiffTooBigException (com.intellij.diff.comparison.DiffTooBigException)1 EmptyContent (com.intellij.diff.contents.EmptyContent)1 LineFragment (com.intellij.diff.fragments.LineFragment)1 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)1