From f71d92114f086ae706d0b59a33951748d02bdbdc Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Sun, 23 May 2021 09:33:08 -0400 Subject: [PATCH] Bug 573646: Open primary terminal view when there is no last available Change-Id: I286d039d6cb3eb1e73fdb5b76c8743a8e0870d94 --- .../view/ui/manager/ConsoleManager.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java index 428ebf5a5f2..8dec9dc5528 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/manager/ConsoleManager.java @@ -237,8 +237,9 @@ public class ConsoleManager { for (IViewReference ref : getActiveWorkbenchPage().getViewReferences()) { if (ref.getId().equals(id)) { + String refSecondaryId = ref.getSecondaryId(); if (ITerminalsConnectorConstants.ANY_ACTIVE_SECONDARY_ID.equals(secondaryId) - || Objects.equals(secondaryId, ref.getSecondaryId())) { + || Objects.equals(secondaryId, refSecondaryId)) { return ref.getView(restore); } } @@ -268,7 +269,14 @@ public class ConsoleManager { } if (part == null) { - part = getTerminalsViewWithSecondaryId(id, secondaryId, true); + String finalSecondaryId; + if (ITerminalsConnectorConstants.LAST_ACTIVE_SECONDARY_ID.equals(secondaryId)) { + // There is no last available, so get any available instead + finalSecondaryId = ITerminalsConnectorConstants.ANY_ACTIVE_SECONDARY_ID; + } else { + finalSecondaryId = secondaryId; + } + part = getTerminalsViewWithSecondaryId(id, finalSecondaryId, true); if (part != null) { lastActiveViewId = part.getViewSite().getId(); lastActiveSecondaryViewId = part.getViewSite().getSecondaryId(); @@ -339,8 +347,19 @@ public class ConsoleManager { try { // show the view IViewPart part = getActiveTerminalsView(id != null ? id : IUIConstants.ID, secondaryId); - if (part == null) - part = page.showView(id != null ? id : IUIConstants.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); + if (part == null) { + String finalSecondaryId; + if (ITerminalsConnectorConstants.LAST_ACTIVE_SECONDARY_ID.equals(secondaryId) + || ITerminalsConnectorConstants.ANY_ACTIVE_SECONDARY_ID.equals(secondaryId)) { + // We have already checked all open views, so since none of the special flags work + // we are opening the first view, which means no secondary id. + finalSecondaryId = null; + } else { + finalSecondaryId = secondaryId; + } + part = page.showView(id != null ? id : IUIConstants.ID, finalSecondaryId, + IWorkbenchPage.VIEW_ACTIVATE); + } // and force the view to the foreground page.bringToTop(part); return part;