diff --git a/platform/platform-resources/src/componentSets/VCS.xml b/platform/platform-resources/src/componentSets/VCS.xml
index c1b2a504f1f1..b0c48c58e7e4 100644
--- a/platform/platform-resources/src/componentSets/VCS.xml
+++ b/platform/platform-resources/src/componentSets/VCS.xml
@@ -102,4 +102,7 @@
com.intellij.openapi.vcs.contentAnnotation.ContentAnnotationCache
com.intellij.openapi.vcs.contentAnnotation.ContentAnnotationCacheImpl
+
+
+
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesNotificationProvider.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesNotificationProvider.java
new file mode 100644
index 000000000000..3ee88aa7d0b3
--- /dev/null
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesNotificationProvider.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2000-2017 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vcs.changes.shelf;
+
+import com.intellij.openapi.fileEditor.FileEditor;
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.ui.EditorNotificationPanel;
+import com.intellij.ui.EditorNotifications;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class ShelvedChangesNotificationProvider extends EditorNotifications.Provider implements DumbAware {
+ private static final Key KEY = Key.create("file.changes.present.on.shelf.notification.panel");
+ final Project myProject;
+
+ public ShelvedChangesNotificationProvider(Project project) {
+ myProject = project;
+ myProject.getMessageBus().connect(project).subscribe(ShelveChangesManager.SHELF_TOPIC, new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ EditorNotifications.getInstance(myProject).updateAllNotifications();
+ }
+ });
+ }
+
+ @NotNull
+ @Override
+ public Key getKey() {
+ return KEY;
+ }
+
+ @Nullable
+ @Override
+ public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
+ final String path = file.getPath();
+ final List foundChangeLists = ShelveChangesManager.getInstance(myProject).getShelvedChangeLists()
+ .stream().filter(l -> findChange(path, l).isPresent()).collect(Collectors.toList());
+ if (foundChangeLists.isEmpty()) {
+ return null;
+ }
+ final EditorNotificationPanel notificationPanel = new EditorNotificationPanel();
+ final int size = foundChangeLists.size();
+ notificationPanel.setText("Changes to this file are present in " + size + " shelved change list" + (size > 1 ? "s" : ""));
+ final int nameLength = size == 1 ? 50 : size == 2 ? 35 : 20;
+ foundChangeLists.stream().limit(3).forEach(
+ l -> notificationPanel.createActionLabel("Show '" + StringUtil.shortenTextWithEllipsis(l.toString(), nameLength, 0, true) + '\'',
+ () -> findChange(path, l).ifPresent(
+ c -> ShelvedChangesViewManager.getInstance(myProject).showChangeInView(c))));
+ return notificationPanel;
+ }
+
+ private Optional findChange(String path, ShelvedChangeList shelvedChangeList) {
+ return shelvedChangeList.getChanges(myProject).stream().filter(c -> path.endsWith(c.getBeforePath())).findAny();
+ }
+}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java
index 76c6bc03fd89..97a2e9f886c5 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java
@@ -320,10 +320,18 @@ public class ShelvedChangesViewManager implements ProjectComponent {
}
}
+ public void showChangeInView(final ShelvedChange change) {
+ showTargetInView(change);
+ }
+
public void activateView(final ShelvedChangeList list) {
+ showTargetInView(list);
+ }
+
+ private void showTargetInView(Object target) {
Runnable runnable = () -> {
- if (list != null) {
- TreeUtil.selectNode(myTree, TreeUtil.findNodeWithObject(myRoot, list));
+ if (target != null) {
+ TreeUtil.selectNode(myTree, TreeUtil.findNodeWithObject(myRoot, target));
}
myContentManager.setSelectedContent(myContent);
ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(ChangesViewContentManager.TOOLWINDOW_ID);