|
@@ -3,6 +3,34 @@ import delay from "delay"
|
|
|
|
|
|
|
|
import { ClineProvider } from "../core/webview/ClineProvider"
|
|
import { ClineProvider } from "../core/webview/ClineProvider"
|
|
|
|
|
|
|
|
|
|
+// Store panel references in both modes
|
|
|
|
|
+let sidebarPanel: vscode.WebviewView | undefined = undefined
|
|
|
|
|
+let tabPanel: vscode.WebviewPanel | undefined = undefined
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Get the currently active panel
|
|
|
|
|
+ * @returns WebviewPanel或WebviewView
|
|
|
|
|
+ */
|
|
|
|
|
+export function getPanel(): vscode.WebviewPanel | vscode.WebviewView | undefined {
|
|
|
|
|
+ return tabPanel || sidebarPanel
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Set panel references
|
|
|
|
|
+ */
|
|
|
|
|
+export function setPanel(
|
|
|
|
|
+ newPanel: vscode.WebviewPanel | vscode.WebviewView | undefined,
|
|
|
|
|
+ type: "sidebar" | "tab",
|
|
|
|
|
+): void {
|
|
|
|
|
+ if (type === "sidebar") {
|
|
|
|
|
+ sidebarPanel = newPanel as vscode.WebviewView
|
|
|
|
|
+ tabPanel = undefined
|
|
|
|
|
+ } else {
|
|
|
|
|
+ tabPanel = newPanel as vscode.WebviewPanel
|
|
|
|
|
+ sidebarPanel = undefined
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export type RegisterCommandOptions = {
|
|
export type RegisterCommandOptions = {
|
|
|
context: vscode.ExtensionContext
|
|
context: vscode.ExtensionContext
|
|
|
outputChannel: vscode.OutputChannel
|
|
outputChannel: vscode.OutputChannel
|
|
@@ -15,6 +43,22 @@ export const registerCommands = (options: RegisterCommandOptions) => {
|
|
|
for (const [command, callback] of Object.entries(getCommandsMap(options))) {
|
|
for (const [command, callback] of Object.entries(getCommandsMap(options))) {
|
|
|
context.subscriptions.push(vscode.commands.registerCommand(command, callback))
|
|
context.subscriptions.push(vscode.commands.registerCommand(command, callback))
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Human Relay Dialog Command
|
|
|
|
|
+ context.subscriptions.push(
|
|
|
|
|
+ vscode.commands.registerCommand(
|
|
|
|
|
+ "roo-cline.showHumanRelayDialog",
|
|
|
|
|
+ (params: { requestId: string; promptText: string }) => {
|
|
|
|
|
+ if (getPanel()) {
|
|
|
|
|
+ getPanel()?.webview.postMessage({
|
|
|
|
|
+ type: "showHumanRelayDialog",
|
|
|
|
|
+ requestId: params.requestId,
|
|
|
|
|
+ promptText: params.promptText,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOptions) => {
|
|
const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOptions) => {
|
|
@@ -65,20 +109,28 @@ const openClineInNewTab = async ({ context, outputChannel }: Omit<RegisterComman
|
|
|
|
|
|
|
|
const targetCol = hasVisibleEditors ? Math.max(lastCol + 1, 1) : vscode.ViewColumn.Two
|
|
const targetCol = hasVisibleEditors ? Math.max(lastCol + 1, 1) : vscode.ViewColumn.Two
|
|
|
|
|
|
|
|
- const panel = vscode.window.createWebviewPanel(ClineProvider.tabPanelId, "Roo Code", targetCol, {
|
|
|
|
|
|
|
+ const newPanel = vscode.window.createWebviewPanel(ClineProvider.tabPanelId, "Roo Code", targetCol, {
|
|
|
enableScripts: true,
|
|
enableScripts: true,
|
|
|
retainContextWhenHidden: true,
|
|
retainContextWhenHidden: true,
|
|
|
localResourceRoots: [context.extensionUri],
|
|
localResourceRoots: [context.extensionUri],
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ // Save as tab type panel
|
|
|
|
|
+ setPanel(newPanel, "tab")
|
|
|
|
|
+
|
|
|
// TODO: use better svg icon with light and dark variants (see
|
|
// TODO: use better svg icon with light and dark variants (see
|
|
|
// https://stackoverflow.com/questions/58365687/vscode-extension-iconpath).
|
|
// https://stackoverflow.com/questions/58365687/vscode-extension-iconpath).
|
|
|
- panel.iconPath = {
|
|
|
|
|
|
|
+ newPanel.iconPath = {
|
|
|
light: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"),
|
|
light: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"),
|
|
|
dark: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"),
|
|
dark: vscode.Uri.joinPath(context.extensionUri, "assets", "icons", "rocket.png"),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await tabProvider.resolveWebviewView(panel)
|
|
|
|
|
|
|
+ await tabProvider.resolveWebviewView(newPanel)
|
|
|
|
|
+
|
|
|
|
|
+ // Handle panel closing events
|
|
|
|
|
+ newPanel.onDidDispose(() => {
|
|
|
|
|
+ setPanel(undefined, "tab")
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
// Lock the editor group so clicking on files doesn't open them over the panel
|
|
// Lock the editor group so clicking on files doesn't open them over the panel
|
|
|
await delay(100)
|
|
await delay(100)
|