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

[JetBrains EAP] Add actions Copy URL and Copy Web URL to the terminal's ports context menu #14356

Merged
merged 1 commit into from
Nov 2, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.latest

import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import com.intellij.openapi.ide.CopyPasteManager
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortForwardingDataKeys
import io.gitpod.jetbrains.remote.GitpodPortsService
import java.awt.datatransfer.StringSelection

@Suppress("ComponentNotRegistered", "UnstableApiUsage")
class GitpodCopyUrlAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
e.dataContext.getData(PortForwardingDataKeys.SUGGESTION)?.getSuggestedHostPort()?.let { hostPort ->
service<GitpodPortsService>().getLocalHostUriFromHostPort(hostPort).let { localHostUri ->
CopyPasteManager.getInstance().setContents(StringSelection(localHostUri.toString()))
}
}
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = (e.place != ActionPlaces.ACTION_SEARCH)
}

override fun getActionUpdateThread() = ActionUpdateThread.BGT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.latest

import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.ide.CopyPasteManager
import com.intellij.util.application
import com.jetbrains.rd.platform.codeWithMe.portForwarding.PortForwardingDataKeys
import io.gitpod.jetbrains.remote.GitpodManager
import io.gitpod.supervisor.api.Status.PortsStatusRequest
import io.gitpod.supervisor.api.StatusServiceGrpc
import kotlinx.coroutines.launch
import java.awt.datatransfer.StringSelection

@Suppress("ComponentNotRegistered", "UnstableApiUsage")
class GitpodCopyWebUrlAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
e.dataContext.getData(PortForwardingDataKeys.SUGGESTION)?.getSuggestedHostPort()?.let { hostPort ->
application.coroutineScope.launch {
getUrlFromPort(hostPort)?.let {
CopyPasteManager.getInstance().setContents(StringSelection(it))
}
}
}
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = (e.place != ActionPlaces.ACTION_SEARCH)
}

override fun getActionUpdateThread() = ActionUpdateThread.BGT

private fun getUrlFromPort(port: Number): String? {
val blockingStub = StatusServiceGrpc.newBlockingStub(GitpodManager.supervisorChannel)
val request = PortsStatusRequest.newBuilder().setObserve(false).build()
val response = blockingStub.portsStatus(request)
while (response.hasNext()) {
val portStatusResponse = response.next()
for (portStatus in portStatusResponse.portsList) {
if (portStatus.localPort == port) return portStatus.exposed.url
}
}
return null
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
<projectService serviceImplementation="io.gitpod.jetbrains.remote.GitpodTerminalService" client="controller" preload="true"/>
<projectService serviceImplementation="io.gitpod.jetbrains.remote.latest.GitpodPortForwardingService" client="controller" preload="true"/>
</extensions>
<!--
<actions>
<action id="io.gitpod.jetbrains.remote.latest.GitpodPortsActionCopyUrl"
class="io.gitpod.jetbrains.remote.latest.GitpodPortsActionCopyUrl"
text="Gitpod: Copy Port URL"
<action id="io.gitpod.jetbrains.remote.latest.GitpodCopyUrlAction"
class="io.gitpod.jetbrains.remote.latest.GitpodCopyUrlAction"
text="Copy URL"
icon="AllIcons.Actions.Copy">
<add-to-group group-id="PortForwardingPortGroup" anchor="last"/>
</action>
<action id="io.gitpod.jetbrains.remote.latest.GitpodCopyWebUrlAction"
class="io.gitpod.jetbrains.remote.latest.GitpodCopyWebUrlAction"
text="Copy Web URL"
icon="AllIcons.Actions.Copy">
<add-to-group group-id="PortForwardingPortGroup" anchor="last"/>
<add-to-group group-id="PortForwardingSuggestionGroup" anchor="last"/>
</action>
</actions>
-->
</idea-plugin>