import { FuzzySuggestModal , App } from "obsidian" ; import type DictionaryPlugin from "src/main" ; import t from "src/l10n/helpers" ; export default class SynonymProviderChooser extends FuzzySuggestModal < string > { plugin : DictionaryPlugin ; available : string [ ] = [ ] ; constructor ( app , plugin ) { super ( app ) ; this . plugin = plugin ; for ( let i = 0 ; i < this . plugin . manager . synonymProvider . length ; i ++ ) { const api = this . plugin . manager . synonymProvider [ i ] ; if ( api . supportedLanguages . contains ( this . plugin . settings . defaultLanguage ) ) { this . available . push ( api . name ) ; } } this . setPlaceholder ( t ( "Choose a Synonym Provider Service" ) ) ; } onOpen ( ) { if ( this . available . length <= 1 ) { this . onChooseItem ( this . available . first ( ) ?? null ) ; } super . onOpen ( ) ; } getItems ( ) { return this . available ; } getItemText ( item ) { return item ; } async onChooseItem ( item ) { const lang = this . plugin . settings . defaultLanguage ; this . plugin . settings . apiSettings [ lang ] . synonymApiName = item ; await this . plugin . saveSettings ( ) ; this . close ( ) ; } }