Skip to content

Commit 6573001

Browse files
committed
Add search scope selection to the select imported files command and internationalize its UI strings
- imported files are being categorized: 'immediate' 'recursive' - if user enters search mode from the action bar, they should be shown a quick pick with two options: 'immediate only' 'immediate & recursive' - 'go back' from search mode should reveal 'search scope' - fix translations in `apps/editor/src/commands/select-imported-files-command/select-imported-files-command.ts`
1 parent 5821802 commit 6573001

3 files changed

Lines changed: 389 additions & 23 deletions

File tree

‎apps/editor/src/commands/select-imported-files-command/select-imported-files-command.ts‎

Lines changed: 132 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export const select_imported_files_command = (
2525
workspace_provider
2626
)
2727
if (starting_uris.length == 0) {
28-
vscode.window.showInformationMessage('No valid files found to select.')
28+
vscode.window.showInformationMessage(
29+
t('command.select-imported-files.no-valid-files')
30+
)
2931
return
3032
}
3133

@@ -40,7 +42,7 @@ export const select_imported_files_command = (
4042
await vscode.window.withProgress(
4143
{
4244
location: vscode.ProgressLocation.Notification,
43-
title: 'Processing imports...',
45+
title: t('command.select-imported-files.processing'),
4446
cancellable: true
4547
},
4648
async (progress, token) => {
@@ -95,20 +97,22 @@ export const select_imported_files_command = (
9597
)
9698

9799
if (valid_immediate.length == 0 && valid_recursive.length == 0) {
98-
vscode.window.showInformationMessage('No imported files found.')
100+
vscode.window.showInformationMessage(
101+
t('command.select-imported-files.no-files')
102+
)
99103
return
100104
}
101105

102106
const currently_checked = workspace_provider.get_checked_files()
103107

104108
const open_file_button = {
105109
iconPath: new vscode.ThemeIcon('go-to-file'),
106-
tooltip: 'Go to file'
110+
tooltip: t('command.select-imported-files.go-to-file')
107111
}
108112

109113
const close_button = {
110114
iconPath: new vscode.ThemeIcon('close'),
111-
tooltip: 'Close'
115+
tooltip: t('command.select-imported-files.close')
112116
}
113117

114118
const search_button = {
@@ -166,7 +170,7 @@ export const select_imported_files_command = (
166170

167171
if (valid_immediate.length > 0) {
168172
quick_pick_items.push({
169-
label: 'immediate',
173+
label: t('command.select-imported-files.immediate'),
170174
kind: vscode.QuickPickItemKind.Separator
171175
})
172176
const immediate_items = await map_to_quick_pick(valid_immediate)
@@ -175,7 +179,7 @@ export const select_imported_files_command = (
175179

176180
if (valid_recursive.length > 0) {
177181
quick_pick_items.push({
178-
label: 'recursive',
182+
label: t('command.select-imported-files.recursive'),
179183
kind: vscode.QuickPickItemKind.Separator
180184
})
181185
const recursive_items = await map_to_quick_pick(valid_recursive)
@@ -204,14 +208,22 @@ export const select_imported_files_command = (
204208
(sum, item) => sum + (item.tokens || 0),
205209
0
206210
)
207-
const total_text =
208-
total > 0 ? ` (totalling ${display_token_count(total)} tokens)` : ''
209-
quick_pick.placeholder = `Select imported files${total_text}`
211+
212+
if (total > 0) {
213+
quick_pick.placeholder = t(
214+
'command.select-imported-files.placeholder-tokens',
215+
{ tokens: display_token_count(total) }
216+
)
217+
} else {
218+
quick_pick.placeholder = t(
219+
'command.select-imported-files.placeholder'
220+
)
221+
}
210222
}
211223
update_placeholder()
212224
quick_pick.onDidChangeSelection(update_placeholder)
213225

214-
quick_pick.title = 'Imported Files'
226+
quick_pick.title = t('command.select-imported-files.title')
215227
quick_pick.ignoreFocusOut = true
216228
quick_pick.buttons = [search_button, close_button]
217229

@@ -251,7 +263,9 @@ export const select_imported_files_command = (
251263
await vscode.window.showTextDocument(doc, { preview: true })
252264
} catch (error) {
253265
vscode.window.showErrorMessage(
254-
`Error opening file: ${String(error)}`
266+
t('command.select-imported-files.error-opening', {
267+
error: String(error)
268+
})
255269
)
256270
}
257271
}
@@ -265,22 +279,118 @@ export const select_imported_files_command = (
265279
}
266280

267281
if (selected_items == 'search') {
268-
const search_result = await search_files({
269-
files: shown_paths,
270-
workspace_provider,
271-
extension_context,
272-
show_back_button: true
273-
})
282+
let should_return = false
283+
let back_to_main = false
284+
285+
while (true) {
286+
let paths_for_search = shown_paths
287+
288+
if (valid_recursive.length > 0) {
289+
const scope_selection = await new Promise<
290+
'immediate' | 'all' | 'back' | undefined
291+
>((resolve) => {
292+
const scope_quick_pick = vscode.window.createQuickPick()
293+
scope_quick_pick.items = [
294+
{ label: t('command.select-imported-files.immediate-only') },
295+
{
296+
label: t(
297+
'command.select-imported-files.immediate-and-recursive'
298+
)
299+
}
300+
]
301+
scope_quick_pick.title = t(
302+
'command.select-imported-files.search-scope'
303+
)
304+
scope_quick_pick.ignoreFocusOut = true
305+
scope_quick_pick.buttons = [
306+
vscode.QuickInputButtons.Back,
307+
close_button
308+
]
309+
310+
let is_accepted = false
311+
312+
scope_quick_pick.onDidTriggerButton((button) => {
313+
if (button === vscode.QuickInputButtons.Back) {
314+
resolve('back')
315+
scope_quick_pick.hide()
316+
} else if (button === close_button) {
317+
resolve(undefined)
318+
scope_quick_pick.hide()
319+
}
320+
})
321+
322+
scope_quick_pick.onDidAccept(() => {
323+
is_accepted = true
324+
const selected = scope_quick_pick.selectedItems[0]?.label
325+
if (
326+
selected ===
327+
t('command.select-imported-files.immediate-only')
328+
) {
329+
resolve('immediate')
330+
} else {
331+
resolve('all')
332+
}
333+
scope_quick_pick.hide()
334+
})
335+
336+
scope_quick_pick.onDidHide(() => {
337+
if (!is_accepted) {
338+
resolve(undefined)
339+
}
340+
scope_quick_pick.dispose()
341+
})
342+
343+
scope_quick_pick.show()
344+
})
345+
346+
if (scope_selection === undefined) {
347+
should_return = true
348+
break
349+
}
274350

275-
if (search_result == 'back') {
276-
continue
351+
if (scope_selection === 'back') {
352+
back_to_main = true
353+
break
354+
}
355+
356+
if (scope_selection === 'immediate') {
357+
paths_for_search = valid_immediate.map((u) => u.fsPath)
358+
}
359+
}
360+
361+
const search_result = await search_files({
362+
files: paths_for_search,
363+
workspace_provider,
364+
extension_context,
365+
show_back_button: true
366+
})
367+
368+
if (search_result == 'back') {
369+
if (valid_recursive.length > 0) {
370+
continue
371+
} else {
372+
back_to_main = true
373+
break
374+
}
375+
}
376+
377+
if (!search_result) {
378+
should_return = true
379+
break
380+
}
381+
382+
selected_paths = search_result.selected_paths
383+
break
277384
}
278385

279-
if (!search_result) {
386+
if (should_return) {
280387
return
281388
}
282389

283-
selected_paths = search_result.selected_paths
390+
if (back_to_main) {
391+
continue
392+
}
393+
284394
break
285395
} else {
286396
const valid_selected = selected_items.filter(

‎apps/editor/src/i18n/translations/commands/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { translations as select_commit_files } from './select-commit-files'
1616
import { translations as select_changed_files } from './select-changed-files'
1717
import { translations as history } from './history'
1818
import { translations as select_clipboard_paths } from './select-clipboard-paths'
19+
import { translations as select_imported_files } from './select-imported-files'
1920

2021
export const translations = {
2122
...generate_commit_message,
@@ -35,5 +36,6 @@ export const translations = {
3536
...select_commit_files,
3637
...select_changed_files,
3738
...history,
38-
...select_clipboard_paths
39+
...select_clipboard_paths,
40+
...select_imported_files
3941
}

0 commit comments

Comments
 (0)