From 9359a570356c0c43a166a0dedccb3f101f73f8a8 Mon Sep 17 00:00:00 2001 From: "Dmitry.Krasilschikov" Date: Mon, 21 Jan 2019 16:38:32 +0200 Subject: [PATCH] IDEA-200666 return immutable views of "back/changed" placed; rename listeners --- .../ide/actions/RecentLocationManager.java | 8 +++--- .../impl/IdeDocumentHistoryImpl.java | 28 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/RecentLocationManager.java b/platform/platform-impl/src/com/intellij/ide/actions/RecentLocationManager.java index f3dcba0837a9..e8bb01aa79bf 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/RecentLocationManager.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/RecentLocationManager.java @@ -96,9 +96,9 @@ public class RecentLocationManager implements ProjectComponent { } private void subscribeRecentPlaces(@NotNull MessageBusConnection connection) { - connection.subscribe(IdeDocumentHistoryImpl.RecentPlacesListener.TOPIC, new IdeDocumentHistoryImpl.RecentPlacesListener() { + connection.subscribe(IdeDocumentHistoryImpl.RecentlyVisitedPlacesListener.TOPIC, new IdeDocumentHistoryImpl.RecentlyVisitedPlacesListener() { @Override - public void recentPlacePushed(@NotNull PlaceInfo changePlace) { + public void recentPlaceAdded(@NotNull PlaceInfo changePlace) { update(changePlace, myProject, myRecentItems); } @@ -110,9 +110,9 @@ public class RecentLocationManager implements ProjectComponent { } private void subscribeChangedPlaces(@NotNull MessageBusConnection connection) { - connection.subscribe(IdeDocumentHistoryImpl.ChangePlacesListener.TOPIC, new IdeDocumentHistoryImpl.ChangePlacesListener() { + connection.subscribe(IdeDocumentHistoryImpl.RecentlyChangedPlacesListener.TOPIC, new IdeDocumentHistoryImpl.RecentlyChangedPlacesListener() { @Override - public void changedPlacePushed(@NotNull PlaceInfo changePlace) { + public void changedPlaceAdded(@NotNull PlaceInfo changePlace) { update(changePlace, myProject, myChangedItems); } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java index e01a68a3e789..2a63e90016b7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/IdeDocumentHistoryImpl.java @@ -37,6 +37,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.psi.ExternalChangeAction; import com.intellij.testFramework.LightVirtualFile; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.messages.Topic; @@ -383,7 +384,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos @Override public List getChangePlaces() { - return myChangePlaces; + return ContainerUtil.immutableList(myChangePlaces); } @Override @@ -479,16 +480,17 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos private void putLastOrMerge(@NotNull LinkedList list, @NotNull PlaceInfo next, int limit) { MessageBus messageBus = myProject.getMessageBus(); + RecentlyVisitedPlacesListener listener = messageBus.syncPublisher(RecentlyVisitedPlacesListener.TOPIC); if (!list.isEmpty()) { PlaceInfo prev = list.getLast(); if (isSame(prev, next)) { PlaceInfo removed = list.removeLast(); - messageBus.syncPublisher(RecentPlacesListener.TOPIC).recentPlaceRemoved(removed); + listener.recentPlaceRemoved(removed); } } list.add(next); - messageBus.syncPublisher(RecentPlacesListener.TOPIC).recentPlacePushed(next); + listener.recentPlaceAdded(next); if (list.size() > limit) { list.removeFirst(); } @@ -545,7 +547,7 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos @Override @NotNull public List getBackPlaces() { - return myBackPlaces; + return ContainerUtil.immutableList(myBackPlaces); } @Override @@ -567,18 +569,24 @@ public class IdeDocumentHistoryImpl extends IdeDocumentHistory implements Dispos return false; } - public interface ChangePlacesListener { - Topic TOPIC = Topic.create("ChangePlacesListener", ChangePlacesListener.class); + /** + * {@link RecentlyChangedPlacesListener} listens recently changed place adding and removing events. + */ + public interface RecentlyChangedPlacesListener { + Topic TOPIC = Topic.create("RecentlyChangedPlacesListener", RecentlyChangedPlacesListener.class); - void changedPlacePushed(@NotNull PlaceInfo changePlace); + void changedPlaceAdded(@NotNull PlaceInfo changePlace); void changedPlaceRemoved(@NotNull PlaceInfo changePlace); } - public interface RecentPlacesListener { - Topic TOPIC = Topic.create("RecentPlacesListener", RecentPlacesListener.class); + /** + * {@link RecentlyVisitedPlacesListener} listens recently viewed place adding and removing events. + */ + public interface RecentlyVisitedPlacesListener { + Topic TOPIC = Topic.create("RecentlyVisitedPlacesListener", RecentlyVisitedPlacesListener.class); - void recentPlacePushed(@NotNull PlaceInfo changePlace); + void recentPlaceAdded(@NotNull PlaceInfo changePlace); void recentPlaceRemoved(@NotNull PlaceInfo changePlace); }