From eb11fd2653b3299fbd00053093ea0b9744bbbe3b Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Mon, 27 Mar 2017 17:29:59 +0300 Subject: [PATCH] [patch]: Apply Patch should report exceptions/errors * (IDEA-170014, IDEA-166917) warn user while show apply patch dialog; * provide additional panel for errors; --- .../patch/ApplyPatchDifferentiatedDialog.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java index 722cf9e9aefc..933573d18dd2 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchDifferentiatedDialog.java @@ -91,6 +91,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { private final List myPatches; private final List myBinaryShelvedPatches; + @NotNull private EditorNotificationPanel myErrorNotificationPanel; @NotNull private final MyChangeTreeList myChangesTreeList; @Nullable private final Collection myPreselectedChanges; private final boolean myUseProjectRootAsPredefinedBase; @@ -155,6 +156,8 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { myRecentPathFileChange = new AtomicReference<>(); myBinaryShelvedPatches = binaryShelvedPatches; myPreselectedChanges = preselectedChanges; + myErrorNotificationPanel = new EditorNotificationPanel(LightColors.RED); + cleanNotifications(); myChangesTreeList = new MyChangeTreeList(project, Collections.emptyList(), new Runnable() { public void run() { @@ -372,15 +375,15 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { private class MyUpdater implements Runnable { public void run() { + cleanNotifications(); final FilePresentationModel filePresentationModel = myRecentPathFileChange.get(); final VirtualFile file = filePresentationModel != null ? filePresentationModel.getVf() : null; if (file == null) { ApplicationManager.getApplication().invokeLater(myReset, ModalityState.stateForComponent(myCenterPanel)); return; } - - final PatchReader patchReader = loadPatches(file); - List filePatches = patchReader != null ? ContainerUtil.newArrayList(patchReader.getAllPatches()) : Collections.emptyList(); + myReader = loadPatches(file); + List filePatches = myReader != null ? ContainerUtil.newArrayList(myReader.getAllPatches()) : Collections.emptyList(); if (!ContainerUtil.isEmpty(myBinaryShelvedPatches)) { filePatches.addAll(myBinaryShelvedPatches); } @@ -393,7 +396,6 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { } myPatches.clear(); myPatches.addAll(matchedPatches); - myReader = patchReader; updateTree(true); paintBusy(false); updateOkActions(); @@ -402,7 +404,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { } @Nullable - private static PatchReader loadPatches(@NotNull VirtualFile patchFile) { + private PatchReader loadPatches(@NotNull VirtualFile patchFile) { PatchReader reader; try { reader = ApplicationManager.getApplication().runReadAction(new ThrowableComputable() { @@ -413,19 +415,31 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { }); } catch (IOException e) { - LOG.warn("Can't read patchFile: " + patchFile.getPresentableName(), e); + addNotificationAndWarn("Can't read patchFile " + patchFile.getPresentableName() + ": " + e.getMessage()); return null; } try { reader.parseAllPatches(); } catch (PatchSyntaxException e) { + addNotificationAndWarn("Can't read patch: " + e.getMessage()); return null; } return reader; } + private void addNotificationAndWarn(@NotNull String errorMessage) { + LOG.warn(errorMessage); + myErrorNotificationPanel.text(errorMessage); + myErrorNotificationPanel.setVisible(true); + } + + private void cleanNotifications() { + myErrorNotificationPanel.setText(""); + myErrorNotificationPanel.setVisible(false); + } + @CalledInAwt private void syncUpdatePatchFileAndScheduleReloadIfNeeded(@Nullable VirtualFile eventFile) { // if dialog is modal and refresh called not from dispatch thread then @@ -516,7 +530,8 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper { ++gb.gridy; gb.weighty = 1; gb.fill = GridBagConstraints.BOTH; - treePanel.add(ScrollPaneFactory.createScrollPane(myChangesTreeList), gb); + JPanel changeTreePanel = JBUI.Panels.simplePanel(myChangesTreeList).addToTop(myErrorNotificationPanel); + treePanel.add(ScrollPaneFactory.createScrollPane(changeTreePanel), gb); ++gb.gridy; gb.weighty = 0;