Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created December 28, 2024 01:33
Show Gist options
  • Select an option

  • Save retorquere/f592e77f06c1376f0cf31dc28589d90c to your computer and use it in GitHub Desktop.

Select an option

Save retorquere/f592e77f06c1376f0cf31dc28589d90c to your computer and use it in GitHub Desktop.

Revisions

  1. retorquere created this gist Dec 28, 2024.
    52 changes: 52 additions & 0 deletions wizard.xhtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    <?xml version="1.0" encoding="utf-8" ?><window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"><linkset><html:link rel="localization" href="toolkit/global/wizard.ftl"/></linkset><script src="chrome://global/content/customElements.js"></script><script>// const { extensions, defaults } = window.arguments[0]
    const extensions = ['pdf', 'docx']
    const defaults = { pdf: 'import' }

    const config = {
    icon: {
    ignore: '\u1F6AB',
    attach: '\u1F4BE',
    link: '\u1F517',
    import: '\u1F5C2',
    },
    extensions: Object.fromEntries(extensions.map(ext => [ext, defaults[ext] || 'ignore'])),
    }

    function init() {
    for (const [mode, icon] of Object.entries(config.icon)) {
    const button = document.querySelector(`#${mode}`)
    button.setAttribute(`${icon} ${button.getAttribute('label')}`)
    }

    const listbox = document.querySelector('#extensions')
    for (const ext of [...extensions].sort()) {
    Zotero.debug(`folder-import ${ext}`)
    const item = document.createXULElement('listitem')
    listbox.appendChild(item)

    let cell = document.createXULElement('listcell')
    cell.setAttribute('label', ext)
    item.appendChild(cell)

    cell = document.createXULElement('listcell')
    cell.setAttribute('label', config.icon[config.extensions[ext]])
    item.appendChild(cell)
    }
    }

    function setMode(newMode) {
    const listbox = document.querySelector('#extensions')
    const selected = listbox.selectedItems

    selected.forEach(item => {
    const [ ext, mode ] = item.querySelectorAll('listcell')
    config.extensions[ext.getAttribute('label')] = newMode
    mode.setAttribute('label', config.icon[newMode])
    })
    }

    function start() {
    const wizard = document.querySelector('#wizard')
    wizard.getButton('cancel').disabled = true
    wizard.canRewind = false
    }</script><wizard id="wizard" title="better-bibtex_error-report.title;" width="700" height="700"><wizardpage label="Add Files from Folder…" onpageshow="init()"><hbox><listbox id="extensions" flex="1" seltype="multiple"><listhead><listheader label="extension"></listheader><listheader label="action"></listheader></listhead><listcols><listcol flex="1"></listcol><listcol flex="1"></listcol></listcols></listbox><vbox><button id="link" label="ignore" oncommand="setMode('ignore')"></button><button id="attach" label="attach" oncommand="setMode('attach')"></button><button id="link" label="link" oncommand="setMode('link')"></button><button id="import" label="import" oncommand="setMode('import')"></button></vbox></hbox></wizardpage><wizardpage label="Importing…" onpageshow="start()"><progressmeter id="progress"></progressmeter></wizardpage></wizard></window>