Skip to content

Commit

Permalink
Allow creating transcriptions at the item level
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed May 8, 2024
1 parent b394704 commit 862fbd8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
9 changes: 9 additions & 0 deletions res/menu/context.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ en:
- label: 'Rotate Right'
command: 'app:rotate-item-right'
accelerator: 'CmdOrCtrl+]'
item-transcribe: &item-transcribe
- label: 'Transcribe Selected Items'
id: 'item-transcribe'
submenu: &item-transcribe-submenu
- label: 'With Tropy'
command: 'app:transcribe-item'
enabled: false
item-bulk: &item-bulk
- label: 'Merge Selected Items'
command: 'app:merge-item'
Expand Down Expand Up @@ -347,6 +354,7 @@ en:
item-bulk-deleted: *item-bulk-deleted
item-view: *item-view
item-rotate: *item-rotate
item-transcribe: *item-transcribe
metadata-list: *metadata-list
metadata-field: *metadata-field
trash: *trash
Expand Down Expand Up @@ -381,6 +389,7 @@ en:
item-bulk-deleted: *item-bulk-deleted
item-view: *item-view
item-rotate: *item-rotate
item-transcribe: *item-transcribe
metadata-list: *metadata-list
metadata-field: *metadata-field
trash: *trash
Expand Down
49 changes: 28 additions & 21 deletions src/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Icon, Menu as MR } from './res.js'
import { getLocale } from './locale.js'
import { error, warn } from '../common/log.js'
import { blank } from '../common/util.js'
import { channel } from '../common/release.js'

const SEPARATOR = { type: 'separator' }

Expand Down Expand Up @@ -219,6 +218,7 @@ export class ContextMenu extends Menu {
...scopes.items,
'item',
'item-read-only',
'item-transcribe',
'item-rotate']
scopes.item.position = 2

Expand Down Expand Up @@ -267,6 +267,7 @@ export class ContextMenu extends Menu {
...scopes.items,
'item-bulk-read-only',
'item-bulk',
'item-transcribe',
'item-rotate']
scopes['item-bulk'].position = 2

Expand All @@ -279,6 +280,7 @@ export class ContextMenu extends Menu {
'item-list',
'item',
'item-read-only',
'item-transcribe',
'item-rotate']
scopes['item-list'].position = 2

Expand All @@ -287,6 +289,7 @@ export class ContextMenu extends Menu {
'item-bulk-list',
'item-bulk-read-only',
'item-bulk',
'item-transcribe',
'item-rotate']
scopes['item-bulk-list'].position = 2

Expand Down Expand Up @@ -454,26 +457,8 @@ Menu.ItemCompiler = {
}
},

'transcribe': (item, app, win, event) => {
let plugins = app.plugins.available('transcribe')

let builtin = item.submenu[0]
builtin.enabled = false // channel !== 'latest'

if (plugins.length > 0) {
item.submenu = [
...item.submenu,
{ type: 'separator' },
...plugins.map(({ id, name }) => ({
label: name,
click: createResponder('app:transcribe-photo', app, win, {
target: event?.target,
plugin: id
})
}))
]
}
},
'transcribe': compileTranscriptionMenu,
'item-transcribe': compileTranscriptionMenu,

'import': (item, app, win) => {
let plugins = app.plugins.available('import')
Expand Down Expand Up @@ -615,6 +600,28 @@ Menu.ItemConditions = {
}
}

function compileTranscriptionMenu(item, app, win, event) {
let plugins = app.plugins.available('transcribe')

let builtin = item.submenu[0]
let command = builtin.command
builtin.enabled = false // channel !== 'latest'

if (plugins.length > 0) {
item.submenu = [
...item.submenu,
{ type: 'separator' },
...plugins.map(({ id, name }) => ({
label: name,
click: createResponder(command, app, win, {
target: event?.target,
plugin: id
})
}))
]
}
}

function createResponder(cmd, app, win, ...params) {
let [prefix, action] = cmd.split(':', 2)

Expand Down
4 changes: 4 additions & 0 deletions src/browser/tropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ export class Tropy extends EventEmitter {
photo: target.id,
selection: target.selection
}, { plugin }), win))
this.on('app:transcribe-item', (win, { target, plugin }) =>
this.dispatch(act.transcriptions.create({
photo: target.photos
}, { plugin }), win))
this.on('app:consolidate-photo-library', () =>
this.dispatch(act.photo.consolidate(), this.wm.current()))

Expand Down
23 changes: 12 additions & 11 deletions src/commands/transcription/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ export class Create extends Command {

// TODO sync/convert data and text if given

let transcription = yield call(db.transaction, tx =>
create(tx, {
config,
data,
parent: selection || photo,
text
}))
let parents = Array.isArray(photo) ?
photo : [selection || photo]

let { id, parent } = transcription
let transcriptions = yield call(db.transaction, async tx =>
Promise.all(parents.map(parent =>
create(tx, { config, data, parent, text }))))

this.undo = slice.remove([id])
this.redo = slice.restore([{ id, parent, idx: -1 }])
this.undo = slice.remove(
transcriptions.map(tr => tr.id))

return { [id]: transcription }
this.redo = slice.restore(
transcriptions.map(({ id, parent }) =>
({ id, parent, idx: -1 })))

return transcriptions.reduce((acc, tr) => (acc[tr.id] = tr, acc), {})
}
}

Expand Down

0 comments on commit 862fbd8

Please sign in to comment.