Skip to content
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
23 changes: 22 additions & 1 deletion platform.bible-extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
},
);

const openSelectorCommandPromise = papi.commands.registerCommand(
'lexicon.openSelector',
async (projectId: string) => {
logger.info(`Opening the lexicon selector for project '${projectId}'`);
const projectManager = projectManagers.getProjectManagerFromProjectId(projectId);
if (!projectManager) return { success: false };

// Selection is sticky (see changeLexiconCommand): a linked project is changed only by first
// clearing its lexicon.lexiconCode setting.
const lexiconCode = await projectManager.getLexiconCode();
if (lexiconCode) {
const error = `Project '${projectId}' already uses lexicon '${lexiconCode}'`;
logger.warn(`Not opening the lexicon selector: ${error}`);
return { success: false, error };
}

return { success: await projectManager.openSelector() };
},
);

// Store the lexicon choice on the project and cache its analysis language. setLexiconCode runs the
// registered validator (a writing-systems check), so it throws if the code doesn't resolve — which
// is how download-and-select refuses to record a project whose download didn't really land.
Expand Down Expand Up @@ -519,14 +539,15 @@ export async function activate(context: ExecutionActivationContext): Promise<voi
await createLexiconCommandPromise,
await deleteDownloadedLexiconCommandPromise,
await displayEntryCommandPromise,
await downloadAndSelectLexiconCommandPromise,
await findEntryCommandPromise,
await findRelatedEntriesCommandPromise,
await lexiconsCommandPromise,
await loginCommandPromise,
await logoutCommandPromise,
await openSelectorCommandPromise,
await remoteProjectsCommandPromise,
await resolveProjectCommandPromise,
await downloadAndSelectLexiconCommandPromise,
await selectLexiconCommandPromise,
// Services
await entryService,
Expand Down
26 changes: 17 additions & 9 deletions platform.bible-extension/src/types/lexicon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ declare module 'papi-shared-types' {
lexiconCode: string,
entryId: string,
) => Promise<SuccessHolder>;
/**
* Downloads a remote project (resolves once its initial sync finishes) and selects it for the
* given project.
*/
'lexicon.downloadAndSelectLexicon': (
projectId: string,
authority: string,
lexiconCode: string,
) => Promise<DownloadAndSelectResult>;
'lexicon.findEntry': (webViewId: string, entry: string) => Promise<SuccessHolder>;
'lexicon.findRelatedEntries': (webViewId: string, entry: string) => Promise<SuccessHolder>;
/**
Expand All @@ -170,17 +179,16 @@ declare module 'papi-shared-types' {
authority: string,
) => Promise<{ result?: LoginResult; servers?: AuthServerStatus[] }>;
'lexicon.logout': (authority: string) => Promise<AuthServerStatus[] | undefined>;
/** Remote (Lexbox server) CRDT projects the signed-in user can download. */
'lexicon.remoteProjects': () => Promise<IProjectModel[] | undefined>;
/**
* Downloads a remote project (resolves once its initial sync finishes) and selects it for the
* given project.
* Opens the lexicon selector on a project that has no lexicon. Refuses a project that already
* has one: selection is sticky, so clear its `lexicon.lexiconCode` setting first.
*
* @returns Whether the selector opened, which is not whether a lexicon was chosen; a chosen
* lexicon lands in the project's `lexicon.lexiconCode` setting.
*/
'lexicon.downloadAndSelectLexicon': (
projectId: string,
authority: string,
lexiconCode: string,
) => Promise<DownloadAndSelectResult>;
'lexicon.openSelector': (projectId: string) => Promise<SuccessHolder>;
/** Remote (Lexbox server) CRDT projects the signed-in user can download. */
'lexicon.remoteProjects': () => Promise<IProjectModel[] | undefined>;
/**
* Resolves the Paratext project a WebView is scoped to, prompting with the core project picker
* when it has none (e.g. a selector tab restored from a saved layout); `projectId` is undefined
Expand Down
Loading