Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part of #198 Added code to shift focus to the terminal #503

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: '**'
pull_request:
branches: [ main ]
branches: [ terminal-focus-fix-branch ]

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2022 IBM Corporation.
* Copyright (c) 2020, 2023 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,15 +13,19 @@
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.terminal.JBTerminalWidget;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import com.sun.istack.Nullable;
import io.openliberty.tools.intellij.LibertyModule;
import io.openliberty.tools.intellij.LibertyModules;
import io.openliberty.tools.intellij.LibertyProjectSettings;
import org.jetbrains.plugins.terminal.ShellTerminalWidget;
import org.jetbrains.plugins.terminal.TerminalToolWindowManager;
import org.jetbrains.plugins.terminal.TerminalView;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -149,6 +153,26 @@ public static ShellTerminalWidget getTerminalWidget(Project project, LibertyModu
TerminalView terminalView = TerminalView.getInstance(project);
// look for existing terminal tab
ShellTerminalWidget widget = getTerminalWidget(libertyModule, terminalView);
TerminalToolWindowManager manager = TerminalToolWindowManager.getInstance(project);
ToolWindow toolWindow = manager.getToolWindow();
String widgetName = libertyModule.getName();

ContentManager contentManager = toolWindow.getContentManager();
Content[] contents = contentManager.getContents();

int index = 0;
for (int i = 0; i < contents.length; i++) {
String displayName = contents[i].getDisplayName();
if (widgetName.equals(displayName)) {
index = i;
break;
}
}
if (contents.length > 0) {
Content terminalContent = contents[index];
contentManager.setSelectedContent(terminalContent);
terminalContent.getComponent().requestFocus();
}
if (widget == null && createWidget) {
// create a new terminal tab
ShellTerminalWidget newTerminal = terminalView.createLocalShellWidget(project.getBasePath(), libertyModule.getName(), true);
Expand Down
Loading