mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 20:31:37 -05:00
Add ability to open images
This commit is contained in:
@@ -10,6 +10,7 @@ import fs from "fs/promises"
|
|||||||
import { HistoryItem } from "../shared/HistoryItem"
|
import { HistoryItem } from "../shared/HistoryItem"
|
||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { getTheme } from "../utils/getTheme"
|
import { getTheme } from "../utils/getTheme"
|
||||||
|
import { openImage } from "../utils/open-image"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
||||||
@@ -398,6 +399,9 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|||||||
const models = await this.getOllamaModels(message.text)
|
const models = await this.getOllamaModels(message.text)
|
||||||
this.postMessageToWebview({ type: "ollamaModels", models })
|
this.postMessageToWebview({ type: "ollamaModels", models })
|
||||||
break
|
break
|
||||||
|
case "openImage":
|
||||||
|
openImage(message.text!)
|
||||||
|
break
|
||||||
// Add more switch case statements here as more webview message commands
|
// Add more switch case statements here as more webview message commands
|
||||||
// are created within the webview context (i.e. inside media/main.js)
|
// are created within the webview context (i.e. inside media/main.js)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface WebviewMessage {
|
|||||||
| "exportTaskWithId"
|
| "exportTaskWithId"
|
||||||
| "resetState"
|
| "resetState"
|
||||||
| "requestOllamaModels"
|
| "requestOllamaModels"
|
||||||
|
| "openImage"
|
||||||
text?: string
|
text?: string
|
||||||
askResponse?: ClaudeAskResponse
|
askResponse?: ClaudeAskResponse
|
||||||
apiConfiguration?: ApiConfiguration
|
apiConfiguration?: ApiConfiguration
|
||||||
|
|||||||
20
src/utils/open-image.ts
Normal file
20
src/utils/open-image.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import * as path from "path"
|
||||||
|
import * as os from "os"
|
||||||
|
import * as vscode from "vscode"
|
||||||
|
|
||||||
|
export async function openImage(dataUri: string) {
|
||||||
|
const matches = dataUri.match(/^data:image\/([a-zA-Z]+);base64,(.+)$/)
|
||||||
|
if (!matches) {
|
||||||
|
vscode.window.showErrorMessage("Invalid data URI format")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const [, format, base64Data] = matches
|
||||||
|
const imageBuffer = Buffer.from(base64Data, "base64")
|
||||||
|
const tempFilePath = path.join(os.tmpdir(), `temp_image_${Date.now()}.${format}`)
|
||||||
|
try {
|
||||||
|
await vscode.workspace.fs.writeFile(vscode.Uri.file(tempFilePath), imageBuffer)
|
||||||
|
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(tempFilePath))
|
||||||
|
} catch (error) {
|
||||||
|
vscode.window.showErrorMessage(`Error opening image: ${error}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
|
|||||||
<style>
|
<style>
|
||||||
{`
|
{`
|
||||||
.history-preview-item {
|
.history-preview-item {
|
||||||
background-color: color-mix(in srgb, var(--vscode-toolbar-hoverBackground) 50%, transparent);
|
background-color: color-mix(in srgb, var(--vscode-toolbar-hoverBackground) 65%, transparent);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
|
|||||||
${totalCost?.toFixed(4)}
|
${totalCost?.toFixed(4)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<VSCodeButton appearance="icon" onClick={onClose} style={{ marginLeft: 10, flexShrink: 0 }}>
|
<VSCodeButton appearance="icon" onClick={onClose} style={{ marginLeft: 6, flexShrink: 0 }}>
|
||||||
<span className="codicon codicon-close"></span>
|
<span className="codicon codicon-close"></span>
|
||||||
</VSCodeButton>
|
</VSCodeButton>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useRef, useLayoutEffect, memo } from "react"
|
import React, { useState, useRef, useLayoutEffect, memo } from "react"
|
||||||
import { useWindowSize } from "react-use"
|
import { useWindowSize } from "react-use"
|
||||||
|
import { vscode } from "../utils/vscode"
|
||||||
|
|
||||||
interface ThumbnailsProps {
|
interface ThumbnailsProps {
|
||||||
images: string[]
|
images: string[]
|
||||||
@@ -31,6 +32,10 @@ const Thumbnails = ({ images, style, setImages, onHeightChange }: ThumbnailsProp
|
|||||||
|
|
||||||
const isDeletable = setImages !== undefined
|
const isDeletable = setImages !== undefined
|
||||||
|
|
||||||
|
const handleImageClick = (image: string) => {
|
||||||
|
vscode.postMessage({ type: "openImage", text: image })
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
@@ -55,7 +60,9 @@ const Thumbnails = ({ images, style, setImages, onHeightChange }: ThumbnailsProp
|
|||||||
height: 34,
|
height: 34,
|
||||||
objectFit: "cover",
|
objectFit: "cover",
|
||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleImageClick(image)}
|
||||||
/>
|
/>
|
||||||
{isDeletable && hoveredIndex === index && (
|
{isDeletable && hoveredIndex === index && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user