MCPcopy
hub / github.com/anomalyco/opencode / DialogSelectFile

Function DialogSelectFile

packages/app/src/components/dialog-select-file.tsx:270–492  ·  view source on GitHub ↗
(props: { mode?: DialogSelectFileMode; onOpenFile?: (path: string) => void })

Source from the content-addressed store, hash-verified

268}
269
270export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFile?: (path: string) => void }) {
271 const command = useCommand()
272 const language = useLanguage()
273 const platform = usePlatform()
274 const settings = useSettings()
275 const layout = useLayout()
276 const file = useFile()
277 const dialog = useDialog()
278 const navigate = useNavigate()
279 const serverSDK = useServerSDK()
280 const serverSync = useServerSync()
281 const { params, tabs, view } = useSessionLayout()
282 const filesOnly = () => props.mode === "files"
283 const state = { cleanup: undefined as (() => void) | void, committed: false }
284 const [grouped, setGrouped] = createSignal(false)
285 const commandEntries = createCommandEntries({ filesOnly, command, language })
286 const fileEntries = createFileEntries({ file, tabs, language })
287
288 const projectDirectory = createMemo(() => decode64(params.dir) ?? "")
289 const project = createMemo(() => {
290 const directory = projectDirectory()
291 if (!directory) return
292 return layout.projects.list().find((p) => p.worktree === directory || p.sandboxes?.includes(directory))
293 })
294 const workspaces = createMemo(() => {
295 const directory = projectDirectory()
296 const current = project()
297 if (!current) return directory ? [directory] : []
298
299 const dirs = [current.worktree, ...(current.sandboxes ?? [])]
300 if (directory && !dirs.includes(directory)) return [...dirs, directory]
301 return dirs
302 })
303 const homedir = createMemo(() => serverSync().data.path.home)
304 const label = (directory: string) => {
305 const current = project()
306 const kind =
307 current && directory === current.worktree
308 ? language.t("workspace.type.local")
309 : language.t("workspace.type.sandbox")
310 const [store] = serverSync().child(directory, { bootstrap: false })
311 const home = homedir()
312 const path = home ? directory.replace(home, "~") : directory
313 const name = store.vcs?.branch ?? getFilename(directory)
314 return `${kind} : ${name || path}`
315 }
316
317 const { sessions } = createSessionEntries({ workspaces, label, serverSDK: serverSDK(), language })
318
319 const items = async (text: string) => {
320 const query = text.trim()
321 setGrouped(query.length > 0)
322
323 if (!query && filesOnly()) {
324 const loaded = file.tree.state("")?.loaded
325 const pending = loaded ? Promise.resolve() : file.tree.list("")
326 const next = uniqueEntries([...fileEntries.recent(), ...fileEntries.root()])
327

Callers

nothing calls this directly

Calls 15

useDialogFunction · 0.90
useSessionLayoutFunction · 0.90
decode64Function · 0.90
getDirectoryFunction · 0.90
getFilenameFunction · 0.90
formatKeybindFunction · 0.90
getRelativeTimeFunction · 0.90
createCommandEntriesFunction · 0.85
createFileEntriesFunction · 0.85
createSessionEntriesFunction · 0.85
filesOnlyFunction · 0.85
groupedFunction · 0.85

Tested by

no test coverage detected